Skip to content

io: remove the .sctmp temporary file when a save fails - #450

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
SteamSmith:fix/write-file-temp-cleanup
Oct 13, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
SteamSmith:fix/write-file-temp-cleanup

Conversation

@SteamSmith

Copy link
Copy Markdown
Contributor

Summary

crates/engine/src/io.rs write_file writes <path>.sctmp and then renames it over the target. If either step fails — a full disk, or the workbook held open/locked by another app (Excel, a sync client) so the rename is refused — the .sctmp file is left next to the user's workbook.

This change removes the temporary file whenever the write or the rename fails, and returns the same error as before. Successful saves are unchanged.

Test

  • New io::tests::failed_save_leaves_no_temporary_file: makes the rename fail by putting a folder where the workbook goes, then checks no .sctmp remains; also checks an ordinary save still works. It fails on main and passes with this change.
  • cargo fmt --all -- --check and cargo clippy -p gridcraft-engine --all-targets -- -D warnings are clean.
  • cargo test -p gridcraft-engine --no-fail-fast: identical results to main plus the new test.

Note (unrelated to this PR)

On Windows (rustc 1.99.0), two engine tests already fail on current main (3926d21) without this change: io::tests::csv_save_keeps_the_separator_it_was_opened_with and tests::saving_an_opened_semicolon_csv_keeps_semicolons. A large number is written as 1.24412E+11 where the tests expect 124412140710. They may pass on Linux CI; flagging in case it's platform-specific.

🤖 Generated with Claude Code

write_file writes `<path>.sctmp` and renames it over the workbook. When the
write or the rename failed (a full disk, or the target locked by another
app such as Excel or a sync client), the temporary file was left beside the
user's workbook. Remove it on either failure and report the same error.

Adds io::tests::failed_save_leaves_no_temporary_file, which fails before
this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit f4acdce into storytold:main Oct 13, 2026
@echelon

echelon commented Oct 13, 2026

Copy link
Copy Markdown
Member

Merged — thank you @SteamSmith for the contribution!

If you haven't already, come join us on Discord: https://discord.gg/artcraft

@SteamSmith

SteamSmith commented Oct 14, 2026 via email

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants