XGameSave: clear stray files at staged version paths #2716

Closed
github-bot wants to merge 3 commits from github-bot/gh-2716 into main AGit
Owner

@⁠TaynanGT on GitHub · 2026-11-25 18:42 UTC · original
fix/xgamesave-staged-version-file → main · +94 −6 · 1 files · 3 commits · closed without merging

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.

**@⁠TaynanGT** on GitHub · 2026-11-25 18:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2716) `fix/xgamesave-staged-version-file` → `main` · +94 −6 · 1 files · 3 commits · closed without merging ## 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](https://github.com/Marvisak/VIctory/actions/runs/45677812801) 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`](https://github.com/Marvisak/VIctory/actions/runs/45680647781) passed both Clippy checks and the full workspace test suite. Adapted from [TaynanGT/VIctory@8ffb049](https://github.com/TaynanGT/VIctory/commit/8ffb04993bac3a6f47d8c61ccebb78e960eaeacf) 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:12:39 +00:00
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-25 18:45 UTC · original

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.

**@⁠DrDarkDK** on GitHub · 2026-11-25 18:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/2716#issuecomment-7171349688) `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.*
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 18:51 UTC · original

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.

**@⁠kotekompotek** on GitHub · 2026-11-25 18:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2716#issuecomment-7171503008) 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<N>.new so unrelated *.new files survive. Sharing the helper between recovery and commit is the right consolidation.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 19:31 UTC · original

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).

**@⁠cloph-dsp** on GitHub · 2026-11-25 19:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2716#issuecomment-7172406686) 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).
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-25 19:41 UTC · original

@⁠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.

**@⁠TaynanGT** on GitHub · 2026-11-25 19:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2716#issuecomment-7172639748) @⁠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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 19:42 UTC · original

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

Verification (rustc 1.98.1 MSVC)

  • cargo xtask policy: 184 files ok.
  • cargo clippy --locked -p victory-hle --all-targets -- -D warnings: 0 warnings.
  • cargo test --locked -p victory-hle: 149 passed, 0 failed (lib, including all 3 new staged-file tests and the Windows file-lock test), plus fidelityfx (1) and no_dll_planting (1) clean.
  • Merge compatibility in xgamesave.rs: clean zero-conflict 3-way git merge-tree with #2674, #2675, and #2720 (and clean 3-way sequential merge of #2716 + #2720 + #2674).

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 19:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2716#issuecomment-7172664808) Independent Windows 11 verification and review of `3e5cdb8` (on `13f91ca`): ### Verification (`rustc 1.98.1` MSVC) - `cargo xtask policy`: **184 files ok**. - `cargo clippy --locked -p victory-hle --all-targets -- -D warnings`: **0 warnings**. - `cargo test --locked -p victory-hle`: **149 passed, 0 failed** (`lib`, including all 3 new staged-file tests and the Windows file-lock test), plus `fidelityfx` (1) and `no_dll_planting` (1) clean. - **Merge compatibility in `xgamesave.rs`:** clean zero-conflict 3-way `git merge-tree` with **#2674**, **#2675**, and **#2720** (and clean 3-way sequential merge of `#2716 + #2720 + #2674`). ### 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.
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-25 21:17 UTC · original

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.

**@⁠TaynanGT** on GitHub · 2026-11-25 21:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2716#issuecomment-7174865066) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:18 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 23:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2716#issuecomment-7177389936) <!-- victory-triage v1 head=3e5cdb8f7dd65d9903ba9ac9bb682d623048e4b9 verdict=merge-candidate at=2026-11-25T23:18:25Z --> 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](https://claude.ai/code)_
github-bot closed this pull request 2026-11-26 08:25:09 +00:00

Pull request closed

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!2716
No description provided.