[Bugfix]Base: fix implementation of isFile() so it is safe to use

Current implementation can freeze the app if called on specific files
This commit is contained in:
0penBrain
2023-07-23 14:41:45 +02:00
committed by Chris Hennes
parent 87eddb9f1d
commit 092c906fe6

View File

@@ -367,25 +367,21 @@ bool FileInfo::setPermissions(Permissions perms)
bool FileInfo::isFile() const
{
#ifdef FC_OS_WIN32
if (exists()) {
#ifdef FC_OS_WIN32
std::wstring wstr = toStdWString();
FILE* fd = _wfopen(wstr.c_str(), L"rb");
bool ok = (fd != 0);
if (fd) fclose(fd);
return ok;
}
#else
if (exists()) {
// If we can open it must be an existing file, otherwise we assume it
// is a directory (which doesn't need to be true for any cases)
std::ifstream str(FileName.c_str(), std::ios::in | std::ios::binary);
if (!str)
struct stat st;
if(stat(FileName.c_str(), &st) != 0)
return false;
str.close();
return true;
}
return S_ISREG(st.st_mode);
#endif
}
// TODO: Check for valid file name
return true;