Repository navigation
file_system: GAME: paths for GetDiskFreeSpaceEx, MoveFileWithProgress, ReplaceFile, GetLong/ShortPathName and GetCompressedFileSize - #4965
Conversation
|
Independent Windows check at 8609659. Windows 11 26300, MSVC 19.51.36260.0, RelWithDebInfo,
One contract mismatch found with a temporary extra check (not included in the PR):
No game data used. AI-assisted. |
|
Independent check of Environment: Windows 11, MSVC 19.44.35230.0 (RelWithDebInfo, Ninja), CPU only, synthetic temp dirs, no game files.
Heads-up for the coordinator: #4966 also edits AI-assisted (Devin). |
|
Second independent Windows check at One more contract gap with a temporary probe at the very start of the test, before any
Once a Also, merging the declared dependency #4621 ( AI-assisted. |
|
Tested 8609659 merged with main 3faac55 on native Windows 11 (MSVC 14.51, RelWithDebInfo, Ninja;
|
illusionart453-max
left a comment
There was a problem hiding this comment.
[P1] Prepare the replacement-source deletion marker before the destructive host ReplaceFileW call.
Reproduced on this PR alone at 86096596 (Windows 11 build 26200, MSVC 19.44, RelWithDebInfo, synthetic files; no GPU/game files). The original 200 checks still pass. The attached 11-check probe adds five failures, so the run ends 211 check(s), 5 failure(s).
At runtime/shims/file_system.cpp:1331-1336, the host replacement succeeds before the shim calls write_marker. Put package and newer overlay copies at both source.txt and target.txt, then make <overlay>/.gta6rt-deleted a regular file to obstruct marker creation. Resolve the real shim's ReplaceFileW and call it with the two GAME: paths:
- Without backup: returns FALSE, GetLastError 183; target now contains the replacement bytes, and the overlay source is gone. The previous overlay target bytes have been lost.
- With backup: the same FALSE/183 result, source removed and destination changed, plus a backup file has been created.
- Raw package inputs stay unchanged; the unmarked package source becomes visible again under the source name.
This is a shim-owned metadata error detected after the host already succeeded, not a claim that every possible host ReplaceFile failure is atomic. Preflight/reserve the needed marker before calling the host, and roll back a newly reserved marker on host failure. When combining with #4885, reuse PendingMarker and hold its overlay lock across view reads, replacement and commit/rollback; ReplaceFileW currently bypasses those guards.
I found this while checking the test-file overlap with #4885. Keeping all suites from #4621, #4965 and #4885 gives 360 passing checks; the same probe makes that combined tree 371 checks / 5 failures. No production changes or competing PR from me. The temporary probe was removed afterward, and the original/integrated tests were restored. The existing PR owner should carry this fix.
AI-assisted (Codex). Synthetic inputs only.
Reproducible test-only patch against 8609659
Build and run file_system_test normally. The probe resolves the production shim through its import table; it does not mock ReplaceFileW or model its behavior.
diff --git a/runtime/test/file_system_test.cpp b/runtime/test/file_system_test.cpp
index c1cd1b88..98672e76 100644
--- a/runtime/test/file_system_test.cpp
+++ b/runtime/test/file_system_test.cpp
@@ -138,6 +138,34 @@ int count(const std::vector<std::wstring>& names, const wchar_t* name) {
bool contains(const std::vector<std::wstring>& names, const wchar_t* name) { return count(names, name) != 0; }
+void check_replace_marker_failure(const std::filesystem::path& root) {
+ const auto replace = resolve<ReplaceFileWFn>("kernel32.dll", "ReplaceFileW");
+ check(replace != nullptr, "review probe resolves the ReplaceFileW shim");
+ if (!replace) return;
+ for (bool backup : {false, true}) {
+ const auto scratch = root / (backup ? "replace-marker-backup" : "replace-marker-plain");
+ const auto package = scratch / "package", overlay = scratch / "overlay";
+ write_path(package / "target.txt", "package target");
+ write_path(package / "source.txt", "package source");
+ write_path(overlay / "target.txt", "overlay target");
+ write_path(overlay / "source.txt", "overlay replacement");
+ write_path(overlay / ".gta6rt-deleted", "marker obstruction");
+ rt::fs::configure(package, overlay);
+ SetLastError(0);
+ const BOOL result = replace(L"GAME:\\target.txt", L"GAME:\\source.txt",
+ backup ? L"GAME:\\backup.txt" : nullptr, 0, nullptr, nullptr);
+ std::printf("review ReplaceFileW backup=%d result=%d error=%lu\n", backup, result, GetLastError());
+ std::printf("review disk target=%s source=%s backup=%s\n", read_path(overlay / "target.txt").c_str(), read_path(overlay / "source.txt").c_str(), read_path(overlay / "backup.txt").c_str());
+ check(result == FALSE, "review: marker obstruction reports failed replace");
+ check(read_path(overlay / "target.txt") == "overlay target", "review: failed replace preserves destination");
+ check(read_path(overlay / "source.txt") == "overlay replacement", "review: failed replace preserves source");
+ check(!std::filesystem::exists(overlay / "backup.txt"), "review: failed replace creates no backup");
+ check(read_path(package / "target.txt") == "package target" &&
+ read_path(package / "source.txt") == "package source", "review: package files stay untouched");
+ }
+ rt::fs::configure({}, {});
+}
+
} // namespace
int main() {
@@ -978,6 +1006,7 @@ int main() {
"ReplaceFileA replaces a package file with an overlay-only one");
}
+ check_replace_marker_failure(root);
std::filesystem::remove_all(root);
std::printf("%d check(s), %d failure(s)\n", g_checks, g_failures);
return g_failures == 0 ? 0 : 1;
…st write Review follow-up on ItsNotRexed#4965 (tupacfan04): - ReplaceFile* now fails with ERROR_PATH_NOT_FOUND when a path's folder is missing (or is a file), and checks the replaced file before the replacement, as the host does. Before, every missing name gave ERROR_FILE_NOT_FOUND. - T:\ is a drive, so it exists before the title's first write there: the scratch folder is made as soon as a T: path is named. GetDiskFreeSpaceEx, GetLong/ShortPathName and GetFileAttributes of T:\ then succeed, and RemoveDirectory of T:\ fails with ERROR_ACCESS_DENIED like a host drive's root instead of removing the scratch folder. file_system: 209 checks, 0 failures; the 8 new checks fail on the previous shim. Each error is compared live against the host's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the checks. Both gaps @tupacfan04 found are fixed in 76e4d58:
On the textual conflicts with #4621, #4885 and #4966 in AI-assisted (Claude Code). No game files used. |
…ingMarker version here supersedes it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Update: one more fix, and trial merges with the other open PRs on these files.
Trial merges (each is this PR plus the other one, conflicts resolved, so whichever lands second can rebase from it):
Each merge also adds checks for how the two PRs interact. Details are in the comments on #4885, #4966 and #5187. AI-assisted (Claude Code). No game files used. |
…a backup From illusionart453-max's review of ItsNotRexed#4965: with overlay copies of both files, an obstructed marker folder, and with or without a backup, ReplaceFileW must fail with the destination, the replacement and the package untouched and no backup written. Their probe, kept with the debug output removed. On defd2e8's shim: 223 checks, 0 failures. On 76e4d58's (marker written after the replace): 6 failures, the probe's 5 plus the existing obstructed-marker check. ctest 151/151. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@illusionart453-max, thanks for the P1 and the probe. I missed this review earlier (I'd only read the PR comments), so I'm sorry it went unanswered for a few hours. I found the same ordering bug while merging with #4885, so it's fixed:
Could you take another look when you have a moment? AI-assisted (Claude Code). Synthetic files only. |
213f87d to
8ebc25f
Compare
|
Rebased on
Results: AI-assisted (Claude Code). No game files. |
…st write Review follow-up on ItsNotRexed#4965 (tupacfan04): - ReplaceFile* now fails with ERROR_PATH_NOT_FOUND when a path's folder is missing (or is a file), and checks the replaced file before the replacement, as the host does. Before, every missing name gave ERROR_FILE_NOT_FOUND. - T:\ is a drive, so it exists before the title's first write there: the scratch folder is made as soon as a T: path is named. GetDiskFreeSpaceEx, GetLong/ShortPathName and GetFileAttributes of T:\ then succeed, and RemoveDirectory of T:\ fails with ERROR_ACCESS_DENIED like a host drive's root instead of removing the scratch folder. file_system: 209 checks, 0 failures; the 8 new checks fail on the previous shim. Each error is compared live against the host's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a backup From illusionart453-max's review of ItsNotRexed#4965: with overlay copies of both files, an obstructed marker folder, and with or without a backup, ReplaceFileW must fail with the destination, the replacement and the package untouched and no backup written. Their probe, kept with the debug output removed. On defd2e8's shim: 223 checks, 0 failures. On 76e4d58's (marker written after the replace): 6 failures, the probe's 5 plus the existing obstructed-marker check. ctest 151/151. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, ReplaceFile, GetLong/ShortPathName and GetCompressedFileSize
These calls took a console path ("GAME:\x", "G:\x", "T:\x") as a host path: relative to the current folder, outside
the package and the write overlay.
- GetDiskFreeSpaceEx*: a console folder answers for the volume that holds the overlay, where the title's writes go.
- MoveFileWithProgress*: the MoveFile* rules; the progress routine goes to the host call that moves the bytes.
- ReplaceFile*: runs on overlay copies; a replacement only the package had gets a deletion marker; the backup goes
in the overlay. Errors match the host's (measured live in the test).
- GetLongPathName*/GetShortPathName*: a visible console name comes back as given.
- GetCompressedFileSize*: the read target's size.
GetFullPathName* is left to ItsNotRexed#4621. Tests: file_system 200 checks; ctest 151/151; docs tests 30/30.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…st write Review follow-up on ItsNotRexed#4965 (tupacfan04): - ReplaceFile* now fails with ERROR_PATH_NOT_FOUND when a path's folder is missing (or is a file), and checks the replaced file before the replacement, as the host does. Before, every missing name gave ERROR_FILE_NOT_FOUND. - T:\ is a drive, so it exists before the title's first write there: the scratch folder is made as soon as a T: path is named. GetDiskFreeSpaceEx, GetLong/ShortPathName and GetFileAttributes of T:\ then succeed, and RemoveDirectory of T:\ fails with ERROR_ACCESS_DENIED like a host drive's root instead of removing the scratch folder. file_system: 209 checks, 0 failures; the 8 new checks fail on the previous shim. Each error is compared live against the host's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ReplaceFile wrote the marker that hides a package replacement after the host's ReplaceFile had consumed the overlay copy, so a marker that couldn't be written failed the call after the replace was done, and the package's replacement became visible again under its name (the failure after both copy-ups and before ReplaceFile, and removed again when ReplaceFile fails. file_system: 212 checks, 0 failures. Three new checks: an obstructed marker folder fails the call with nothing replaced (fails with the old order), the retry succeeds, and a refused ReplaceFile leaves no marker. ctest 151/151, docs tests 30/30. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a backup From illusionart453-max's review of ItsNotRexed#4965: with overlay copies of both files, an obstructed marker folder, and with or without a backup, ReplaceFileW must fail with the destination, the replacement and the package untouched and no backup written. Their probe, kept with the debug output removed. On defd2e8's shim: 223 checks, 0 failures. On 76e4d58's (marker written after the replace): 6 failures, the probe's 5 plus the existing obstructed-marker check. ctest 151/151. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rebased on main 561b65a. Main now has its own T:\ handling (the scratch folder is made on the first T: call; drive_root() refuses removing or moving GAME:\ and T:\, and only a T: spelling names the T:\ root), so this PR's ensure_scratch_root()/is_scratch_root() are dropped in favour of main's code; what remains of "T:\ before the first write" is two checks that the free-space and long/short-name calls find T:\ on a fresh overlay. - RT-294 (main): an explicit GAME: path into the overlay's own folders is refused in parse_console(), so the six calls here refuse it too; one check covers free space, long name, compressed size, move-with-progress and replace. - docs/runtime_imports.md: the duplicate T:\ sentence is removed (main has its own), and the import list no longer mentions full-path calls (GetFullPathName is ItsNotRexed#4621's). file_system: 322 checks, 0 failures. Docs tests 33/33. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8ebc25f to
8862803
Compare
|
Rebased again on
AI-assisted (Claude Code). No game files. |
Since ItsNotRexed#5946 a read-only package file refuses DeleteFile. ReplaceFile consumes its replacement and overwrites the replaced file, so the same question applies: the host's ReplaceFileW fails with ERROR_ACCESS_DENIED (measured live in the test) when either file is read-only, and the shim already does the same, because the overlay copy keeps the read-only bit. Two checks pin it, with the title's view unchanged afterwards; the docs say so. file_system: 498 checks, 0 failures. Docs tests 33/33. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent native Windows/MSVC 19.44 (SDK 10.0.26100), RelWithDebInfo at fdb6e0f: configured an isolated CPU-only runtime build, built file_system_test and ran it: 498 checks, 0 failures. This includes obstructed-marker ReplaceFileW cases with/without backup preserving destination, replacement, package, and backup absence. One test-source warning: C4456 at runtime/test/file_system_test.cpp:1204 (h shadows h at 1099). Also MSB8029 because this review build is under TEMP. Vulkan headers unavailable, so no GPU/layer coverage claimed. Synthetic files only, no game files. AI-assisted (Codex). |
|
Tested fdb6e0f merged with main 86a7807 on Windows 11 (MSVC 14.51, RelWithDebInfo, Ninja), Python 3.12.16 for the docs guards: pass |
Claimed in the coordination issue as: #4683 (comment)
Depends on: #4621 (same three files; it maps
GetFullPathName*, which this PR leaves out)What and why
These file calls read a console path (
GAME:\x,G:\x,T:\x) as relative to the current folder, so the title's request never reached the package or the write overlay. This PR maps them, following the rules the existing shims use (RT-97/RT-107):GetDiskFreeSpaceEx*: a console folder answers for the volume holding the overlay, which is where the title's writes go. It walks up to the nearest folder that exists. A missing path givesERROR_PATH_NOT_FOUNDand a file givesERROR_DIRECTORY.MoveFileWithProgress*: follows theMoveFile*rules. The progress routine goes to the host call that actually moves the bytes, which is either the copy of a package file into the overlay or the overlay rename. A routine that cancels leaves the package name visible.ReplaceFile*: runs the host'sReplaceFileWon overlay copies of both files.ERROR_NOT_SAME_DEVICE.GetLongPathName*/GetShortPathName*: a visible console name comes back as given. A missing file gives 2, a missing folder gives 3, and a short buffer gets the size it needs. The input buffer can also be the output buffer.GetCompressedFileSize*: returns the size of the file a read would open (overlay or package).All of them are registered under kernel32, kernelbase and the
api-ms-win-core-file-*sets.docs/runtime_imports.mddocuments each one and lists what is still unmapped:CreateFile3,CreateHardLink*,CreateSymbolicLink*, change notifications, andSetCurrentDirectoryon a console path.Tested
Windows 11, MSVC 19.51 (VS 18), on
main@ 98fa503:file_systemtest: 200 checks, 0 failures. The new checks compareReplaceFile*and long/short-name error codes live against the host's answers for the same situation.ctest: 151/151 passed (one test disabled: gameinput, no SDL3).tests/test_docs_*.py): 30/30.Whether GTA VI imports these calls is unknown until the game executable is available (RT-5).
AI-assisted: yes (Claude Code)
Checklist
docs/design.md, with how it was confirmed. (Not applicable: no translator change.)🤖 Generated with Claude Code