upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/file_system_test.cpp
diff options
context:
space:
mode:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-23 17:41:05 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-23 17:41:05 -0500
commitbacf6f4e2a554848b2c7419195a852c229d3b15b (patch)
treec0c25cdbf51e67546f30c73eb0361f96b947a9e5 /runtime/test/file_system_test.cpp
parent0f7dbdd4e93d304670150e49934932132b4493ce (diff)
parent3101e317afdac5a8fd0342d3fd86d9a3c107701d (diff)
Merge remote-tracking branch 'origin/pr/8953'
Diffstat (limited to 'runtime/test/file_system_test.cpp')
-rw-r--r--runtime/test/file_system_test.cpp116
1 files changed, 116 insertions, 0 deletions
diff --git a/runtime/test/file_system_test.cpp b/runtime/test/file_system_test.cpp
index 73665411f..7a5ea6f08 100644
--- a/runtime/test/file_system_test.cpp
+++ b/runtime/test/file_system_test.cpp
@@ -1438,6 +1438,122 @@ void run_checks(const std::filesystem::path& root) {
1438 check(move_w(L"GAME:\\moves", L"GAME:\\MOVES") == FALSE && GetLastError() == ERROR_ACCESS_DENIED, 1438 check(move_w(L"GAME:\\moves", L"GAME:\\MOVES") == FALSE && GetLastError() == ERROR_ACCESS_DENIED,
1439 "a case rename of a package folder is refused like any other move of one"); 1439 "a case rename of a package folder is refused like any other move of one");
1440 } 1440 }
1441
1442 // The guest can reach a deeply nested file even when its executable and the configured roots are short.
1443 // Use the explicit Win32 namespace to set up the fixtures, independently of the shim under test.
1444 {
1445 const auto extended = [](const std::filesystem::path& path) {
1446 const auto& native = path.native();
1447 if (native.starts_with(L"\\\\?\\")) return path;
1448 if (native.starts_with(L"\\\\")) return std::filesystem::path(L"\\\\?\\UNC\\" + native.substr(2));
1449 return std::filesystem::path(L"\\\\?\\" + native);
1450 };
1451 const auto fixture = root / "long_paths";
1452 const auto long_package = fixture / "package";
1453 const auto long_overlay = fixture / "overlay";
1454 const std::wstring first(105, L'a'), second(105, L'b');
1455 const auto relative = std::filesystem::path(first) / second;
1456 const auto package_dir = extended(long_package / relative);
1457 const auto overlay_dir = extended(long_overlay / relative);
1458 const auto leaf = L"pr\u00f8be.bin";
1459 const std::wstring guest_dir = L"GAME:\\" + relative.native() + L"\\";
1460 const std::wstring guest_file = guest_dir + leaf;
1461 check((long_package / relative / leaf).native().size() > MAX_PATH,
1462 "the fixture resolves to a host path beyond MAX_PATH");
1463 write_path(package_dir / leaf, "package");
1464 write_path(package_dir / "legacy.bin", "legacy");
1465 std::filesystem::create_directories(package_dir / "empty");
1466 check(read_path(package_dir / leaf) == "package", "native extended paths can provision the deep fixture");
1467
1468 rt::fs::configure(long_package, long_overlay);
1469 const auto read_guest = [&](const std::wstring& name) {
1470 const HANDLE h = create_w(name.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
1471 if (h == INVALID_HANDLE_VALUE) return std::string{};
1472 auto bytes = read_handle(h);
1473 ::CloseHandle(h);
1474 return bytes;
1475 };
1476 check(read_guest(guest_file) == "package", "GAME: reads a deeply nested Unicode path from the package");
1477 check(read_guest(guest_file + L". ") == "package",
1478 "a long resolved name retains Win32 trailing-dot and trailing-space normalization");
1479 check(attributes_w(guest_file.c_str()) != INVALID_FILE_ATTRIBUTES, "attributes resolve the same long path");
1480 const std::string guest_ansi = "G:\\" + std::string(first.size(), 'a') + "\\" + std::string(second.size(), 'b') +
1481 "\\legacy.bin";
1482 HANDLE h = create_a(guest_ansi.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
1483 check(h != INVALID_HANDLE_VALUE && read_handle(h) == "legacy", "the G: alias opens a long path through CreateFileA");
1484 if (h != INVALID_HANDLE_VALUE) ::CloseHandle(h);
1485
1486 h = create_w(guest_file.c_str(), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr);
1487 DWORD written = 0;
1488 check(h != INVALID_HANDLE_VALUE && ::WriteFile(h, "overlay", 7, &written, nullptr) && written == 7,
1489 "the write-open copies up and writes a long path");
1490 if (h != INVALID_HANDLE_VALUE) ::CloseHandle(h);
1491 check(read_guest(guest_file) == "overlay" && read_path(overlay_dir / leaf) == "overlay" &&
1492 read_path(package_dir / leaf) == "package",
1493 "long paths prefer the overlay copy and keep the original package immutable");
1494
1495 const std::wstring copy = guest_dir + L"copy.bin", moved = guest_dir + L"moved.bin";
1496 check(copy_w(guest_file.c_str(), copy.c_str(), TRUE) && move_w(copy.c_str(), moved.c_str()) &&
1497 read_guest(moved) == "overlay", "copy and move use the same long resolved overlay paths");
1498 check(delete_w((guest_dir + L"legacy.bin").c_str()) && rmdir_w((guest_dir + L"empty").c_str()) &&
1499 read_path(package_dir / "legacy.bin") == "legacy",
1500 "long file and directory deletions create markers and preserve the package");
1501 const auto names = list(first_w, next_w, find_close, (guest_dir + L"*").c_str());
1502 check(count(names, leaf) == 1 && contains(names, L"moved.bin") &&
1503 !contains(names, L"legacy.bin") && !contains(names, L"empty"),
1504 "listing long paths merges both roots and honors file and directory markers");
1505 check(attributes_w((guest_dir + L"legacy.bin").c_str()) == INVALID_FILE_ATTRIBUTES,
1506 "a read-only query respects the long file's delete marker");
1507
1508 // Compare the same merged listing against the short-path Win32 search, including the names
1509 // hidden by package deletion markers.
1510 const wchar_t* const masks[] = {L"*.", L"?.", L"mesh*.", L"mesh*..", L"mesh?.", L"mesh.*.",
1511 L"*.?.", L"*. ", L"*.*", L"mesh?.txt"};
1512 const auto list_masks = [&](const std::filesystem::path& pack, const std::filesystem::path& layer,
1513 const std::filesystem::path& subdir) {
1514 for (const wchar_t* name : {L"a", L"a.txt", L"mesh", L"mesh1", L"mesh.txt", L"mesh-old", L".dot"})
1515 write_path(extended(pack / subdir / name), "package");
1516 for (const wchar_t* name : {L"mesh", L"mesh-cache", L"mesh-cache.tmp"})
1517 write_path(extended(layer / subdir / name), "overlay");
1518 rt::fs::configure(pack, layer);
1519 const auto guest = L"GAME:\\" + subdir.native() + L"\\";
1520 check(delete_w((guest + L"mesh-old").c_str()), "the wildcard fixture hides an extensionless package file");
1521 std::vector<std::vector<std::wstring>> results;
1522 for (const wchar_t* mask : masks) {
1523 auto entries = list(first_w, next_w, find_close, (guest + mask).c_str());
1524 std::sort(entries.begin(), entries.end());
1525 results.push_back(std::move(entries));
1526 }
1527 return results;
1528 };
1529 const auto short_matches = list_masks(fixture / "short_package", fixture / "short_overlay", L"masks");
1530 const auto long_matches = list_masks(long_package, long_overlay, relative / L"masks");
1531 check(count(short_matches[0], L"mesh") == 1 && contains(short_matches[0], L"mesh-cache") &&
1532 !contains(short_matches[0], L"mesh.txt") && !contains(short_matches[0], L"mesh-old"),
1533 "the short *. control merges extensionless entries and hides the deleted name");
1534 for (size_t i = 0; i < short_matches.size(); ++i) {
1535 char detail[96];
1536 std::snprintf(detail, sizeof detail, "the long listing matches short Win32 for %ls", masks[i]);
1537 check(long_matches[i] == short_matches[i], detail);
1538 }
1539
1540 // The scratch drive is usable with a short guest name and a long configured overlay root.
1541 const auto scratch_overlay = fixture / relative / "scratch_overlay";
1542 rt::fs::configure(long_package, scratch_overlay);
1543 h = create_a("T:\\scratch.bin", GENERIC_WRITE, 0, nullptr, CREATE_NEW, 0, nullptr);
1544 written = 0;
1545 check(h != INVALID_HANDLE_VALUE && ::WriteFile(h, "test", 4, &written, nullptr) && written == 4,
1546 "T: creates and writes its scratch directory under a long overlay root");
1547 if (h != INVALID_HANDLE_VALUE) ::CloseHandle(h);
1548 check(read_guest(L"T:\\scratch.bin") == "test" &&
1549 read_path(extended(scratch_overlay / ".gta6rt-temp" / "scratch.bin")) == "test",
1550 "T: reads from the same long backing directory");
1551 rt::fs::configure(package, overlay);
1552
1553 std::error_code cleanup_error;
1554 std::filesystem::remove_all(extended(fixture), cleanup_error);
1555 check(!cleanup_error, "the synthetic long paths are removed after the test");
1556 }
1441} 1557}
1442 1558
1443} // namespace 1559} // namespace