From 033dec4e18ed8ac61ab6f070afc7aa53de7693a0 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 15 Jan 2026 16:08:53 -0600 Subject: [PATCH] Refactor metadata file name generation in `syncback_lua` and `AdjacentMetadata` to strip known script type suffixes (.server, .client, .plugin) for improved compatibility. This change ensures accurate base name extraction for meta files while maintaining handling of Windows-invalid characters. --- src/snapshot_middleware/lua.rs | 30 ++++++++++++++++++---------- src/snapshot_middleware/meta_file.rs | 11 ++++++++-- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index 5e691e78..88e5ac3f 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -159,20 +159,28 @@ pub fn syncback_lua<'sync>( if !meta.is_empty() { let parent_location = snapshot.path.parent_err()?; - // Use the file stem from the script path (e.g., "Foo.server" from "Foo.server.luau") - // to match how AdjacentMetadata::read_and_apply_all looks for meta files. - let meta_name = snapshot + // Use the base name from the script path, stripping the script type suffix + // (e.g., "Foo" from "Foo.server.luau") to match how AdjacentMetadata::read_and_apply_all + // looks for meta files. + let file_stem = snapshot .path .file_stem() .and_then(|s| s.to_str()) - .map(|s| s.to_string()) - .unwrap_or_else(|| { - if snapshot.encode_windows_invalid_chars() { - encode_path_name(&new_inst.name) - } else { - new_inst.name.clone() - } - }); + .unwrap_or(""); + let meta_name = file_stem + .strip_suffix(".server") + .or_else(|| file_stem.strip_suffix(".client")) + .or_else(|| file_stem.strip_suffix(".plugin")) + .unwrap_or(file_stem); + let meta_name = if meta_name.is_empty() { + if snapshot.encode_windows_invalid_chars() { + encode_path_name(&new_inst.name) + } else { + new_inst.name.clone() + } + } else { + meta_name.to_string() + }; fs_snapshot.add_file( parent_location.join(format!("{}.meta.json", meta_name)), crate::json::to_vec_pretty_sorted(&meta).context("cannot serialize metadata")?, diff --git a/src/snapshot_middleware/meta_file.rs b/src/snapshot_middleware/meta_file.rs index eef96bff..1fa99b63 100644 --- a/src/snapshot_middleware/meta_file.rs +++ b/src/snapshot_middleware/meta_file.rs @@ -55,12 +55,19 @@ impl AdjacentMetadata { // Use the file stem from the actual path (which has encoded chars) // rather than the decoded name, so meta files are found correctly // when encodeWindowsInvalidChars is enabled. + // Strip known script type suffixes (.server, .client, .plugin) to get + // the base name for the meta file. let file_stem = path .file_stem() .and_then(|s| s.to_str()) .unwrap_or(""); - let meta_path_json = path.with_file_name(format!("{file_stem}.meta.json")); - let meta_path_jsonc = path.with_file_name(format!("{file_stem}.meta.jsonc")); + let base_name = file_stem + .strip_suffix(".server") + .or_else(|| file_stem.strip_suffix(".client")) + .or_else(|| file_stem.strip_suffix(".plugin")) + .unwrap_or(file_stem); + let meta_path_json = path.with_file_name(format!("{base_name}.meta.json")); + let meta_path_jsonc = path.with_file_name(format!("{base_name}.meta.jsonc")); if let Some(meta_contents) = vfs.read(&meta_path_json).with_not_found()? { let mut metadata = Self::from_slice(&meta_contents, meta_path_json.clone())?;