@@ -41,8 +41,8 @@ pub struct FileAttr {
41
41
42
42
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
43
43
pub struct FileType {
44
- attributes : u32 ,
45
- reparse_tag : u32 ,
44
+ is_directory : bool ,
45
+ is_symlink : bool ,
46
46
}
47
47
48
48
pub struct ReadDir {
@@ -1111,32 +1111,29 @@ impl FileTimes {
1111
1111
}
1112
1112
1113
1113
impl FileType {
1114
- fn new ( attrs : u32 , reparse_tag : u32 ) -> FileType {
1115
- FileType { attributes : attrs, reparse_tag }
1114
+ fn new ( attributes : u32 , reparse_tag : u32 ) -> FileType {
1115
+ let is_directory = attributes & c:: FILE_ATTRIBUTE_DIRECTORY != 0 ;
1116
+ let is_symlink = {
1117
+ let is_reparse_point = attributes & c:: FILE_ATTRIBUTE_REPARSE_POINT != 0 ;
1118
+ let is_reparse_tag_name_surrogate = reparse_tag & 0x20000000 != 0 ;
1119
+ is_reparse_point && is_reparse_tag_name_surrogate
1120
+ } ;
1121
+ FileType { is_directory, is_symlink }
1116
1122
}
1117
1123
pub fn is_dir ( & self ) -> bool {
1118
- !self . is_symlink ( ) && self . is_directory ( )
1124
+ !self . is_symlink && self . is_directory
1119
1125
}
1120
1126
pub fn is_file ( & self ) -> bool {
1121
- !self . is_symlink ( ) && !self . is_directory ( )
1127
+ !self . is_symlink && !self . is_directory
1122
1128
}
1123
1129
pub fn is_symlink ( & self ) -> bool {
1124
- self . is_reparse_point ( ) && self . is_reparse_tag_name_surrogate ( )
1130
+ self . is_symlink
1125
1131
}
1126
1132
pub fn is_symlink_dir ( & self ) -> bool {
1127
- self . is_symlink ( ) && self . is_directory ( )
1133
+ self . is_symlink && self . is_directory
1128
1134
}
1129
1135
pub fn is_symlink_file ( & self ) -> bool {
1130
- self . is_symlink ( ) && !self . is_directory ( )
1131
- }
1132
- fn is_directory ( & self ) -> bool {
1133
- self . attributes & c:: FILE_ATTRIBUTE_DIRECTORY != 0
1134
- }
1135
- fn is_reparse_point ( & self ) -> bool {
1136
- self . attributes & c:: FILE_ATTRIBUTE_REPARSE_POINT != 0
1137
- }
1138
- fn is_reparse_tag_name_surrogate ( & self ) -> bool {
1139
- self . reparse_tag & 0x20000000 != 0
1136
+ self . is_symlink && !self . is_directory
1140
1137
}
1141
1138
}
1142
1139
0 commit comments