mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 23:26:19 +00:00
Descent-based create/update mechanism
This commit is contained in:
@@ -105,6 +105,16 @@ impl Imfs {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_root_for_path<'a>(&'a self, path: &Path) -> Option<&'a Path> {
|
||||||
|
for root_path in &self.roots {
|
||||||
|
if path.starts_with(root_path) {
|
||||||
|
return Some(root_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
fn remove_item(&mut self, path: &Path) {
|
fn remove_item(&mut self, path: &Path) {
|
||||||
if let Some(ImfsItem::Directory(directory)) = self.items.remove(path) {
|
if let Some(ImfsItem::Directory(directory)) = self.items.remove(path) {
|
||||||
for child_path in &directory.children {
|
for child_path in &directory.children {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
path::{Path, PathBuf},
|
path::{self, Path, PathBuf},
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,4 +70,27 @@ impl<T> PathMap<T> {
|
|||||||
|
|
||||||
Some(root_value)
|
Some(root_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn descend(&self, start_path: &Path, target_path: &Path) -> PathBuf {
|
||||||
|
let relative_path = target_path.strip_prefix(start_path)
|
||||||
|
.expect("target_path did not begin with start_path");
|
||||||
|
let mut current_path = start_path.to_path_buf();
|
||||||
|
|
||||||
|
for component in relative_path.components() {
|
||||||
|
match component {
|
||||||
|
path::Component::Normal(name) => {
|
||||||
|
let next_path = current_path.join(name);
|
||||||
|
|
||||||
|
if self.nodes.contains_key(&next_path) {
|
||||||
|
current_path = next_path;
|
||||||
|
} else {
|
||||||
|
return current_path;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
current_path
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ use crate::{
|
|||||||
message_queue::{Message, MessageQueue},
|
message_queue::{Message, MessageQueue},
|
||||||
imfs::{Imfs, ImfsItem, ImfsFile},
|
imfs::{Imfs, ImfsItem, ImfsFile},
|
||||||
path_map::PathMap,
|
path_map::PathMap,
|
||||||
rbx_snapshot::{RbxSnapshotInstance, reify_root},
|
rbx_snapshot::{RbxSnapshotInstance, reify_root, reconcile_subtree},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct RbxSession {
|
pub struct RbxSession {
|
||||||
@@ -47,13 +47,16 @@ impl RbxSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn path_created_or_updated(&mut self, path: &Path) {
|
fn path_created_or_updated(&mut self, path: &Path) {
|
||||||
if let Some(instance_id) = self.paths_to_node_ids.get(path) {
|
let imfs = self.imfs.lock().unwrap();
|
||||||
// TODO: Replace instance with ID `instance_id` with new instance
|
let root_path = imfs.get_root_for_path(path)
|
||||||
}
|
.expect("Path was outside in-memory filesystem roots");
|
||||||
|
|
||||||
// TODO: Crawl up path to find first node represented in the tree or a
|
let closest_path = self.paths_to_node_ids.descend(root_path, path);
|
||||||
// sync point root. That path immediately before we find an existing
|
let &instance_id = self.paths_to_node_ids.get(&closest_path).unwrap();
|
||||||
// node should be read into the tree.
|
|
||||||
|
let snapshot = snapshot_instances_from_imfs(&imfs, &closest_path)
|
||||||
|
.expect("Could not generate instance snapshot");
|
||||||
|
reconcile_subtree(&mut self.tree, instance_id, &snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn path_created(&mut self, path: &Path) {
|
pub fn path_created(&mut self, path: &Path) {
|
||||||
@@ -167,7 +170,7 @@ fn construct_instance_node<'a>(
|
|||||||
name: Cow::Borrowed(instance_name),
|
name: Cow::Borrowed(instance_name),
|
||||||
properties: HashMap::new(),
|
properties: HashMap::new(),
|
||||||
children,
|
children,
|
||||||
update_trigger_paths: Vec::new(),
|
source_path: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +228,7 @@ fn snapshot_instances_from_imfs<'a>(imfs: &'a Imfs, imfs_path: &Path) -> Option<
|
|||||||
class_name: Cow::Borrowed(class_name),
|
class_name: Cow::Borrowed(class_name),
|
||||||
properties,
|
properties,
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
update_trigger_paths: vec![file.path.clone()],
|
source_path: Some(file.path.clone()),
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
ImfsItem::Directory(directory) => {
|
ImfsItem::Directory(directory) => {
|
||||||
@@ -239,7 +242,7 @@ fn snapshot_instances_from_imfs<'a>(imfs: &'a Imfs, imfs_path: &Path) -> Option<
|
|||||||
name: Cow::Borrowed(""), // Assigned later in the method
|
name: Cow::Borrowed(""), // Assigned later in the method
|
||||||
properties: HashMap::new(),
|
properties: HashMap::new(),
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
update_trigger_paths: vec![directory.path.clone()],
|
source_path: Some(directory.path.clone()),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ pub struct RbxSnapshotInstance<'a> {
|
|||||||
pub class_name: Cow<'a, str>,
|
pub class_name: Cow<'a, str>,
|
||||||
pub properties: HashMap<String, RbxValue>,
|
pub properties: HashMap<String, RbxValue>,
|
||||||
pub children: Vec<RbxSnapshotInstance<'a>>,
|
pub children: Vec<RbxSnapshotInstance<'a>>,
|
||||||
pub update_trigger_paths: Vec<PathBuf>,
|
pub source_path: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reify_core(snapshot: &RbxSnapshotInstance) -> RbxInstance {
|
fn reify_core(snapshot: &RbxSnapshotInstance) -> RbxInstance {
|
||||||
|
|||||||
Reference in New Issue
Block a user