mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 14:01:37 +00:00
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.
This commit is contained in:
parent
73684a97bb
commit
033dec4e18
2 changed files with 28 additions and 13 deletions
|
|
@ -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")?,
|
||||
|
|
|
|||
|
|
@ -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())?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue