Skip to content

Commit

Permalink
[Bugfix]Base: fix implementation of isFile() so it is safe to use
Browse files Browse the repository at this point in the history
  Current implementation can freeze the app if called on specific files
  • Loading branch information
0penBrain committed Jul 23, 2023
1 parent 2167fb6 commit e01a691
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/Base/FileInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e01a691

Please sign in to comment.