[pr-fix][startup][shaders] Publish a moved shader cache after the copy completes #293
Loading…
Reference in a new issue
No description provided.
Delete branch "andrewpozdnakov7-jpg/Darner:fix/stage-cross-drive-cache-move"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Contributor role (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
f3840d7with 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
39160b4onf3840d7.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 on39160b4are in issuecomment-865700.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 resultChecklist
Checked for overlap
Independent Windows build, gate, and code-read review of
39160b41a(based onmainf3840d73d). Not run in-game or across physical drives.Environment
x86_64-pc-windows-msvc), MSVC 19.44.35230.Measured results
cargo clippy --workspace --all-targets --locked -- -D warnings): PASScargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASScargo xtask policy: PASS (asset policy: 555 files ok)cargo test --locked -p darner-core: PASS (32 passed; 0 failedin 0.04 s, including newfolders::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)
tostages the cache in CWD (".") (crates/darner-core/src/folders.rs:261): On Windows,Path::new("cache").parent()returnsSome("")(single relative component, where"."is appropriate), whereas a drive root likePath::new(r"E:\").parent()returnsNone(no parent exists and a directory cannot be renamed onto a drive root). Falling back toPath::new(".")forNonecausestempfile::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) beforefs::rename(staging.path(), to)inevitably fails. DistinguishSome("")(Path::new(".")) fromNone(return an error immediately).todirectory wastes a full copy then always fails (crates/darner-core/src/folders.rs:268-274, 296):move_cacherunslet _ = 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).std::fs::rename(staging.path(), to)onto an existing directory always fails (ERROR_ACCESS_DENIED/ERROR_ALREADY_EXISTS), even iftois empty — whereascopy_tree(from, to, ...)previously populated it in place.tostill exists before callingcopy_tree(from, staging.path(), ...),copy_cachecopies the entire cache intostaging, failsrename, deletesstaging, and returns an error (andapply()atfolders.rs:138-139still clearsMOVE_CACHE_FROM, so the move is never retried). Either checkto.exists()before copying (fail fast or handle a pre-existing emptytoexplicitly).Minor non-blocking notes
fs::rename(staging.path(), to)succeeds, callinglet _ = staging.keep();avoidsTempDir::dropinvokingremove_dir_allon the renamed-away temp path.stagingcan cause a singlefs::rename(staging.path(), to)to fail withPermissionDenied; a short retry loop (similar tomove_cache's same-drive rename loop atfolders.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 emptytobefore doing a multi-GB staged copy).AI-assisted: yes (Gemini 4 Neon).
Thanks for the Windows review, @lewis499.
c2897ddrejects 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.
PASS
Follow-up verification of
c2897dd88ce9dd9cabb8c97d302fd5bfb5493253(basef3840d73d3504c30218debfbc8795b9225447317).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: 2cache_pathstests and 8picked_folderstests passed; 0 failed.Code-read audit
move_cacherejects 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).:261-273,290-317). Regression tests cover drive-root rejection, an in-use empty destination, and source preservation (:366-400).Not run in-game.
AI-assisted: yes (GitHub Copilot, Auto mode).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.