-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Saving changed file triggers remove_self #58
Comments
I see now that if I watch for the containing folder instead of the specific file, it works. I guess I need to check that the event comes from the file I care about and ignore others. Is that expected? It would be nice to include an example of how to watch for changes on a specific file. It's not as easy as it seems because editors do all kinds of tricks when a file is being saved: they create a temporary copy, make changes to that copy, rename the old file, move the new file, then delete the old file. This may trigger 15 different notifications (if you listen for all types). And they do this in different order. How do programs watch for file changes reliably? I came to inotify thinking that it should be the most efficient way, but now I feel that watching for datestamp changes may be more reliable and simpler. |
Hi Hamoid,
watching the folder:
Does the example produces the same result for you? And how does your code differ from the example code? If you only want notifications for modifications of a single file, then just watching that file on |
Hi @erikzenker . Thank you for writing back. As I didn't want to install inotify-cpp in my system, I added all the .h and .cpp files to my project which is available here: https://gitlab.com/hamoid/ofjsoninotify In my project I use https://openframeworks.cc/ (graphics) and https://uscilab.github.io/cereal/ (serialization). My goal is to detect json file changes, then unserialize that json to affect animation and graphics (so the json file becomes the "gui"). The A theory: if you watch a file, and you save changes to it, in many editors the file is moved and a new file with the original name takes its place. The file you were watching will receive no more changes. Therefore we need to watch the enclosing folder to keep track of changes to a file, or start a new watch after each change. How does that sound like? I also wonder if /etc/fstab have an effect on this, and the fact that I use an SSD. In any case, this is a personal project and it's working well enough for me now :) |
I tested my folder example again with the qtcreator and got the following event stream:
As we already assumed, the qtcreator is creating temporaries and moves them onto the original file. Such that, the original file will be removed and also its watch. Currently, the library can't rewatch files in the event handler. I created a ticket #43 which should add this functionality. |
Now I remember that years ago I figured out this behavior and then I forgot :) It might be nice to document somewhere the difference between watching a file and watching it's parent folder (watching the file may stop when saving it with editors that create a new file and rename it). Cheers! |
Hi, this is not necessarily an issue with inotify-cpp but maybe lack of understanding on my part on inotify.
I'm watching a single file for all events (I'm actually interested only in changes). The problem is that the event is only triggered once. This is the log when saving a change from QtCreator on the watched json file:
And this is what happens when I edit and save the file from vim:
Both end in
remove_self
, which means the file will no longer be watched. Why is that happening? Also, why no modify event?The text was updated successfully, but these errors were encountered: