From 63b21b90ffce710653ecb608ab7622648140821c Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Fri, 1 Dec 2017 00:17:29 -0800 Subject: [PATCH] Ripple verbosity flags through the server --- src/bin.rs | 5 +++-- src/vfs.rs | 11 ++++++++++- src/vfs_watch.rs | 10 +++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/bin.rs b/src/bin.rs index ceef6eff..7b24940b 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -128,7 +128,7 @@ fn main() { } let vfs = { - let mut vfs = Vfs::new(); + let mut vfs = Vfs::new(config.clone()); for (name, project_partition) in &project.partitions { let path = { @@ -158,9 +158,10 @@ fn main() { { let vfs = vfs.clone(); + let config = config.clone(); thread::spawn(move || { - VfsWatcher::new(vfs).start(); + VfsWatcher::new(config, vfs).start(); }); } diff --git a/src/vfs.rs b/src/vfs.rs index 8a001d04..7a709b14 100644 --- a/src/vfs.rs +++ b/src/vfs.rs @@ -5,6 +5,8 @@ use std::io::Read; use std::path::{Path, PathBuf}; use std::time::Instant; +use core::Config; + /// Represents a virtual layer over multiple parts of the filesystem. /// /// Paths in this system are represented as slices of strings, and are always @@ -21,6 +23,8 @@ pub struct Vfs { /// A chronologically-sorted list of routes that changed since the Vfs was /// created, along with a timestamp denoting when. pub change_history: Vec, + + config: Config, } #[derive(Debug, Serialize, Deserialize)] @@ -38,11 +42,12 @@ pub enum VfsItem { } impl Vfs { - pub fn new() -> Vfs { + pub fn new(config: Config) -> Vfs { Vfs { partitions: HashMap::new(), start_time: Instant::now(), change_history: Vec::new(), + config, } } @@ -140,6 +145,10 @@ impl Vfs { } pub fn add_change(&mut self, timestamp: f64, route: Vec) { + if self.config.verbose { + println!("Added change {:?}", route); + } + self.change_history.push(VfsChange { timestamp, route, diff --git a/src/vfs_watch.rs b/src/vfs_watch.rs index 741fb25e..84808805 100644 --- a/src/vfs_watch.rs +++ b/src/vfs_watch.rs @@ -6,17 +6,20 @@ use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher}; use vfs::Vfs; use pathext::path_to_route; +use core::Config; pub struct VfsWatcher { vfs: Arc>, watchers: Vec, + config: Config, } impl VfsWatcher { - pub fn new(vfs: Arc>) -> VfsWatcher { + pub fn new(config: Config, vfs: Arc>) -> VfsWatcher { VfsWatcher { vfs, watchers: Vec::new(), + config, } } @@ -40,6 +43,7 @@ impl VfsWatcher { { let vfs = self.vfs.clone(); + let config = self.config.clone(); thread::spawn(move || { loop { @@ -47,6 +51,10 @@ impl VfsWatcher { let mut vfs = vfs.lock().unwrap(); let current_time = vfs.current_time(); + if config.verbose { + println!("FS event {:?}", event); + } + match event { DebouncedEvent::Write(ref change_path) | DebouncedEvent::Create(ref change_path) |