Skip to content

XGameSave: clear stray files at staged version paths - #2716

Closed
TaynanGT wants to merge 3 commits into
Marvisak:mainfrom
TaynanGT:fix/xgamesave-staged-version-file
Closed

TaynanGT wants to merge 3 commits into
Marvisak:mainfrom
TaynanGT:fix/xgamesave-staged-version-file

Conversation

@TaynanGT

@TaynanGT TaynanGT commented Nov 25, 2026 •

Copy link
Copy Markdown

Problem

XGameSave stages a save version in v<N>.new before renaming it to v<N>. If a regular file occupies that staging path, remove_dir_all returns NotADirectory (Windows error 267). This can hide the last committed save during recovery and block a new commit.

Change

Use the same cleanup for recovery and commit. It removes a staging entry according to its type. Recovery uses the existing canonical version-name parser to clean up v<N>.new entries and preserve unrelated names such as notes.new.

Verification

  • On main at 13f91ca with the two regression tests applied by themselves, both tests fail with NotADirectory.
  • On this branch, cargo test -p victory-hle --lib --locked staged_version_file passes both tests. They cover reading the committed save, preserving an unrelated file, and replacing the stale staging file on commit.
  • cargo test -p victory-hle --lib --locked passes all 148 tests. cargo xtask policy --staged passed before commit. The tests use temporary files and synthetic data.
  • The local workspace run had GPU test failures and a shader test process crash. Two of those GPU tests also failed on the unchanged base. See the Windows CI run for the project's checks.

Follow-up from review

On Windows, a file opened without delete sharing cannot be removed. Recovery now tries to clear an unfinished version without requiring deletion to succeed before reading the committed save. Writing a new version still requires the staging path it will reuse to be clear.

The new test, a_locked_staged_version_file_only_blocks_commit, failed on the previous PR head with Windows error 32. It now verifies that the old save stays readable while v2.new is locked, the write fails while the lock is held, and a retry commits the new version after the lock is released. All 149 victory-hle unit tests and cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings passed.

The Windows CI run for 3e5cdb8 passed both Clippy checks and the full workspace test suite.

Adapted from TaynanGT/VIctory@8ffb049 in #2257. Related #1981 covers recovery when a committed version is missing a blob. Prepared with Codex assistance.

A regular file at v<N>.new made save reads and writes fail when cleanup tried to remove it as a directory. Clean up the reserved staging paths according to their file type.

Adapted from Vice-Tay 8ffb049 with Codex assistance.
@TaynanGT
TaynanGT marked this pull request as ready for review November 25, 2026 18:44
@DrDarkDK

Copy link
Copy Markdown

current() still returns an error before reading a valid committed save if it can’t delete an unpublished v<N>.new entry. I confirmed on Windows that deleting a temporary file fails while it’s held open without delete sharing. In this path, remove_staged_version(...)? propagates that error before current() checks the committed manifest.

Could cleanup be best-effort in current(), while commit() still requires cleanup of the staging path it will reuse? A Windows regression could hold v2.new open without delete sharing and verify that v1 remains readable.

AI-assisted with Codex.

@TaynanGT TaynanGT mentioned this pull request Nov 25, 2026
@kotekompotek

Copy link
Copy Markdown

Correct on both halves: remove_staged_version dispatches on symlink_metadata (dir / dir-symlink / other), and the recovery sweep now only touches names that parse as v.new so unrelated *.new files survive. Sharing the helper between recovery and commit is the right consolidation.

@cloph-dsp

Copy link
Copy Markdown

Independent local verification of PR #2716 (claim VERIFY-2716-XGAMESAVE-STAGING on #1633).

Environment: Windows, rustc/cargo 1.100.0, MSVC, CARGO_BUILD_JOBS=2, --locked. No game data, no GPU, no clippy/rustup.

  • cargo test --locked -p victory-hle --lib staged_version_file --quiet → 3 passed, 0 failed (146 filtered).
  • cargo test --locked -p victory-hle --lib --quiet → 149 passed, 0 failed, 0 ignored.
  • git diff --check origin/main..HEAD → clean.
  • Negative control: remove_staged_version and the three new test names are absent from origin/main in crates/victory-hle/src/modules/xgamesave.rs (git grep no matches), so the added tests are genuinely new.

Only pre-existing #[warn(deprecated)] notes in the crate (fetch_update) appeared; non-blocking. No functional issues found. AI-assisted (Hy4 flash).

@TaynanGT

Copy link
Copy Markdown
Author

@DrDarkDK Done in 520268f: current() now ignores a failed cleanup of a v<N>.new entry, so a locked staging file no longer hides the committed save, while commit() still has to clear the staging path it reuses. The Windows test a_locked_staged_version_file_only_blocks_commit holds v2.new open without sharing, checks that v1 stays readable and that the update returns NO_ACCESS, then releases the file and checks that the update succeeds.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Independent Windows 11 verification and review of 3e5cdb8 (on 13f91ca):

Verification (rustc 1.98.1 MSVC)

Review Notes

  • remove_staged_version uses symlink_metadata and checks is_symlink_dir on Windows (calling remove_dir rather than recursing through reparse points), current() restricts best-effort cleanup strictly to v<n>.new names without blocking reads on locked strays, and commit() strictly propagates removal errors before staging. Clean and ready to merge.

@TaynanGT

Copy link
Copy Markdown
Author

Thanks, @kotekompotek, for reviewing the staging cleanup, and @cloph-dsp and @fuzeofficlal for testing it on Windows. The lock test confirms that the previous save stays readable, the write fails while the staging file is locked, and the retry succeeds after the file is released. I appreciate you checking the base branch and the related PRs as well.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

In crates/victory-hle/src/modules/xgamesave.rs, the new remove_staged_version clears a v<N>.new staging path whether it holds a directory, a directory symlink or a file. current now removes unfinished versions on a best-effort basis and only for names that parse as v<N>.new, so a staging entry it cannot delete no longer hides the last committed save. commit still fails if it cannot clear the path it reuses. On main, current calls remove_dir_all(...)? on every *.new entry, so a locked or non-directory entry fails the whole read. VIctory itself never leaves a stray file there, so most of the value is in the best-effort recovery. The three tests (one Windows-only lock test) cover the read, the commit and the retry. CI (check) passes.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

@TaynanGT TaynanGT closed this by deleting the head repository Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants