MCPcopy Create free account
hub / github.com/cortexkit/magic-context / write_config_atomic

Function write_config_atomic

packages/dashboard/src-tauri/src/config.rs:195–217  ·  view source on GitHub ↗
(
    path: &Path,
    content: &str,
    project_root: Option<&Path>,
)

Source from the content-addressed store, hash-verified

193}
194
195fn 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
219fn create_temp_config_file(
220 parent: &Path,

Callers 2

write_configFunction · 0.85
write_project_configFunction · 0.85

Calls 3

create_temp_config_fileFunction · 0.85
replace_with_tempFunction · 0.85

Tested by

no test coverage detected