Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inotify backend: MOVE_SELF event keeps watch and reports incorrect path #555

Open
feileacan opened this issue Jan 18, 2024 · 1 comment
Open

Comments

@feileacan
Copy link

feileacan commented Jan 18, 2024

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 :).

@0xpr03
Copy link
Member

0xpr03 commented Jan 18, 2024

See #554 the OS details are leaking here..

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

No branches or pull requests

2 participants