Drop watches of directories that leave the tree

A directory moved out of a watched tree kept its kernel watches, so
later changes inside it were reported under the old path. Its
watches and those of its subdirectories are now removed on
`MOVED_FROM`. Watches the kernel reports as `IGNORED` are forgotten
as well, so a reused descriptor number cannot map to a stale path.
This commit is contained in:
T. R. Bernstein
2026-09-13 23:10:30 +02:00
parent 6375a23328
commit e6ed232087
5 changed files with 60 additions and 1 deletions
@@ -33,6 +33,8 @@ let descriptors = try await inotify.addWatchWithAutomaticSubtreeWatching(
Internally this listens for `CREATE` events carrying the ``InotifyEventMask/isDir`` flag and installs a new watch with the same mask whenever a subdirectory appears.
When a directory is moved out of the watched tree, the watches on it and on its subdirectories are removed, so no events are reported under the stale path.
### Excluding Directories
When watching large trees you often want to skip certain subdirectories entirely — version-control metadata, build artefacts, dependency caches, and so on. Call ``Inotify/Inotify/exclude(names:)`` **before** adding a recursive or automatic-subtree watch: