Commit 830a1bd1 authored by Max Kellermann's avatar Max Kellermann

fs/File{System,Info}: fix regular file check

Don't use FILE_ATTRIBUTE_NORMAL, it's a "magic" value for something else. To check if a file is a regular file, we need to check if it's NOT a directory (or a device).
parent 5c5ea8a2
...@@ -65,7 +65,8 @@ class FileInfo { ...@@ -65,7 +65,8 @@ class FileInfo {
public: public:
bool IsRegular() const { bool IsRegular() const {
#ifdef WIN32 #ifdef WIN32
return data.dwFileAttributes & FILE_ATTRIBUTE_NORMAL; return (data.dwFileAttributes &
(FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_DEVICE)) == 0;
#else #else
return S_ISREG(st.st_mode); return S_ISREG(st.st_mode);
#endif #endif
......
...@@ -152,7 +152,8 @@ FileExists(Path path, bool follow_symlinks = true) ...@@ -152,7 +152,8 @@ FileExists(Path path, bool follow_symlinks = true)
(void)follow_symlinks; (void)follow_symlinks;
const auto a = GetFileAttributes(path.c_str()); const auto a = GetFileAttributes(path.c_str());
return a != INVALID_FILE_ATTRIBUTES && (a & FILE_ATTRIBUTE_NORMAL); return a != INVALID_FILE_ATTRIBUTES &&
(a & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_DEVICE)) == 0;
#else #else
struct stat buf; struct stat buf;
return StatFile(path, buf, follow_symlinks) && S_ISREG(buf.st_mode); return StatFile(path, buf, follow_symlinks) && S_ISREG(buf.st_mode);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment