refactor(config): reuse storage::atomic_write for save_to_file
`AppConfig::save_to_file` had its own copy of the temp-file + rename + cleanup-on-failure dance. `storage::atomic_write` is already `pub(crate)` and does exactly that — `google_tasks.rs` was migrated to use it earlier. Drop the duplicate so there's one canonical atomic write path in the crate.
This commit is contained in:
parent
069afe8d5e
commit
8c8735b2b4
|
|
@ -116,13 +116,7 @@ impl AppConfig {
|
|||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
let content = serde_json::to_string_pretty(&self)?;
|
||||
// Atomic write: write to temp file then rename to prevent corruption on crash
|
||||
let temp = path.with_extension("tmp");
|
||||
std::fs::write(&temp, &content)?;
|
||||
if let Err(e) = std::fs::rename(&temp, path) {
|
||||
let _ = std::fs::remove_file(&temp);
|
||||
return Err(e.into());
|
||||
}
|
||||
crate::storage::atomic_write(path, content.as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue