diff options
| author | ezbyDev <198480541+ezbyDev@users.noreply.github.com> | 2026-11-23 00:31:35 +0100 |
|---|---|---|
| committer | ezbyDev <198480541+ezbyDev@users.noreply.github.com> | 2026-11-23 00:31:35 +0100 |
| commit | c49b5ec65fbdb315fc760da6256cafebf4325fb1 (patch) | |
| tree | 4d0c0d793c7385a0a58e4b40bd92eed69d930b73 /runtime/shims/file_system.cpp | |
| parent | 0f3d467f0ae3c3dae52c58c32cadc0125fe04924 (diff) | |
file_system: collect falls back to deleted() and dedupes by _wcsicmp (RT-257)
Review on #3955 (@pedro470), both reproduced here:
- A marker folder that cannot be listed (FILE_LIST_DIRECTORY denied, the
markers still reachable by path) read as "no markers", so a deleted
package file came back in the listing. Only ERROR_FILE_NOT_FOUND or
ERROR_PATH_NOT_FOUND now means nothing is deleted; any other failure,
an incomplete FindNextFileW scan or a marker that cannot be checked
sends each entry through deleted().
- A _wcslwr_s key is not _wcsicmp in every locale: under .UTF-8 it folds
U+00C9 and U+00E9, which _wcsicmp keeps apart, so a package entry was
dropped. The names seen are now a std::set ordered by _wcsicmp, so two
names are one entry exactly when same_name says so. Same timing.
Tests: the listing-denied marker folder (through the ACL API, restored
after), and a .UTF-8 merged listing checked against _wcsicmp itself. The
previous head fails both; each single fix removed fails its own check.
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 | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp index 92e7935cf..d6f8df877 100644 --- a/runtime/shims/file_system.cpp +++ b/runtime/shims/file_system.cpp | |||
| @@ -31,6 +31,7 @@ | |||
| 31 | #include <map> | 31 | #include <map> |
| 32 | #include <memory> | 32 | #include <memory> |
| 33 | #include <mutex> | 33 | #include <mutex> |
| 34 | #include <set> | ||
| 34 | #include <string> | 35 | #include <string> |
| 35 | #include <unordered_set> | 36 | #include <unordered_set> |
| 36 | #include <vector> | 37 | #include <vector> |
| @@ -515,8 +516,18 @@ bool collect(const std::wstring& pattern, const std::vector<std::wstring>& parts | |||
| 515 | const bool dir = (m.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; | 516 | const bool dir = (m.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; |
| 516 | if (!dir || std::filesystem::is_regular_file(marks / m.cFileName / kRemovedDirMarker, ec)) | 517 | if (!dir || std::filesystem::is_regular_file(marks / m.cFileName / kRemovedDirMarker, ec)) |
| 517 | deleted_here.insert(ascii_key(m.cFileName)); | 518 | deleted_here.insert(ascii_key(m.cFileName)); |
| 519 | if (ec) markers_exact = false; // the folder's marker could not be checked: ask deleted() per entry | ||
| 518 | } while (::FindNextFileW(mh, &m)); | 520 | } while (::FindNextFileW(mh, &m)); |
| 521 | if (::GetLastError() != ERROR_NO_MORE_FILES) markers_exact = false; // an incomplete scan | ||
| 519 | ::FindClose(mh); | 522 | ::FindClose(mh); |
| 523 | } else { | ||
| 524 | // Only a missing marker folder means "nothing deleted here". Any other failure (a folder that cannot be | ||
| 525 | // listed although its markers can be queried by path, for one) leaves the decision to deleted(). | ||
| 526 | const DWORD e = ::GetLastError(); | ||
| 527 | if (e != ERROR_FILE_NOT_FOUND && e != ERROR_PATH_NOT_FOUND) { | ||
| 528 | has_markers = true; | ||
| 529 | markers_exact = false; | ||
| 530 | } | ||
| 520 | } | 531 | } |
| 521 | } | 532 | } |
| 522 | auto entry_deleted = [&](const wchar_t* name) { | 533 | auto entry_deleted = [&](const wchar_t* name) { |
| @@ -526,14 +537,13 @@ bool collect(const std::wstring& pattern, const std::vector<std::wstring>& parts | |||
| 526 | entry_parts.push_back(name); | 537 | entry_parts.push_back(name); |
| 527 | return deleted(r.overlay, entry_parts); | 538 | return deleted(r.overlay, entry_parts); |
| 528 | }; | 539 | }; |
| 529 | // Names already listed, folded the way same_name (_wcsicmp) compares them: _wcslwr_s uses the same locale rule. | 540 | // Names already listed, ordered by _wcsicmp itself, so two names are one entry exactly when same_name says so, in |
| 530 | std::unordered_set<std::wstring> seen; | 541 | // whatever locale the title set (a lower-cased key is not: under .UTF-8 _wcslwr_s folds É and é, _wcsicmp not). |
| 531 | auto key = [](const wchar_t* name) { | 542 | struct NoCase { |
| 532 | std::wstring k = name; | 543 | bool operator()(const std::wstring& a, const std::wstring& b) const { return _wcsicmp(a.c_str(), b.c_str()) < 0; } |
| 533 | _wcslwr_s(k.data(), k.size() + 1); | ||
| 534 | return k; | ||
| 535 | }; | 544 | }; |
| 536 | for (const auto& e : out) seen.insert(key(e.cFileName)); | 545 | std::set<std::wstring, NoCase> seen; |
| 546 | for (const auto& e : out) seen.insert(e.cFileName); | ||
| 537 | 547 | ||
| 538 | auto add_root = [&](const std::filesystem::path& root, bool overlay_root) { | 548 | auto add_root = [&](const std::filesystem::path& root, bool overlay_root) { |
| 539 | if (root.empty()) return; | 549 | if (root.empty()) return; |
| @@ -546,7 +556,7 @@ bool collect(const std::wstring& pattern, const std::vector<std::wstring>& parts | |||
| 546 | if (overlay_root && internal_dir(found.cFileName)) continue; | 556 | if (overlay_root && internal_dir(found.cFileName)) continue; |
| 547 | const bool dot = same_name(found.cFileName, L".") || same_name(found.cFileName, L".."); | 557 | const bool dot = same_name(found.cFileName, L".") || same_name(found.cFileName, L".."); |
| 548 | if (!overlay_root && !dot && entry_deleted(found.cFileName)) continue; | 558 | if (!overlay_root && !dot && entry_deleted(found.cFileName)) continue; |
| 549 | if (seen.insert(key(found.cFileName)).second) out.push_back(found); | 559 | if (seen.insert(found.cFileName).second) out.push_back(found); |
| 550 | } while (::FindNextFileW(h, &found)); | 560 | } while (::FindNextFileW(h, &found)); |
| 551 | ::FindClose(h); | 561 | ::FindClose(h); |
| 552 | }; | 562 | }; |