From d57d27064168bd92fdaa89ec138d31602dba1fc5 Mon Sep 17 00:00:00 2001 From: Boegie19 Date: Tue, 9 Aug 2022 23:05:40 +0200 Subject: [PATCH 1/8] init 2 way sync meta --- src/change_processor.rs | 44 ++++++++++++++++++++++++++-- src/snapshot_middleware/meta_file.rs | 8 ++++- src/snapshot_middleware/mod.rs | 2 +- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/change_processor.rs b/src/change_processor.rs index ac9cb8693..b30d579f8 100644 --- a/src/change_processor.rs +++ b/src/change_processor.rs @@ -1,5 +1,6 @@ use std::{ - fs, + fs::{self, File}, + io::Write, sync::{Arc, Mutex}, }; @@ -10,10 +11,11 @@ use rbx_dom_weak::types::{Ref, Variant}; use crate::{ message_queue::MessageQueue, + resolution::UnresolvedValue, snapshot::{ apply_patch_set, compute_patch_set, AppliedPatchSet, InstigatingSource, PatchSet, RojoTree, }, - snapshot_middleware::{snapshot_from_vfs, snapshot_project_node}, + snapshot_middleware::{meta_file::AdjacentMetadata, snapshot_from_vfs, snapshot_project_node}, }; /// Processes file change events, updates the DOM, and sends those updates @@ -238,6 +240,44 @@ impl JobThreadContext { } } } else { + if instance.metadata().relevant_paths.len() >= 2 { + let meta_path = instance.metadata().relevant_paths[2].clone(); + if let Some(meta_contents) = + self.vfs.read(&meta_path).with_not_found().unwrap() + { + let mut metadata = AdjacentMetadata::from_slice( + &meta_contents, + meta_path.clone(), + ) + .unwrap(); + metadata.properties.insert( + key.clone(), + UnresolvedValue::FullyQualified( + changed_value.as_ref().unwrap().clone(), + ), + ); + let data = serde_json::to_string(&metadata).unwrap(); + fs::write(meta_path, data).unwrap(); + } else { + let mut metadata = AdjacentMetadata::new(meta_path.clone()); + metadata.properties.insert( + key.clone(), + UnresolvedValue::FullyQualified( + changed_value.as_ref().unwrap().clone(), + ), + ); + let data = serde_json::to_string(&metadata).unwrap(); + let file_name = + meta_path.file_name().unwrap().to_str().unwrap(); + let mut file = File::create(file_name).unwrap(); + write!(file, "{}", data).unwrap(); + } + } else { + log::warn!( + "Cannot update instance {:?}, has no meta support.", + id + ); + } log::warn!( "Cannot update instance {:?}, it is not an instigating source.", id diff --git a/src/snapshot_middleware/meta_file.rs b/src/snapshot_middleware/meta_file.rs index abf53fbab..c427f882d 100644 --- a/src/snapshot_middleware/meta_file.rs +++ b/src/snapshot_middleware/meta_file.rs @@ -22,8 +22,14 @@ pub struct AdjacentMetadata { #[serde(skip)] pub path: PathBuf, } - impl AdjacentMetadata { + pub fn new(path: PathBuf) -> AdjacentMetadata { + AdjacentMetadata { + ignore_unknown_instances: None, + properties: HashMap::new(), + path: path, + } + } pub fn from_slice(slice: &[u8], path: PathBuf) -> anyhow::Result { let mut meta: Self = serde_json::from_slice(slice).with_context(|| { format!( diff --git a/src/snapshot_middleware/mod.rs b/src/snapshot_middleware/mod.rs index 3d5de76bd..536a312b6 100644 --- a/src/snapshot_middleware/mod.rs +++ b/src/snapshot_middleware/mod.rs @@ -10,7 +10,7 @@ mod dir; mod json; mod json_model; mod lua; -mod meta_file; +pub mod meta_file; mod project; mod rbxm; mod rbxmx; From dce55c888f0ae55ea1eb2557c05fa3c155204639 Mon Sep 17 00:00:00 2001 From: Boegie19 Date: Wed, 10 Aug 2022 00:35:59 +0200 Subject: [PATCH 2/8] Fixed issues --- src/change_processor.rs | 81 ++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/change_processor.rs b/src/change_processor.rs index b30d579f8..7c6e501b7 100644 --- a/src/change_processor.rs +++ b/src/change_processor.rs @@ -1,6 +1,5 @@ use std::{ - fs::{self, File}, - io::Write, + fs, sync::{Arc, Mutex}, }; @@ -240,51 +239,51 @@ impl JobThreadContext { } } } else { - if instance.metadata().relevant_paths.len() >= 2 { - let meta_path = instance.metadata().relevant_paths[2].clone(); - if let Some(meta_contents) = - self.vfs.read(&meta_path).with_not_found().unwrap() - { - let mut metadata = AdjacentMetadata::from_slice( - &meta_contents, - meta_path.clone(), - ) - .unwrap(); - metadata.properties.insert( - key.clone(), - UnresolvedValue::FullyQualified( - changed_value.as_ref().unwrap().clone(), - ), - ); - let data = serde_json::to_string(&metadata).unwrap(); - fs::write(meta_path, data).unwrap(); - } else { - let mut metadata = AdjacentMetadata::new(meta_path.clone()); - metadata.properties.insert( - key.clone(), - UnresolvedValue::FullyQualified( - changed_value.as_ref().unwrap().clone(), - ), - ); - let data = serde_json::to_string(&metadata).unwrap(); - let file_name = - meta_path.file_name().unwrap().to_str().unwrap(); - let mut file = File::create(file_name).unwrap(); - write!(file, "{}", data).unwrap(); - } - } else { - log::warn!( - "Cannot update instance {:?}, has no meta support.", - id - ); - } log::warn!( "Cannot update instance {:?}, it is not an instigating source.", id ); } } else { - log::warn!("Cannot change properties besides BaseScript.Source."); + if instance.metadata().relevant_paths.len() >= 2 { + let meta_path = instance.metadata().relevant_paths[1].clone(); + println!("{:?}", meta_path); + if let Some(meta_contents) = + self.vfs.read(&meta_path).with_not_found().unwrap() + { + println!("File exists"); + let mut metadata = AdjacentMetadata::from_slice( + &meta_contents, + meta_path.clone(), + ) + .unwrap(); + metadata.properties.insert( + key.clone(), + UnresolvedValue::FullyQualified( + changed_value.as_ref().unwrap().clone(), + ), + ); + let data = serde_json::to_string_pretty(&metadata).unwrap(); + fs::write(meta_path, data).unwrap(); + println!("File writen"); + } else { + println!("File did not exists"); + let mut metadata = AdjacentMetadata::new(meta_path.clone()); + metadata.properties.insert( + key.clone(), + UnresolvedValue::FullyQualified( + changed_value.as_ref().unwrap().clone(), + ), + ); + let data = serde_json::to_string_pretty(&metadata).unwrap(); + fs::write(meta_path, data).unwrap(); + println!("File created and written to"); + } + } else { + log::warn!( + "Cannot change properties of instances with no meta support" + ); + } } } } else { From d6ea59a1b7af7fdae8a35b70cd054f57b9eb533b Mon Sep 17 00:00:00 2001 From: Boegie19 Date: Wed, 10 Aug 2022 19:23:02 +0200 Subject: [PATCH 3/8] Removed print statements --- src/change_processor.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/change_processor.rs b/src/change_processor.rs index 7c6e501b7..a94c5fa3d 100644 --- a/src/change_processor.rs +++ b/src/change_processor.rs @@ -251,7 +251,6 @@ impl JobThreadContext { if let Some(meta_contents) = self.vfs.read(&meta_path).with_not_found().unwrap() { - println!("File exists"); let mut metadata = AdjacentMetadata::from_slice( &meta_contents, meta_path.clone(), @@ -265,9 +264,7 @@ impl JobThreadContext { ); let data = serde_json::to_string_pretty(&metadata).unwrap(); fs::write(meta_path, data).unwrap(); - println!("File writen"); } else { - println!("File did not exists"); let mut metadata = AdjacentMetadata::new(meta_path.clone()); metadata.properties.insert( key.clone(), @@ -277,7 +274,6 @@ impl JobThreadContext { ); let data = serde_json::to_string_pretty(&metadata).unwrap(); fs::write(meta_path, data).unwrap(); - println!("File created and written to"); } } else { log::warn!( From b4c764e61f92119011eeb1bc093b51971d63cdd5 Mon Sep 17 00:00:00 2001 From: Boegie19 Date: Wed, 10 Aug 2022 19:23:20 +0200 Subject: [PATCH 4/8] forogt 1 print --- src/change_processor.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/change_processor.rs b/src/change_processor.rs index a94c5fa3d..1062535af 100644 --- a/src/change_processor.rs +++ b/src/change_processor.rs @@ -247,7 +247,6 @@ impl JobThreadContext { } else { if instance.metadata().relevant_paths.len() >= 2 { let meta_path = instance.metadata().relevant_paths[1].clone(); - println!("{:?}", meta_path); if let Some(meta_contents) = self.vfs.read(&meta_path).with_not_found().unwrap() { From 92435e61639cbd72f62b06dc8558833f13093c65 Mon Sep 17 00:00:00 2001 From: Boegie19 Date: Fri, 12 Aug 2022 14:30:20 +0200 Subject: [PATCH 5/8] changed else { if to else if --- src/change_processor.rs | 60 +++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/src/change_processor.rs b/src/change_processor.rs index 1062535af..69ce59432 100644 --- a/src/change_processor.rs +++ b/src/change_processor.rs @@ -244,41 +244,37 @@ impl JobThreadContext { id ); } - } else { - if instance.metadata().relevant_paths.len() >= 2 { - let meta_path = instance.metadata().relevant_paths[1].clone(); - if let Some(meta_contents) = - self.vfs.read(&meta_path).with_not_found().unwrap() - { - let mut metadata = AdjacentMetadata::from_slice( - &meta_contents, - meta_path.clone(), - ) - .unwrap(); - metadata.properties.insert( - key.clone(), - UnresolvedValue::FullyQualified( - changed_value.as_ref().unwrap().clone(), - ), - ); - let data = serde_json::to_string_pretty(&metadata).unwrap(); - fs::write(meta_path, data).unwrap(); - } else { - let mut metadata = AdjacentMetadata::new(meta_path.clone()); - metadata.properties.insert( - key.clone(), - UnresolvedValue::FullyQualified( - changed_value.as_ref().unwrap().clone(), - ), - ); - let data = serde_json::to_string_pretty(&metadata).unwrap(); - fs::write(meta_path, data).unwrap(); - } + } else if instance.metadata().relevant_paths.len() >= 2 { + let meta_path = instance.metadata().relevant_paths[1].clone(); + if let Some(meta_contents) = + self.vfs.read(&meta_path).with_not_found().unwrap() + { + let mut metadata = + AdjacentMetadata::from_slice(&meta_contents, meta_path.clone()) + .unwrap(); + metadata.properties.insert( + key.clone(), + UnresolvedValue::FullyQualified( + changed_value.as_ref().unwrap().clone(), + ), + ); + let data = serde_json::to_string_pretty(&metadata).unwrap(); + fs::write(meta_path, data).unwrap(); } else { - log::warn!( - "Cannot change properties of instances with no meta support" + let mut metadata = AdjacentMetadata::new(meta_path.clone()); + metadata.properties.insert( + key.clone(), + UnresolvedValue::FullyQualified( + changed_value.as_ref().unwrap().clone(), + ), ); + let data = serde_json::to_string_pretty(&metadata).unwrap(); + fs::write(meta_path, data).unwrap(); } + } else { + log::warn!( + "Cannot change properties of instances with no meta support" + ); } } } else { From 112fb47949823d39bfe26bae1e3633d85ac8d115 Mon Sep 17 00:00:00 2001 From: Boegie19 Date: Sun, 11 Jun 2023 19:05:37 +0200 Subject: [PATCH 6/8] better meta.json finder implementation --- src/change_processor.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/change_processor.rs b/src/change_processor.rs index 69ce59432..684360a97 100644 --- a/src/change_processor.rs +++ b/src/change_processor.rs @@ -219,6 +219,15 @@ impl JobThreadContext { } for (key, changed_value) in &update.changed_properties { + log::debug!("{:?}", key); + let mut meta_path = None; + for path in instance.metadata().relevant_paths.iter() { + log::debug!("{:?}", path); + if path.to_str().unwrap().ends_with(".meta.json") { + meta_path = Some(path); + break; + } + } if key == "Source" { if let Some(instigating_source) = &instance.metadata().instigating_source @@ -244,8 +253,7 @@ impl JobThreadContext { id ); } - } else if instance.metadata().relevant_paths.len() >= 2 { - let meta_path = instance.metadata().relevant_paths[1].clone(); + } else if let Some(meta_path) = meta_path { if let Some(meta_contents) = self.vfs.read(&meta_path).with_not_found().unwrap() { From 39ed263cc60abb8430fd9382f8023f97dc95ca0c Mon Sep 17 00:00:00 2001 From: Boegie19 Date: Mon, 12 Jun 2023 01:58:09 +0200 Subject: [PATCH 7/8] add attributes to new AdjacentMetadata --- src/snapshot_middleware/meta_file.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/snapshot_middleware/meta_file.rs b/src/snapshot_middleware/meta_file.rs index f5b381e2a..3d639b269 100644 --- a/src/snapshot_middleware/meta_file.rs +++ b/src/snapshot_middleware/meta_file.rs @@ -30,6 +30,7 @@ impl AdjacentMetadata { AdjacentMetadata { ignore_unknown_instances: None, properties: HashMap::new(), + attributes: HashMap::new(), path: path, } } From b856e1de0d3ead47b5cc161e8ed5647d2e32060e Mon Sep 17 00:00:00 2001 From: Boegie19 Date: Mon, 12 Jun 2023 04:13:52 +0200 Subject: [PATCH 8/8] remove debug stuff --- src/change_processor.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/change_processor.rs b/src/change_processor.rs index d462a0a96..180ba8afd 100644 --- a/src/change_processor.rs +++ b/src/change_processor.rs @@ -194,10 +194,8 @@ impl JobThreadContext { } for (key, changed_value) in &update.changed_properties { - log::debug!("{:?}", key); let mut meta_path = None; for path in instance.metadata().relevant_paths.iter() { - log::debug!("{:?}", path); if path.to_str().unwrap().ends_with(".meta.json") { meta_path = Some(path); break;