Insulate VFS internals a little bit

This commit is contained in:
Lucien Greathouse
2018-01-03 18:13:49 -08:00
parent 78a1c658d8
commit 2df1dfa1cb
3 changed files with 19 additions and 7 deletions

View File

@@ -79,7 +79,7 @@ pub fn serve(project_path: &PathBuf, verbose: bool, port: Option<u64>) {
} }
}; };
vfs.partitions.insert(name.clone(), path); vfs.insert_partition(name, path);
} }
Arc::new(Mutex::new(vfs)) Arc::new(Mutex::new(vfs))

View File

@@ -15,14 +15,14 @@ pub struct VfsSession {
/// Contains all of the partitions mounted by the Vfs. /// Contains all of the partitions mounted by the Vfs.
/// ///
/// These must be absolute paths! /// These must be absolute paths!
pub partitions: HashMap<String, PathBuf>, partitions: HashMap<String, PathBuf>,
/// When the Vfs was initialized; used for change tracking.
pub start_time: Instant,
/// A chronologically-sorted list of routes that changed since the Vfs was /// A chronologically-sorted list of routes that changed since the Vfs was
/// created, along with a timestamp denoting when. /// created, along with a timestamp denoting when.
pub change_history: Vec<VfsChange>, change_history: Vec<VfsChange>,
/// When the Vfs was initialized; used for change tracking.
start_time: Instant,
plugin_chain: &'static PluginChain, plugin_chain: &'static PluginChain,
} }
@@ -44,6 +44,18 @@ impl VfsSession {
} }
} }
pub fn get_partitions(&self) -> &HashMap<String, PathBuf> {
&self.partitions
}
pub fn insert_partition<P: Into<PathBuf>>(&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<PathBuf> { fn route_to_path(&self, route: &[String]) -> Option<PathBuf> {
let (partition_name, rest) = match route.split_first() { let (partition_name, rest) = match route.split_first() {
Some((first, rest)) => (first, rest), Some((first, rest)) => (first, rest),

View File

@@ -25,7 +25,7 @@ impl VfsWatcher {
pub fn start(mut self) { pub fn start(mut self) {
let outer_vfs = self.vfs.lock().unwrap(); 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 (tx, rx) = mpsc::channel();
let partition_name = partition_name.clone(); let partition_name = partition_name.clone();
let root_path = root_path.clone(); let root_path = root_path.clone();