Use error kind to determine if a watch is not found

This commit is contained in:
sxyazi 2024-07-26 00:12:10 +08:00
parent 1fd452f6b6
commit 6a6e44b6fe
No known key found for this signature in database

View file

@ -72,7 +72,14 @@ impl Watcher {
(old.difference(new).cloned().collect(), new.difference(old).cloned().collect())
};
to_unwatch.retain(|u| watcher.unwatch(u).is_ok() || !u.exists());
to_unwatch.retain(|u| match watcher.unwatch(u) {
Ok(_) => true,
Err(e) if matches!(e.kind, notify::ErrorKind::WatchNotFound) => true,
Err(e) => {
error!("Unwatch failed: {e:?}");
false
}
});
to_watch.retain(|u| watcher.watch(u, RecursiveMode::NonRecursive).is_ok());
{