diff --git a/Cargo.lock b/Cargo.lock index 21ddc3c4..bdc90964 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1083,7 +1083,7 @@ dependencies = [ [[package]] name = "memofs" -version = "0.1.2" +version = "0.1.3" dependencies = [ "crossbeam-channel", "fs-err", diff --git a/Cargo.toml b/Cargo.toml index 772560fe..96723065 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,7 +95,7 @@ uuid = { version = "0.8.1", features = ["v4", "serde"] } winreg = "0.6.2" [build-dependencies] -memofs = { version = "0.1.0", path = "memofs" } +memofs = { version = "0.1.3", path = "memofs" } anyhow = "1.0.27" bincode = "1.2.1" diff --git a/memofs/CHANGELOG.md b/memofs/CHANGELOG.md index cd4647f2..78dd22aa 100644 --- a/memofs/CHANGELOG.md +++ b/memofs/CHANGELOG.md @@ -1,6 +1,10 @@ # memofs Changelog ## Unreleased Changes +* Added `set_watch_enabled` to `Vfs` and `VfsLock` to allow turning off file watching. + +## 0.1.2 (2020-03-29) +* `VfsSnapshot` now implements Serde's `Serialize` and `Deserialize` traits. ## 0.1.1 (2020-03-18) * Improved error messages using the [fs-err](https://crates.io/crates/fs-err) crate. diff --git a/memofs/Cargo.toml b/memofs/Cargo.toml index 3484c765..12c67caa 100644 --- a/memofs/Cargo.toml +++ b/memofs/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "memofs" description = "Virtual filesystem with configurable backends." -version = "0.1.2" +version = "0.1.3" authors = ["Lucien Greathouse "] edition = "2018" readme = "README.md" diff --git a/memofs/src/lib.rs b/memofs/src/lib.rs index a04bf71d..f6a17ef6 100644 --- a/memofs/src/lib.rs +++ b/memofs/src/lib.rs @@ -140,13 +140,18 @@ pub enum VfsEvent { /// the public interfaces to this type. struct VfsInner { backend: Box, + watch_enabled: bool, } impl VfsInner { fn read>(&mut self, path: P) -> io::Result>> { let path = path.as_ref(); let contents = self.backend.read(path)?; - self.backend.watch(path)?; + + if self.watch_enabled { + self.backend.watch(path)?; + } + Ok(Arc::new(contents)) } @@ -159,7 +164,11 @@ impl VfsInner { fn read_dir>(&mut self, path: P) -> io::Result { let path = path.as_ref(); let dir = self.backend.read_dir(path)?; - self.backend.watch(path)?; + + if self.watch_enabled { + self.backend.watch(path)?; + } + Ok(dir) } @@ -215,6 +224,7 @@ impl Vfs { pub fn new(backend: B) -> Self { let lock = VfsInner { backend: Box::new(backend), + watch_enabled: true, }; Self { @@ -229,6 +239,16 @@ impl Vfs { } } + /// Turns automatic file watching on or off. Enabled by default. + /// + /// Turning off file watching may be useful for single-use cases, especially + /// on platforms like macOS where registering file watches has significant + /// performance cost. + pub fn set_watch_enabled(&self, enabled: bool) { + let mut inner = self.inner.lock().unwrap(); + inner.watch_enabled = enabled; + } + /// Read a file from the VFS, or the underlying backend if it isn't /// resident. /// @@ -318,6 +338,15 @@ pub struct VfsLock<'a> { } impl VfsLock<'_> { + /// Turns automatic file watching on or off. Enabled by default. + /// + /// Turning off file watching may be useful for single-use cases, especially + /// on platforms like macOS where registering file watches has significant + /// performance cost. + pub fn set_watch_enabled(&mut self, enabled: bool) { + self.inner.watch_enabled = enabled; + } + /// Read a file from the VFS, or the underlying backend if it isn't /// resident. ///