diff --git a/Audit.md b/Audit.md index 8831902..eb5cab9 100644 --- a/Audit.md +++ b/Audit.md @@ -1,5 +1,13 @@ # Audit Log +## 2026-04-29 + +Found and fixed 3 issues: + +1. **Code quality: duplicated atomic-write in `OfflineQueue::save`** (sync.rs:332) — the function maintained its own copy of the temp-file + rename + cleanup-on-failure dance even though `storage::atomic_write` is `pub(crate)` and was already shared by `AppConfig::save_to_file` (fixed 04-25) and `google_tasks.rs`. Replaced the inline implementation with a call to `crate::storage::atomic_write`. +2. **Code quality: duplicated atomic-write in `SyncState::save`** (sync.rs:534) — same pattern as `OfflineQueue::save`. Replaced with a call to `atomic_write`, completing the consolidation of every per-call atomic write into a single shared helper. +3. **Code quality: redundant clone in `start_watcher`** (tauri/lib.rs:1206) — `start_watcher(handle: tauri::AppHandle, ...)` took `handle` by value, then immediately did `let handle = handle.clone();` before moving it into the file-watcher closure. The parameter was unused outside the closure, so the intermediate clone was pure waste. Removed it. + ## 2026-04-27 Found and fixed 3 issues: diff --git a/apps/tauri/src-tauri/src/lib.rs b/apps/tauri/src-tauri/src/lib.rs index eae1c25..a15ecbb 100644 --- a/apps/tauri/src-tauri/src/lib.rs +++ b/apps/tauri/src-tauri/src/lib.rs @@ -1203,7 +1203,6 @@ fn start_watcher(handle: tauri::AppHandle, path: PathBuf) { if let Ok(mut w) = WATCHER.lock() { *w = None; } - let handle = handle.clone(); let debouncer = new_debouncer( std::time::Duration::from_millis(500), move |events: Result, notify::Error>| { diff --git a/crates/onyx-core/src/sync.rs b/crates/onyx-core/src/sync.rs index 6bb626d..307337e 100644 --- a/crates/onyx-core/src/sync.rs +++ b/crates/onyx-core/src/sync.rs @@ -341,13 +341,7 @@ impl OfflineQueue { return Ok(()); } let content = serde_json::to_string_pretty(self)?; - // Atomic write: write to temp then rename - let temp_path = workspace_path.join(".syncqueue.json.tmp"); - std::fs::write(&temp_path, &content)?; - if let Err(e) = std::fs::rename(&temp_path, &queue_path) { - let _ = std::fs::remove_file(&temp_path); - return Err(e.into()); - } + atomic_write(&queue_path, content.as_bytes())?; Ok(()) } @@ -534,14 +528,7 @@ impl SyncState { pub fn save(&self, workspace_path: &Path) -> Result<()> { let state_path = workspace_path.join(".syncstate.json"); let content = serde_json::to_string_pretty(self)?; - // Atomic write: write to temp file then rename to prevent corruption on crash - 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()); - } + atomic_write(&state_path, content.as_bytes())?; Ok(()) }