diff --git a/crates/memofs/src/lib.rs b/crates/memofs/src/lib.rs index 35935f2f..2eaaba1c 100644 --- a/crates/memofs/src/lib.rs +++ b/crates/memofs/src/lib.rs @@ -252,13 +252,17 @@ impl VfsInner { fn remove_file>(&mut self, path: P) -> io::Result<()> { let path = path.as_ref(); - let _ = self.backend.unwatch(path); + if self.watch_enabled { + let _ = self.backend.unwatch(path); + } self.backend.remove_file(path) } fn remove_dir_all>(&mut self, path: P) -> io::Result<()> { let path = path.as_ref(); - let _ = self.backend.unwatch(path); + if self.watch_enabled { + let _ = self.backend.unwatch(path); + } self.backend.remove_dir_all(path) } diff --git a/crates/memofs/src/std_backend.rs b/crates/memofs/src/std_backend.rs index cd0c5411..67bc1651 100644 --- a/crates/memofs/src/std_backend.rs +++ b/crates/memofs/src/std_backend.rs @@ -373,10 +373,14 @@ impl VfsBackend for StdBackend { Ok(()) } Err(err) => { - if matches!( + let is_not_watched = matches!( err.kind, notify::ErrorKind::WatchNotFound | notify::ErrorKind::PathNotFound - ) { + ) || matches!( + &err.kind, + notify::ErrorKind::Generic(msg) if msg.contains("No watch was found") + ); + if is_not_watched { log::trace!( "Path was not directly watched (likely covered by parent): {}", path.display()