Skip to content

Conversation

jikamens
Copy link
Contributor

@jikamens jikamens commented Sep 3, 2025

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant