Skip to content

Commit

Permalink
resolve symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
fatanugraha committed Jan 9, 2025
1 parent 15645e5 commit d8ee81b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/utils/filewatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ func NewFileWatcher(path string) (*FileWatcher, error) {
}

func (fw *FileWatcher) Start(changeHandler func()) error {
// Ensure that the target that we're watching is not a symlink as we won't get any events when we're watching
// a symlink.
dir, err := filepath.EvalSymlinks(filepath.Dir(fw.path))
if err != nil {
return fmt.Errorf("adding watcher failed: %s", err)
}

// watch the directory instead of the individual file to ensure the notification still works when the file is modified
// through moving/renaming rather than writing into it directly (like what most modern editor does by default).
// ref: https://github.com/fsnotify/fsnotify/blob/a9bc2e01792f868516acf80817f7d7d7b3315409/README.md#watching-a-file-doesnt-work-well
err := fw.w.Add(filepath.Dir(fw.path))
if err != nil {
if err = fw.w.Add(dir); err != nil {
return fmt.Errorf("adding watcher failed: %s", err)
}

Expand Down

0 comments on commit d8ee81b

Please sign in to comment.