Enhance file and directory removal logic in VFS

- Added a check for `watch_enabled` before calling `unwatch` in the `remove_file` and `remove_dir_all` methods to prevent unnecessary operations when watching is disabled.
- Updated error handling in the `StdBackend` to include a new condition for `Generic` errors related to watch status, improving logging clarity.

These changes aim to optimize the file system operations and enhance error handling in the virtual file system.
This commit is contained in:
Joe 2026-02-19 05:24:56 -06:00
parent 4f0afe873e
commit d360ebe66f
2 changed files with 12 additions and 4 deletions

View file

@ -252,13 +252,17 @@ impl VfsInner {
fn remove_file<P: AsRef<Path>>(&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<P: AsRef<Path>>(&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)
}

View file

@ -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()