about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorPeter Atashian <retep998@gmail.com>2018-02-01 20:18:33 -0500
committerPeter Atashian <retep998@gmail.com>2018-02-01 20:29:19 -0500
commitb1b9edf5ae3c6a8a862e480174f9fefafeba7143 (patch)
treeb948ae60cde2f5d5afc9595534e0d6dce6378946 /src/libstd/sys
parent56733bc9f8302409a2b6110f422512923c878154 (diff)
downloadrust-b1b9edf5ae3c6a8a862e480174f9fefafeba7143.tar.gz
rust-b1b9edf5ae3c6a8a862e480174f9fefafeba7143.zip
This is what FileType on Windows should ideally be.
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/windows/fs.rs39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs
index 165e1b0609b..001e7ceeb71 100644
--- a/src/libstd/sys/windows/fs.rs
+++ b/src/libstd/sys/windows/fs.rs
@@ -38,8 +38,9 @@ pub struct FileAttr {
 }
 
 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
-pub enum FileType {
-    Dir, File, SymlinkFile, SymlinkDir, ReparsePoint, MountPoint,
+pub struct FileType {
+    attributes: c::DWORD,
+    reparse_tag: c::DWORD,
 }
 
 pub struct ReadDir {
@@ -516,30 +517,28 @@ impl FilePermissions {
 
 impl FileType {
     fn new(attrs: c::DWORD, reparse_tag: c::DWORD) -> FileType {
-        match (attrs & c::FILE_ATTRIBUTE_DIRECTORY != 0,
-               attrs & c::FILE_ATTRIBUTE_REPARSE_POINT != 0,
-               reparse_tag) {
-            (false, false, _) => FileType::File,
-            (true, false, _) => FileType::Dir,
-            (false, true, c::IO_REPARSE_TAG_SYMLINK) => FileType::SymlinkFile,
-            (true, true, c::IO_REPARSE_TAG_SYMLINK) => FileType::SymlinkDir,
-            (true, true, c::IO_REPARSE_TAG_MOUNT_POINT) => FileType::MountPoint,
-            (_, true, _) => FileType::ReparsePoint,
-            // Note: if a _file_ has a reparse tag of the type IO_REPARSE_TAG_MOUNT_POINT it is
-            // invalid, as junctions always have to be dirs. We set the filetype to ReparsePoint
-            // to indicate it is something symlink-like, but not something you can follow.
+        FileType {
+            attributes: attrs,
+            reparse_tag: reparse_tag,
         }
     }
 
-    pub fn is_dir(&self) -> bool { *self == FileType::Dir }
-    pub fn is_file(&self) -> bool { *self == FileType::File }
+    pub fn is_dir(&self) -> bool {
+        self.attributes & c::FILE_ATTRIBUTE_DIRECTORY != 0
+    }
+    pub fn is_file(&self) -> bool {
+        self.attributes & c::FILE_ATTRIBUTE_DIRECTORY == 0
+    }
     pub fn is_symlink(&self) -> bool {
-        *self == FileType::SymlinkFile ||
-        *self == FileType::SymlinkDir ||
-        *self == FileType::MountPoint
+        self.is_reparse_point() && (
+            self.reparse_tag == c::IO_REPARSE_TAG_SYMLINK ||
+            self.reparse_tag == c::IO_REPARSE_TAG_MOUNT_POINT)
     }
     pub fn is_symlink_dir(&self) -> bool {
-        *self == FileType::SymlinkDir || *self == FileType::MountPoint
+        self.is_symlink() && self.is_dir()
+    }
+    pub fn is_reparse_point(&self) -> bool {
+        self.attributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0
     }
 }