Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch directories and not files. #506

Merged
merged 1 commit into from
Mar 20, 2024
Merged

Watch directories and not files. #506

merged 1 commit into from
Mar 20, 2024

Conversation

floitsch
Copy link
Member

Editors, like VIM, often save files by writing into a temporary file first and then only replacing the original file. If we watch a file we wouldn't get any notifications as we would watch a deleted file.

Watching directories is the recommended approach:
https://github.com/fsnotify/fsnotify?tab=readme-ov-file#watching-a-file-doesnt-work-well

Editors, like VIM, often save files by writing into a temporary file first
and then only replacing the original file. If we watch a file we
wouldn't get any notifications as we would watch a deleted file.

Watching directories is the recommended approach:
  https://github.com/fsnotify/fsnotify?tab=readme-ov-file#watching-a-file-doesnt-work-well
@floitsch floitsch requested a review from kasperl March 19, 2024 17:51
Copy link
Member

@kasperl kasperl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

for p := range w.paths {
if _, ok := candidates[p]; !ok {
w.Mutex.Lock()
w.watcher.Remove(p)
delete(w.paths, p)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check that deleting while iterating is okay and add a comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
for d := range w.dirs {
if _, ok := candidateDirs[d]; !ok {
delete(w.dirs, d)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check that deleting while iterating is okay and add a comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@floitsch floitsch merged commit b9e9e32 into main Mar 20, 2024
7 checks passed
@floitsch floitsch deleted the floitsch/watch-dir branch March 20, 2024 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants