[pr-fix][startup][shaders] Publish a moved shader cache after the copy completes #293

Open
andrewpozdnakov7-jpg wants to merge 2 commits from andrewpozdnakov7-jpg/Darner:fix/stage-cross-drive-cache-move into main
First-time contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

When a cache move has to copy files, the current code writes directly to the destination. A Windows sharing violation on one source file can leave the destination visible with only some files. I reproduced it on f3840d7 with two synthetic files and an exclusive read handle. Copy into a temporary sibling on the destination volume and publish that directory with a rename after the copy succeeds. A failed copy leaves the old cache intact and cleans up the staging directory.

Related discussion: cache relocation in #288. Prepared by andrewpozdnakov7-jpg (GitHub profile).

How it was tested

  • Tested revision: 39160b4 on f3840d7.
  • Commands and results: cargo test --offline --locked -p darner-core --lib folders::tests passed all four Windows tests. The new regression holds a source file open, verifies that a failed copy leaves no destination, then releases it and verifies both files after retrying. Asset policy (555 files) and git diff --check passed.
  • Changes a default: no.
  • Review follow-up at c2897dd: reject drive roots and stop before staging if the destination cannot be prepared. All six Windows folder tests passed, including a locked empty destination. Asset policy passed. Independent checks on 39160b4 are in issuecomment-865700.
  • Independent Windows verification on c2897dd: both workspace Clippy gates, asset policy, 34 darner-core tests, 2 cache_paths and 8 picked_folders tests passed. The tests used temporary directories. Review result
  • Gates run on that revision: none of the three workspace-wide gates.
  • Coverage gaps: Windows filesystem behavior was exercised with synthetic files. Gameplay and a physical cross-drive move were not run.

Checklist

  • I ran this change in the game.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: None for the folder-copy path. #234 covers save acknowledgment during preload.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: <!-- optional --> ## What it changes When a cache move has to copy files, the current code writes directly to the destination. A Windows sharing violation on one source file can leave the destination visible with only some files. I reproduced it on f3840d7 with two synthetic files and an exclusive read handle. Copy into a temporary sibling on the destination volume and publish that directory with a rename after the copy succeeds. A failed copy leaves the old cache intact and cleans up the staging directory. Related discussion: [cache relocation in #288](https://git.gtahub.st/TrustNo1/Darner/issues/288). Prepared by [andrewpozdnakov7-jpg](https://git.gtahub.st/andrewpozdnakov7-jpg) ([GitHub profile](https://github.com/andrewpozdnakov7-jpg)). ## How it was tested - Tested revision: 39160b4 on f3840d7. - Commands and results: cargo test --offline --locked -p darner-core --lib folders::tests passed all four Windows tests. The new regression holds a source file open, verifies that a failed copy leaves no destination, then releases it and verifies both files after retrying. Asset policy (555 files) and git diff --check passed. - Changes a default: no. - Review follow-up at c2897dd: reject drive roots and stop before staging if the destination cannot be prepared. All six Windows folder tests passed, including a locked empty destination. Asset policy passed. Independent checks on 39160b4 are in issuecomment-865700. - Independent Windows verification on c2897dd: both workspace Clippy gates, asset policy, 34 darner-core tests, 2 cache_paths and 8 picked_folders tests passed. The tests used temporary directories. [Review result](https://git.gtahub.st/TrustNo1/Darner/pulls/293#issuecomment-867576) - Gates run on that revision: none of the three workspace-wide gates. - Coverage gaps: Windows filesystem behavior was exercised with synthetic files. Gameplay and a physical cross-drive move were not run. ## Checklist - [ ] I ran this change in the game. - [x] This PR contains one change based on main. - [x] The diff follows docs/asset-policy.md. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: None for the folder-copy path. #234 covers save acknowledgment during preload. - Replaces or overlaps: none found
When moving by copying, stage the cache on the destination volume and rename it into place after the copy completes. If a source file is locked, the old cache remains and the destination does not present a partial copy.

https://git.gtahub.st/andrewpozdnakov7-jpg
https://github.com/andrewpozdnakov7-jpg
First-time contributor

Independent Windows build, gate, and code-read review of 39160b41a (based on main f3840d73d). Not run in-game or across physical drives.

Environment

  • Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (x86_64-pc-windows-msvc), MSVC 19.44.35230.

Measured results

  • Gate 1 (cargo clippy --workspace --all-targets --locked -- -D warnings): PASS
  • Gate 2 (cargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASS
  • cargo xtask policy: PASS (asset policy: 555 files ok)
  • cargo test --locked -p darner-core: PASS (32 passed; 0 failed in 0.04 s, including new folders::tests::a_failed_cache_copy_keeps_the_source_and_hides_the_destination)
  • cargo test --locked -p darner --test cache_paths --test picked_folders: PASS (2 passed + 8 passed; 0 failed)

Findings (blocking)

  1. Drive-root to stages the cache in CWD (".") (crates/darner-core/src/folders.rs:261):
    let parent = to.parent().filter(|p| !p.as_os_str().is_empty()).unwrap_or(Path::new("."));
    
    On Windows, Path::new("cache").parent() returns Some("") (single relative component, where "." is appropriate), whereas a drive root like Path::new(r"E:\").parent() returns None (no parent exists and a directory cannot be renamed onto a drive root). Falling back to Path::new(".") for None causes tempfile::tempdir_in(".") to copy a potentially multi-GB shader cache into the current working directory (likely a different volume or inside the game/repo tree) before fs::rename(staging.path(), to) inevitably fails. Distinguish Some("") (Path::new(".")) from None (return an error immediately).
  2. Existing unremovable empty to directory wastes a full copy then always fails (crates/darner-core/src/folders.rs:268-274, 296):
    • move_cache runs let _ = std::fs::remove_dir(to); and ignores errors (e.g. if the empty destination directory is open in Explorer/a shell or is an empty volume mount point).
    • On Windows, std::fs::rename(staging.path(), to) onto an existing directory always fails (ERROR_ACCESS_DENIED / ERROR_ALREADY_EXISTS), even if to is empty — whereas copy_tree(from, to, ...) previously populated it in place.
    • Without checking whether to still exists before calling copy_tree(from, staging.path(), ...), copy_cache copies the entire cache into staging, fails rename, deletes staging, and returns an error (and apply() at folders.rs:138-139 still clears MOVE_CACHE_FROM, so the move is never retried). Either check to.exists() before copying (fail fast or handle a pre-existing empty to explicitly).

Minor non-blocking notes

  • After fs::rename(staging.path(), to) succeeds, calling let _ = staging.keep(); avoids TempDir::drop invoking remove_dir_all on the renamed-away temp path.
  • On Windows, Defender/search indexer briefly scanning freshly copied shader files inside staging can cause a single fs::rename(staging.path(), to) to fail with PermissionDenied; a short retry loop (similar to move_cache's same-drive rename loop at folders.rs:278-283) and a recognizable prefix (tempfile::Builder::new().prefix(".darner-cache-move-")) would make publish errors and crash-orphans easier to handle.

Verdict: Changes requested (reject to.parent().is_none() instead of staging in ".", and check/handle an existing unremovable empty to before doing a multi-GB staged copy).

AI-assisted: yes (Gemini 4 Neon).

Independent Windows build, gate, and code-read review of `39160b41a` (based on `main` `f3840d73d`). Not run in-game or across physical drives. ### Environment - Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (`x86_64-pc-windows-msvc`), MSVC 19.44.35230. ### Measured results - Gate 1 (`cargo clippy --workspace --all-targets --locked -- -D warnings`): **PASS** - Gate 2 (`cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`): **PASS** - `cargo xtask policy`: **PASS** (`asset policy: 555 files ok`) - `cargo test --locked -p darner-core`: **PASS** (`32 passed; 0 failed` in 0.04 s, including new `folders::tests::a_failed_cache_copy_keeps_the_source_and_hides_the_destination`) - `cargo test --locked -p darner --test cache_paths --test picked_folders`: **PASS** (`2 passed` + `8 passed; 0 failed`) ### Findings (blocking) 1. **Drive-root `to` stages the cache in CWD (`"."`) (`crates/darner-core/src/folders.rs:261`):** ```rust let parent = to.parent().filter(|p| !p.as_os_str().is_empty()).unwrap_or(Path::new(".")); ``` On Windows, `Path::new("cache").parent()` returns `Some("")` (single relative component, where `"."` is appropriate), whereas a drive root like `Path::new(r"E:\").parent()` returns `None` (no parent exists and a directory cannot be renamed onto a drive root). Falling back to `Path::new(".")` for `None` causes `tempfile::tempdir_in(".")` to copy a potentially multi-GB shader cache into the current working directory (likely a different volume or inside the game/repo tree) before `fs::rename(staging.path(), to)` inevitably fails. Distinguish `Some("")` (`Path::new(".")`) from `None` (return an error immediately). 2. **Existing unremovable empty `to` directory wastes a full copy then always fails (`crates/darner-core/src/folders.rs:268-274, 296`):** - `move_cache` runs `let _ = std::fs::remove_dir(to);` and ignores errors (e.g. if the empty destination directory is open in Explorer/a shell or is an empty volume mount point). - On Windows, `std::fs::rename(staging.path(), to)` onto an existing directory always fails (`ERROR_ACCESS_DENIED` / `ERROR_ALREADY_EXISTS`), even if `to` is empty — whereas `copy_tree(from, to, ...)` previously populated it in place. - Without checking whether `to` still exists before calling `copy_tree(from, staging.path(), ...)`, `copy_cache` copies the entire cache into `staging`, fails `rename`, deletes `staging`, and returns an error (and `apply()` at `folders.rs:138-139` still clears `MOVE_CACHE_FROM`, so the move is never retried). Either check `to.exists()` before copying (fail fast or handle a pre-existing empty `to` explicitly). ### Minor non-blocking notes - After `fs::rename(staging.path(), to)` succeeds, calling `let _ = staging.keep();` avoids `TempDir::drop` invoking `remove_dir_all` on the renamed-away temp path. - On Windows, Defender/search indexer briefly scanning freshly copied shader files inside `staging` can cause a single `fs::rename(staging.path(), to)` to fail with `PermissionDenied`; a short retry loop (similar to `move_cache`'s same-drive rename loop at `folders.rs:278-283`) and a recognizable prefix (`tempfile::Builder::new().prefix(".darner-cache-move-")`) would make publish errors and crash-orphans easier to handle. **Verdict:** Changes requested (reject `to.parent().is_none()` instead of staging in `"."`, and check/handle an existing unremovable empty `to` before doing a multi-GB staged copy). AI-assisted: yes (Gemini 4 Neon).
A drive root cannot be published by renaming a sibling directory. Reject roots and report destination preparation failures before making the staged copy. Check availability again before copying and retain the staging path only until the rename succeeds.

Review: #293 (comment)
https://git.gtahub.st/andrewpozdnakov7-jpg
https://github.com/andrewpozdnakov7-jpg
Author
First-time contributor

Thanks for the Windows review, @lewis499. c2897dd rejects a drive root before creating a staging directory. It also stops on a destination-preparation error and checks again for an existing destination before copying. A successful rename now disarms the temporary-directory cleanup.

All six folder tests passed on Windows, including a locked empty destination and drive-root inputs. The locked-directory case exits before creating any staging directory and keeps the source cache. The asset-policy check also passed.

Thanks for the Windows review, @lewis499. `c2897dd` rejects a drive root before creating a staging directory. It also stops on a destination-preparation error and checks again for an existing destination before copying. A successful rename now disarms the temporary-directory cleanup. All six folder tests passed on Windows, including a locked empty destination and drive-root inputs. The locked-directory case exits before creating any staging directory and keeps the source cache. The asset-policy check also passed.
First-time contributor

PASS

Follow-up verification of c2897dd88ce9dd9cabb8c97d302fd5bfb5493253 (base f3840d73d3504c30218debfbc8795b9225447317).

Environment

Windows 11 Pro 26H2 build 26300.10075; Intel Core i9-14900K; NVIDIA RTX A2000 12 GB (driver 621.47); Rust 1.98.1 x86_64-pc-windows-msvc; MSVC 19.44.35230.

Measured results

  • cargo clippy --workspace --all-targets --locked -- -D warnings: PASS.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: PASS.
  • cargo xtask policy: PASS (555 files ok).
  • cargo test --locked -p darner-core: 34 passed, 0 failed, 0 ignored.
  • cargo test --locked -p darner --test cache_paths --test picked_folders: 2 cache_paths tests and 8 picked_folders tests passed; 0 failed.

Code-read audit

  • move_cache rejects a destination with no parent (including a drive root) before creating staging data, while handling an empty parent for a single relative path; it also rejects moving the source drive root (crates/darner-core/src/folders.rs:279-288).
  • Non-empty destinations remain untouched; an empty destination that cannot be removed returns before copying. Cross-volume copies are staged under the destination parent, recheck that the destination does not exist, publish by rename, and remove the source only after the copy succeeds (:261-273, 290-317). Regression tests cover drive-root rejection, an in-use empty destination, and source preservation (:366-400).
  • The targeted tests use temporary directories; no physical cross-volume move was exercised.

Not run in-game.

AI-assisted: yes (GitHub Copilot, Auto mode).

**PASS** Follow-up verification of `c2897dd88ce9dd9cabb8c97d302fd5bfb5493253` (base `f3840d73d3504c30218debfbc8795b9225447317`). ### Environment Windows 11 Pro 26H2 build 26300.10075; Intel Core i9-14900K; NVIDIA RTX A2000 12 GB (driver 621.47); Rust 1.98.1 x86_64-pc-windows-msvc; MSVC 19.44.35230. ### Measured results - `cargo clippy --workspace --all-targets --locked -- -D warnings`: PASS. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: PASS. - `cargo xtask policy`: PASS (`555 files ok`). - `cargo test --locked -p darner-core`: 34 passed, 0 failed, 0 ignored. - `cargo test --locked -p darner --test cache_paths --test picked_folders`: 2 `cache_paths` tests and 8 `picked_folders` tests passed; 0 failed. ### Code-read audit - `move_cache` rejects a destination with no parent (including a drive root) before creating staging data, while handling an empty parent for a single relative path; it also rejects moving the source drive root (`crates/darner-core/src/folders.rs:279-288`). - Non-empty destinations remain untouched; an empty destination that cannot be removed returns before copying. Cross-volume copies are staged under the destination parent, recheck that the destination does not exist, publish by rename, and remove the source only after the copy succeeds (`:261-273`, `290-317`). Regression tests cover drive-root rejection, an in-use empty destination, and source preservation (`:366-400`). - The targeted tests use temporary directories; no physical cross-volume move was exercised. Not run in-game. AI-assisted: yes (GitHub Copilot, Auto mode).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'fix/stage-cross-drive-cache-move:andrewpozdnakov7-jpg-fix/stage-cross-drive-cache-move'
git switch 'andrewpozdnakov7-jpg-fix/stage-cross-drive-cache-move'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'andrewpozdnakov7-jpg-fix/stage-cross-drive-cache-move'
git switch 'andrewpozdnakov7-jpg-fix/stage-cross-drive-cache-move'
git rebase 'main'
git switch 'main'
git merge --ff-only 'andrewpozdnakov7-jpg-fix/stage-cross-drive-cache-move'
git switch 'andrewpozdnakov7-jpg-fix/stage-cross-drive-cache-move'
git rebase 'main'
git switch 'main'
git merge --no-ff 'andrewpozdnakov7-jpg-fix/stage-cross-drive-cache-move'
git switch 'main'
git merge --squash 'andrewpozdnakov7-jpg-fix/stage-cross-drive-cache-move'
git switch 'main'
git merge --ff-only 'andrewpozdnakov7-jpg-fix/stage-cross-drive-cache-move'
git switch 'main'
git merge 'andrewpozdnakov7-jpg-fix/stage-cross-drive-cache-move'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
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
TrustNo1/Darner!293
No description provided.