From 3143f3d2eb98d61078c153463bca79b223ded5f5 Mon Sep 17 00:00:00 2001 From: J Reece Wilson Date: Thu, 4 Jul 2024 18:50:33 +0100 Subject: [PATCH] [*] Handling of edge case special dirs under Torbalds OS --- Source/IO/FS/FS.Unix.cpp | 41 ++++++++++++++++++++++++++++++++++++---- Source/IO/FS/FS.cpp | 34 +++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/Source/IO/FS/FS.Unix.cpp b/Source/IO/FS/FS.Unix.cpp index ceb4c4df..a04324ef 100755 --- a/Source/IO/FS/FS.Unix.cpp +++ b/Source/IO/FS/FS.Unix.cpp @@ -130,8 +130,9 @@ namespace Aurora::IO::FS continue; } - stat.path = NormalizePathRet(this->sPath + stat.fileName); - + AuString name = stat.fileName; + AuReplaceAll(name, "\\", "\\\\"); + stat.path = this->sPath + name; if (this->bFast) { // nvm wont work. still need the is type dir/file flags @@ -142,7 +143,6 @@ namespace Aurora::IO::FS { bTryAgain = true; } - } while (AuExchange(bTryAgain, false)); @@ -244,6 +244,34 @@ namespace Aurora::IO::FS return true; } + bool SpecialsInDirectory(const AuROString &string, AuList &dirs) + { + auto itr = ReadDirEx(string, true); + if (!itr) + { + AuLogDbg("failed to open special read dir"); + return false; + } + + // SECURITY(): if next fails, its indistinguishable from end of file list, and will return true. it kinda sucks + while (auto stat = itr->Next()) + { + #if 0 + if (!stat->bExistsSystemResource) + { + continue; + } + #endif + + if (!AuTryInsert(dirs, stat->fileName)) + { + return false; + } + } + + return true; + } + AUKN_SYM bool ReadFile(const AuROString &path, AuByteBuffer &buffer) { AuMemoryViewWrite writeView; @@ -595,19 +623,24 @@ namespace Aurora::IO::FS { SysPushErrorIO("Critical IO error while stating file (errno: {}, path: {})", errno, path); } + return false; } stat.bExistsFile = S_ISREG(s.st_mode); stat.bExistsDirectory = S_ISDIR(s.st_mode); - stat.bExistsSystemResource = S_ISSOCK(s.st_mode); + stat.bExistsSystemResource = S_ISSOCK(s.st_mode) || S_ISBLK(s.st_mode) || S_ISCHR(s.st_mode); stat.bExists = stat.bExistsFile || stat.bExistsDirectory || stat.bExistsSystemResource; + #if 0 if (!stat.bExists) { SysPushErrorIO("Missing attribute type in stat mode {} (of path {})", s.st_mode, path); return false; } + #else + stat.bExists = true; + #endif stat.uSize = s.st_size; diff --git a/Source/IO/FS/FS.cpp b/Source/IO/FS/FS.cpp index 2119ae65..01c86df8 100644 --- a/Source/IO/FS/FS.cpp +++ b/Source/IO/FS/FS.cpp @@ -274,10 +274,27 @@ namespace Aurora::IO::FS // best case -> O(n) wherein we merely check each BYTE with a handful of branch conditions int doubleDots = 0; int doubleSlash = 0; - for (auto &character : str) + char prevC = '\0'; + + //for (auto &character : str) + for (auto itr = str.begin(); + itr != str.end(); + itr++) { + auto character = *itr; + auto holding = *itr; + if ((character == '\\') || (character == '/')) { + #if defined(AURORA_IS_POSIX_DERIVED) + if (character == '\\' && + prevC == '\\') + { + *(itr - 1) = '\\'; + itr = str.erase(itr); + } + #endif + character = kPathSplitter; doubleSlash++; } @@ -297,6 +314,7 @@ namespace Aurora::IO::FS requiresExpanding |= doubleDots >= 2; requiresExpanding |= doubleSlash >= 2; + prevC = holding; } // plus this, i guess @@ -719,7 +737,19 @@ namespace Aurora::IO::FS AuUInt indexA {}, indexB {}; auto a = path.find_last_of('\\'); - if (a != AuString::npos) indexA = a; + if (a != AuString::npos) + { + indexA = a; + #if defined(AURORA_IS_POSIX_DERIVED) + if (a) + { + if (path[(a - 1)] == '\\') + { + indexA = 0; + } + } + #endif + } auto b = path.find_last_of('/'); if (b != AuString::npos) indexB = b;