Save import and settings: a crash leaves the old or the new, never a part #819

Open
0xkn0wh3r3 wants to merge 2 commits from upstream-pr/819 into main
0xkn0wh3r3 commented 2026-11-28 07:02:30 +00:00 (Migrated from github.com)

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.

  • Staging went straight into 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.
  • Putting an import in place removed the old part before renaming the new one to its name. A crash between the two left no save at all. A crash between the two parts (saves, then storage) left one part of each, and the next start didn't finish the job, because import-pending\saves had already been moved.
  • The F1 settings file was written in place. A crash while saving left it empty or cut short, and every setting saved there was gone. The launcher's MFG Unlocker choice is written to the same file the same way.

What

  • Staging writes into import-pending.part, flushing each file to the disk, then renames it to import-pending once all of it is there. A .part folder left by a crash is removed at the next start.
  • An apply marks itself as begun before it moves a part: import-pending\applying, which holds the backup's path. Until import-pending is 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.
  • A part being replaced is renamed aside (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 .replaced folders are tidied at the next start: put back where their place is empty, removed where the import took it.
  • Settings go through victory_core::fs::replace: written whole to <file>.new, flushed to the disk, then renamed over the file.
  • New module victory_core::fs holds write_synced (write, then sync_all), sync and replace. victory-gpu now depends on victory-core for it.
  • Clippy: the four findings that stop CI on main (Rust 1.98) is the same commit as in #816. Without it, main itself fails clippy. Drop it if main fixes 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::exit at 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_whole covers eight steps, using a save with both parts and the player's own settings container:

    step the game dies at save after the next start
    stage:file: while the import is being written old
    stage:written: written, not yet marked as waiting old
    apply:backed-up: backup made, apply not yet marked new
    apply:saves-aside: old saves set aside, new not yet in place new
    apply:saves-placed: new saves in place, storage not yet new
    apply:storage-aside new
    apply:storage-placed new
    apply:placed: both in place, import-pending not yet removed new

    At every step, the test checks that:

    • every file of the save is from the same save, never one part of each;
    • the player's game settings are kept;
    • where the import went in, the backup it reports restores the old save;
    • nothing is left in the save folder beside saves and storage;
    • a further start does nothing.
  • fs::tests::a_settings_file_replaced_by_a_process_that_dies_is_whole stops replace between the write and the rename. The old file is whole, and the next replace reuses the .new file and leaves nothing beside it.

Other tests:

  • an_import_that_cannot_be_put_in_place_leaves_the_save_as_it_was holds 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_whole simulates the leftovers directly (a half-staged folder, a part set aside) without a child process.
  • written_and_synced_files_hold_their_bytes and a_replaced_file_holds_the_new_bytes_and_nothing_is_left_beside_it cover victory_core::fs.

Checked against the old behaviour. With staging pointed back at import-pending, the crash test fails at stage: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.
  • The same with --all-features: passes.
  • cargo test --workspace --locked: passes. 1,132 passed, 0 failed, 51 ignored.

Not covered:

  • A real power cut. Whether the flushed bytes really reach the disk is up to Windows and the drive. The tests stop the process; they don't cut the power.
  • Not yet tried by importing a save in the game.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5537687637 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/819). Originally posted by [0xkn0wh3r3](https://github.com/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. - **Staging went straight into `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. - **Putting an import in place removed the old part before renaming the new one to its name.** A crash between the two left no save at all. A crash between the two parts (`saves`, then `storage`) left one part of each, and the next start didn't finish the job, because `import-pending\saves` had already been moved. - **The F1 settings file was written in place.** A crash while saving left it empty or cut short, and every setting saved there was gone. The launcher's MFG Unlocker choice is written to the same file the same way. ## What - **Staging** writes into `import-pending.part`, flushing each file to the disk, then renames it to `import-pending` once all of it is there. A `.part` folder left by a crash is removed at the next start. - **An apply marks itself as begun** before it moves a part: `import-pending\applying`, which holds the backup's path. Until `import-pending` is 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. - **A part being replaced is renamed aside** (`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 `.replaced` folders are tidied at the next start: put back where their place is empty, removed where the import took it. - **Settings** go through `victory_core::fs::replace`: written whole to `<file>.new`, flushed to the disk, then renamed over the file. - **New module `victory_core::fs`** holds `write_synced` (write, then `sync_all`), `sync` and `replace`. `victory-gpu` now depends on `victory-core` for it. - **`Clippy: the four findings that stop CI on main (Rust 1.98)`** is the same commit as in #816. Without it, `main` itself fails clippy. Drop it if `main` fixes 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::exit` at 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_whole` covers eight steps, using a save with both parts and the player's own settings container: | step the game dies at | save after the next start | |---|---| | `stage:file`: while the import is being written | old | | `stage:written`: written, not yet marked as waiting | old | | `apply:backed-up`: backup made, apply not yet marked | new | | `apply:saves-aside`: old `saves` set aside, new not yet in place | new | | `apply:saves-placed`: new `saves` in place, `storage` not yet | new | | `apply:storage-aside` | new | | `apply:storage-placed` | new | | `apply:placed`: both in place, `import-pending` not yet removed | new | At every step, the test checks that: - every file of the save is from the same save, never one part of each; - the player's game settings are kept; - where the import went in, the backup it reports restores the old save; - nothing is left in the save folder beside `saves` and `storage`; - a further start does nothing. - `fs::tests::a_settings_file_replaced_by_a_process_that_dies_is_whole` stops `replace` between the write and the rename. The old file is whole, and the next replace reuses the `.new` file and leaves nothing beside it. **Other tests:** - `an_import_that_cannot_be_put_in_place_leaves_the_save_as_it_was` holds 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_whole` simulates the leftovers directly (a half-staged folder, a part set aside) without a child process. - `written_and_synced_files_hold_their_bytes` and `a_replaced_file_holds_the_new_bytes_and_nothing_is_left_beside_it` cover `victory_core::fs`. **Checked against the old behaviour.** With staging pointed back at `import-pending`, the crash test fails at `stage: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. - The same with `--all-features`: passes. - `cargo test --workspace --locked`: passes. 1,132 passed, 0 failed, 51 ignored. **Not covered:** - A real power cut. Whether the flushed bytes really reach the disk is up to Windows and the drive. The tests stop the process; they don't cut the power. - Not yet tried by importing a save in the game.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/819:upstream-pr/819'
git switch 'upstream-pr/819'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/819'
git switch 'upstream-pr/819'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/819'
git switch 'upstream-pr/819'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/819'
git switch 'main'
git merge --squash 'upstream-pr/819'
git switch 'main'
git merge --ff-only 'upstream-pr/819'
git switch 'main'
git merge 'upstream-pr/819'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!819
No description provided.