Repository navigation
engine: close the AutoRecover temporary file before the rename - #2286
tomaszstaniak wants to merge 1 commit into
Conversation
write_atomic renamed the temporary file over the recovery entry while the file was still open. On a system whose rename needs the source to itself, such as AROS, replacing an existing entry then fails with "File exists" and the entry is not updated. The file is now closed first, as io::write_file already does; the temporary file is still removed when the rename fails.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
AI-generated review (Claude Opus 5.5). Not a maintainer decision.
No blocking problems found.
write_atomic now closes the temporary file before renaming it over the recovery entry, as io::write_file already does, and keeps the cleanup when the write or the rename fails.
- crates/engine/src/recovery.rs:98-103: the write result is kept, the file is dropped, then the rename runs only if the write and sync succeeded. This is the same order as crates/engine/src/io.rs:62-64.
- crates/engine/src/recovery.rs:104: if the write, sync or rename fails, the temporary file is still removed. It is now closed before removal, which also helps on platforms that will not delete an open file.
- Error messages are unchanged: a write, sync or rename failure is still reported against the entry path.
- The settings writer (crates/ui-egui/src/settings.rs:44) uses std::fs::write, which closes the file before its rename, so no other write-then-rename path needs the same change.
Claims checked:
- verified: write_atomic closes the temporary file before renaming it, the way io::write_file does (crates/engine/src/recovery.rs:98 keeps the write/sync result, :102 drops the file, :103 renames only afterwards. crates/engine/src/io.rs:62-64 uses the same order (written, drop(file), rename).)
- verified: The temporary file is still removed when the rename fails (crates/engine/src/recovery.rs:103-105: map_err on the combined write/sync/rename result calls std::fs::remove_file(&tmp) before returning the error.)
- verified: Nothing else changes (The diff only touches crates/engine/src/recovery.rs:98-103. The open options (:90-97), error text (:105) and callers (save at :158/:160, open at :226) are unchanged.)
- verified: Fixes issue 2285: updating an existing AutoRecover entry fails on systems whose rename needs exclusive access to the source (crates/engine/src/recovery.rs:102 drops the handle before the rename at :103, which removes the open-source-during-rename pattern the issue describes. The AROS behaviour itse…
Reviewed at 89b1e75.
Recommendation: merge, after a maintainer's decision.
Fixes #2285.
recovery::write_atomicnow closes the temporary file before renaming it over the recovery entry, the wayio::write_filealready does. On a system whose rename needs the source to itself (AROS: its C library replaces an existing destination only when it can lock the source exclusively), an update of an existing AutoRecover entry fails with "File exists" (the same pattern broke saving in a GridCraft port there). The temporary file is still removed when the rename fails; nothing else changes.Testing:
cargo test -p deckcraft-engine: 614 passed, 0 failed (macOS). The 6 recovery tests pass.cargo clippy -p deckcraft-engine --all-targets: nothing inrecovery.rs.No new test: on Linux, macOS and Windows a rename over an existing file succeeds with the source still open, so a test cannot fail without the fix on the platforms CI runs. I could not find a way to observe the open handle at the moment of the rename without adding a hook to production code only for the test; I can add one if you prefer that.
Summary by CodeRabbit