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).
This commit is contained in:
Max Kellermann 2015-03-05 09:43:51 +01:00
parent 5c5ea8a254
commit 830a1bd130
2 changed files with 4 additions and 2 deletions

View File

@ -65,7 +65,8 @@ class FileInfo {
public:
bool IsRegular() const {
#ifdef WIN32
return data.dwFileAttributes & FILE_ATTRIBUTE_NORMAL;
return (data.dwFileAttributes &
(FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_DEVICE)) == 0;
#else
return S_ISREG(st.st_mode);
#endif

View File

@ -152,7 +152,8 @@ FileExists(Path path, bool follow_symlinks = true)
(void)follow_symlinks;
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
struct stat buf;
return StatFile(path, buf, follow_symlinks) && S_ISREG(buf.st_mode);