notify
notify copied to clipboard
Rename Event ,How to be one Event
System details
- OS/Platform name and version:Windows 10
- Rust version (if building from source):
rustc --version
:rustc 1.54.0 (a178d0322 2021-07-26) - Notify version (or commit hash if building from git):5.0.0-pre.13
- 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:
- On Linux: Kernel version:
- On Windows: version and if you're running under Windows, Cygwin (unsupported), Linux Subsystem:
- If you're running as a privileged user (root, System):
- If you're running in a container, details on the runtime and overlay:
- If you're running in a VM, details on the hypervisor:
What you did (as detailed as you can)
I follow the notify/examples/monitor_raw.rs
to watch a directory
code like
let (tx,rx) = channel();
let mut watcher = RecommendedWatcher::new(move |res|tx.send(
res
).unwrap()).unwrap();
watcher.watch(path,RecursiveMode::Recursive).unwrap();
// Create Rename Remove
for res in rx {
match res {
Ok(e) => {
println!("{:?}",e);
handle(e);
},
Err(err) =>{
println!("{:?}",err);
},
}
}
fn handle(e:Event){
match e.kind {
EventKind::Create(CreateKind::Any) => {
},
EventKind::Remove(RemoveKind::Any) => {
},
EventKind::Modify(ModifyKind::Name(RenameMode::To)) => {
},
EventKind::Modify(ModifyKind::Name(RenameMode::From)) => {
},
_ => (),
};
}
What you expected
I want rename event be one event when trigger rename,
What happened
As now When rename trigger will have
Modify(Name(From))
and Modify(Name(To))
two Event
Sadly I've been trying to figure out a workaround this one for few hours now
As far as I'm aware you will have to handle this on your own. The OS doesn't give you more than these two events and you may have to connect them on your own. The underlying issue being that, from my understanding, the OS wouldn't know about "from where" the file move comes, if its happening from/to an outside directory.
the OS wouldn't know about "from where" the file move comes, if its happening from/to an outside directory.
According to my test, ReadDirectoryChangesWatcher
will treat rename happened with move as create/delete events, and only rename in the same directory will become rename events. So that's not a real problem on Windows.
But there are still other problems in connecting these two events:
- Is it possible for rename events to be emitted recursively? If so, is the order FIFO, LIFO or random?
- Is it really possible that only a part of the events are being emitted? If so, it's possible that two rename operations only emit two of four events and going to be connected incorrectly.