Skip to content

Commit

Permalink
Fix FileExists in Utils.cpp
Browse files Browse the repository at this point in the history
Testing for st.st_mode & S_IFLNK doesn't work on OSX, because IFLNK and IFREG
share bits, so regular files have a nonzero result and appear to be links. It
seems safer and more readable to use the mode test macros, e.g. S_ISLNK and
S_ISDIR.
  • Loading branch information
qris committed Aug 7, 2017
1 parent 1a84481 commit dde9c77
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/common/Utils.cpp
Expand Up @@ -346,9 +346,9 @@ bool FileExists(const std::string& rFilename, int64_t *pFileSize,
}

// is it a file?
if((st.st_mode & S_IFDIR) == 0)
if(!S_ISDIR(st.st_mode))
{
if(TreatLinksAsNotExisting && ((st.st_mode & S_IFLNK) != 0))
if(TreatLinksAsNotExisting && S_ISLNK(st.st_mode))
{
return false;
}
Expand Down

0 comments on commit dde9c77

Please sign in to comment.