inotify backend: MOVE_SELF event keeps watch and reports incorrect path
On Linux, kernel 6.5.13 but probably applies to all versions. No VM/root/container/etc, ext4 filesystem.
Notify version 6.1.1.
Repro steps
let watcher, rx = ...;
let temp = tempdir()?;
let from = temp.path().join("from");
let to = temp.path().join("to");
create_dir(&from)?;
watcher.watcher.watch(&from, notify::RecursiveMode::NonRecursive)?;
rename(&from, &to)?;
create_dir(&to.join("should_not_appear"))?;
std::thread::sleep(Duration::from_secs(1));
while let Ok(e) = rx.try_recv() {
println!("Got event {:?}", e)
}
gives the following output:
[2024-01-18T03:32:45Z TRACE notify::inotify] adding inotify watch: /tmp/.tmpx60Uvj/from [2024-01-18T03:32:45Z TRACE notify::inotify] inotify event: Event { wd: WatchDescriptor { id: 2, fd: (Weak) }, mask: MOVE_SELF, cookie: 0, name: None } [2024-01-18T03:32:45Z TRACE icros::server::fs::fs_watcher] Got event: Ok(Event { kind: Modify(Name(From)), paths: ["/tmp/.tmpx60Uvj/from"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }) [2024-01-18T03:32:45Z TRACE notify::inotify] inotify event: Event { wd: WatchDescriptor { id: 2, fd: (Weak) }, mask: CREATE | ISDIR, cookie: 0, name: Some("should_not_appear") } [2024-01-18T03:32:45Z TRACE icros::server::fs::fs_watcher] Got event: Ok(Event { kind: Create(Folder), paths: ["/tmp/.tmpx60Uvj/from/should_not_appear"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None })
Outcome
The watch remains on the moved folder, but still reports the old path
Expected
Either:
- The watch is removed when the folder is moved
- The reported path is the folder's new path
I see the latter is an open TODO https://github.com/notify-rs/notify/blob/main/notify/src/inotify.rs#L271, though for what its worth I personally would expect the watch to get removed like what happens for MOVED_FROM events, rather than getting events for a path I didn't set a watch on. But I can work wither either behaviour :).
See https://github.com/notify-rs/notify/issues/554 the OS details are leaking here..