diff options
| author | ezbyDev <198480541+ezbyDev@users.noreply.github.com> | 2026-11-23 00:16:25 +0100 |
|---|---|---|
| committer | ezbyDev <198480541+ezbyDev@users.noreply.github.com> | 2026-11-23 00:16:25 +0100 |
| commit | 0f3d467f0ae3c3dae52c58c32cadc0125fe04924 (patch) | |
| tree | e8a6f0dea4150c1dc59c91f705729adf88407ce5 /runtime/shims/file_system.cpp | |
| parent | 8518626c1b4925ad93bd852d58faa50c1a86e7cc (diff) | |
file_system: read the folder's deletion markers once, also when it has some (RT-257)
Review on #3955 (@Parakeet-Wheat, @shdann): the fast path only held while
the folder had no marker folder. One DeleteFileW creates it, and every
package entry was probed with deleted() again: 1,073 ms for 16,000 files
after two deletes, against 27 ms now.
collect() lists the marker folder once and keeps the deleted names in a
set, with deleted()'s rule: a marker file, or a marker folder holding
kRemovedDirMarker. The lookup folds ASCII letters only, which is exactly
the file system's case-insensitive compare when both names are ASCII. A
non-ASCII entry, or a marker that is not plain ASCII or is a reparse
point, still goes through deleted(), so the file system's Unicode case
rule decides (deleting éclair.txt hides the package's Éclair.txt, as on
main).
Tests: a delete under another ASCII case in a 300-file folder hides only
that file; the Éclair case above.
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 | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp index 17a0c689f..92e7935cf 100644 --- a/runtime/shims/file_system.cpp +++ b/runtime/shims/file_system.cpp | |||
| @@ -480,10 +480,52 @@ bool collect(const std::wstring& pattern, const std::vector<std::wstring>& parts | |||
| 480 | return false; | 480 | return false; |
| 481 | } | 481 | } |
| 482 | 482 | ||
| 483 | // Every deletion marker for an entry of this folder lives inside its marker folder, so when that folder is missing | 483 | // Every deletion marker for an entry of this folder lives inside its marker folder, so that folder is read once |
| 484 | // nothing here is deleted and the per-entry probes (two file checks each) can be skipped. | 484 | // instead of probing it twice per package entry (deleted()). An entry is deleted when its marker is a file, or a |
| 485 | std::error_code ec; | 485 | // folder holding kRemovedDirMarker: the rule deleted() applies. The lookup folds ASCII letters only, which matches |
| 486 | const bool has_markers = !r.overlay.empty() && std::filesystem::is_directory(marker(r.overlay, dirs), ec); | 486 | // the file system's case-insensitive compare exactly when both names are ASCII. Any other name, a non-ASCII entry |
| 487 | // or a marker that is not plain ASCII or is a reparse point, goes through deleted() and the file system's rule. | ||
| 488 | auto ascii = [](const wchar_t* s) { | ||
| 489 | for (; *s; ++s) | ||
| 490 | if (*s > 0x7f) return false; | ||
| 491 | return true; | ||
| 492 | }; | ||
| 493 | auto ascii_key = [](const wchar_t* s) { | ||
| 494 | std::wstring k = s; | ||
| 495 | for (auto& c : k) | ||
| 496 | if (c >= L'A' && c <= L'Z') c = static_cast<wchar_t>(c - L'A' + L'a'); | ||
| 497 | return k; | ||
| 498 | }; | ||
| 499 | bool has_markers = false; | ||
| 500 | bool markers_exact = true; | ||
| 501 | std::unordered_set<std::wstring> deleted_here; | ||
| 502 | if (!r.overlay.empty()) { | ||
| 503 | const std::filesystem::path marks = marker(r.overlay, dirs); | ||
| 504 | WIN32_FIND_DATAW m{}; | ||
| 505 | const HANDLE mh = ::FindFirstFileW((marks / L"*").c_str(), &m); | ||
| 506 | if (mh != INVALID_HANDLE_VALUE) { | ||
| 507 | has_markers = true; | ||
| 508 | do { | ||
| 509 | if (same_name(m.cFileName, L".") || same_name(m.cFileName, L"..")) continue; | ||
| 510 | if (!ascii(m.cFileName) || (m.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) { | ||
| 511 | markers_exact = false; | ||
| 512 | continue; | ||
| 513 | } | ||
| 514 | std::error_code ec; | ||
| 515 | const bool dir = (m.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; | ||
| 516 | if (!dir || std::filesystem::is_regular_file(marks / m.cFileName / kRemovedDirMarker, ec)) | ||
| 517 | deleted_here.insert(ascii_key(m.cFileName)); | ||
| 518 | } while (::FindNextFileW(mh, &m)); | ||
| 519 | ::FindClose(mh); | ||
| 520 | } | ||
| 521 | } | ||
| 522 | auto entry_deleted = [&](const wchar_t* name) { | ||
| 523 | if (!has_markers) return false; | ||
| 524 | if (markers_exact && ascii(name)) return deleted_here.count(ascii_key(name)) != 0; | ||
| 525 | std::vector<std::wstring> entry_parts = dirs; | ||
| 526 | entry_parts.push_back(name); | ||
| 527 | return deleted(r.overlay, entry_parts); | ||
| 528 | }; | ||
| 487 | // Names already listed, folded the way same_name (_wcsicmp) compares them: _wcslwr_s uses the same locale rule. | 529 | // Names already listed, folded the way same_name (_wcsicmp) compares them: _wcslwr_s uses the same locale rule. |
| 488 | std::unordered_set<std::wstring> seen; | 530 | std::unordered_set<std::wstring> seen; |
| 489 | auto key = [](const wchar_t* name) { | 531 | auto key = [](const wchar_t* name) { |
| @@ -503,11 +545,7 @@ bool collect(const std::wstring& pattern, const std::vector<std::wstring>& parts | |||
| 503 | do { | 545 | do { |
| 504 | if (overlay_root && internal_dir(found.cFileName)) continue; | 546 | if (overlay_root && internal_dir(found.cFileName)) continue; |
| 505 | const bool dot = same_name(found.cFileName, L".") || same_name(found.cFileName, L".."); | 547 | const bool dot = same_name(found.cFileName, L".") || same_name(found.cFileName, L".."); |
| 506 | if (!overlay_root && !dot && has_markers) { | 548 | if (!overlay_root && !dot && entry_deleted(found.cFileName)) continue; |
| 507 | std::vector<std::wstring> entry_parts = dirs; | ||
| 508 | entry_parts.push_back(found.cFileName); | ||
| 509 | if (deleted(r.overlay, entry_parts)) continue; | ||
| 510 | } | ||
| 511 | if (seen.insert(key(found.cFileName)).second) out.push_back(found); | 549 | if (seen.insert(key(found.cFileName)).second) out.push_back(found); |
| 512 | } while (::FindNextFileW(h, &found)); | 550 | } while (::FindNextFileW(h, &found)); |
| 513 | ::FindClose(h); | 551 | ::FindClose(h); |