mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Refactor file handling in JobThreadContext and ApiService for improved metadata management
- Updated the logic for deriving file names in JobThreadContext to utilize encoded base names from filesystem paths, enhancing consistency and preserving character encoding. - Enhanced ApiService to differentiate between model files and other file types, ensuring correct handling of in-place updates and adjacent meta file creation for unsupported formats. - Improved logging for property persistence operations, providing clearer insights during file updates and enhancing debugging capabilities.
This commit is contained in:
parent
9912d86896
commit
e6121a651c
2 changed files with 70 additions and 20 deletions
|
|
@ -674,7 +674,6 @@ impl JobThreadContext {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some((actual_file, file_parent)) = init_result {
|
if let Some((actual_file, file_parent)) = init_result {
|
||||||
let name = instance.name();
|
|
||||||
let new_suffix = match new_class.as_str() {
|
let new_suffix = match new_class.as_str() {
|
||||||
"ModuleScript" => "",
|
"ModuleScript" => "",
|
||||||
"Script" => ".server",
|
"Script" => ".server",
|
||||||
|
|
@ -693,10 +692,28 @@ impl JobThreadContext {
|
||||||
} else {
|
} else {
|
||||||
format!("init{}.luau", new_suffix)
|
format!("init{}.luau", new_suffix)
|
||||||
}
|
}
|
||||||
} else if new_suffix.is_empty() {
|
|
||||||
format!("{}.luau", name)
|
|
||||||
} else {
|
} else {
|
||||||
format!("{}{}.luau", name, new_suffix)
|
// Derive the encoded base name from the
|
||||||
|
// filesystem path, not instance.name()
|
||||||
|
// (which is decoded). This preserves
|
||||||
|
// encoding like What%QUESTION% on disk.
|
||||||
|
let stem = actual_file
|
||||||
|
.file_stem()
|
||||||
|
.and_then(|s| s.to_str())
|
||||||
|
.unwrap_or("");
|
||||||
|
let known_suffixes = [
|
||||||
|
".server", ".client", ".plugin",
|
||||||
|
".local", ".legacy",
|
||||||
|
];
|
||||||
|
let base = known_suffixes
|
||||||
|
.iter()
|
||||||
|
.find_map(|s| stem.strip_suffix(s))
|
||||||
|
.unwrap_or(stem);
|
||||||
|
if new_suffix.is_empty() {
|
||||||
|
format!("{}.luau", base)
|
||||||
|
} else {
|
||||||
|
format!("{}{}.luau", base, new_suffix)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_path = file_parent.join(&new_file_name);
|
let new_path = file_parent.join(&new_file_name);
|
||||||
|
|
|
||||||
|
|
@ -2218,23 +2218,56 @@ impl ApiService {
|
||||||
meta_path.display()
|
meta_path.display()
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Non-script standalone file (e.g., .model.json5): update in place
|
// Non-script standalone file. Only .model.json5/.model.json support
|
||||||
let meta = self.merge_or_build_meta(
|
// in-place JSON property updates. Other file types (.txt, .csv, .toml,
|
||||||
inst_path,
|
// .yaml, etc.) require an adjacent .meta.json5 file — writing JSON
|
||||||
Some(class_name.as_str()),
|
// directly to them would corrupt their content.
|
||||||
properties,
|
let file_name = inst_path
|
||||||
attributes,
|
.file_name()
|
||||||
)?;
|
.and_then(|f| f.to_str())
|
||||||
let content = crate::json::to_vec_pretty_sorted(&meta)
|
.unwrap_or("");
|
||||||
.context("Failed to serialize model file")?;
|
let is_model_file = file_name.ends_with(".model.json5")
|
||||||
self.suppress_path(inst_path);
|
|| file_name.ends_with(".model.json");
|
||||||
fs::write(inst_path, &content)
|
|
||||||
.with_context(|| format!("Failed to write {}", inst_path.display()))?;
|
|
||||||
|
|
||||||
log::info!(
|
if is_model_file {
|
||||||
"Syncback: Persisted non-Source properties to {}",
|
let meta = self.merge_or_build_meta(
|
||||||
inst_path.display()
|
inst_path,
|
||||||
);
|
Some(class_name.as_str()),
|
||||||
|
properties,
|
||||||
|
attributes,
|
||||||
|
)?;
|
||||||
|
let content = crate::json::to_vec_pretty_sorted(&meta)
|
||||||
|
.context("Failed to serialize model file")?;
|
||||||
|
self.suppress_path(inst_path);
|
||||||
|
fs::write(inst_path, &content)
|
||||||
|
.with_context(|| format!("Failed to write {}", inst_path.display()))?;
|
||||||
|
|
||||||
|
log::info!(
|
||||||
|
"Syncback: Persisted non-Source properties to {}",
|
||||||
|
inst_path.display()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// For .txt, .csv, .toml, .yaml, etc. — use adjacent meta file
|
||||||
|
let parent_dir = inst_path.parent().context("No parent directory")?;
|
||||||
|
let file_stem = inst_path
|
||||||
|
.file_stem()
|
||||||
|
.and_then(|s| s.to_str())
|
||||||
|
.unwrap_or("");
|
||||||
|
let meta_path = parent_dir.join(format!("{}.meta.json5", file_stem));
|
||||||
|
|
||||||
|
let meta =
|
||||||
|
self.merge_or_build_meta(&meta_path, None, properties, attributes)?;
|
||||||
|
let content = crate::json::to_vec_pretty_sorted(&meta)
|
||||||
|
.context("Failed to serialize meta.json5")?;
|
||||||
|
self.suppress_path(&meta_path);
|
||||||
|
fs::write(&meta_path, &content)
|
||||||
|
.with_context(|| format!("Failed to write {}", meta_path.display()))?;
|
||||||
|
|
||||||
|
log::info!(
|
||||||
|
"Syncback: Persisted non-Source properties to {}",
|
||||||
|
meta_path.display()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue