mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Refactor file path handling in JobThreadContext and ApiService
- Streamlined the logic for encoding new file names and paths, enhancing consistency in file operations across both JobThreadContext and ApiService. - Improved readability by consolidating multiple lines of code into single statements, particularly in the handling of metadata file paths and script suffixes. - Enhanced error logging for snapshot retrieval in compute_and_apply_changes, ensuring better debugging capabilities during file operations.
This commit is contained in:
parent
e33cf7ae77
commit
9912d86896
2 changed files with 17 additions and 31 deletions
|
|
@ -520,8 +520,7 @@ impl JobThreadContext {
|
|||
.file_name()
|
||||
.and_then(|f| f.to_str())
|
||||
.unwrap_or("");
|
||||
let encoded_new_name =
|
||||
encode_path_name(new_name);
|
||||
let encoded_new_name = encode_path_name(new_name);
|
||||
let new_dir_path =
|
||||
grandparent.join(&encoded_new_name);
|
||||
|
||||
|
|
@ -549,12 +548,11 @@ impl JobThreadContext {
|
|||
dir_name
|
||||
));
|
||||
if old_meta.exists() {
|
||||
let new_meta = grandparent.join(
|
||||
format!(
|
||||
let new_meta =
|
||||
grandparent.join(format!(
|
||||
"{}.meta.json5",
|
||||
encoded_new_name
|
||||
),
|
||||
);
|
||||
));
|
||||
let _ =
|
||||
fs::rename(&old_meta, &new_meta);
|
||||
}
|
||||
|
|
@ -589,19 +587,13 @@ impl JobThreadContext {
|
|||
&stem[..stem.len() - script_suffix.len()]
|
||||
};
|
||||
|
||||
let encoded_new_name =
|
||||
encode_path_name(new_name);
|
||||
let encoded_new_name = encode_path_name(new_name);
|
||||
let new_file_name = if extension.is_empty() {
|
||||
format!(
|
||||
"{}{}",
|
||||
encoded_new_name, script_suffix
|
||||
)
|
||||
format!("{}{}", encoded_new_name, script_suffix)
|
||||
} else {
|
||||
format!(
|
||||
"{}{}.{}",
|
||||
encoded_new_name,
|
||||
script_suffix,
|
||||
extension
|
||||
encoded_new_name, script_suffix, extension
|
||||
)
|
||||
};
|
||||
let new_path = parent.join(&new_file_name);
|
||||
|
|
@ -621,10 +613,8 @@ impl JobThreadContext {
|
|||
);
|
||||
} else {
|
||||
overridden_source_path = Some(new_path.clone());
|
||||
let old_meta = parent.join(format!(
|
||||
"{}.meta.json5",
|
||||
old_base
|
||||
));
|
||||
let old_meta = parent
|
||||
.join(format!("{}.meta.json5", old_base));
|
||||
if old_meta.exists() {
|
||||
let new_meta = parent.join(format!(
|
||||
"{}.meta.json5",
|
||||
|
|
@ -897,14 +887,13 @@ fn compute_and_apply_changes(tree: &mut RojoTree, vfs: &Vfs, id: Ref) -> Option<
|
|||
snapshot_path.display()
|
||||
);
|
||||
|
||||
let snapshot =
|
||||
match snapshot_from_vfs(&metadata.context, vfs, snapshot_path) {
|
||||
Ok(snapshot) => snapshot,
|
||||
Err(err) => {
|
||||
log::error!("Snapshot error: {:?}", err);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
let snapshot = match snapshot_from_vfs(&metadata.context, vfs, snapshot_path) {
|
||||
Ok(snapshot) => snapshot,
|
||||
Err(err) => {
|
||||
log::error!("Snapshot error: {:?}", err);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
let patch_set = compute_patch_set(snapshot, tree, id);
|
||||
let applied = apply_patch_set(tree, patch_set);
|
||||
|
|
|
|||
|
|
@ -351,10 +351,7 @@ impl ApiService {
|
|||
// Strip known script suffixes (.server, .client, etc.)
|
||||
// rather than splitting on dots, so that names containing
|
||||
// dots (e.g. "Config.Client.server.luau") resolve correctly.
|
||||
if let Some(file_stem) = path
|
||||
.file_stem()
|
||||
.and_then(|s| s.to_str())
|
||||
{
|
||||
if let Some(file_stem) = path.file_stem().and_then(|s| s.to_str()) {
|
||||
let base_name = file_stem
|
||||
.strip_suffix(".server")
|
||||
.or_else(|| file_stem.strip_suffix(".client"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue