diff --git a/src/change_processor.rs b/src/change_processor.rs index 756423c7..f7717a9e 100644 --- a/src/change_processor.rs +++ b/src/change_processor.rs @@ -567,74 +567,73 @@ impl JobThreadContext { // For directory-format scripts, the path is the directory // (e.g., src/MyModule/), not the init file inside. We must // find and rename the init file, not the directory. - let (actual_file, file_parent) = if path.is_dir() { - // Find the init file inside the directory - let init_file = Self::find_init_file(path); - match init_file { - Some(f) => (f.clone(), path.to_path_buf()), - None => { - log::warn!( - "Cannot change ClassName for directory {} \ - — no init file found inside", - path.display() - ); - continue; - } - } + // Resolve the actual file to rename. For directories, + // find the init file inside; for files, use directly. + let init_result = if path.is_dir() { + Self::find_init_file(path) + .map(|f| (f.clone(), path.to_path_buf())) } else { - ( + Some(( path.clone(), path.parent() .unwrap_or(path.as_path()) .to_path_buf(), - ) + )) }; - let name = instance.name(); - let new_suffix = match new_class.as_str() { - "ModuleScript" => "", - "Script" => ".server", - "LocalScript" => ".local", - _ => "", - }; - let is_init = actual_file - .file_name() - .and_then(|f| f.to_str()) - .map(|f| f.starts_with("init.")) - .unwrap_or(false); + if let Some((actual_file, file_parent)) = init_result { + let name = instance.name(); + let new_suffix = match new_class.as_str() { + "ModuleScript" => "", + "Script" => ".server", + "LocalScript" => ".local", + _ => "", + }; + let is_init = actual_file + .file_name() + .and_then(|f| f.to_str()) + .map(|f| f.starts_with("init.")) + .unwrap_or(false); - let new_file_name = if is_init { - if new_suffix.is_empty() { - "init.luau".to_string() + let new_file_name = if is_init { + if new_suffix.is_empty() { + "init.luau".to_string() + } else { + format!("init{}.luau", new_suffix) + } + } else if new_suffix.is_empty() { + format!("{}.luau", name) } else { - format!("init{}.luau", new_suffix) - } - } else if new_suffix.is_empty() { - format!("{}.luau", name) - } else { - format!("{}{}.luau", name, new_suffix) - }; + format!("{}{}.luau", name, new_suffix) + }; - let new_path = file_parent.join(&new_file_name); - if new_path != actual_file { - log::info!( - "Two-way sync: Changing class {} -> {}, \ - renaming {} -> {}", - old_class, - new_class, - actual_file.display(), - new_path.display() - ); - if let Err(err) = - fs::rename(&actual_file, &new_path) - { - log::error!( - "Failed to rename {:?} to {:?}: {}", - actual_file, - new_path, - err + let new_path = file_parent.join(&new_file_name); + if new_path != actual_file { + log::info!( + "Two-way sync: Changing class {} -> {}, \ + renaming {} -> {}", + old_class, + new_class, + actual_file.display(), + new_path.display() ); + if let Err(err) = + fs::rename(&actual_file, &new_path) + { + log::error!( + "Failed to rename {:?} to {:?}: {}", + actual_file, + new_path, + err + ); + } } + } else { + log::warn!( + "Cannot change ClassName for directory {} \ + — no init file found inside", + path.display() + ); } } else if old_is_script != new_is_script { log::warn!( diff --git a/src/serve_session.rs b/src/serve_session.rs index baecb9c7..60430d25 100644 --- a/src/serve_session.rs +++ b/src/serve_session.rs @@ -178,7 +178,9 @@ impl ServeSession { /// Returns a handle to the suppressed paths map, used to avoid /// file watcher echo when the API writes files to disk. #[allow(dead_code)] - pub fn suppressed_paths(&self) -> Arc>> { + pub fn suppressed_paths( + &self, + ) -> Arc>> { Arc::clone(&self.suppressed_paths) } diff --git a/src/web/api.rs b/src/web/api.rs index cb60e36a..4d97aab7 100644 --- a/src/web/api.rs +++ b/src/web/api.rs @@ -180,7 +180,9 @@ impl ApiService { } else if let Some(parent) = path.parent() { if let Ok(canonical_parent) = std::fs::canonicalize(parent) { 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 { let gitkeep = dir_path.join(".gitkeep"); self.suppress_path(&gitkeep); - fs::write(gitkeep, b"") - .with_context(|| "Failed to write .gitkeep")?; + fs::write(gitkeep, b"").with_context(|| "Failed to write .gitkeep")?; } log::info!(