mirror of
https://github.com/sharkdp/fd.git
synced 2024-11-17 17:35:16 +01:00
88bebb8aac
* The detection of executable files was not exactly the same as the original find
37 lines
1.2 KiB
Rust
37 lines
1.2 KiB
Rust
use crate::dir_entry;
|
|
use crate::filesystem;
|
|
|
|
use faccess::PathExt;
|
|
|
|
/// Whether or not to show
|
|
#[derive(Default)]
|
|
pub struct FileTypes {
|
|
pub files: bool,
|
|
pub directories: bool,
|
|
pub symlinks: bool,
|
|
pub sockets: bool,
|
|
pub pipes: bool,
|
|
pub executables_only: bool,
|
|
pub empty_only: bool,
|
|
}
|
|
|
|
impl FileTypes {
|
|
pub fn should_ignore(&self, entry: &dir_entry::DirEntry) -> bool {
|
|
if let Some(ref entry_type) = entry.file_type() {
|
|
(!self.files && entry_type.is_file())
|
|
|| (!self.directories && entry_type.is_dir())
|
|
|| (!self.symlinks && entry_type.is_symlink())
|
|
|| (!self.sockets && filesystem::is_socket(*entry_type))
|
|
|| (!self.pipes && filesystem::is_pipe(*entry_type))
|
|
|| (self.executables_only && !entry.path().executable())
|
|
|| (self.empty_only && !filesystem::is_empty(entry))
|
|
|| !(entry_type.is_file()
|
|
|| entry_type.is_dir()
|
|
|| entry_type.is_symlink()
|
|
|| filesystem::is_socket(*entry_type)
|
|
|| filesystem::is_pipe(*entry_type))
|
|
} else {
|
|
true
|
|
}
|
|
}
|
|
}
|