mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
SnapshotMetadata -> SnapshotContext
This commit is contained in:
parent
da4ed72bb9
commit
47a47fca8f
2 changed files with 25 additions and 25 deletions
|
|
@ -15,7 +15,7 @@ use crate::{
|
||||||
message_queue::MessageQueue,
|
message_queue::MessageQueue,
|
||||||
imfs::{Imfs, ImfsItem},
|
imfs::{Imfs, ImfsItem},
|
||||||
path_map::PathMap,
|
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},
|
snapshot_reconciler::{InstanceChanges, reify_root, reconcile_subtree},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -102,10 +102,10 @@ impl RbxSession {
|
||||||
let instance_name = path_metadata.instance_name.as_ref()
|
let instance_name = path_metadata.instance_name.as_ref()
|
||||||
.map(|value| Cow::Owned(value.to_owned()));
|
.map(|value| Cow::Owned(value.to_owned()));
|
||||||
|
|
||||||
let mut snapshot_meta = SnapshotMetadata {
|
let mut context = SnapshotContext {
|
||||||
metadata_per_path: &mut self.metadata_per_path,
|
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()));
|
.unwrap_or_else(|_| panic!("Could not generate instance snapshot for path {}", path_to_snapshot.display()));
|
||||||
|
|
||||||
let snapshot = match maybe_snapshot {
|
let snapshot = match maybe_snapshot {
|
||||||
|
|
@ -199,10 +199,10 @@ fn reify_initial_tree(
|
||||||
metadata_per_path: &mut PathMap<MetadataPerPath>,
|
metadata_per_path: &mut PathMap<MetadataPerPath>,
|
||||||
metadata_per_instance: &mut HashMap<RbxId, MetadataPerInstance>,
|
metadata_per_instance: &mut HashMap<RbxId, MetadataPerInstance>,
|
||||||
) -> RbxTree {
|
) -> RbxTree {
|
||||||
let mut meta = SnapshotMetadata {
|
let mut context = SnapshotContext {
|
||||||
metadata_per_path,
|
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("Could not snapshot project tree")
|
||||||
.expect("Project did not produce any instances");
|
.expect("Project did not produce any instances");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ const INIT_CLIENT_NAME: &str = "init.client.lua";
|
||||||
|
|
||||||
pub type SnapshotResult<'a> = Result<Option<RbxSnapshotInstance<'a>>, SnapshotError>;
|
pub type SnapshotResult<'a> = Result<Option<RbxSnapshotInstance<'a>>, SnapshotError>;
|
||||||
|
|
||||||
pub struct SnapshotMetadata<'meta> {
|
pub struct SnapshotContext<'meta> {
|
||||||
pub metadata_per_path: &'meta mut PathMap<MetadataPerPath>,
|
pub metadata_per_path: &'meta mut PathMap<MetadataPerPath>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,34 +83,34 @@ impl fmt::Display for SnapshotError {
|
||||||
|
|
||||||
pub fn snapshot_project_tree<'source>(
|
pub fn snapshot_project_tree<'source>(
|
||||||
imfs: &'source Imfs,
|
imfs: &'source Imfs,
|
||||||
metadata: &mut SnapshotMetadata,
|
context: &mut SnapshotContext,
|
||||||
project: &'source Project,
|
project: &'source Project,
|
||||||
) -> SnapshotResult<'source> {
|
) -> 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>(
|
fn snapshot_project_node<'source>(
|
||||||
imfs: &'source Imfs,
|
imfs: &'source Imfs,
|
||||||
metadata: &mut SnapshotMetadata,
|
context: &mut SnapshotContext,
|
||||||
node: &'source ProjectNode,
|
node: &'source ProjectNode,
|
||||||
instance_name: Cow<'source, str>,
|
instance_name: Cow<'source, str>,
|
||||||
) -> SnapshotResult<'source> {
|
) -> SnapshotResult<'source> {
|
||||||
match node {
|
match node {
|
||||||
ProjectNode::Instance(instance_node) => snapshot_instance_node(imfs, metadata, instance_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, metadata, sync_node, instance_name),
|
ProjectNode::SyncPoint(sync_node) => snapshot_sync_point_node(imfs, context, sync_node, instance_name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn snapshot_instance_node<'source>(
|
fn snapshot_instance_node<'source>(
|
||||||
imfs: &'source Imfs,
|
imfs: &'source Imfs,
|
||||||
metadata: &mut SnapshotMetadata,
|
context: &mut SnapshotContext,
|
||||||
node: &'source InstanceProjectNode,
|
node: &'source InstanceProjectNode,
|
||||||
instance_name: Cow<'source, str>,
|
instance_name: Cow<'source, str>,
|
||||||
) -> SnapshotResult<'source> {
|
) -> SnapshotResult<'source> {
|
||||||
let mut children = Vec::new();
|
let mut children = Vec::new();
|
||||||
|
|
||||||
for (child_name, child_project_node) in &node.children {
|
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);
|
children.push(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -129,11 +129,11 @@ fn snapshot_instance_node<'source>(
|
||||||
|
|
||||||
fn snapshot_sync_point_node<'source>(
|
fn snapshot_sync_point_node<'source>(
|
||||||
imfs: &'source Imfs,
|
imfs: &'source Imfs,
|
||||||
metadata: &mut SnapshotMetadata,
|
context: &mut SnapshotContext,
|
||||||
node: &'source SyncPointProjectNode,
|
node: &'source SyncPointProjectNode,
|
||||||
instance_name: Cow<'source, str>,
|
instance_name: Cow<'source, str>,
|
||||||
) -> SnapshotResult<'source> {
|
) -> 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
|
// If the snapshot resulted in no instances, like if it targets an unknown
|
||||||
// file or an empty model file, we can early-return.
|
// 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.
|
// 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());
|
path_meta.instance_name = Some(snapshot.name.clone().into_owned());
|
||||||
|
|
||||||
Ok(Some(snapshot))
|
Ok(Some(snapshot))
|
||||||
|
|
@ -151,33 +151,33 @@ fn snapshot_sync_point_node<'source>(
|
||||||
|
|
||||||
pub fn snapshot_imfs_path<'source>(
|
pub fn snapshot_imfs_path<'source>(
|
||||||
imfs: &'source Imfs,
|
imfs: &'source Imfs,
|
||||||
metadata: &mut SnapshotMetadata,
|
context: &mut SnapshotContext,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
instance_name: Option<Cow<'source, str>>,
|
instance_name: Option<Cow<'source, str>>,
|
||||||
) -> SnapshotResult<'source> {
|
) -> SnapshotResult<'source> {
|
||||||
// If the given path doesn't exist in the in-memory filesystem, we consider
|
// If the given path doesn't exist in the in-memory filesystem, we consider
|
||||||
// that an error.
|
// that an error.
|
||||||
match imfs.get(path) {
|
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())),
|
None => return Err(SnapshotError::DidNotExist(path.to_owned())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn snapshot_imfs_item<'source>(
|
fn snapshot_imfs_item<'source>(
|
||||||
imfs: &'source Imfs,
|
imfs: &'source Imfs,
|
||||||
metadata: &mut SnapshotMetadata,
|
context: &mut SnapshotContext,
|
||||||
item: &'source ImfsItem,
|
item: &'source ImfsItem,
|
||||||
instance_name: Option<Cow<'source, str>>,
|
instance_name: Option<Cow<'source, str>>,
|
||||||
) -> SnapshotResult<'source> {
|
) -> SnapshotResult<'source> {
|
||||||
match item {
|
match item {
|
||||||
ImfsItem::File(file) => snapshot_imfs_file(file, instance_name),
|
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>(
|
fn snapshot_imfs_directory<'source>(
|
||||||
imfs: &'source Imfs,
|
imfs: &'source Imfs,
|
||||||
metadata: &mut SnapshotMetadata,
|
context: &mut SnapshotContext,
|
||||||
directory: &'source ImfsDirectory,
|
directory: &'source ImfsDirectory,
|
||||||
instance_name: Option<Cow<'source, str>>,
|
instance_name: Option<Cow<'source, str>>,
|
||||||
) -> SnapshotResult<'source> {
|
) -> SnapshotResult<'source> {
|
||||||
|
|
@ -193,11 +193,11 @@ fn snapshot_imfs_directory<'source>(
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut snapshot = if directory.children.contains(&init_path) {
|
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) {
|
} 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) {
|
} 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 {
|
} else {
|
||||||
RbxSnapshotInstance {
|
RbxSnapshotInstance {
|
||||||
class_name: Cow::Borrowed("Folder"),
|
class_name: Cow::Borrowed("Folder"),
|
||||||
|
|
@ -223,7 +223,7 @@ fn snapshot_imfs_directory<'source>(
|
||||||
// them here.
|
// 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);
|
snapshot.children.push(child);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue