Repository navigation
file_system: copy-up through a staging name, one at a time - #3063
Conversation
A write-open of a package file copied it straight to its overlay name with no lock. A process killed mid-copy left a truncated file there that every later read preferred over the package; two threads write-opening the same package file both copied, and the second copy_file failed on the taken name, so that open failed. write_target now copies into <overlay>\.gta6rt-copy under a private name and renames it into place, under a mutex that only copy-ups take. Listings hide the staging folder like .gta6rt-deleted. Without the mutex, copy-then-rename alone still failed about 2 in 100 runs: a losing rename onto the existing name briefly holds it, and the winner's open got ERROR_SHARING_VIOLATION. file_system_test: two threads write-open one 256 KiB package file, 50 rounds; both opens succeed and the overlay copy matches (fails 3 of 3 runs on the old code, passes 200 of 200 with this); no staging file is left; a crash leftover is hidden from a GAME: listing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested fc1e005 (merged on current main) on Windows 11 23H2 (22631), MSVC 2022 / Ninja: pass. AI-assisted test run. |
|
Tested
(Scope: CPU/filesystem AI-assisted (Antigravity / Gemini); no game files used. |
Kam471
left a comment
There was a problem hiding this comment.
Built the three TUs with /W4 /permissive- (0 warnings): file_system_test -> 138 checks, 0 failures, 6/6 runs; the same test with main's shim gives 138 checks, 3 failures, 3/3 runs (the two-thread check fails every time). A review-only failure probe passes 7/7: a blocked staging name and a failing copy both leave no target file, a retry copies correctly, and staging is empty afterward. The staging name is <overlay>\.gta6rt-copy\<pid>-<n> on the same overlay, and MoveFileExW(..., 0) means the target name only appears via rename; both error paths remove the temporary file. The copy mutex is acquired after roots()/g_mutex and nothing takes them in reverse, so there is no lock-order deadlock. No game data or absolute host paths. Approve.
Caveats: the mutex serializes every keep-contents write-open, not only actual copy-ups, so unrelated saves can queue behind a large copy; crash leftovers in the staging folder are hidden but never swept; DeleteFile is not under the same lock (pre-existing).
New RT item, claimed in #3047.
When the title write-opens a package file,
write_target(runtime/shims/file_system.cpp) copies it into the overlay first (copy-up). It copied straight to the overlay name, with no lock:copy_file(copy_options::none) failed on the now-taken name, so that open failed.Fix:
<overlay>\.gta6rt-copyunder a private name, thenMoveFileExWrenames it into place. After a crash, the only leftover is in that folder.ERROR_SHARING_VIOLATION..gta6rt-copylike.gta6rt-deleted(internal_dir, used byempty_in_viewandcollect).docs/runtime_imports.md(the "Console paths and the write overlay" rules) mentions the staging folder.Test (
file_system_test):mainand passes 200 of 200 with this PR..gta6rt-copydoesn't appear in aGAME:\*listing.Tested on Windows 11, MSVC (VS 2026), RTX 4060 Ti / NVIDIA 621.24:
ctest -C RelWithDebInfo122/122. No game files.I haven't confirmed that the game write-opens its own package files. This matters only if it does, but then a crash at the wrong moment corrupts that file for every later run.
AI-assisted (Claude Code).
🤖 Generated with Claude Code