Skip to content

file_system: a folder has to exist in the title's view; same-name moves succeed (RT-233) - #3651

Merged
ItsNotRexed merged 3 commits into
ProjectLeonida:mainfrom
MrCheese5:claude/fs-view-rules
Nov 23, 2026
Merged

ItsNotRexed merged 3 commits into
ProjectLeonida:mainfrom
MrCheese5:claude/fs-view-rules

Conversation

@MrCheese5

Copy link
Copy Markdown
Contributor

RT-233 (claim)

AI-assisted (Claude Code). I ran everything under "Tested" on Windows.

Problem

Three places where runtime/shims/file_system.cpp disagreed with the host about a GAME: path. Each is reproduced by a check in file_system_test that fails on main. They are three entries in one PR because they share the test file and the same rule (a folder must exist in the title's view); I will split it into three if you prefer.

  1. A write-open created the parent folders before checking anything (write_target).
    • A failed OPEN_EXISTING on GAME:\nodir\sub\x.dat left GAME:\nodir\sub behind.
    • CREATE_ALWAYS succeeded in a folder that was never made (host: ERROR_PATH_NOT_FOUND).
    • CREATE_ALWAYS on GAME:\rules\file.txt\x.dat, below a package file, succeeded, and file.txt then read as a folder.
    • CREATE_ALWAYS inside a folder the title had removed brought the folder back.
  2. FindFirstFile did not check that the folder exists (collect). Inside a removed package folder it returned . and ..; inside a folder that never existed it reported ERROR_FILE_NOT_FOUND where the host reports ERROR_PATH_NOT_FOUND.
  3. MoveFile onto the same name, or to the same name in another case, failed with ERROR_ALREADY_EXISTS (move_file_ex_w): the destination was found "already there" because it is the source.

Change

  • write_target requires the parent to be a folder in the title's view, the check CreateDirectory, MoveFile and CopyFile already make; otherwise ERROR_PATH_NOT_FOUND and nothing is created. A folder only the package has is still mirrored into the overlay, which the title cannot see.
  • collect requires the listed folder to be one in the title's view; otherwise ERROR_PATH_NOT_FOUND. A pattern that matches nothing in a folder that exists is still ERROR_FILE_NOT_FOUND.
  • A move onto the identical name returns TRUE and changes nothing. A case-only rename renames the overlay entry; a package file gets an overlay copy under the new spelling (no deletion marker: the listing takes the overlay's entry and skips the package's as the same name); a package folder is refused with ERROR_ACCESS_DENIED, like any other move of one.
  • docs/runtime_imports.md: two bullets under "Console paths and the write overlay".

Two existing checks change, because they encoded the old answers. Please look at these two on purpose:

  • "A new file, in folders the package does not have" made GAME:\save\slot1.bin without making GAME:\save. It now calls CreateDirectoryW first, as a title must on the host. If creating the parents was intended for CreateFile, say so and I will keep that case and fix only the other three; it is the one behaviour change here that a title could notice in the other direction.
  • FindFirstFileW(L"GAME:\\missing\\*") expected ERROR_FILE_NOT_FOUND under the label "a pattern with no match"; it is a listing inside a missing folder, and now expects ERROR_PATH_NOT_FOUND.

Host reference

The same calls on NTFS (Windows 11 26200, a script of my own over a folder in %TEMP%): CREATE_ALWAYS or OPEN_EXISTING in a missing folder and CREATE_ALWAYS below a file fail with error 3; FindFirstFile inside a missing folder fails with 3, and with 2 for a pattern without a match in a folder that exists; MoveFile onto the same name returns 1; MoveFile to another case returns 1 and the listing shows the new case, for a file and for a folder.

Tested

Windows 11 (build 26200), MSVC 19.44.35222, Visual Studio's CMake and ctest 3.31.6 with Ninja, RelWithDebInfo, built by scripts/build_runtime.ps1. Base f847748c (main).

  • file_system_test with the new checks on main's file_system.cpp: 20 failures of 170, the same 20 on two runs: 8 for the write-open, 3 for the listing (the two new checks and the existing missing-folder check with its corrected error code), 9 for the moves. With the change: 170 checks, 0 failures.
  • ctest --test-dir runtime/build -C RelWithDebInfo with LEONIDA_GAME_DIR set: 140 run, 134 passed, 6 skipped, 0 failed (gameinput is disabled, no SDL3 here). NVIDIA GeForce RTX 4090, driver 32.0.16.2114, for the Vulkan tests in that run; this change needs no GPU.
  • One earlier run of the suite had winhttp_offline fail. That test fails about two runs in five on main on this machine without this change (it does not link file_system.cpp); it is TEST-721, which test: winhttp_offline waits for every HANDLE_CLOSING before counting (TEST-721) #3542 fixes.
  • No game files: every folder in the test is made by the test.

#3063 (copy-up through a staging name) edits write_target a few lines below the new check and will need a small rebase on whichever lands second; #2957 does not touch these functions. My other open change, the MAXIMUM_ALLOWED fix, edits writes() and a different test block; the two apply in either order.

🤖 Generated with Claude Code

@shdann

shdann commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

One case next to the two FindFirstFile answers this fixes, measured at e949c0d: a listing whose path goes through a file still differs from the host.

Host (real FindFirstFileW on scratch folders, dir\f.txt being a file):

Pattern Handle GetLastError
nodir\*, nodir\name.txt, nodir\sub\* (folder does not exist) invalid 3 ERROR_PATH_NOT_FOUND
dir\f.txt\*, dir\f.txt\x (path through a file) invalid 267 ERROR_DIRECTORY
dir\*.nomatch, dir\absent.txt (folder exists, no match) invalid 2 ERROR_FILE_NOT_FOUND

Shim at e949c0d for the middle row: invalid handle, GetLastError 3 (on main f847748 it is 2).

Steps. In runtime/test/file_system_test.cpp, before the final remove_all(root):

write_path(package / "through" / "file.txt", "package");
for (const wchar_t* pattern : {L"GAME:\\through\\file.txt\\*", L"GAME:\\through\\file.txt\\x"}) {
    SetLastError(0);
    WIN32_FIND_DATAW none{};
    const HANDLE found = first_w(pattern, &none);
    const DWORD error = GetLastError();
    check(found == INVALID_HANDLE_VALUE && error == ERROR_DIRECTORY,
          "a listing below a file reports ERROR_DIRECTORY (267), as the host does");
    if (found != INVALID_HANDLE_VALUE) find_close(found);
}

Built with MSVC 14.51 / Ninja, RelWithDebInfo: both checks fail, actual 3, expected 267 (the pull request's own 170 checks pass).

Where. The new test in collect is if (!is_folder(r, dirs)) error = ERROR_PATH_NOT_FOUND, which does not tell "nothing there" from "a file is there". view(r, dirs).kind has the answer: Kind::None is 3 and Kind::File is 267.

Not measured here: whether the write-open below a package file, which this pull request answers with ERROR_PATH_NOT_FOUND, matches the host. I only measured FindFirstFileW.

No game files, no GPU. AI-assisted.

@dea7hsmiless

Copy link
Copy Markdown
Contributor

Independent check of e949c0da on Windows 11 Pro 26300, MSVC 19.44, RelWithDebInfo (Ninja), RTX 3070:

  • file_system_test: exit 0, 170 check(s), 0 failure(s).
  • The new checks pass on this machine, including:
    • a write-open in a missing folder fails with ERROR_PATH_NOT_FOUND and leaves no folders behind;
    • CREATE_ALWAYS below a package file fails and the file stays a file in the title's view;
    • CREATE_ALWAYS inside a removed folder does not bring the folder back;
    • FindFirstFile distinguishes a missing folder (ERROR_PATH_NOT_FOUND) from an existing folder with no match (ERROR_FILE_NOT_FOUND);
    • MoveFile onto the same name and same-name case renames succeed for overlay and package files.

No game files; this test is CPU-only.

@MrCheese5

Copy link
Copy Markdown
Contributor Author

Thanks, that is a real gap, and your host table reproduces here (Windows 11 26200: dir\f.txt\* and dir\f.txt\x give 267; dir\f.txt\sub\*, one level further, gives 3 again). Fixed in 83000f3 as you suggested: collect asks view() for the kind, so a file in the folder's place is ERROR_DIRECTORY and nothing there is ERROR_PATH_NOT_FOUND. Your two patterns are in file_system_test, plus the two-levels-down case.

On the part you did not measure: the write-open below a file. The host gives 3 (ERROR_PATH_NOT_FOUND) for CreateFileW(dir\f.txt\x.dat, GENERIC_WRITE, CREATE_ALWAYS), which is what this PR answers; it is in the description's host reference.

On this head: file_system_test 173 checks, 0 failures; full ctest (Visual Studio's 3.31.6, LEONIDA_GAME_DIR set) 140 run, 134 passed, 6 skipped, 0 failed. Against main's file_system.cpp the count of failing checks is now 23 of 173 (the 20 in the description and these three).

@Maraco91

Copy link
Copy Markdown
Contributor

Tested 83000f3 (the head with the ERROR_DIRECTORY follow-up) on Windows 11 26200, MSVC 19.42 (VS 2022 Build Tools), Windows SDK 10.0.28000.0, NVIDIA RTX 3080 Ti, driver 616.56: pass

  • scripts\build_runtime.ps1: builds clean.
  • ctest -R file_system: passes, 173 check(s), 0 failure(s).
  • Full ctest: 132 of 132 pass (the same 8 skipped and 1 disabled as on main here).
  • Negative control: with runtime/shims/file_system.cpp restored to main and the test kept, "173 check(s), 23 failure(s)", all of them the new checks: the missing-folder and below-a-file write-opens, the FindFirstFileW answers, and the same-name and case-only moves.

The host answers the new checks claim, asked of this machine's kernel32 from a ctypes script on a scratch folder (dir\f.txt is a file, nodir doesn't exist):

Call Host here
FindFirstFileW nodir\* fails, 3 (ERROR_PATH_NOT_FOUND)
FindFirstFileW dir\f.txt\* fails, 267 (ERROR_DIRECTORY)
FindFirstFileW dir\f.txt\sub\* fails, 3
CreateFileW OPEN_EXISTING nodir\sub\x.dat fails, 3; nodir is not created
CreateFileW CREATE_ALWAYS nodir\x.dat fails, 3
CreateFileW CREATE_ALWAYS dir\f.txt\x.dat fails, 3
MoveFileW dir\f.txt → dir\f.txt succeeds
MoveFileW dir\f.txt → dir\F.TXT succeeds; the listing shows F.TXT once

Every row matches what file_system_test now expects of the shim, including the 267 / 3 pair from the last commit.

No blocker found.

AI-assisted (Claude Code); synthetic fixtures and a scratch folder only, no game files.

MrCheese5 and others added 3 commits November 22, 2026 22:05
…es succeed

Three places where the shim disagreed with the host about GAME: paths:

- write_target created the parent folders before checking anything. A failed
  OPEN_EXISTING left the missing folders behind, and a create succeeded in a
  folder that was never made, below a package file (which then read as a folder)
  and inside a folder the title had removed. The parent now has to be a folder in
  the title's view, as CreateDirectory, MoveFile and CopyFile already require;
  otherwise ERROR_PATH_NOT_FOUND and nothing is created.
- FindFirstFile inside a removed package folder returned "." and "..", and inside
  a folder that never existed reported ERROR_FILE_NOT_FOUND. Both are now
  ERROR_PATH_NOT_FOUND.
- MoveFile onto the same name, or to the same name in another case, failed with
  ERROR_ALREADY_EXISTS. The first now succeeds and changes nothing; the second
  renames the overlay entry (a package file gets an overlay copy under the new
  spelling; a package folder is refused like any other move of one).

Two existing checks encoded the old answers and are changed: the test that made
GAME:\save\slot1.bin without making GAME:\save first, and the one that expected
ERROR_FILE_NOT_FOUND for a listing inside a missing folder.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…n the host

collect answered ERROR_PATH_NOT_FOUND for any folder that is not one in the title's
view. The host tells a missing folder (3) from a file in the folder's place (267);
view() already knows which. Reported in review by shdann, with the host table.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
main's G:/T: drives (4c52ce2) made a T: create build its parent folders and pinned
that in file_system_test. The folder-exists rule of this branch now applies to the
package view (GAME:, G:) only, so that merged behaviour stands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MrCheese5
MrCheese5 force-pushed the claude/fs-view-rules branch from 83000f3 to 08fc8ec Compare November 22, 2026 22:18
@MrCheese5

Copy link
Copy Markdown
Contributor Author

Rebased onto main 4c52ce27 (head now 08fc8ec). Since this PR was opened, main gained the G:\/T:\ drives (RT-218), the staging copy-up (#3063) and the absolute game folder (#2957), all in file_system.cpp.

  • The test file conflicted only because both sides appended a block at the end; both are kept.
  • One behaviour decision to look at: a check that came in with RT-218 expects a T:\ create to make its own parent folders ("CreateFileW creates a file on T: (parent folders and all)"). That contradicts this PR's rule that the folder must already exist. I kept the merged T: behaviour, and the rule now applies to the package view (GAME: and G:) only (commit 08fc8ec, one line in write_target and one clause in docs/runtime_imports.md). On a real drive the host would fail that create with ERROR_PATH_NOT_FOUND. If you want T: to follow the host too, say so and I will drop the exception and update that check.

On this head: file_system_test 190 checks, 0 failures; full ctest (Visual Studio's 3.31.6, LEONIDA_GAME_DIR set) 153 run, 146 passed, 7 skipped, 0 failed. AI-assisted (Claude Code).

@FaKL-Code

Copy link
Copy Markdown
Contributor

Tested 08fc8ec (merged onto main aa2988c) on NVIDIA GeForce RTX 4060 Ti, driver 610.88 (32.0.16.1088), Windows 11 26200, MSVC 14.51.36231 (VS 2026), Vulkan SDK 1.4.363.0: pass

  • Merges cleanly; no new compiler warnings against main.

  • ctest: 144 of 144 pass (same 9 skips as main). Loader test passes; validation run: 56 tests clean.

  • file_system -V: "190 check(s), 0 failure(s)".

  • I also built this PR's file_system_test.cpp against main's file_system.cpp: "190 check(s), 23 failure(s)". The 23 are the new checks:

    • a listing or a write-open in a missing folder (ERROR_PATH_NOT_FOUND, nothing created);
    • CREATE_ALWAYS in missing, removed or below-a-file folders;
    • FindFirstFileW in removed or never-existing folders, and below a file (ERROR_DIRECTORY, and ERROR_PATH_NOT_FOUND two levels down);
    • the same-name and case-only MoveFileW cases.

    So each new check fails on main and passes here.

  • (The earlier head, e949c0d on main f847748, also passed here: 131 of 131, file_system 170 checks, 20 of them failing against main's shim.)

  • Heads-up for merge order: file_system: serve the file shims under the three other API sets a title imports them by #3683 also adds checks to runtime/test/file_system_test.cpp, and with both rebased, git merge-tree still reports a conflict there (file_system.cpp merges cleanly). file_system: CopyFile2 falls back to CopyFileExW on Wine 9 (RT-237) #3655 merges cleanly with this one.

AI-assisted (Claude).

@kapitche

Copy link
Copy Markdown
Collaborator

Tested 08fc8ec merged with main 3faac55 on Windows (MSVC 14.51, RelWithDebInfo) and with main 98fa503 on Linux (Python 3.12.16): pass. ctest file_system 1/1 (it does not use the GPU; the result is the same with the NVIDIA and the Intel selection). Negative control with main's runtime/shims/file_system.cpp: file_system fails. Linux: the four tests/test_docs_*.py 4/4 ok.

@ItsNotRexed
ItsNotRexed merged commit 0c1437d into ProjectLeonida:main Nov 23, 2026
3 of 10 checks 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.

7 participants