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/test/file_system_test.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/test/file_system_test.cpp')
| -rw-r--r-- | runtime/test/file_system_test.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/runtime/test/file_system_test.cpp b/runtime/test/file_system_test.cpp index fd450769f..b99345a4a 100644 --- a/runtime/test/file_system_test.cpp +++ b/runtime/test/file_system_test.cpp | |||
| @@ -5,7 +5,10 @@ | |||
| 5 | // folder that stands in for the game install, an overlay folder, and a "GAME:" path in each variant. | 5 | // folder that stands in for the game install, an overlay folder, and a "GAME:" path in each variant. |
| 6 | #include <windows.h> | 6 | #include <windows.h> |
| 7 | 7 | ||
| 8 | #include <aclapi.h> | ||
| 9 | |||
| 8 | #include <algorithm> | 10 | #include <algorithm> |
| 11 | #include <clocale> | ||
| 9 | #include <cstdio> | 12 | #include <cstdio> |
| 10 | #include <filesystem> | 13 | #include <filesystem> |
| 11 | #include <initializer_list> | 14 | #include <initializer_list> |
| @@ -268,6 +271,67 @@ int main() { | |||
| 268 | "and the listing hides it, as the file system's compare does"); | 271 | "and the listing hides it, as the file system's compare does"); |
| 269 | } | 272 | } |
| 270 | 273 | ||
| 274 | // Duplicates are decided by _wcsicmp (same_name) in the title's locale, not by a lower-cased key: under .UTF-8, | ||
| 275 | // _wcslwr_s folds U+00C9 and U+00E9 while _wcsicmp keeps them apart. | ||
| 276 | { | ||
| 277 | write_path(overlay / "loc" / L"Éclair.txt", "overlay"); | ||
| 278 | write_path(package / "loc" / L"éclair.txt", "package"); | ||
| 279 | const char* old = std::setlocale(LC_CTYPE, nullptr); | ||
| 280 | const std::string saved = old ? old : "C"; | ||
| 281 | if (std::setlocale(LC_CTYPE, ".UTF-8")) { | ||
| 282 | const int expected = _wcsicmp(L"Éclair.txt", L"éclair.txt") == 0 ? 1 : 2; | ||
| 283 | const std::vector<std::wstring> names = list(first_w, next_w, find_close, L"GAME:\\loc\\*"); | ||
| 284 | int files = 0; | ||
| 285 | for (const auto& n : names) | ||
| 286 | if (n != L"." && n != L"..") ++files; | ||
| 287 | check(files == expected, "under .UTF-8 the merged listing keeps exactly the names _wcsicmp tells apart"); | ||
| 288 | } | ||
| 289 | std::setlocale(LC_CTYPE, saved.c_str()); | ||
| 290 | } | ||
| 291 | |||
| 292 | // A marker folder that cannot be listed (listing denied, lookups by path still allowed) is not "no markers": | ||
| 293 | // the deleted file stays hidden, as GetFileAttributesW already reports it. | ||
| 294 | { | ||
| 295 | write_path(package / "acl" / "a.txt", "package"); | ||
| 296 | write_path(package / "acl" / "b.txt", "package"); | ||
| 297 | check(delete_w(L"GAME:\\acl\\a.txt") != FALSE, "DeleteFileW hides a.txt"); | ||
| 298 | const std::wstring marks = (overlay / ".gta6rt-deleted" / "acl").wstring(); | ||
| 299 | PACL old_dacl = nullptr; | ||
| 300 | PSECURITY_DESCRIPTOR sd = nullptr; | ||
| 301 | bool denied = false; | ||
| 302 | if (GetNamedSecurityInfoW(marks.c_str(), SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, nullptr, nullptr, | ||
| 303 | &old_dacl, nullptr, &sd) == ERROR_SUCCESS) { | ||
| 304 | EXPLICIT_ACCESS_W deny{}; | ||
| 305 | deny.grfAccessPermissions = FILE_LIST_DIRECTORY; | ||
| 306 | deny.grfAccessMode = DENY_ACCESS; | ||
| 307 | deny.grfInheritance = NO_INHERITANCE; | ||
| 308 | BuildTrusteeWithNameW(&deny.Trustee, const_cast<LPWSTR>(L"CURRENT_USER")); | ||
| 309 | PACL new_dacl = nullptr; | ||
| 310 | if (SetEntriesInAclW(1, &deny, old_dacl, &new_dacl) == ERROR_SUCCESS) { | ||
| 311 | denied = SetNamedSecurityInfoW(const_cast<LPWSTR>(marks.c_str()), SE_FILE_OBJECT, | ||
| 312 | DACL_SECURITY_INFORMATION, nullptr, nullptr, new_dacl, | ||
| 313 | nullptr) == ERROR_SUCCESS; | ||
| 314 | LocalFree(new_dacl); | ||
| 315 | } | ||
| 316 | } | ||
| 317 | WIN32_FIND_DATAW probe{}; | ||
| 318 | const HANDLE ph = ::FindFirstFileW((marks + L"\\*").c_str(), &probe); | ||
| 319 | const bool listing_denied = ph == INVALID_HANDLE_VALUE && GetLastError() == ERROR_ACCESS_DENIED; | ||
| 320 | if (ph != INVALID_HANDLE_VALUE) ::FindClose(ph); | ||
| 321 | if (denied && listing_denied) { | ||
| 322 | check(attributes_w(L"GAME:\\acl\\a.txt") == INVALID_FILE_ATTRIBUTES, "a.txt is still missing by path"); | ||
| 323 | const std::vector<std::wstring> names = list(first_w, next_w, find_close, L"GAME:\\acl\\*"); | ||
| 324 | check(!contains(names, L"a.txt") && contains(names, L"b.txt"), | ||
| 325 | "a marker folder that cannot be listed still hides its deleted files"); | ||
| 326 | } else { | ||
| 327 | std::printf("SKIP could not deny listing the marker folder\n"); | ||
| 328 | } | ||
| 329 | if (denied) | ||
| 330 | SetNamedSecurityInfoW(const_cast<LPWSTR>(marks.c_str()), SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, | ||
| 331 | nullptr, nullptr, old_dacl, nullptr); | ||
| 332 | if (sd) LocalFree(sd); | ||
| 333 | } | ||
| 334 | |||
| 271 | // A delete hides the package file without removing it. | 335 | // A delete hides the package file without removing it. |
| 272 | { | 336 | { |
| 273 | check(delete_w(L"GAME:\\data\\dup.txt") != FALSE, "DeleteFileW accepts a package file"); | 337 | check(delete_w(L"GAME:\\data\\dup.txt") != FALSE, "DeleteFileW accepts a package file"); |