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-22 23:09:53 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 23:09:53 -0500
commitaa19ee37cf5b095526d2d8fed424183d43cc26ce (patch)
tree88aadf71638904ed3d22e866c8db7d173353a945 /runtime/test/file_system_test.cpp
parentbdf45c603043f188c5dfc1118961cd09ea8423ab (diff)
parentf09f1b26e43d6858b70810a3d08365104e911d2d (diff)
Merge pull request #3955 from ezbyDev
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.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/runtime/test/file_system_test.cpp b/runtime/test/file_system_test.cpp
index 1ea3ef51f..a36dcba37 100644
--- a/runtime/test/file_system_test.cpp
+++ b/runtime/test/file_system_test.cpp
@@ -5,6 +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
10#include <algorithm>
11#include <clocale>
8#include <cstdio> 12#include <cstdio>
9#include <filesystem> 13#include <filesystem>
10#include <initializer_list> 14#include <initializer_list>
@@ -223,6 +227,111 @@ int main() {
223 "a listing inside a folder that does not exist reports ERROR_PATH_NOT_FOUND, as the host does"); 227 "a listing inside a folder that does not exist reports ERROR_PATH_NOT_FOUND, as the host does");
224 } 228 }
225 229
230 // Names that differ only in case are one entry, as on the host, and the overlay's spelling is the one listed.
231 {
232 write_path(overlay / "data" / "Mixed.TXT", "overlay");
233 write_path(package / "data" / "mixed.txt", "package");
234 const std::vector<std::wstring> names = list(first_w, next_w, find_close, L"GAME:\\data\\*");
235 check(count(names, L"mixed.txt") == 1, "names that differ only in case are listed once");
236 check(std::find(names.begin(), names.end(), std::wstring(L"Mixed.TXT")) != names.end(),
237 "and the overlay's spelling wins");
238 }
239
240 // A folder with no deletion markers at all (its marker folder does not exist) lists every package entry once.
241 {
242 for (int i = 0; i < 300; ++i) write_path(package / "many" / ("f" + std::to_string(i) + ".bin"), "x");
243 write_path(overlay / "many" / "F7.BIN", "overlay");
244 check(!std::filesystem::exists(overlay / ".gta6rt-deleted" / "many"), "GAME:\\many has no marker folder");
245 const std::vector<std::wstring> names = list(first_w, next_w, find_close, L"GAME:\\many\\*");
246 int files = 0;
247 for (const auto& n : names)
248 if (n != L"." && n != L"..") ++files;
249 check(files == 300 && count(names, L"f7.bin") == 1 && count(names, L"f299.bin") == 1,
250 "a folder without markers lists all 300 files, with the overlay's copy once");
251
252 // Once the folder has a marker folder, the listing reads it once: a delete under another ASCII case hides
253 // exactly that file and every other file stays.
254 check(delete_w(L"GAME:\\many\\F3.BIN") != FALSE, "DeleteFileW hides f3.bin under another case");
255 const std::vector<std::wstring> after = list(first_w, next_w, find_close, L"GAME:\\many\\*");
256 int left = 0;
257 for (const auto& n : after)
258 if (n != L"." && n != L"..") ++left;
259 check(left == 299 && !contains(after, L"f3.bin") && count(after, L"f30.bin") == 1,
260 "with a marker folder the listing hides only the deleted file");
261 }
262
263 // Names with non-ASCII letters keep the file system's case rule: deleting U+00E9 hides the package's U+00C9.
264 {
265 write_path(package / "names" / L"Éclair.txt", "package");
266 write_path(package / "names" / "plain.txt", "package");
267 check(delete_w(L"GAME:\\names\\éclair.txt") != FALSE, "DeleteFileW takes a name that differs in a non-ASCII case");
268 const std::vector<std::wstring> names = list(first_w, next_w, find_close, L"GAME:\\names\\*");
269 check(std::find(names.begin(), names.end(), std::wstring(L"Éclair.txt")) == names.end() &&
270 contains(names, L"plain.txt"),
271 "and the listing hides it, as the file system's compare does");
272 }
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
226 // A delete hides the package file without removing it. 335 // A delete hides the package file without removing it.
227 { 336 {
228 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");