Don't crash on ENOENT when adding watch inside event_gen#121
Open
jikamens wants to merge 3 commits intodsoprea:masterfrom
Open
Don't crash on ENOENT when adding watch inside event_gen#121jikamens wants to merge 3 commits intodsoprea:masterfrom
jikamens wants to merge 3 commits intodsoprea:masterfrom
Conversation
If we get an event notification about a directory being moved and then it disappears before we have time to add a watch to it, we need to catch the resulting ENOENT error and warn about it rather than crashing. This is similar to the fix made in ef6769d.
It is almost certainly not the intention of the user to follow symbolic links to directories when using InotifyTree / InotifyTrees, so default to not doing that. *** This is a change in behavior. *** I believe it is the correct thing to do, but if it would be preferred to provide the ability not to follow symlinks without changing the behavior by default, then the way to do that is to change `follow_symlinks=False` to `follow_symlinks=True` in the `__init__` function definitions for `_BaseTree`, `InotifyTree`, and `InotifyTrees`.
1) When a directory is moved from inside a directory we watch, to a different directory that we don't watch, then we get a MOVED_FROM event but no MOVED_TO event, in which case we need to clean up the watch for that directory because we are no longer supposed to be watching it. 2) When a directory is moved from inside a directory we watch to inside another directory we watch, then we need to update our internal data to reflect the new location of the directory. 3) For both of the above, we need to handle subdirectories of moved directories, not just the directories themselves. To facilitate these fixes, we: * Add a new `watches()` iterator to the `Inotify` class so the tree classes can iterate through all watches to find ones that need to be removed. * Add a new `remove_tree()` function to the tree classes which handles removing entire trees. Both of these new functions are available to end users of the library since they're useful and there's no reason for them not to be. See the big comment added to the code for additional details about how this fix is implemented.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If we get an event notification about a directory being moved and then it disappears before we have time to add a watch to it, we need to catch the resulting ENOENT error and warn about it rather than crashing.
This is similar to the fix made in
ef6769d.
N.B. there are now two additional bug fixes here on my master branch in addition to the one described above for which I originally opened this PR.