Save import and settings: a crash leaves the old or the new, never a part #819
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/819"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 0xkn0wh3r3 on 2026-11-28T07:02:30Z.
Why
Importing a shared save, and saving the F1 settings, could each lose the player's data if the game died at the wrong moment: killed, crashed, closed from the taskbar, or the PC losing power.
import-pending. An import cut short while it was being written still looked staged, and the next start put the half-written import in place.saves, thenstorage) left one part of each, and the next start didn't finish the job, becauseimport-pending\saveshad already been moved.What
import-pending.part, flushing each file to the disk, then renames it toimport-pendingonce all of it is there. A.partfolder left by a crash is removed at the next start.import-pending\applying, which holds the backup's path. Untilimport-pendingis removed,staged()stays true and the next start finishes the apply with that same backup. So the save always ends up the old one or the import, whole.saves.replaced) and removed only once the import's part has its name. If the import's part can be neither moved nor copied (another program holding a file of it), the part set aside goes back, with the player's game settings, and the import waits for the next start. Leftover.replacedfolders are tidied at the next start: put back where their place is empty, removed where the import took it.victory_core::fs::replace: written whole to<file>.new, flushed to the disk, then renamed over the file.victory_core::fsholdswrite_synced(write, thensync_all),syncandreplace.victory-gpunow depends onvictory-corefor it.Clippy: the four findings that stop CI on main (Rust 1.98)is the same commit as in #816. Without it,mainitself fails clippy. Drop it ifmainfixes them first.Tests
Acceptance (crash) tests. These run the real code in a child process (the test binary re-run on one ignored test) and stop it with
process::exitat a named step. That's like a crash: nothing after the step runs, and no cleanup or destructors happen. The parent then does what the next start does.save_share::tests::a_game_that_dies_anywhere_in_an_import_leaves_one_save_wholecovers eight steps, using a save with both parts and the player's own settings container:stage:file: while the import is being writtenstage:written: written, not yet marked as waitingapply:backed-up: backup made, apply not yet markedapply:saves-aside: oldsavesset aside, new not yet in placeapply:saves-placed: newsavesin place,storagenot yetapply:storage-asideapply:storage-placedapply:placed: both in place,import-pendingnot yet removedAt every step, the test checks that:
savesandstorage;fs::tests::a_settings_file_replaced_by_a_process_that_dies_is_wholestopsreplacebetween the write and the rename. The old file is whole, and the next replace reuses the.newfile and leaves nothing beside it.Other tests:
an_import_that_cannot_be_put_in_place_leaves_the_save_as_it_washolds a file of the staged import open with no sharing, so the part can be neither renamed nor copied. The apply fails, the save is the old one with the player's settings, and the import still waits. With the file closed, the next start puts it in place.an_import_cut_short_leaves_one_save_wholesimulates the leftovers directly (a half-staged folder, a part set aside) without a child process.written_and_synced_files_hold_their_bytesanda_replaced_file_holds_the_new_bytes_and_nothing_is_left_beside_itcovervictory_core::fs.Checked against the old behaviour. With staging pointed back at
import-pending, the crash test fails atstage:file. With the old part removed instead of set aside, the held-file test fails, because the old save is gone. With the settings not moved back on a failed apply, the held-file test fails on the settings.CI steps run locally on this branch:
cargo clippy --workspace --all-targets --locked -- -D warnings: passes.--all-features: passes.cargo test --workspace --locked: passes. 1,132 passed, 0 failed, 51 ignored.Not covered:
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.