Skip to content

Port upstream #560: stage prepared images in per-writer files - #47

Merged
DesertGamer merged 1 commit into
DesertGamer:mainfrom
lcg007xd-c:port/upstream-560-stage-per-writer
Nov 26, 2026
Merged

DesertGamer merged 1 commit into
DesertGamer:mainfrom
lcg007xd-c:port/upstream-560-stage-per-writer

Conversation

@lcg007xd-c

Copy link
Copy Markdown
Contributor

What this changes

This ports Marvisak/VIctory#560 by quaternion. It is cherry-picked with -x, so the commit keeps their authorship. It applied cleanly.

write_if_changed in crates/viport-loader/src/windows.rs publishes a prepared image by writing <hash>.tmp and renaming it over <hash>.dll. Every writer uses the same staging name. So two cold launches of the same image at once can truncate each other's staging bytes, or one rename can fail after the other has already published. A failed rename also leaves the .tmp behind.

The fix moves publication into a portable module, publish.rs. It stages under a unique pid/sequence name and removes the staging file when publishing fails. Two tests come with it: concurrent publishers never share a staging file, and a failed rename leaves no staging file behind.

Checked

  • No game data of any kind (files, extracts, screenshots, dumps, saves): see docs/asset-policy.md
  • No binary files or archives
  • No new dependency, build.rs, git hook, .cargo config, CI change or script (or an issue explains why)
  • No download, no started program, no network connection added (or an issue explains why)
  • cargo test --workspace passes (only viport-loader --lib on Linux, see below)
  • cargo clippy --workspace --all-targets --locked -- -D warnings passes (Windows target, run on Linux)
  • The code I wrote is formatted with rustfmt; I did not reformat lines I did not change

What I ran

On Linux, Rust 1.98.1:

  • cargo test -p viport-loader --lib --locked publish: both new tests pass. publish.rs is portable.
  • write_if_changed as on main, compiled standalone, with the target path made a non-empty directory so the rename fails: result=Err(IsADirectory), leftover image.tmp exists=true. Every writer stages to the same image.tmp.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings, cross-checked from Linux on this branch (rebased on the current main): clean.
  • cargo test -p viport-loader --lib --locked on Linux also shows 4 failures in prepare::tests. They read the test binary as a PE, which it is only on Windows, and they fail the same way on main.

Not run: two real launches at once on Windows.

Overlaps

None. No open PR touches viport-loader.

🤖 Generated with Claude Code

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.

(cherry picked from commit 1aac20a)
@DesertGamer
DesertGamer merged commit 2a676f2 into DesertGamer:main Nov 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants