Skip to content

Commit b1b9edf

Browse files
committed
This is what FileType on Windows should ideally be.
1 parent 56733bc commit b1b9edf

File tree

1 file changed

+19
-20
lines changed
  • src/libstd/sys/windows

1 file changed

+19
-20
lines changed

src/libstd/sys/windows/fs.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ pub struct FileAttr {
3838
}
3939

4040
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
41-
pub enum FileType {
42-
Dir, File, SymlinkFile, SymlinkDir, ReparsePoint, MountPoint,
41+
pub struct FileType {
42+
attributes: c::DWORD,
43+
reparse_tag: c::DWORD,
4344
}
4445

4546
pub struct ReadDir {
@@ -516,30 +517,28 @@ impl FilePermissions {
516517

517518
impl FileType {
518519
fn new(attrs: c::DWORD, reparse_tag: c::DWORD) -> FileType {
519-
match (attrs & c::FILE_ATTRIBUTE_DIRECTORY != 0,
520-
attrs & c::FILE_ATTRIBUTE_REPARSE_POINT != 0,
521-
reparse_tag) {
522-
(false, false, _) => FileType::File,
523-
(true, false, _) => FileType::Dir,
524-
(false, true, c::IO_REPARSE_TAG_SYMLINK) => FileType::SymlinkFile,
525-
(true, true, c::IO_REPARSE_TAG_SYMLINK) => FileType::SymlinkDir,
526-
(true, true, c::IO_REPARSE_TAG_MOUNT_POINT) => FileType::MountPoint,
527-
(_, true, _) => FileType::ReparsePoint,
528-
// Note: if a _file_ has a reparse tag of the type IO_REPARSE_TAG_MOUNT_POINT it is
529-
// invalid, as junctions always have to be dirs. We set the filetype to ReparsePoint
530-
// to indicate it is something symlink-like, but not something you can follow.
520+
FileType {
521+
attributes: attrs,
522+
reparse_tag: reparse_tag,
531523
}
532524
}
533525

534-
pub fn is_dir(&self) -> bool { *self == FileType::Dir }
535-
pub fn is_file(&self) -> bool { *self == FileType::File }
526+
pub fn is_dir(&self) -> bool {
527+
self.attributes & c::FILE_ATTRIBUTE_DIRECTORY != 0
528+
}
529+
pub fn is_file(&self) -> bool {
530+
self.attributes & c::FILE_ATTRIBUTE_DIRECTORY == 0
531+
}
536532
pub fn is_symlink(&self) -> bool {
537-
*self == FileType::SymlinkFile ||
538-
*self == FileType::SymlinkDir ||
539-
*self == FileType::MountPoint
533+
self.is_reparse_point() && (
534+
self.reparse_tag == c::IO_REPARSE_TAG_SYMLINK ||
535+
self.reparse_tag == c::IO_REPARSE_TAG_MOUNT_POINT)
540536
}
541537
pub fn is_symlink_dir(&self) -> bool {
542-
*self == FileType::SymlinkDir || *self == FileType::MountPoint
538+
self.is_symlink() && self.is_dir()
539+
}
540+
pub fn is_reparse_point(&self) -> bool {
541+
self.attributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0
543542
}
544543
}
545544

0 commit comments

Comments
 (0)