Loader: stage prepared images in per-writer files #560

Manually merged
github merged 1 commit from gh-pr/560/head into gh-pr/560/base 2026-11-26 04:08:22 +00:00
Owner

@⁠Quat3rnion on GitHub · 2026-11-24 04:56 UTC · original
Quat3rnion:victory-image-publication → main · +79 −7 · 3 files · 1 commits · merged 2026-11-25 00:20 UTC

What

write_if_changed staged every prepared image into the same
<hash>.tmp file. Two cold launches of the same title could truncate each
other's staged bytes, or the second rename could fail after the first had
already published a correct image. Publication now lives in a portable
module that stages under a name unique to the process and call, and removes
the staging file if the rename fails. The Windows loader path delegates to
it; the file content and cache layout are unchanged.

An AI tool wrote part of this change.

Tested

  • Linux: cargo test --workspace: 166 passed, 0 failed, 3 ignored. Two hermetic tests: concurrent publishers of the same destination both succeed with the exact bytes and leave no staging files, and a failed publication leaves none behind.
  • Windows cross-build: cargo check --target x86_64-pc-windows-gnu --workspace --tests passes. No Windows host here, so the actual LoadLibraryExW step was not exercised.
  • cargo xtask policy passes (151 files ok). No game files or data from them were added.

Checklist

  • Workspace tests and Windows cross-check pass.
  • cargo xtask policy passes. No game files or data from them were added.
  • AI authorship is disclosed above.
**@⁠Quat3rnion** on GitHub · 2026-11-24 04:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/560) `Quat3rnion:victory-image-publication` → `main` · +79 −7 · 3 files · 1 commits · merged 2026-11-25 00:20 UTC ## What `write_if_changed` staged every prepared image into the same `<hash>.tmp` file. Two cold launches of the same title could truncate each other's staged bytes, or the second rename could fail after the first had already published a correct image. Publication now lives in a portable module that stages under a name unique to the process and call, and removes the staging file if the rename fails. The Windows loader path delegates to it; the file content and cache layout are unchanged. An AI tool wrote part of this change. ## Tested - Linux: `cargo test --workspace`: 166 passed, 0 failed, 3 ignored. Two hermetic tests: concurrent publishers of the same destination both succeed with the exact bytes and leave no staging files, and a failed publication leaves none behind. - Windows cross-build: `cargo check --target x86_64-pc-windows-gnu --workspace --tests` passes. No Windows host here, so the actual `LoadLibraryExW` step was not exercised. - `cargo xtask policy` passes (151 files ok). No game files or data from them were added. ## Checklist - [x] Workspace tests and Windows cross-check pass. - [x] `cargo xtask policy` passes. No game files or data from them were added. - [x] AI authorship is disclosed above.
write_if_changed used a shared <hash>.tmp file, so two concurrent cold launches of the same image could truncate each other's staging bytes or fail the rename after the other had published. Move publication into a portable module that stages under a unique pid/sequence name and removes it on failure. Two hermetic tests cover concurrent publishers and a failed rename.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:08:20 +00:00
github manually merged commit 1aac20aa8f into gh-pr/560/base 2026-11-26 04:08:22 +00:00
Author
Owner

@⁠sebastianspicker on GitHub · 2026-11-24 11:02 UTC · original

Tested 49df7e1 applied onto main ffe310e (macOS, Rust 1.98.1). Both new tests pass, 5 out of 5 runs, and Windows-target clippy (x86_64-pc-windows-msvc, plain and --all-features) is clean. Three things:

  1. Off Windows, publish is only used by tests, so cargo clippy -p victory-loader --all-targets -- -D warnings fails on Linux and macOS: static NEXT_STAGING is never used and function write_if_changed is never used. cargo test passes because it doesn't deny warnings, but a Linux lint job (like the one in #112) would go red. #[cfg(any(windows, test))] on mod publish; would fix it.
  2. On Windows, I think the second rename can still fail when the first launcher has already loaded the published file with LoadLibraryExW. Replacing a file that's mapped as a loaded DLL is refused, even though its bytes are already correct. I can't run that here. A cheap fallback would be: if the rename fails and path now reads back equal to bytes, remove the staging file and return Ok.
  3. If std::fs::write(&staging, bytes) fails partway (a full disk), the staging file stays behind. The rename branch already removes it, so the write could do the same.

Also, publish.rs isn't rustfmt-clean (two hunks with rustfmt 1.98.1), though main isn't either yet.

AI-assisted.

**@⁠sebastianspicker** on GitHub · 2026-11-24 11:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/560#issuecomment-7129569452) Tested `49df7e1` applied onto `main` `ffe310e` (macOS, Rust 1.98.1). Both new tests pass, 5 out of 5 runs, and Windows-target clippy (`x86_64-pc-windows-msvc`, plain and `--all-features`) is clean. Three things: 1. Off Windows, `publish` is only used by tests, so `cargo clippy -p victory-loader --all-targets -- -D warnings` fails on Linux and macOS: `static NEXT_STAGING is never used` and `function write_if_changed is never used`. `cargo test` passes because it doesn't deny warnings, but a Linux lint job (like the one in #112) would go red. `#[cfg(any(windows, test))]` on `mod publish;` would fix it. 2. On Windows, I think the second rename can still fail when the first launcher has already loaded the published file with `LoadLibraryExW`. Replacing a file that's mapped as a loaded DLL is refused, even though its bytes are already correct. I can't run that here. A cheap fallback would be: if the rename fails and `path` now reads back equal to `bytes`, remove the staging file and return `Ok`. 3. If `std::fs::write(&staging, bytes)` fails partway (a full disk), the staging file stays behind. The rename branch already removes it, so the write could do the same. Also, `publish.rs` isn't rustfmt-clean (two hunks with rustfmt 1.98.1), though `main` isn't either yet. AI-assisted.
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!560
No description provided.