[*] 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;
}
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<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)
{
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;

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
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;