Update POSIXFileio.cpp

fixe fileio test linux
This commit is contained in:
marauder2k7 2023-07-27 20:23:30 +01:00
parent 2e91837f6a
commit 3d46cf51d0

View file

@ -992,17 +992,41 @@ bool Platform::isFile(const char *pFilePath)
{ {
if (!pFilePath || !*pFilePath) if (!pFilePath || !*pFilePath)
return false; return false;
// Get file info
struct stat fStat; char pathName[MaxPath];
if (stat(pFilePath, &fStat) < 0)
// if it starts with cwd, we need to strip that off so that we can look for
// the file in the pref dir
char cwd[MaxPath];
getcwd(cwd, MaxPath);
if (dStrstr(pFilePath, cwd) == pFilePath)
pFilePath = pFilePath + dStrlen(cwd) + 1;
// if its relative, first look in the pref dir
if (pFilePath[0] != '/' && pFilePath[0] != '\\')
{ {
// Since file does not exist on disk see if it exists in a zip file loaded MungePath(pathName, MaxPath, pFilePath, GetPrefDir());
return Torque::FS::IsFile(pFilePath); }
else
{
// here if the path is absolute or not in the pref dir
MungePath(pathName, MaxPath, pFilePath, cwd);
} }
// if the file is a "regular file" then true // Get file info
if ( (fStat.st_mode & S_IFMT) == S_IFREG) struct stat fStat;
if (stat(pFilePath, &fStat) == 0)
if ((fStat.st_mode & S_IFMT) == S_IFREG)
return true; return true;
// Since stat failed see if it exists in a zip file loaded
if (Torque::FS::IsFile(pFilePath))
return true;
// if the file is a "regular file" then true
// must be some other file (directory, device, etc.) // must be some other file (directory, device, etc.)
return false; return false;
} }