refactor(sync): use shared atomic_write in SyncState::save
SyncState::save duplicated the temp+rename+cleanup-on-failure pattern that storage::atomic_write already provides. Replace the inline implementation with a call to atomic_write, completing the consolidation begun for AppConfig::save_to_file and OfflineQueue::save. https://claude.ai/code/session_01Vk2NBZGFP3YVshDj1CwDjt
This commit is contained in:
parent
80757345ab
commit
6c0d7257df
|
|
@ -528,14 +528,7 @@ impl SyncState {
|
||||||
pub fn save(&self, workspace_path: &Path) -> Result<()> {
|
pub fn save(&self, workspace_path: &Path) -> Result<()> {
|
||||||
let state_path = workspace_path.join(".syncstate.json");
|
let state_path = workspace_path.join(".syncstate.json");
|
||||||
let content = serde_json::to_string_pretty(self)?;
|
let content = serde_json::to_string_pretty(self)?;
|
||||||
// Atomic write: write to temp file then rename to prevent corruption on crash
|
atomic_write(&state_path, content.as_bytes())?;
|
||||||
let temp_path = workspace_path.join(".syncstate.json.tmp");
|
|
||||||
std::fs::write(&temp_path, &content)?;
|
|
||||||
if let Err(e) = std::fs::rename(&temp_path, &state_path) {
|
|
||||||
// Clean up temp file on rename failure to prevent accumulation
|
|
||||||
let _ = std::fs::remove_file(&temp_path);
|
|
||||||
return Err(e.into());
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue