notify-rs/notify

Spurious delete event on new file

inferiorhumanorgans opened this issue · 4 comments

System details

  • OS/Platform name and version: Darwin Kernel Version 18.7.0: Tue Jun 22 19:37:08 PDT 2021; root:xnu-4903.278.70~1/RELEASE_X86_64
  • Rust version (if building from source): rustc --version: rustc 1.72.0-nightly (fe7454bf4 2023-06-19)
  • If you're coming from a project that makes use of Notify, what it is, and a link to the downstream issue if there is one:
  • Filesystem type and options: APFS, encrypted

What you did (as detailed as you can)

notify = { version = "6", features = [ "macos_fsevent" ], default-features = false }
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let (tx, rx) = std::sync::mpsc::channel();

    let mut watcher = notify::recommended_watcher(tx)?;

    watcher.watch(Path::new("empty-directory"), RecursiveMode::Recursive)?;

    for res in rx {
        match res {
            Ok(event) => println!("changed: {:?}", event),
            Err(e) => println!("watch error: {:?}", e),
        }
    }

    Ok(())
}

With the example running:

touch empty-directory/newfile

What you expected

changed: Event { kind: Create(File), paths: ["empty-directory/newfile"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }

What happened

changed: Event { kind: Create(File), paths: ["empty-directory/newfile"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }
changed: Event { kind: Remove(File), paths: ["empty-directory/newfile"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }

Note: this appears to work as expected with the kqueue back end. Things also seem to work as expected if the directory already has files in it when the program is launched.

0xpr03 commented

So it happens with fseven, but not kqueue ?
And if I get this right: the folder already exists, the file doesn't. And it happens only when you then run "touch" on the non-existing file ?

Yep. To add fuel to the fire, the pattern seems to be:

make directory
run program
touch file
works normally
quit program
remove file
run program
touch same file
continues to work abnormally with that file only

0xpr03 commented

Note: someone with macos will have to debug this.

Hi, for what its worth, the above code works fine on
22.6.0 Darwin Kernel Version 22.6.0: Wed Jul 5 22:21:56 PDT 2023; root:xnu-8796.141.3~6/RELEASE_X86_64 x86_64
using
rustc 1.75.0 (82e1608df 2023-12-21)
and
Filesystem type and options: APFS, encrypted