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:
parent
5c5ea8a254
commit
830a1bd130
@ -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)
|
|||||||
(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);
|
||||||
|
Loading…
Reference in New Issue
Block a user