From 3d46cf51d0bc7510c7c12e3df56f1a77f9135204 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Thu, 27 Jul 2023 20:23:30 +0100 Subject: [PATCH] Update POSIXFileio.cpp fixe fileio test linux --- Engine/source/platformPOSIX/POSIXFileio.cpp | 44 ++++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/Engine/source/platformPOSIX/POSIXFileio.cpp b/Engine/source/platformPOSIX/POSIXFileio.cpp index c9bfdd49c..cc5eb9299 100644 --- a/Engine/source/platformPOSIX/POSIXFileio.cpp +++ b/Engine/source/platformPOSIX/POSIXFileio.cpp @@ -990,19 +990,43 @@ StringTableEntry Platform::getExecutablePath() //----------------------------------------------------------------------------- bool Platform::isFile(const char *pFilePath) { - if (!pFilePath || !*pFilePath) - return false; + if (!pFilePath || !*pFilePath) + return false; + + char pathName[MaxPath]; + + // 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] != '\\') + { + MungePath(pathName, MaxPath, pFilePath, GetPrefDir()); + } + else + { + // here if the path is absolute or not in the pref dir + MungePath(pathName, MaxPath, pFilePath, cwd); + } + // Get file info struct stat fStat; - if (stat(pFilePath, &fStat) < 0) - { - // Since file does not exist on disk see if it exists in a zip file loaded - return Torque::FS::IsFile(pFilePath); - } + if (stat(pFilePath, &fStat) == 0) + if ((fStat.st_mode & S_IFMT) == S_IFREG) + 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 - if ( (fStat.st_mode & S_IFMT) == S_IFREG) - return true; + + // must be some other file (directory, device, etc.) return false; } @@ -1341,4 +1365,4 @@ void setExePathName(const char* exePathName) sBinName = binName; } } -#endif \ No newline at end of file +#endif