[*] Handling of edge case special dirs under Torbalds OS

This commit is contained in:
Reece Wilson 2024-07-04 18:50:33 +01:00
parent 937016e9f3
commit 3143f3d2eb
2 changed files with 69 additions and 6 deletions

View File

@ -130,8 +130,9 @@ namespace Aurora::IO::FS
continue; continue;
} }
stat.path = NormalizePathRet(this->sPath + stat.fileName); AuString name = stat.fileName;
AuReplaceAll(name, "\\", "\\\\");
stat.path = this->sPath + name;
if (this->bFast) if (this->bFast)
{ {
// nvm wont work. still need the is type dir/file flags // nvm wont work. still need the is type dir/file flags
@ -142,7 +143,6 @@ namespace Aurora::IO::FS
{ {
bTryAgain = true; bTryAgain = true;
} }
} }
while (AuExchange(bTryAgain, false)); while (AuExchange(bTryAgain, false));
@ -244,6 +244,34 @@ namespace Aurora::IO::FS
return true; return true;
} }
bool SpecialsInDirectory(const AuROString &string, AuList<AuString> &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) AUKN_SYM bool ReadFile(const AuROString &path, AuByteBuffer &buffer)
{ {
AuMemoryViewWrite writeView; AuMemoryViewWrite writeView;
@ -595,19 +623,24 @@ namespace Aurora::IO::FS
{ {
SysPushErrorIO("Critical IO error while stating file (errno: {}, path: {})", errno, path); SysPushErrorIO("Critical IO error while stating file (errno: {}, path: {})", errno, path);
} }
return false; return false;
} }
stat.bExistsFile = S_ISREG(s.st_mode); stat.bExistsFile = S_ISREG(s.st_mode);
stat.bExistsDirectory = S_ISDIR(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; stat.bExists = stat.bExistsFile || stat.bExistsDirectory || stat.bExistsSystemResource;
#if 0
if (!stat.bExists) if (!stat.bExists)
{ {
SysPushErrorIO("Missing attribute type in stat mode {} (of path {})", s.st_mode, path); SysPushErrorIO("Missing attribute type in stat mode {} (of path {})", s.st_mode, path);
return false; return false;
} }
#else
stat.bExists = true;
#endif
stat.uSize = s.st_size; stat.uSize = s.st_size;

View File

@ -274,10 +274,27 @@ namespace Aurora::IO::FS
// best case -> O(n) wherein we merely check each BYTE with a handful of branch conditions // best case -> O(n) wherein we merely check each BYTE with a handful of branch conditions
int doubleDots = 0; int doubleDots = 0;
int doubleSlash = 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 ((character == '\\') || (character == '/'))
{ {
#if defined(AURORA_IS_POSIX_DERIVED)
if (character == '\\' &&
prevC == '\\')
{
*(itr - 1) = '\\';
itr = str.erase(itr);
}
#endif
character = kPathSplitter; character = kPathSplitter;
doubleSlash++; doubleSlash++;
} }
@ -297,6 +314,7 @@ namespace Aurora::IO::FS
requiresExpanding |= doubleDots >= 2; requiresExpanding |= doubleDots >= 2;
requiresExpanding |= doubleSlash >= 2; requiresExpanding |= doubleSlash >= 2;
prevC = holding;
} }
// plus this, i guess // plus this, i guess
@ -719,7 +737,19 @@ namespace Aurora::IO::FS
AuUInt indexA {}, indexB {}; AuUInt indexA {}, indexB {};
auto a = path.find_last_of('\\'); 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('/'); auto b = path.find_last_of('/');
if (b != AuString::npos) indexB = b; if (b != AuString::npos) indexB = b;