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
@@ -36,6 +36,14 @@ struct InotifyWatchManager {
return self.watchPaths[watchDescriptor]
}
/// The descriptors of the watch on `path` itself and of every watch below it.
func descriptors(under path: String) -> [CInt] {
let prefix = path.hasSuffix("/") ? path : path + "/"
return self.watchPaths
.filter { $0.value == path || $0.value.hasPrefix(prefix) }
.map(\.key)
}
func mask(forId watchDescriptor: CInt) -> InotifyEventMask? {
return self.watchMasks[watchDescriptor]
}