diff options
| author | kotorvr <332716892+kotorvr@users.noreply.github.com> | 2026-11-22 20:59:34 +0000 |
|---|---|---|
| committer | kotorvr <332716892+kotorvr@users.noreply.github.com> | 2026-11-22 22:05:06 +0000 |
| commit | 95f023f62b1fb5c28d88cfbc176de3d6a0c4de17 (patch) | |
| tree | 7c70ba1cad2e7daf9a682185af305cce712f03e8 /runtime/shims/file_system.cpp | |
| parent | 4c52ce27a6cf4af2bbf07a343ede39c5f1572b8d (diff) | |
file_system: a folder has to exist in the title's view; same-name moves 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>
Diffstat (limited to 'runtime/shims/file_system.cpp')
| -rw-r--r-- | runtime/shims/file_system.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp index 5b9f92199..947700139 100644 --- a/runtime/shims/file_system.cpp +++ b/runtime/shims/file_system.cpp | |||
| @@ -271,6 +271,14 @@ View view(const Roots& r, const std::vector<std::wstring>& parts) { | |||
| 271 | 271 | ||
| 272 | bool is_folder(const Roots& r, const std::vector<std::wstring>& parts) { return view(r, parts).kind == Kind::Directory; } | 272 | bool is_folder(const Roots& r, const std::vector<std::wstring>& parts) { return view(r, parts).kind == Kind::Directory; } |
| 273 | 273 | ||
| 274 | // Whether two console paths name the same entry: names compare without case, as the lookups do. | ||
| 275 | bool same_entry(const std::vector<std::wstring>& a, const std::vector<std::wstring>& b) { | ||
| 276 | if (a.size() != b.size()) return false; | ||
| 277 | for (size_t i = 0; i < a.size(); ++i) | ||
| 278 | if (!same_name(a[i].c_str(), b[i].c_str())) return false; | ||
| 279 | return true; | ||
| 280 | } | ||
| 281 | |||
| 274 | std::vector<std::wstring> parent_of(const std::vector<std::wstring>& parts) { | 282 | std::vector<std::wstring> parent_of(const std::vector<std::wstring>& parts) { |
| 275 | return parts.empty() ? parts : std::vector<std::wstring>(parts.begin(), parts.end() - 1); | 283 | return parts.empty() ? parts : std::vector<std::wstring>(parts.begin(), parts.end() - 1); |
| 276 | } | 284 | } |
| @@ -348,6 +356,12 @@ Target write_target(const std::wstring& path, bool copy_up) { | |||
| 348 | if (r.overlay.empty()) return fail(ERROR_PATH_NOT_FOUND); | 356 | if (r.overlay.empty()) return fail(ERROR_PATH_NOT_FOUND); |
| 349 | if (parts.empty()) return fail(ERROR_INVALID_NAME); // "GAME:" is a folder, not a file | 357 | if (parts.empty()) return fail(ERROR_INVALID_NAME); // "GAME:" is a folder, not a file |
| 350 | 358 | ||
| 359 | // The folder has to exist in the title's view, as CreateDirectory, MoveFile and CopyFile require: without the | ||
| 360 | // check a failed open left the missing folders behind, and a create succeeded in a folder that was never made, | ||
| 361 | // below a package file (which then read as a folder) and inside a folder the title had removed. The overlay may | ||
| 362 | // still lack a folder only the package has, so it is mirrored here, which the title cannot see. | ||
| 363 | if (!is_folder(r, parent_of(parts))) return fail(ERROR_PATH_NOT_FOUND); | ||
| 364 | |||
| 351 | Target t; | 365 | Target t; |
| 352 | t.path = join(r.overlay, parts); | 366 | t.path = join(r.overlay, parts); |
| 353 | 367 | ||
| @@ -454,6 +468,12 @@ bool collect(const std::wstring& pattern, const std::vector<std::wstring>& parts | |||
| 454 | error = ERROR_PATH_NOT_FOUND; | 468 | error = ERROR_PATH_NOT_FOUND; |
| 455 | return false; | 469 | return false; |
| 456 | } | 470 | } |
| 471 | // The folder being listed has to exist in the title's view. The host would still enumerate a package folder the | ||
| 472 | // title removed (its "." and ".."), and a folder that is missing is a missing path, not a missing file. | ||
| 473 | if (!is_folder(r, dirs)) { | ||
| 474 | error = ERROR_PATH_NOT_FOUND; | ||
| 475 | return false; | ||
| 476 | } | ||
| 457 | 477 | ||
| 458 | auto add_root = [&](const std::filesystem::path& root, bool overlay_root) { | 478 | auto add_root = [&](const std::filesystem::path& root, bool overlay_root) { |
| 459 | if (root.empty()) return; | 479 | if (root.empty()) return; |
| @@ -909,12 +929,31 @@ BOOL WINAPI move_file_ex_w(LPCWSTR from, LPCWSTR to, DWORD flags) { | |||
| 909 | if (src.empty() || dst.empty()) return fail_bool(ERROR_ACCESS_DENIED); | 929 | if (src.empty() || dst.empty()) return fail_bool(ERROR_ACCESS_DENIED); |
| 910 | const View from_view = view(r, src); | 930 | const View from_view = view(r, src); |
| 911 | if (from_view.kind == Kind::None) return fail_bool(ERROR_FILE_NOT_FOUND); | 931 | if (from_view.kind == Kind::None) return fail_bool(ERROR_FILE_NOT_FOUND); |
| 932 | const std::filesystem::path overlay_from = join(r.overlay, src), overlay_to = join(r.overlay, dst); | ||
| 933 | if (same_entry(src, dst)) { | ||
| 934 | // The destination is the source, so it is not "already there". The host succeeds at a move onto the same | ||
| 935 | // name and changes nothing, and renames when only the case differs. Here the case of a name is the overlay's | ||
| 936 | // when the overlay holds it, so a package file gets an overlay copy under the new spelling (no marker: the | ||
| 937 | // listing takes the overlay's entry and skips the package's as the same name); a package folder is left | ||
| 938 | // where it is, as for any other move of one. | ||
| 939 | if (src == dst) return TRUE; | ||
| 940 | if (from_view.kind == Kind::Directory && from_view.in_package) return fail_bool(ERROR_ACCESS_DENIED); | ||
| 941 | if (from_view.in_overlay) | ||
| 942 | return ::MoveFileExW(overlay_from.c_str(), overlay_to.c_str(), flags & MOVEFILE_WRITE_THROUGH); | ||
| 943 | std::error_code same_ec; | ||
| 944 | std::filesystem::create_directories(overlay_to.parent_path(), same_ec); | ||
| 945 | if (same_ec) return fail_bool(static_cast<DWORD>(same_ec.value())); | ||
| 946 | if (!::CopyFileW(join(r.game, src).c_str(), overlay_to.c_str(), TRUE)) return FALSE; | ||
| 947 | DWORD flush_error = 0; | ||
| 948 | if ((flags & MOVEFILE_WRITE_THROUGH) != 0 && !flush_file(overlay_to, flush_error)) return fail_bool(flush_error); | ||
| 949 | return TRUE; | ||
| 950 | } | ||
| 951 | |||
| 912 | const View to_view = view(r, dst); | 952 | const View to_view = view(r, dst); |
| 913 | if (to_view.kind == Kind::Directory) return fail_bool(ERROR_ACCESS_DENIED); | 953 | if (to_view.kind == Kind::Directory) return fail_bool(ERROR_ACCESS_DENIED); |
| 914 | if (to_view.kind == Kind::File && (flags & MOVEFILE_REPLACE_EXISTING) == 0) return fail_bool(ERROR_ALREADY_EXISTS); | 954 | if (to_view.kind == Kind::File && (flags & MOVEFILE_REPLACE_EXISTING) == 0) return fail_bool(ERROR_ALREADY_EXISTS); |
| 915 | if (!is_folder(r, parent_of(dst))) return fail_bool(ERROR_PATH_NOT_FOUND); | 955 | if (!is_folder(r, parent_of(dst))) return fail_bool(ERROR_PATH_NOT_FOUND); |
| 916 | 956 | ||
| 917 | const std::filesystem::path overlay_from = join(r.overlay, src), overlay_to = join(r.overlay, dst); | ||
| 918 | std::error_code ec; | 957 | std::error_code ec; |
| 919 | std::filesystem::create_directories(overlay_to.parent_path(), ec); | 958 | std::filesystem::create_directories(overlay_to.parent_path(), ec); |
| 920 | if (ec) return fail_bool(static_cast<DWORD>(ec.value())); | 959 | if (ec) return fail_bool(static_cast<DWORD>(ec.value())); |