fix(file_system): check is_regular_file for deletion markers so nested deletes do not hide parent directories

This commit is contained in:
totonii
2026-11-22 10:41:32 -03:00
parent 89b047cd8f
commit 3f26a95a10
2 changed files with 13 additions and 2 deletions
+3 -1
View File
@@ -142,7 +142,9 @@ std::filesystem::path marker(const std::filesystem::path& overlay, const std::ve
bool deleted(const std::filesystem::path& overlay, const std::vector<std::wstring>& parts) {
if (overlay.empty() || parts.empty()) return false;
std::error_code ec;
return std::filesystem::exists(marker(overlay, parts), ec);
// Only regular files are deletion markers; parent directories inside .gta6rt-deleted/ exist only to hold markers
// for nested deleted files and must not hide the corresponding ancestor directories in the package.
return std::filesystem::is_regular_file(marker(overlay, parts), ec);
}
Target read_target(const std::wstring& path) {
+10 -1
View File
@@ -99,7 +99,7 @@ int main() {
write_path(package / "data" / "hello.txt", "package");
write_path(package / "data" / "dup.txt", "package");
write_path(package / "data" / "bye.txt", "package");
std::filesystem::create_directories(package / "data" / "sub");
write_path(package / "data" / "sub" / "nested.txt", "nested");
rt::fs::configure(package, overlay);
check(rt::fs::game_dir() == package, "configure() sets the game folder");
@@ -249,6 +249,15 @@ int main() {
SetLastError(0);
check(delete_w(L"GAME:\\nope\\missing.txt") == FALSE && GetLastError() == ERROR_FILE_NOT_FOUND,
"deleting a file that never existed reports ERROR_FILE_NOT_FOUND");
// Deleting a nested package file creates parent directories inside .gta6rt-deleted/; those marker parent
// directories must not hide the corresponding ancestor directories in the package.
check(delete_w(L"GAME:\\data\\sub\\nested.txt") != FALSE, "DeleteFileW accepts a nested package file");
const DWORD sub_attrs = attributes_w(L"GAME:\\data\\sub");
check(sub_attrs != INVALID_FILE_ATTRIBUTES && (sub_attrs & FILE_ATTRIBUTE_DIRECTORY) != 0,
"deleting a nested package file does not hide its parent folder");
check(contains(list(first_w, next_w, find_close, L"GAME:\\data\\*"), L"sub"),
"the parent folder stays listed after deleting a nested package file");
}
// Nothing leaves the package and the overlay.