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
can fsnotify watch file change for more than one time? #94
Comments
If you are watching an individual file and it moves, it may no longer be being watched. Better to watch the directory the file is in. If you believe there is a bug, can you please provide more details, such as operating system you are using and a code snippet to reproduce the issue? Thanks. (sorry for the late reply) |
I'm experiencing similar behavior to this: EDIT: well...removing that token...
I'd expect the goroutine to receive a second event:
|
OS: OS X El Capitan |
Hm, apparently it was cause I was triggering off of any event rather than just watches. I got it fixed with the example_test.go code, but it wasn't clear. |
@kkirsche Glad you got it working. Do you have any suggestions for improving the example code or documentation? |
For me, the biggest issue was that I'm running this as a longer running daemon, so cleanup was something that was a problem. It seemed as though I was leaving the watcher active (
This then sent the messages to close the watcher and close any open channels. Once I added that, I didn't run into any more gocode running after ctrl+c ended the application running. The second thing for me which was unclear from the example was what the purpose of the done channel was since it was a bit too simplistic for me to really be able to use as a template to really base my code on. I made a more generic version to show what I was using the watch event for if it helps understand the situation. https://github.com/kkirsche/notify-git/blob/master/cmd/root.go Lastly, I had to exit the goroutine on the above done event, or else the watcher would catch a ton (near infinite it seemed) errors / "" events. For this reason I'd have the done channel also exit the background goroutine in case they do any debug messaging to avoid flooding stdout. I guess my takeaways were that it would be nice to include cleanup code in the example, and provide a more "complete" implementation that leverages the done channel. Potentially it'd also be helpful to have a wiki page of known programs that don't trigger write events to avoid the "hm, why doesn't vim editing the file work?" Does that help? |
@nathany, I was also using vim to test and it wasn't working. I would instead see RENAME, CHMOD, REMOVE events. It would be great to perhaps have a list of known applications that perhaps don't interract with fsnotify as you might expect, this could become a FAQ page or similar. Examples of how you might trigger specific events might be useful. While these may seem obvious and would be platform-specific, it would be great to show what happens when you chmod, touch, append and delete (rm) a file from the command line. |
Hey I am also facing the same issue, if anyone could help with any resolutions for this? |
Hello, with fsnotify new watcher for a single file, the event is triggered only when the file is copied from elsewhere to the interested directory with WRITE mode, for file thats moved with CREATE mode and edited its not working in either modes. Is this expected? Are there any resolutions for these? |
i find fsnotify can only watch file change for one time. when i change the file twice. the watcher.Event chan is close, so i can not get the change event.
The text was updated successfully, but these errors were encountered: