(
path: &Path,
content: &str,
project_root: Option<&Path>,
)
| 193 | } |
| 194 | |
| 195 | fn write_config_atomic( |
| 196 | path: &Path, |
| 197 | content: &str, |
| 198 | project_root: Option<&Path>, |
| 199 | ) -> Result<(), String> { |
| 200 | let parent = path |
| 201 | .parent() |
| 202 | .ok_or_else(|| "Config path has no parent directory".to_string())?; |
| 203 | std::fs::create_dir_all(parent).map_err(|e| format!("Failed to create directory: {e}"))?; |
| 204 | |
| 205 | let temp_path = create_temp_config_file(parent, path.file_name(), content)?; |
| 206 | if let Some(root) = project_root { |
| 207 | if let Err(e) = validate_project_config_target(root, path) { |
| 208 | let _ = std::fs::remove_file(&temp_path); |
| 209 | return Err(e); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | replace_with_temp(&temp_path, path).map_err(|e| { |
| 214 | let _ = std::fs::remove_file(&temp_path); |
| 215 | format!("Failed to replace config atomically: {e}") |
| 216 | }) |
| 217 | } |
| 218 | |
| 219 | fn create_temp_config_file( |
| 220 | parent: &Path, |
no test coverage detected