From 092c906fe655dd15456ec815c40fe506ee3f5ac3 Mon Sep 17 00:00:00 2001 From: 0penBrain <48731257+0penBrain@users.noreply.github.com> Date: Sun, 23 Jul 2023 14:41:45 +0200 Subject: [PATCH] [Bugfix]Base: fix implementation of isFile() so it is safe to use Current implementation can freeze the app if called on specific files --- src/Base/FileInfo.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Base/FileInfo.cpp b/src/Base/FileInfo.cpp index 943b81d825..a2fca09a70 100644 --- a/src/Base/FileInfo.cpp +++ b/src/Base/FileInfo.cpp @@ -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;