From 47a47fca8fbf9b7cbd3f51d5d28cb39c5c3e99d4 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Thu, 17 Jan 2019 15:56:34 -0800 Subject: [PATCH] SnapshotMetadata -> SnapshotContext --- server/src/rbx_session.rs | 10 +++++----- server/src/rbx_snapshot.rs | 40 +++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/server/src/rbx_session.rs b/server/src/rbx_session.rs index 25e515c1..37dbe1d0 100644 --- a/server/src/rbx_session.rs +++ b/server/src/rbx_session.rs @@ -15,7 +15,7 @@ use crate::{ message_queue::MessageQueue, imfs::{Imfs, ImfsItem}, path_map::PathMap, - rbx_snapshot::{SnapshotMetadata, snapshot_project_tree, snapshot_imfs_path}, + rbx_snapshot::{SnapshotContext, snapshot_project_tree, snapshot_imfs_path}, snapshot_reconciler::{InstanceChanges, reify_root, reconcile_subtree}, }; @@ -102,10 +102,10 @@ impl RbxSession { let instance_name = path_metadata.instance_name.as_ref() .map(|value| Cow::Owned(value.to_owned())); - let mut snapshot_meta = SnapshotMetadata { + let mut context = SnapshotContext { metadata_per_path: &mut self.metadata_per_path, }; - let maybe_snapshot = snapshot_imfs_path(&imfs, &mut snapshot_meta, &path_to_snapshot, instance_name) + let maybe_snapshot = snapshot_imfs_path(&imfs, &mut context, &path_to_snapshot, instance_name) .unwrap_or_else(|_| panic!("Could not generate instance snapshot for path {}", path_to_snapshot.display())); let snapshot = match maybe_snapshot { @@ -199,10 +199,10 @@ fn reify_initial_tree( metadata_per_path: &mut PathMap, metadata_per_instance: &mut HashMap, ) -> RbxTree { - let mut meta = SnapshotMetadata { + let mut context = SnapshotContext { metadata_per_path, }; - let snapshot = snapshot_project_tree(imfs, &mut meta, project) + let snapshot = snapshot_project_tree(imfs, &mut context, project) .expect("Could not snapshot project tree") .expect("Project did not produce any instances"); diff --git a/server/src/rbx_snapshot.rs b/server/src/rbx_snapshot.rs index 191b8544..06a8e2ce 100644 --- a/server/src/rbx_snapshot.rs +++ b/server/src/rbx_snapshot.rs @@ -39,7 +39,7 @@ const INIT_CLIENT_NAME: &str = "init.client.lua"; pub type SnapshotResult<'a> = Result>, SnapshotError>; -pub struct SnapshotMetadata<'meta> { +pub struct SnapshotContext<'meta> { pub metadata_per_path: &'meta mut PathMap, } @@ -83,34 +83,34 @@ impl fmt::Display for SnapshotError { pub fn snapshot_project_tree<'source>( imfs: &'source Imfs, - metadata: &mut SnapshotMetadata, + context: &mut SnapshotContext, project: &'source Project, ) -> SnapshotResult<'source> { - snapshot_project_node(imfs, metadata, &project.tree, Cow::Borrowed(&project.name)) + snapshot_project_node(imfs, context, &project.tree, Cow::Borrowed(&project.name)) } fn snapshot_project_node<'source>( imfs: &'source Imfs, - metadata: &mut SnapshotMetadata, + context: &mut SnapshotContext, node: &'source ProjectNode, instance_name: Cow<'source, str>, ) -> SnapshotResult<'source> { match node { - ProjectNode::Instance(instance_node) => snapshot_instance_node(imfs, metadata, instance_node, instance_name), - ProjectNode::SyncPoint(sync_node) => snapshot_sync_point_node(imfs, metadata, sync_node, instance_name), + ProjectNode::Instance(instance_node) => snapshot_instance_node(imfs, context, instance_node, instance_name), + ProjectNode::SyncPoint(sync_node) => snapshot_sync_point_node(imfs, context, sync_node, instance_name), } } fn snapshot_instance_node<'source>( imfs: &'source Imfs, - metadata: &mut SnapshotMetadata, + context: &mut SnapshotContext, node: &'source InstanceProjectNode, instance_name: Cow<'source, str>, ) -> SnapshotResult<'source> { let mut children = Vec::new(); for (child_name, child_project_node) in &node.children { - if let Some(child) = snapshot_project_node(imfs, metadata, child_project_node, Cow::Borrowed(child_name))? { + if let Some(child) = snapshot_project_node(imfs, context, child_project_node, Cow::Borrowed(child_name))? { children.push(child); } } @@ -129,11 +129,11 @@ fn snapshot_instance_node<'source>( fn snapshot_sync_point_node<'source>( imfs: &'source Imfs, - metadata: &mut SnapshotMetadata, + context: &mut SnapshotContext, node: &'source SyncPointProjectNode, instance_name: Cow<'source, str>, ) -> SnapshotResult<'source> { - let maybe_snapshot = snapshot_imfs_path(imfs, metadata, &node.path, Some(instance_name))?; + let maybe_snapshot = snapshot_imfs_path(imfs, context, &node.path, Some(instance_name))?; // If the snapshot resulted in no instances, like if it targets an unknown // file or an empty model file, we can early-return. @@ -143,7 +143,7 @@ fn snapshot_sync_point_node<'source>( }; // Otherwise, we can log the name of the sync point we just snapshotted. - let path_meta = metadata.metadata_per_path.entry(node.path.to_owned()).or_default(); + let path_meta = context.metadata_per_path.entry(node.path.to_owned()).or_default(); path_meta.instance_name = Some(snapshot.name.clone().into_owned()); Ok(Some(snapshot)) @@ -151,33 +151,33 @@ fn snapshot_sync_point_node<'source>( pub fn snapshot_imfs_path<'source>( imfs: &'source Imfs, - metadata: &mut SnapshotMetadata, + context: &mut SnapshotContext, path: &Path, instance_name: Option>, ) -> SnapshotResult<'source> { // If the given path doesn't exist in the in-memory filesystem, we consider // that an error. match imfs.get(path) { - Some(imfs_item) => snapshot_imfs_item(imfs, metadata, imfs_item, instance_name), + Some(imfs_item) => snapshot_imfs_item(imfs, context, imfs_item, instance_name), None => return Err(SnapshotError::DidNotExist(path.to_owned())), } } fn snapshot_imfs_item<'source>( imfs: &'source Imfs, - metadata: &mut SnapshotMetadata, + context: &mut SnapshotContext, item: &'source ImfsItem, instance_name: Option>, ) -> SnapshotResult<'source> { match item { ImfsItem::File(file) => snapshot_imfs_file(file, instance_name), - ImfsItem::Directory(directory) => snapshot_imfs_directory(imfs, metadata, directory, instance_name), + ImfsItem::Directory(directory) => snapshot_imfs_directory(imfs, context, directory, instance_name), } } fn snapshot_imfs_directory<'source>( imfs: &'source Imfs, - metadata: &mut SnapshotMetadata, + context: &mut SnapshotContext, directory: &'source ImfsDirectory, instance_name: Option>, ) -> SnapshotResult<'source> { @@ -193,11 +193,11 @@ fn snapshot_imfs_directory<'source>( }); let mut snapshot = if directory.children.contains(&init_path) { - snapshot_imfs_path(imfs, metadata, &init_path, Some(snapshot_name))?.unwrap() + snapshot_imfs_path(imfs, context, &init_path, Some(snapshot_name))?.unwrap() } else if directory.children.contains(&init_server_path) { - snapshot_imfs_path(imfs, metadata, &init_server_path, Some(snapshot_name))?.unwrap() + snapshot_imfs_path(imfs, context, &init_server_path, Some(snapshot_name))?.unwrap() } else if directory.children.contains(&init_client_path) { - snapshot_imfs_path(imfs, metadata, &init_client_path, Some(snapshot_name))?.unwrap() + snapshot_imfs_path(imfs, context, &init_client_path, Some(snapshot_name))?.unwrap() } else { RbxSnapshotInstance { class_name: Cow::Borrowed("Folder"), @@ -223,7 +223,7 @@ fn snapshot_imfs_directory<'source>( // them here. }, _ => { - if let Some(child) = snapshot_imfs_path(imfs, metadata, child_path, None)? { + if let Some(child) = snapshot_imfs_path(imfs, context, child_path, None)? { snapshot.children.push(child); } },