diff --git a/vfs/src/lib.rs b/vfs/src/lib.rs index c2f434e4..d9fe2f38 100644 --- a/vfs/src/lib.rs +++ b/vfs/src/lib.rs @@ -25,6 +25,8 @@ pub trait VfsBackend: sealed::Sealed { fn write(&mut self, path: &Path, data: &[u8]) -> io::Result<()>; fn read_dir(&mut self, path: &Path) -> io::Result; fn metadata(&mut self, path: &Path) -> io::Result; + fn remove_file(&mut self, path: &Path) -> io::Result<()>; + fn remove_dir_all(&mut self, path: &Path) -> io::Result<()>; fn event_receiver(&self) -> crossbeam_channel::Receiver; fn watch(&mut self, path: &Path) -> io::Result<()>; @@ -84,6 +86,7 @@ impl VfsLock { pub fn read>(&mut self, path: P) -> io::Result>> { let path = path.as_ref(); let contents = self.backend.read(path)?; + self.backend.watch(path)?; Ok(Arc::new(contents)) } @@ -99,7 +102,9 @@ impl VfsLock { pub fn read_dir>(&mut self, path: P) -> io::Result { let path = path.as_ref(); - self.backend.read_dir(path) + let dir = self.backend.read_dir(path)?; + self.backend.watch(path)?; + Ok(dir) } pub fn event_receiver(&self) -> crossbeam_channel::Receiver { diff --git a/vfs/src/noop_backend.rs b/vfs/src/noop_backend.rs index b28103ab..383119c5 100644 --- a/vfs/src/noop_backend.rs +++ b/vfs/src/noop_backend.rs @@ -35,6 +35,20 @@ impl VfsBackend for NoopBackend { )) } + fn remove_file(&mut self, _path: &Path) -> io::Result<()> { + Err(io::Error::new( + io::ErrorKind::Other, + "NoopBackend doesn't do anything", + )) + } + + fn remove_dir_all(&mut self, _path: &Path) -> io::Result<()> { + Err(io::Error::new( + io::ErrorKind::Other, + "NoopBackend doesn't do anything", + )) + } + fn metadata(&mut self, _path: &Path) -> io::Result { Err(io::Error::new( io::ErrorKind::Other, diff --git a/vfs/src/std_backend.rs b/vfs/src/std_backend.rs index d0236c8c..fa0857b8 100644 --- a/vfs/src/std_backend.rs +++ b/vfs/src/std_backend.rs @@ -74,6 +74,14 @@ impl VfsBackend for StdBackend { }) } + fn remove_file(&mut self, path: &Path) -> io::Result<()> { + fs::remove_file(path) + } + + fn remove_dir_all(&mut self, path: &Path) -> io::Result<()> { + fs::remove_dir_all(path) + } + fn metadata(&mut self, path: &Path) -> io::Result { let inner = fs::metadata(path)?;