mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Refactor file renaming logic in JobThreadContext and improve path handling
- Simplified the logic for resolving the actual file to rename, consolidating the handling of directory and file paths. - Enhanced the script renaming process to ensure correct naming conventions based on class type, improving clarity and consistency. - Updated logging to provide better insights during class name changes and file renaming operations, aiding in debugging. - Made minor formatting adjustments to improve code readability in the `suppressed_paths` method and API service file handling.
This commit is contained in:
parent
f38c96e12b
commit
e6944e3132
3 changed files with 62 additions and 60 deletions
|
|
@ -567,29 +567,21 @@ impl JobThreadContext {
|
||||||
// For directory-format scripts, the path is the directory
|
// For directory-format scripts, the path is the directory
|
||||||
// (e.g., src/MyModule/), not the init file inside. We must
|
// (e.g., src/MyModule/), not the init file inside. We must
|
||||||
// find and rename the init file, not the directory.
|
// find and rename the init file, not the directory.
|
||||||
let (actual_file, file_parent) = if path.is_dir() {
|
// Resolve the actual file to rename. For directories,
|
||||||
// Find the init file inside the directory
|
// find the init file inside; for files, use directly.
|
||||||
let init_file = Self::find_init_file(path);
|
let init_result = if path.is_dir() {
|
||||||
match init_file {
|
Self::find_init_file(path)
|
||||||
Some(f) => (f.clone(), path.to_path_buf()),
|
.map(|f| (f.clone(), path.to_path_buf()))
|
||||||
None => {
|
|
||||||
log::warn!(
|
|
||||||
"Cannot change ClassName for directory {} \
|
|
||||||
— no init file found inside",
|
|
||||||
path.display()
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
(
|
Some((
|
||||||
path.clone(),
|
path.clone(),
|
||||||
path.parent()
|
path.parent()
|
||||||
.unwrap_or(path.as_path())
|
.unwrap_or(path.as_path())
|
||||||
.to_path_buf(),
|
.to_path_buf(),
|
||||||
)
|
))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if let Some((actual_file, file_parent)) = init_result {
|
||||||
let name = instance.name();
|
let name = instance.name();
|
||||||
let new_suffix = match new_class.as_str() {
|
let new_suffix = match new_class.as_str() {
|
||||||
"ModuleScript" => "",
|
"ModuleScript" => "",
|
||||||
|
|
@ -636,6 +628,13 @@ impl JobThreadContext {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log::warn!(
|
||||||
|
"Cannot change ClassName for directory {} \
|
||||||
|
— no init file found inside",
|
||||||
|
path.display()
|
||||||
|
);
|
||||||
|
}
|
||||||
} else if old_is_script != new_is_script {
|
} else if old_is_script != new_is_script {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"Cannot change ClassName from {} to {} — \
|
"Cannot change ClassName from {} to {} — \
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,9 @@ impl ServeSession {
|
||||||
/// Returns a handle to the suppressed paths map, used to avoid
|
/// Returns a handle to the suppressed paths map, used to avoid
|
||||||
/// file watcher echo when the API writes files to disk.
|
/// file watcher echo when the API writes files to disk.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn suppressed_paths(&self) -> Arc<Mutex<std::collections::HashMap<std::path::PathBuf, usize>>> {
|
pub fn suppressed_paths(
|
||||||
|
&self,
|
||||||
|
) -> Arc<Mutex<std::collections::HashMap<std::path::PathBuf, usize>>> {
|
||||||
Arc::clone(&self.suppressed_paths)
|
Arc::clone(&self.suppressed_paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,9 @@ impl ApiService {
|
||||||
} else if let Some(parent) = path.parent() {
|
} else if let Some(parent) = path.parent() {
|
||||||
if let Ok(canonical_parent) = std::fs::canonicalize(parent) {
|
if let Ok(canonical_parent) = std::fs::canonicalize(parent) {
|
||||||
if let Some(file_name) = path.file_name() {
|
if let Some(file_name) = path.file_name() {
|
||||||
*suppressed.entry(canonical_parent.join(file_name)).or_insert(0) += 1;
|
*suppressed
|
||||||
|
.entry(canonical_parent.join(file_name))
|
||||||
|
.or_insert(0) += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1545,8 +1547,7 @@ impl ApiService {
|
||||||
if !has_children && !has_metadata {
|
if !has_children && !has_metadata {
|
||||||
let gitkeep = dir_path.join(".gitkeep");
|
let gitkeep = dir_path.join(".gitkeep");
|
||||||
self.suppress_path(&gitkeep);
|
self.suppress_path(&gitkeep);
|
||||||
fs::write(gitkeep, b"")
|
fs::write(gitkeep, b"").with_context(|| "Failed to write .gitkeep")?;
|
||||||
.with_context(|| "Failed to write .gitkeep")?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue