diff --git a/src/fs/file.rs b/src/fs/file.rs index bb692fb..2966d96 100644 --- a/src/fs/file.rs +++ b/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> for File<'a> { fn as_ref(&self) -> &File<'a> {