From 70f5daee7794e17e78e02614031db330a53858a3 Mon Sep 17 00:00:00 2001 From: Micah Date: Fri, 15 Nov 2024 09:52:14 -0800 Subject: [PATCH 1/2] Only delete the old file if serializing as an rbxm succeeds --- src/syncback/mod.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/syncback/mod.rs b/src/syncback/mod.rs index d0b3ff8bf..e0529600c 100644 --- a/src/syncback/mod.rs +++ b/src/syncback/mod.rs @@ -199,11 +199,6 @@ pub fn syncback_loop( let syncback = match middleware.syncback(&snapshot) { Ok(syncback) => syncback, Err(err) if middleware == Middleware::Dir => { - if snapshot.old_inst().is_some() { - // We need to remove the old FS representation if we're - // reserializing it as an rbxm. - fs_snapshot.remove_dir(&snapshot.path); - } let new_middleware = match env::var(DEBUG_MODEL_FORMAT_VAR) { Ok(value) if value == "1" => Middleware::Rbxmx, Ok(value) if value == "2" => Middleware::JsonModel, @@ -224,9 +219,15 @@ pub fn syncback_loop( "Could not syncback {inst_path} as a Directory because: {err}.\n\ It will instead be synced back as a {new_middleware:?}." ); - new_middleware + let new_syncback_result = new_middleware .syncback(&new_snapshot) - .with_context(|| format!("Failed to syncback {inst_path}"))? + .with_context(|| format!("Failed to syncback {inst_path}")); + if new_syncback_result.is_ok() && snapshot.old_inst().is_some() { + // We need to remove the old FS representation if we're + // reserializing it as an rbxm. + fs_snapshot.remove_dir(&snapshot.path); + } + new_syncback_result? } Err(err) => anyhow::bail!("Failed to syncback {inst_path} because {err}"), }; From c788bbf1d526ceb7cee2034f90657f11db1813bc Mon Sep 17 00:00:00 2001 From: Micah Date: Fri, 15 Nov 2024 10:49:45 -0800 Subject: [PATCH 2/2] Only use ambiguous syntax if a property exists in the database --- src/resolution.rs | 111 +++++++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 51 deletions(-) diff --git a/src/resolution.rs b/src/resolution.rs index ba10f115b..73b6575f9 100644 --- a/src/resolution.rs +++ b/src/resolution.rs @@ -41,62 +41,71 @@ impl UnresolvedValue { /// Creates an `UnresolvedValue` from a variant, using a class and property /// name to potentially allow for ambiguous Enum variants. pub fn from_variant(variant: Variant, class_name: &str, prop_name: &str) -> Self { - Self::Ambiguous(match variant { - Variant::Enum(rbx_enum) => { - if let Some(property) = find_descriptor(class_name, prop_name) { - if let DataType::Enum(enum_name) = &property.data_type { - let database = rbx_reflection_database::get(); - if let Some(enum_descriptor) = database.enums.get(enum_name) { - for (variant_name, id) in &enum_descriptor.items { - if *id == rbx_enum.to_u32() { - return Self::Ambiguous(AmbiguousValue::String( - variant_name.to_string(), - )); + let descriptor = find_descriptor(class_name, prop_name); + if descriptor.is_some() { + // We can only use an ambiguous syntax if the property is known + // to the reflection database. + Self::Ambiguous(match variant { + Variant::Enum(rbx_enum) => { + if let Some(property) = descriptor { + if let DataType::Enum(enum_name) = &property.data_type { + let database = rbx_reflection_database::get(); + if let Some(enum_descriptor) = database.enums.get(enum_name) { + for (variant_name, id) in &enum_descriptor.items { + if *id == rbx_enum.to_u32() { + return Self::Ambiguous(AmbiguousValue::String( + variant_name.to_string(), + )); + } } } } } + return Self::FullyQualified(variant); } - return Self::FullyQualified(variant); - } - Variant::Bool(bool) => AmbiguousValue::Bool(bool), - Variant::Float32(n) => AmbiguousValue::Number(n as f64), - Variant::Float64(n) => AmbiguousValue::Number(n), - Variant::Int32(n) => AmbiguousValue::Number(n as f64), - Variant::Int64(n) => AmbiguousValue::Number(n as f64), - Variant::String(str) => AmbiguousValue::String(str), - Variant::Tags(tags) => { - AmbiguousValue::StringArray(tags.iter().map(|s| s.to_string()).collect()) - } - Variant::Content(content) => AmbiguousValue::String(content.into_string()), - Variant::Vector2(vector) => AmbiguousValue::Array2([vector.x as f64, vector.y as f64]), - Variant::Vector3(vector) => { - AmbiguousValue::Array3([vector.x as f64, vector.y as f64, vector.z as f64]) - } - Variant::Color3(color) => { - AmbiguousValue::Array3([color.r as f64, color.g as f64, color.b as f64]) - } - Variant::CFrame(cf) => AmbiguousValue::Array12([ - cf.position.x as f64, - cf.position.y as f64, - cf.position.z as f64, - cf.orientation.x.x as f64, - cf.orientation.x.y as f64, - cf.orientation.x.z as f64, - cf.orientation.y.x as f64, - cf.orientation.y.y as f64, - cf.orientation.y.z as f64, - cf.orientation.z.x as f64, - cf.orientation.z.y as f64, - cf.orientation.z.z as f64, - ]), - Variant::Attributes(attr) => AmbiguousValue::Attributes(attr), - Variant::Font(font) => AmbiguousValue::Font(font), - Variant::MaterialColors(colors) => AmbiguousValue::MaterialColors(colors), - _ => { - return Self::FullyQualified(variant); - } - }) + Variant::Bool(bool) => AmbiguousValue::Bool(bool), + Variant::Float32(n) => AmbiguousValue::Number(n as f64), + Variant::Float64(n) => AmbiguousValue::Number(n), + Variant::Int32(n) => AmbiguousValue::Number(n as f64), + Variant::Int64(n) => AmbiguousValue::Number(n as f64), + Variant::String(str) => AmbiguousValue::String(str), + Variant::Tags(tags) => { + AmbiguousValue::StringArray(tags.iter().map(|s| s.to_string()).collect()) + } + Variant::Content(content) => AmbiguousValue::String(content.into_string()), + Variant::Vector2(vector) => { + AmbiguousValue::Array2([vector.x as f64, vector.y as f64]) + } + Variant::Vector3(vector) => { + AmbiguousValue::Array3([vector.x as f64, vector.y as f64, vector.z as f64]) + } + Variant::Color3(color) => { + AmbiguousValue::Array3([color.r as f64, color.g as f64, color.b as f64]) + } + Variant::CFrame(cf) => AmbiguousValue::Array12([ + cf.position.x as f64, + cf.position.y as f64, + cf.position.z as f64, + cf.orientation.x.x as f64, + cf.orientation.x.y as f64, + cf.orientation.x.z as f64, + cf.orientation.y.x as f64, + cf.orientation.y.y as f64, + cf.orientation.y.z as f64, + cf.orientation.z.x as f64, + cf.orientation.z.y as f64, + cf.orientation.z.z as f64, + ]), + Variant::Attributes(attr) => AmbiguousValue::Attributes(attr), + Variant::Font(font) => AmbiguousValue::Font(font), + Variant::MaterialColors(colors) => AmbiguousValue::MaterialColors(colors), + _ => { + return Self::FullyQualified(variant); + } + }) + } else { + Self::FullyQualified(variant) + } } /// Creates an `UnresolvedValue` from a variant, only returning ambiguous