diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:08:07 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:08:07 -0500 |
| commit | 0c1437dfd988e5d7d57d5ffdf144b8ea7bd08391 (patch) | |
| tree | 9730e263294374bdabf5bbb00dff98b91cec96cb /runtime/shims/file_system.cpp | |
| parent | 8d3a8336bc07b5e7347c202e484c50c1533213d4 (diff) | |
| parent | 08fc8ec748e35bc79985cf040310a7898b5d694c (diff) | |
Merge pull request #3651 from kotorvr
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/file_system.cpp')
| -rw-r--r-- | runtime/shims/file_system.cpp | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp index 014514597..7b932be3c 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,14 @@ 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 | // T:'s scratch folder is the exception: it creates its parent folders, as merged with RT-218. | ||
| 364 | const bool scratch = !parts.empty() && same_name(parts.front().c_str(), kScratchDir); | ||
| 365 | if (!scratch && !is_folder(r, parent_of(parts))) return fail(ERROR_PATH_NOT_FOUND); | ||
| 366 | |||
| 351 | Target t; | 367 | Target t; |
| 352 | t.path = join(r.overlay, parts); | 368 | t.path = join(r.overlay, parts); |
| 353 | 369 | ||
| @@ -456,6 +472,14 @@ bool collect(const std::wstring& pattern, const std::vector<std::wstring>& parts | |||
| 456 | error = ERROR_PATH_NOT_FOUND; | 472 | error = ERROR_PATH_NOT_FOUND; |
| 457 | return false; | 473 | return false; |
| 458 | } | 474 | } |
| 475 | // The folder being listed has to exist in the title's view. The host would still enumerate a package folder the | ||
| 476 | // title removed (its "." and ".."), and a folder that is missing is a missing path, not a missing file. A listing | ||
| 477 | // below a file is a third answer on the host, ERROR_DIRECTORY. | ||
| 478 | const Kind listed = view(r, dirs).kind; | ||
| 479 | if (listed != Kind::Directory) { | ||
| 480 | error = listed == Kind::File ? ERROR_DIRECTORY : ERROR_PATH_NOT_FOUND; | ||
| 481 | return false; | ||
| 482 | } | ||
| 459 | 483 | ||
| 460 | auto add_root = [&](const std::filesystem::path& root, bool overlay_root) { | 484 | auto add_root = [&](const std::filesystem::path& root, bool overlay_root) { |
| 461 | if (root.empty()) return; | 485 | if (root.empty()) return; |
| @@ -911,12 +935,31 @@ BOOL WINAPI move_file_ex_w(LPCWSTR from, LPCWSTR to, DWORD flags) { | |||
| 911 | if (src.empty() || dst.empty()) return fail_bool(ERROR_ACCESS_DENIED); | 935 | if (src.empty() || dst.empty()) return fail_bool(ERROR_ACCESS_DENIED); |
| 912 | const View from_view = view(r, src); | 936 | const View from_view = view(r, src); |
| 913 | if (from_view.kind == Kind::None) return fail_bool(ERROR_FILE_NOT_FOUND); | 937 | if (from_view.kind == Kind::None) return fail_bool(ERROR_FILE_NOT_FOUND); |
| 938 | const std::filesystem::path overlay_from = join(r.overlay, src), overlay_to = join(r.overlay, dst); | ||
| 939 | if (same_entry(src, dst)) { | ||
| 940 | // The destination is the source, so it is not "already there". The host succeeds at a move onto the same | ||
| 941 | // name and changes nothing, and renames when only the case differs. Here the case of a name is the overlay's | ||
| 942 | // when the overlay holds it, so a package file gets an overlay copy under the new spelling (no marker: the | ||
| 943 | // listing takes the overlay's entry and skips the package's as the same name); a package folder is left | ||
| 944 | // where it is, as for any other move of one. | ||
| 945 | if (src == dst) return TRUE; | ||
| 946 | if (from_view.kind == Kind::Directory && from_view.in_package) return fail_bool(ERROR_ACCESS_DENIED); | ||
| 947 | if (from_view.in_overlay) | ||
| 948 | return ::MoveFileExW(overlay_from.c_str(), overlay_to.c_str(), flags & MOVEFILE_WRITE_THROUGH); | ||
| 949 | std::error_code same_ec; | ||
| 950 | std::filesystem::create_directories(overlay_to.parent_path(), same_ec); | ||
| 951 | if (same_ec) return fail_bool(static_cast<DWORD>(same_ec.value())); | ||
| 952 | if (!::CopyFileW(join(r.game, src).c_str(), overlay_to.c_str(), TRUE)) return FALSE; | ||
| 953 | DWORD flush_error = 0; | ||
| 954 | if ((flags & MOVEFILE_WRITE_THROUGH) != 0 && !flush_file(overlay_to, flush_error)) return fail_bool(flush_error); | ||
| 955 | return TRUE; | ||
| 956 | } | ||
| 957 | |||
| 914 | const View to_view = view(r, dst); | 958 | const View to_view = view(r, dst); |
| 915 | if (to_view.kind == Kind::Directory) return fail_bool(ERROR_ACCESS_DENIED); | 959 | if (to_view.kind == Kind::Directory) return fail_bool(ERROR_ACCESS_DENIED); |
| 916 | if (to_view.kind == Kind::File && (flags & MOVEFILE_REPLACE_EXISTING) == 0) return fail_bool(ERROR_ALREADY_EXISTS); | 960 | if (to_view.kind == Kind::File && (flags & MOVEFILE_REPLACE_EXISTING) == 0) return fail_bool(ERROR_ALREADY_EXISTS); |
| 917 | if (!is_folder(r, parent_of(dst))) return fail_bool(ERROR_PATH_NOT_FOUND); | 961 | if (!is_folder(r, parent_of(dst))) return fail_bool(ERROR_PATH_NOT_FOUND); |
| 918 | 962 | ||
| 919 | const std::filesystem::path overlay_from = join(r.overlay, src), overlay_to = join(r.overlay, dst); | ||
| 920 | std::error_code ec; | 963 | std::error_code ec; |
| 921 | std::filesystem::create_directories(overlay_to.parent_path(), ec); | 964 | std::filesystem::create_directories(overlay_to.parent_path(), ec); |
| 922 | if (ec) return fail_bool(static_cast<DWORD>(ec.value())); | 965 | if (ec) return fail_bool(static_cast<DWORD>(ec.value())); |