From 8c8735b2b4b172fc285284575abfbf248a8501e9 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 25 Apr 2026 07:27:25 +0000 Subject: [PATCH] refactor(config): reuse storage::atomic_write for save_to_file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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. --- crates/onyx-core/src/config.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/crates/onyx-core/src/config.rs b/crates/onyx-core/src/config.rs index 1ad7769..e5af3fc 100644 --- a/crates/onyx-core/src/config.rs +++ b/crates/onyx-core/src/config.rs @@ -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(()) }