Просмотр исходного кода

Make FileTypeExt non-optional

We already use MetadataExt and PermissionsExt, so it already requires a Unix system — there’s no point providing fallback implementations if it wouldn’t build on those systems anyway.
Benjamin Sago 8 лет назад
Родитель
Сommit
f14ee48658
1 измененных файлов с 22 добавлено и 50 удалено
  1. 22 50
      src/fs/file.rs

+ 22 - 50
src/fs/file.rs

@@ -3,15 +3,12 @@
 use std::fs;
 use std::io::Error as IOError;
 use std::io::Result as IOResult;
-use std::os::unix::fs::{MetadataExt, PermissionsExt};
+use std::os::unix::fs::{MetadataExt, PermissionsExt, FileTypeExt};
 use std::path::{Path, PathBuf};
 
 use fs::dir::Dir;
 use fs::fields as f;
 
-#[cfg(any(target_os = "macos", target_os = "linux"))]
-use std::os::unix::fs::FileTypeExt;
-
 
 #[allow(trivial_numeric_casts)]
 mod modes {
@@ -140,6 +137,27 @@ impl<'dir> File<'dir> {
         self.metadata.file_type().is_symlink()
     }
 
+    /// Whether this file is a named pipe on the filesystem.
+    pub fn is_pipe(&self) -> bool {
+       self.metadata.file_type().is_fifo()
+   }
+
+   /// Whether this file is a char device on the filesystem.
+   pub fn is_char_device(&self) -> bool {
+       self.metadata.file_type().is_char_device()
+   }
+
+   /// Whether this file is a block device on the filesystem.
+   pub fn is_block_device(&self) -> bool {
+       self.metadata.file_type().is_block_device()
+   }
+
+   /// Whether this file is a socket on the filesystem.
+   pub fn is_socket(&self) -> bool {
+       self.metadata.file_type().is_socket()
+   }
+
+
     /// Whether this file is a dotfile, based on its name. In Unix, file names
     /// beginning with a dot represent system or configuration files, and
     /// should be hidden by default.
@@ -350,52 +368,6 @@ impl<'dir> File<'dir> {
     }
 }
 
-#[cfg(any(target_os = "macos", target_os = "linux"))]
-impl<'dir> File<'dir> {
-    /// Whether this file is a named pipe on the filesystem.
-    pub fn is_pipe(&self) -> bool {
-        self.metadata.file_type().is_fifo()
-    }
-
-    /// Whether this file is a char device on the filesystem.
-    pub fn is_char_device(&self) -> bool {
-        self.metadata.file_type().is_char_device()
-    }
-
-    /// Whether this file is a block device on the filesystem.
-    pub fn is_block_device(&self) -> bool {
-        self.metadata.file_type().is_block_device()
-    }
-
-    /// Whether this file is a socket on the filesystem.
-    pub fn is_socket(&self) -> bool {
-        self.metadata.file_type().is_socket()
-    }
-}
-
-#[cfg(not(any(target_os = "macos", target_os = "linux")))]
-impl<'dir> File<'dir> {
-    /// Whether this file is a named pipe on the filesystem.
-    pub fn is_pipe(&self) -> bool {
-        false
-    }
-
-    /// Whether this file is a char device on the filesystem.
-    pub fn is_char_device(&self) -> bool {
-        false
-    }
-
-    /// Whether this file is a block device on the filesystem.
-    pub fn is_block_device(&self) -> bool {
-        false
-    }
-
-    /// Whether this file is a socket on the filesystem.
-    pub fn is_socket(&self) -> bool {
-        false
-    }
-}
-
 
 impl<'a> AsRef<File<'a>> for File<'a> {
     fn as_ref(&self) -> &File<'a> {