Skip to content

Commit

Permalink
Don't filter properties for project nodes with no paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekkonot committed May 2, 2024
1 parent 3434d01 commit b9754c6
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/snapshot_middleware/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
PathIgnoreRule, SyncRule,
},
snapshot_middleware::Middleware,
syncback::{FsSnapshot, SyncbackReturn, SyncbackSnapshot},
syncback::{filter_properties, FsSnapshot, SyncbackReturn, SyncbackSnapshot},
variant_eq::variant_eq,
RojoRef,
};
Expand Down Expand Up @@ -401,10 +401,10 @@ pub fn syncback_project<'sync>(

// We only want to set properties if it needs it.
if !middleware.handles_own_properties() {
project_node_property_syncback(snapshot, new_inst, node);
project_node_property_syncback_path(snapshot, new_inst, node);
}
} else {
project_node_property_syncback(snapshot, new_inst, node);
project_node_property_syncback_no_path(snapshot, new_inst, node);
}

for child_ref in new_inst.children() {
Expand Down Expand Up @@ -520,17 +520,15 @@ pub fn syncback_project<'sync>(
})
}

fn project_node_property_syncback(
fn project_node_property_syncback<'inst>(
snapshot: &SyncbackSnapshot,
filtered_properties: HashMap<&'inst str, &'inst Variant>,
new_inst: &Instance,
node: &mut ProjectNode,
) {
let properties = &mut node.properties;
let mut attributes = BTreeMap::new();
for (name, value) in snapshot
.get_path_filtered_properties(new_inst.referent())
.unwrap()
{
for (name, value) in filtered_properties {
match value {
Variant::Attributes(attrs) => {
for (attr_name, attr_value) in attrs.iter() {
Expand All @@ -557,6 +555,26 @@ fn project_node_property_syncback(
node.attributes = attributes;
}

fn project_node_property_syncback_path(
snapshot: &SyncbackSnapshot,
new_inst: &Instance,
node: &mut ProjectNode,
) {
let filtered_properties = snapshot
.get_path_filtered_properties(new_inst.referent())
.unwrap();
project_node_property_syncback(snapshot, filtered_properties, new_inst, node)
}

fn project_node_property_syncback_no_path(
snapshot: &SyncbackSnapshot,
new_inst: &Instance,
node: &mut ProjectNode,
) {
let filtered_properties = filter_properties(snapshot.project(), new_inst);
project_node_property_syncback(snapshot, filtered_properties, new_inst, node)
}

fn project_node_should_reserialize(
node_properties: &BTreeMap<String, UnresolvedValue>,
node_attributes: &BTreeMap<String, UnresolvedValue>,
Expand Down

0 comments on commit b9754c6

Please sign in to comment.