From 2df1dfa1cbd4e44626a0e815d5e1f1b435a423f3 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Wed, 3 Jan 2018 18:13:49 -0800 Subject: [PATCH] Insulate VFS internals a little bit --- src/commands/serve.rs | 2 +- src/vfs/vfs_session.rs | 22 +++++++++++++++++----- src/vfs/vfs_watcher.rs | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/commands/serve.rs b/src/commands/serve.rs index b456f9c9..e8cb2b82 100644 --- a/src/commands/serve.rs +++ b/src/commands/serve.rs @@ -79,7 +79,7 @@ pub fn serve(project_path: &PathBuf, verbose: bool, port: Option) { } }; - vfs.partitions.insert(name.clone(), path); + vfs.insert_partition(name, path); } Arc::new(Mutex::new(vfs)) diff --git a/src/vfs/vfs_session.rs b/src/vfs/vfs_session.rs index 504f16b6..efe86ea7 100644 --- a/src/vfs/vfs_session.rs +++ b/src/vfs/vfs_session.rs @@ -15,14 +15,14 @@ pub struct VfsSession { /// Contains all of the partitions mounted by the Vfs. /// /// These must be absolute paths! - pub partitions: HashMap, - - /// When the Vfs was initialized; used for change tracking. - pub start_time: Instant, + partitions: HashMap, /// A chronologically-sorted list of routes that changed since the Vfs was /// created, along with a timestamp denoting when. - pub change_history: Vec, + change_history: Vec, + + /// When the Vfs was initialized; used for change tracking. + start_time: Instant, plugin_chain: &'static PluginChain, } @@ -44,6 +44,18 @@ impl VfsSession { } } + pub fn get_partitions(&self) -> &HashMap { + &self.partitions + } + + pub fn insert_partition>(&mut self, name: &str, path: P) { + let path = path.into(); + + assert!(path.is_absolute()); + + self.partitions.insert(name.to_string(), path.into()); + } + fn route_to_path(&self, route: &[String]) -> Option { let (partition_name, rest) = match route.split_first() { Some((first, rest)) => (first, rest), diff --git a/src/vfs/vfs_watcher.rs b/src/vfs/vfs_watcher.rs index 4598e72b..b1db63b7 100644 --- a/src/vfs/vfs_watcher.rs +++ b/src/vfs/vfs_watcher.rs @@ -25,7 +25,7 @@ impl VfsWatcher { pub fn start(mut self) { let outer_vfs = self.vfs.lock().unwrap(); - for (partition_name, root_path) in &outer_vfs.partitions { + for (partition_name, root_path) in outer_vfs.get_partitions() { let (tx, rx) = mpsc::channel(); let partition_name = partition_name.clone(); let root_path = root_path.clone();