XGameSave: clear stray files at staged version paths #2714

Closed
TaynanGT wants to merge 3 commits from upstream-pr/2716 into main
TaynanGT commented 2026-11-25 18:42:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TaynanGT on 2026-11-25T18:42:00Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6611276731 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2716). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-25T18:42:00Z. --- ## 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.
DrDarkDK commented 2026-11-25 19:06:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DrDarkDK on 2026-11-25T18:45:18Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171349688 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2716#issuecomment-7171349688). Originally posted by [DrDarkDK](https://github.com/DrDarkDK) on 2026-11-25T18:45:18Z. --- `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.*
kotekompotek commented 2026-11-25 19:06:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T18:51:41Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171503008 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2716#issuecomment-7171503008). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T18:51:41Z. --- 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.
DrDarkDK commented 2026-11-25 20:05:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DrDarkDK on 2026-11-25T19:53:24Z.

Review: APPROVED


No description provided.

<!-- greyfinch-sync:Marvisak/VIctory:review:6064041993 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2716#pullrequestreview-6064041993). Originally posted by [DrDarkDK](https://github.com/DrDarkDK) on 2026-11-25T19:53:24Z. **Review:** APPROVED --- _No description provided._
cloph-dsp commented 2026-11-25 20:06:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T19:31:06Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7172406686 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2716#issuecomment-7172406686). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-25T19:31:06Z. --- 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 commented 2026-11-25 20:06:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TaynanGT on 2026-11-25T19:41:29Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7172639748 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2716#issuecomment-7172639748). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-25T19:41:29Z. --- @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 commented 2026-11-25 20:06:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T19:42:39Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7172664808 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2716#issuecomment-7172664808). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T19:42:39Z. --- 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.
TaynanGT commented 2026-11-25 22:04:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TaynanGT on 2026-11-25T21:17:00Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7174865066 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2716#issuecomment-7174865066). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-25T21:17:00Z. --- 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.
Marvisak commented 2026-11-26 00:03:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:18:35Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177389936 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2716#issuecomment-7177389936). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:18:35Z. --- <!-- 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)_
upstream-sync closed this pull request 2026-11-26 09:05:21 +00:00

Pull request closed

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