@@ -38,8 +38,9 @@ pub struct FileAttr {
38
38
}
39
39
40
40
#[ 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 ,
43
44
}
44
45
45
46
pub struct ReadDir {
@@ -516,30 +517,28 @@ impl FilePermissions {
516
517
517
518
impl FileType {
518
519
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,
531
523
}
532
524
}
533
525
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
+ }
536
532
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 )
540
536
}
541
537
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
543
542
}
544
543
}
545
544
0 commit comments