Skip to content

Commit c16562f

Browse files
committed
Fix incorrect file detection when path is a folder
1 parent 473cc4a commit c16562f

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

DesktopEmulator/DesktopInfrastructure/FilePaths.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@ bool IsFileNameValid( const string& FileName )
117117

118118
bool FileExists( const string& FilePath )
119119
{
120-
ifstream TestedFile;
121-
TestedFile.open( FilePath );
122-
123-
return (bool)TestedFile;
120+
struct stat Info;
121+
122+
if( stat( FilePath.c_str(), &Info ) != 0 )
123+
return false;
124+
125+
return !(Info.st_mode & S_IFDIR);
124126
}
125127

126128
// -----------------------------------------------------------------------------

DevelopmentTools/DevToolsInfrastructure/FilePaths.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,12 @@ bool IsFileNameValid( const string& FileName )
138138

139139
bool FileExists( const string& FilePath )
140140
{
141-
ifstream TestedFile;
142-
TestedFile.open( FilePath );
143-
144-
return (bool)TestedFile;
141+
struct stat Info;
142+
143+
if( stat( FilePath.c_str(), &Info ) != 0 )
144+
return false;
145+
146+
return !(Info.st_mode & S_IFDIR);
145147
}
146148

147149
// -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)