the problem is when i change/edit a file it showing the event twice instead of one, in terminal it showing
Data(Any)
Data(Any)
for a single file change/edit
my code
fn watch<P: AsRef<Path>>(path: P) -> notify::Result<()> {
let (tx, rx) = sync::mpsc::channel();
let mut watcher = RecommendedWatcher::new(tx, Config::default())?;
watcher.watch(path.as_ref(), RecursiveMode::Recursive)?;
for res in rx {
let event = res?;
match event.kind {
EventKind::Modify(s) => println!("{s:?}"),
_ => (),
}
}
Ok(())
}
Yes, this can be a problem. How is it related to Rust, though?
Crate documentation even explicitly says: Editor Behaviour: If you rely on precise events (Write/Delete/Create..), you will notice that the actual events can differ a lot between file editors. Some truncate the file on save, some create a new one and replace the old one. See also this and this issues for example.
Maybe someone would crate a crate which includes extensive online-database with process-tracker and lots of other anti-cheat things which would solve your “problem”, but I, for one, is happy than simple notify crate is not a privacy disaster like such tool would, by necessity, be.
Whether it is successful at this goal is another matter, but the point is that using file system events is surprisingly difficult. In part because a lot of the behavior is not only platform-specific, but application-specific. Debouncing is a strategy to avoid spurious duplicate events that comes with its own downsides. Including but not limited to throwing away information which might seem useful, but it actually isn't in practice.