xgamesave: preserve last complete save when a newer version is incomplete or an old-layout blob is unreadable #673

Open
MasterWolf wants to merge 1 commit from MasterWolf/Darner:pr/post-merge-xgamesave-recovery into post-merge
First-time contributor

Not run in the game (verified via cargo build, cargo test, cargo clippy, and cargo check --workspace on a156401; container recovery and old-layout migration paths are covered by unit tests).

Contributor role (optional)

  • Fluxer ID: 1577824307575267331

What it changes

  • The problem on post-merge: read from crates/darner-hle/src/modules/xgamesave.rs (28a9b42, carried over from CNF without save-recovery hardening):
    1. current() deletes all older committed versions (v1..v(N-1)) before reading/validating the newest folder's manifest and verifying that every blob file 0..blobs.len() exists. If vN has a broken manifest or missing blob, every older save is erased and loading fails.
    2. current() propagates ? when removing .new leftovers or older v<old> directories; if a scanner or backup briefly holds a file in an old version folder, save reads/updates fail.
    3. current() accepts non-canonical v0 / v01 / v+1 names, and Update::submit() uses current.number + 1, which can collide with a skipped broken v(N+1) folder.
    4. migrate() silently skips blobs whose std::fs::read fails (filter_map), treats non-NotFound .display read errors as empty, and then deletes the old folder anyway.

This PR:

  • Splits manifest + blob-completeness validation into load() and scans committed canonical v<N> folders newest-first in current(), falling back to the highest complete version and deleting older versions (committed[at + 1..]) and .new leftovers on a best-effort basis only after a complete save is loaded.
  • Tracks highest version number in Version and adds next_version() so commits always step strictly above any existing canonical v<N> folder, even when a newer folder was skipped as incomplete.
  • Updates migrate() to keep the legacy folder intact if .display (other than NotFound) or any decoded blob fails to read, and leaves cleanup errors non-fatal after commit.
  • Adds 4 unit tests covering incomplete/corrupt newest-version fallback, non-canonical version filtering, unreadable old-layout blob preservation, and successful old-layout migration.

How it was tested

  • Tested revision: a156401 (on top of post-merge 28a9b42)
  • Commands and results:
    • cargo test --offline -p darner-hle --lib modules::xgamesave — 4 passed; 0 failed (0.04s)
    • cargo clippy --offline -p darner-hle --tests — passed (0 warnings in darner-hle)
    • cargo build --offline -p darner — passed (0 errors)
    • cargo check --offline --workspace — passed (0 errors)
  • Changes a default: no
  • A/B result: not applicable (save-integrity and error-recovery bugfix).
  • Checks run on that revision: cargo build, cargo test, cargo clippy, cargo check --workspace
  • Gameplay, when relevant: not run in the game
  • Hardware dependence: likely general (file locking behaviour is especially relevant on Windows)
  • Coverage gaps: tested with real filesystem operations in unit tests rather than an in-game launch.

Checklist

  • I ran this change in the game, or say below why it can't be (not run in the game; save container recovery and migration tested with real temp filesystem tests, build, and clippy).
  • This PR contains one change based on post-merge.
  • The diff contains no game files, code or assets.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found
  • Replaces or overlaps: none found
