notify-rs / notify

🔭 Cross-platform filesystem notification library for Rust.
https://docs.rs/notify
2.75k stars 219 forks source link

Moving subdirectory of recursive watch does not include to and from paths for Modify Name event #626

Open eighty4 opened 3 months ago

eighty4 commented 3 months ago

System details

notify-debouncer-full = {version = "0.3.1", default-features = false}
notify = {version = "6.1.1", default-features = false, features = ["macos_kqueue"]}

Example usage:

https://github.com/eighty4/l3/blob/dev-mode/src/dev.rs#L107

What you did (as detailed as you can)

After setting up a recursive watch on a directory, doing a move directory dispatches a Modify(Name(Any)) and does not include a path for the directory's original path.

self.w.watcher().watch(PathBuf::from("routes"), RecursiveMode::Recursive)?;
mv routes/subdir routes/anotherdir

What you expected

I thought there would be enough context to react to the from path and to path for an operation like moving a directory.

What happened

Using this watch, I would never know that anotherdir was originally subdir, and the app would have to stat every previously tracked file to determine whether they were moved.

eighty4 commented 3 months ago

(these following observations and events are with fsevents backend)

I used a recursive directory watch without the debouncer and I got two Modify Name Any events for a mv file on OSX

Modify(Name(Any)) ["/Users/adam/work/eighty4/install.sh/lambdas/routes/foo/lambda.get.env"]
Modify(Name(Any)) ["/Users/adam/work/eighty4/install.sh/lambdas/routes/foo/lambda.post.env"]

It seems like the debouncer squashes those into one event. If the watcher is for a single file and it's moved to a different path and then back to the original path, both Modify Name Anys will have the the watcher is watching with the backend.

If I do multiple mv during the debounce duration, then the path just gets repeated for the watch path and not the path that it was moved to and back from:

Modify(Name(Both)) ["/Users/adam/work/eighty4/install.sh/lambdas/routes/foo/lambda.js", "/Users/adam/work/eighty4/install.sh/lambdas/routes/foo/lambda.js"]