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.
This commit is contained in:
Benjamin Sago 2017-05-03 17:51:17 +01:00
parent 7b2e701b25
commit f14ee48658

View File

@ -3,15 +3,12 @@
use std::fs; use std::fs;
use std::io::Error as IOError; use std::io::Error as IOError;
use std::io::Result as IOResult; 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 std::path::{Path, PathBuf};
use fs::dir::Dir; use fs::dir::Dir;
use fs::fields as f; use fs::fields as f;
#[cfg(any(target_os = "macos", target_os = "linux"))]
use std::os::unix::fs::FileTypeExt;
#[allow(trivial_numeric_casts)] #[allow(trivial_numeric_casts)]
mod modes { mod modes {
@ -140,6 +137,27 @@ impl<'dir> File<'dir> {
self.metadata.file_type().is_symlink() 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 /// Whether this file is a dotfile, based on its name. In Unix, file names
/// beginning with a dot represent system or configuration files, and /// beginning with a dot represent system or configuration files, and
/// should be hidden by default. /// 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> { impl<'a> AsRef<File<'a>> for File<'a> {
fn as_ref(&self) -> &File<'a> { fn as_ref(&self) -> &File<'a> {