**Not run in the game** (verified via `cargo build`, `cargo test`, `cargo clippy`, and `cargo check --workspace` on `a156401`; container recovery and old-layout migration paths are covered by unit tests). ## Contributor role (optional) - Fluxer ID: 1577824307575267331 ## What it changes - The problem on `post-merge`: read from `crates/darner-hle/src/modules/xgamesave.rs` (`28a9b42`, carried over from CNF without save-recovery hardening): 1. `current()` deletes all older committed versions (`v1..v(N-1)`) **before** reading/validating the newest folder's `manifest` and verifying that every blob file `0..blobs.len()` exists. If `vN` has a broken manifest or missing blob, every older save is erased and loading fails. 2. `current()` propagates `?` when removing `.new` leftovers or older `v<old>` directories; if a scanner or backup briefly holds a file in an old version folder, save reads/updates fail. 3. `current()` accepts non-canonical `v0` / `v01` / `v+1` names, and `Update::submit()` uses `current.number + 1`, which can collide with a skipped broken `v(N+1)` folder. 4. `migrate()` silently skips blobs whose `std::fs::read` fails (`filter_map`), treats non-`NotFound` `.display` read errors as empty, and then deletes the old folder anyway. This PR: - Splits manifest + blob-completeness validation into `load()` and scans committed canonical `v<N>` folders newest-first in `current()`, falling back to the highest complete version and deleting older versions (`committed[at + 1..]`) and `.new` leftovers on a best-effort basis only *after* a complete save is loaded. - Tracks `highest` version number in `Version` and adds `next_version()` so commits always step strictly above any existing canonical `v<N>` folder, even when a newer folder was skipped as incomplete. - Updates `migrate()` to keep the legacy folder intact if `.display` (other than `NotFound`) or any decoded blob fails to read, and leaves cleanup errors non-fatal after commit. - Adds 4 unit tests covering incomplete/corrupt newest-version fallback, non-canonical version filtering, unreadable old-layout blob preservation, and successful old-layout migration. ## How it was tested - Tested revision: `a156401` (on top of `post-merge` `28a9b42`) - Commands and results: - `cargo test --offline -p darner-hle --lib modules::xgamesave` — `4 passed; 0 failed` (`0.04s`) - `cargo clippy --offline -p darner-hle --tests` — passed (0 warnings in `darner-hle`) - `cargo build --offline -p darner` — passed (0 errors) - `cargo check --offline --workspace` — passed (0 errors) - Changes a default: no - A/B result: not applicable (save-integrity and error-recovery bugfix). - Checks run on that revision: `cargo build`, `cargo test`, `cargo clippy`, `cargo check --workspace` - Gameplay, when relevant: not run in the game - Hardware dependence: likely general (file locking behaviour is especially relevant on Windows) - Coverage gaps: tested with real filesystem operations in unit tests rather than an in-game launch. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (not run in the game; save container recovery and migration tested with real temp filesystem tests, build, and clippy). - [x] This PR contains one change based on `post-merge`. - [x] The diff contains no game files, code or assets. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found - Replaces or overlaps: none found
TrustNo1 changed title from [pr-fix][saves] xgamesave: preserve last complete save when a newer version is incomplete or an old-layout blob is unreadable to xgamesave: preserve last complete save when a newer version is incomplete or an old-layout blob is unreadable 2026-12-06 03:25:18 +00:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'pr/post-merge-xgamesave-recovery:MasterWolf-pr/post-merge-xgamesave-recovery'
git switch 'MasterWolf-pr/post-merge-xgamesave-recovery'

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 'post-merge'
git merge --no-ff 'MasterWolf-pr/post-merge-xgamesave-recovery'
git switch 'MasterWolf-pr/post-merge-xgamesave-recovery'
git rebase 'post-merge'
git switch 'post-merge'
git merge --ff-only 'MasterWolf-pr/post-merge-xgamesave-recovery'
git switch 'MasterWolf-pr/post-merge-xgamesave-recovery'
git rebase 'post-merge'
git switch 'post-merge'
git merge --no-ff 'MasterWolf-pr/post-merge-xgamesave-recovery'
git switch 'post-merge'
git merge --squash 'MasterWolf-pr/post-merge-xgamesave-recovery'
git switch 'post-merge'
git merge --ff-only 'MasterWolf-pr/post-merge-xgamesave-recovery'
git switch 'post-merge'
git merge 'MasterWolf-pr/post-merge-xgamesave-recovery'
git push origin 'post-merge'
Sign in to join this conversation.
No reviewers
No milestone
No project
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.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!673
No description provided.