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

Manually merged
github merged 1 commit from gh-pr/1729/head into gh-pr/1729/base 2026-11-26 04:43:01 +00:00
Owner

@⁠moe-miau on GitHub · 2026-11-24 21:27 UTC · original
moe-miau:fix/xgamesave-stray-versions → main · +129 −24 · 1 files · 1 commits · merged 2026-11-25 00:09 UTC

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

**@⁠moe-miau** on GitHub · 2026-11-24 21:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/1729) `moe-miau:fix/xgamesave-stray-versions` → `main` · +129 −24 · 1 files · 1 commits · merged 2026-11-25 00:09 UTC 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)
Recovery took any name `v<digits>` as a version, so a leftover `v01`
next to a committed `v1` parsed as version 1, and the cleanup rebuilt
the name as `v1` and deleted the committed save (#870). A correctly
named but unreadable newer entry (an empty `v2`, a file, a broken
manifest) did the same: `v1` was pruned as older, the read failed, and
the next update committed a fresh `v1` holding only the changed blobs,
which the following read pruned again.

Now only `v<N>` exactly as `commit` writes it is a version. `current`
takes the newest version whose manifest reads, removes only versions
below it, and leaves unreadable newer entries alone. An update goes
above the highest version name present, so a stray entry neither hides
the save nor blocks writes. With no readable version at all, reads and
updates still fail and nothing is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:43:01 +00:00
github manually merged commit b8dbcba260 into gh-pr/1729/base 2026-11-26 04:43:01 +00:00
Author
Owner

@⁠kais7654 on GitHub · 2026-11-24 22:49 UTC · original

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.

**@⁠kais7654** on GitHub · 2026-11-24 22:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/1729#issuecomment-7146692477) 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.
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1729
No description provided.