The From<FileMode> implementation for FileType uses the bitflags contains function to check the file mode against the FileMode enum members, e.g. mode.contains(FileMode::DIR).
However, the file modes are not flags - their set bits overlap.
As a result, the FileType will be wrong for certain file modes.
Example:
The file is a socket, file mode 0xC000 == 1100000000000000.
The first test is against FileMode::DIR which is 0x4000 == 100000000000000.
Since all set bits in 110000000000000 are also set in 1000000000000000, the check succeeds and the file type is set to FileType::Dir.
The
From<FileMode>
implementation forFileType
uses the bitflagscontains
function to check the file mode against theFileMode
enum members, e.g.mode.contains(FileMode::DIR)
.However, the file modes are not flags - their set bits overlap.
As a result, the
FileType
will be wrong for certain file modes.Example:
The file is a socket, file mode
0xC000 == 1100000000000000
.The first test is against
FileMode::DIR
which is0x4000 == 100000000000000
.Since all set bits in
110000000000000
are also set in1000000000000000
, the check succeeds and the file type is set toFileType::Dir
.