Add support for removing files, handled in ChangeProcessor

This commit is contained in:
Lucien Greathouse
2019-11-18 18:08:12 -08:00
parent 459bf62fab
commit bcffd2eb99

View File

@@ -11,9 +11,11 @@ use rbx_dom_weak::RbxId;
use crate::{ use crate::{
message_queue::MessageQueue, message_queue::MessageQueue,
snapshot::{apply_patch_set, compute_patch_set, AppliedPatchSet, InstigatingSource, RojoTree}, snapshot::{
apply_patch_set, compute_patch_set, AppliedPatchSet, InstigatingSource, PatchSet, RojoTree,
},
snapshot_middleware::{snapshot_from_vfs, snapshot_project_node, InstanceSnapshotContext}, snapshot_middleware::{snapshot_from_vfs, snapshot_project_node, InstanceSnapshotContext},
vfs::{Vfs, VfsEvent, VfsFetcher}, vfs::{FsResultExt, Vfs, VfsEvent, VfsFetcher},
}; };
pub struct ChangeProcessor { pub struct ChangeProcessor {
@@ -143,29 +145,57 @@ fn update_affected_instances<F: VfsFetcher>(
// every time. // every time.
let mut snapshot_context = InstanceSnapshotContext::default(); let mut snapshot_context = InstanceSnapshotContext::default();
let snapshot = match instigating_source { // How we process a file change event depends on what created this
// file/folder in the first place.
let applied_patch_set = match instigating_source {
InstigatingSource::Path(path) => { InstigatingSource::Path(path) => {
let entry = vfs let maybe_entry = vfs
.get(path) .get(path)
.expect("could not get instigating path from filesystem"); .with_not_found()
.expect("unexpected VFS error");
snapshot_from_vfs(&mut snapshot_context, &vfs, &entry) match maybe_entry {
.expect("snapshot failed") Some(entry) => {
.expect("snapshot did not return an instance") // Our instance was previously created from a path and
} // that path still exists. We can generate a snapshot
InstigatingSource::ProjectNode(instance_name, project_node) => { // starting at that path and use it as the source for
snapshot_project_node(&mut snapshot_context, instance_name, project_node, &vfs) // our patch.
.expect("snapshot failed")
.expect("snapshot did not return an instance")
}
};
log::trace!("Computed snapshot: {:#?}", snapshot); let snapshot = snapshot_from_vfs(&mut snapshot_context, &vfs, &entry)
.expect("snapshot failed")
.expect("snapshot did not return an instance");
let patch_set = compute_patch_set(&snapshot, &tree, id); let patch_set = compute_patch_set(&snapshot, &tree, id);
let applied_patch_set = apply_patch_set(tree, patch_set); apply_patch_set(tree, patch_set)
}
None => {
// Our instance was previously created from a path, but
// that path no longer exists.
//
// We associate deleting the instigating file for an
// instance with deleting that instance.
log::trace!("Applied patch: {:#?}", applied_patch_set); let mut patch_set = PatchSet::new();
patch_set.removed_instances.push(id);
apply_patch_set(tree, patch_set)
}
}
}
InstigatingSource::ProjectNode(instance_name, project_node) => {
// This instance is the direct subject of a project node. Since
// there might be information associated with our instance from
// the project file, we snapshot the entire project node again.
let snapshot =
snapshot_project_node(&mut snapshot_context, instance_name, project_node, &vfs)
.expect("snapshot failed")
.expect("snapshot did not return an instance");
let patch_set = compute_patch_set(&snapshot, &tree, id);
apply_patch_set(tree, patch_set)
}
};
applied_patches.push(applied_patch_set); applied_patches.push(applied_patch_set);
} }