XGameSave: a stray or unreadable version folder never costs the save (#870) #1728

Merged
moe-miau merged 1 commit from upstream-pr/1729 into main 2026-11-25 00:09:52 +00:00
moe-miau commented 2026-11-24 21:27:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by moe-miau on 2026-11-24T21:27:01Z.


Fixes #870, including the case found in the review of the earlier attempts.

The three PRs for #870 (#1006, #1035, #1102) were closed by their authors, so nothing open fixes it on its own. As measured in the issue, they covered v01-style names but not a correctly named stray: an empty v2, a file named v2, or a v2 with a broken manifest next to a committed v1 still cost the save. v1 was pruned as older, the read failed, and the next update returned S_OK while committing a fresh v1 with only the changed blobs, which the following read pruned again.

Change (crates/victory-hle/src/modules/xgamesave.rs only)

  • Only v<N> exactly as commit writes it is a version (version_number): no leading zeros, no sign, not v0. v01, v+1, v001 are neither read, counted nor removed.
  • current takes the newest version whose manifest reads, removes only versions below it, and leaves unreadable newer entries alone. Only directories are versions.
  • An update goes above the highest version name present (Version::highest), so a stray v2 neither hides the save nor blocks writes; the next read then treats the stray as older and removes it.
  • With no readable version at all, reads and updates still fail (NO_ACCESS) and nothing is removed, as before.

This follows the "fuller fix" in winne42's comment on #870. A crash between commit's rename and the removal of the old version still leaves two readable versions, of which the newer one wins, as before.

Tests

Three synthetic tests in temporary directories (no game data):

  • a_noncanonical_folder_does_not_remove_a_committed_save: v01, v001, v+1, v0, v02 next to v1.
  • an_unreadable_newer_version_does_not_cost_the_save: an empty v2 folder, a file named v2, and a v2 with a broken manifest. Each reads the old save, keeps v1, then updates (lands as v3 with the kept blob), and reads again.
  • no_readable_version_is_refused_and_kept: a corrupt only version is refused for read and update and stays on disk.

The first two fail on main (ffe310e) with only the tests applied (the committed save is removed), and pass with the change. The existing crash test (a_kill_at_any_step_leaves_old_or_new) and the other save tests pass unchanged.

On Windows 11 x64, Rust 1.98.1 MSVC:

  • cargo clippy --workspace --all-targets --locked -- -D warnings, and the --all-features variant: clean
  • cargo test --workspace --locked: pass (victory-hle: 97 passed)
  • cargo xtask policy: ok

AI-assisted (Claude Code); I reviewed the change and ran the checks.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6591752505 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1729). Originally posted by [moe-miau](https://github.com/moe-miau) on 2026-11-24T21:27:01Z. --- Fixes #870, including the case found in the review of the earlier attempts. The three PRs for #870 (#1006, #1035, #1102) were closed by their authors, so nothing open fixes it on its own. As measured in the issue, they covered `v01`-style names but not a correctly named stray: an empty `v2`, a file named `v2`, or a `v2` with a broken manifest next to a committed `v1` still cost the save. `v1` was pruned as older, the read failed, and the next update returned `S_OK` while committing a fresh `v1` with only the changed blobs, which the following read pruned again. ## Change (`crates/victory-hle/src/modules/xgamesave.rs` only) - **Only `v<N>` exactly as `commit` writes it is a version** (`version_number`): no leading zeros, no sign, not `v0`. `v01`, `v+1`, `v001` are neither read, counted nor removed. - **`current` takes the newest version whose manifest reads**, removes only versions below it, and leaves unreadable newer entries alone. Only directories are versions. - **An update goes above the highest version name present** (`Version::highest`), so a stray `v2` neither hides the save nor blocks writes; the next read then treats the stray as older and removes it. - **With no readable version at all**, reads and updates still fail (`NO_ACCESS`) and nothing is removed, as before. This follows the "fuller fix" in winne42's comment on #870. A crash between `commit`'s rename and the removal of the old version still leaves two readable versions, of which the newer one wins, as before. ## Tests Three synthetic tests in temporary directories (no game data): - `a_noncanonical_folder_does_not_remove_a_committed_save`: `v01`, `v001`, `v+1`, `v0`, `v02` next to `v1`. - `an_unreadable_newer_version_does_not_cost_the_save`: an empty `v2` folder, a file named `v2`, and a `v2` with a broken manifest. Each reads the old save, keeps `v1`, then updates (lands as `v3` with the kept blob), and reads again. - `no_readable_version_is_refused_and_kept`: a corrupt only version is refused for read and update and stays on disk. The first two fail on `main` (`ffe310e`) with only the tests applied (the committed save is removed), and pass with the change. The existing crash test (`a_kill_at_any_step_leaves_old_or_new`) and the other save tests pass unchanged. On Windows 11 x64, Rust 1.98.1 MSVC: - `cargo clippy --workspace --all-targets --locked -- -D warnings`, and the `--all-features` variant: clean - `cargo test --workspace --locked`: pass (`victory-hle`: 97 passed) - `cargo xtask policy`: ok AI-assisted (Claude Code); I reviewed the change and ran the checks. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
catminou4 commented 2026-11-24 22:02:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:36:45Z.

Review: COMMENTED


Static review only: this crate is Windows-only (D3D12/windows_sys/Win32) — nothing compiles or runs on macOS; source review of the diff.

XGameSave stray/unreadable version folders: version_number() accepts only canonical 'v' (rejects v01, v+1, v0 via format round-trip), load() treats a missing manifest as Ok(None) and a parse failure as None too, and 'highest' tracks the max version across entries so the next commit goes above it. The canonical-name check is a nice guard against weird folder names. HLE is Windows-only — static review.

<!-- greyfinch-sync:Marvisak/VIctory:review:6047808431 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1729#pullrequestreview-6047808431). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T21:36:45Z. **Review:** COMMENTED --- Static review only: this crate is Windows-only (D3D12/windows_sys/Win32) — nothing compiles or runs on macOS; source review of the diff. XGameSave stray/unreadable version folders: version_number() accepts only canonical 'v<N>' (rejects v01, v+1, v0 via format round-trip), load() treats a missing manifest as Ok(None) and a parse failure as None too, and 'highest' tracks the max version across entries so the next commit goes above it. The canonical-name check is a nice guard against weird folder names. HLE is Windows-only — static review.
kais7654 commented 2026-11-24 23:06:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kais7654 on 2026-11-24T22:49:46Z.


Reviewed and verified: 10/10 xgamesave tests pass on Windows, including
the three new ones — a stray v01 no longer removes the committed
save, an unreadable newer version neither hides nor prunes it and the
next update goes above it, and with nothing readable nothing is removed
and reads fail. Canonical v<N> only, directories only, highest + 1
to commit: solid.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146692477 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1729#issuecomment-7146692477). Originally posted by [kais7654](https://github.com/kais7654) on 2026-11-24T22:49:46Z. --- Reviewed and verified: 10/10 xgamesave tests pass on Windows, including the three new ones — a stray `v01` no longer removes the committed save, an unreadable newer version neither hides nor prunes it and the next update goes above it, and with nothing readable nothing is removed and reads fail. Canonical `v<N>` only, directories only, `highest + 1` to commit: solid.
upstream-sync closed this pull request 2026-11-25 01:07:06 +00:00
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
Marvisak/VIctory!1728
No description provided.