mirror of
https://github.com/sharkdp/fd.git
synced 2024-11-17 09:28:25 +01:00
parent
c06c9952b6
commit
115ae93df9
3 changed files with 30 additions and 22 deletions
|
@ -1,3 +1,6 @@
|
|||
use crate::filesystem;
|
||||
use crate::walk;
|
||||
|
||||
/// Whether or not to show
|
||||
pub struct FileTypes {
|
||||
pub files: bool,
|
||||
|
@ -22,3 +25,28 @@ impl Default for FileTypes {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FileTypes {
|
||||
pub fn should_ignore(&self, entry: &walk::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
|
||||
.metadata()
|
||||
.map(|m| filesystem::is_executable(&m))
|
||||
.unwrap_or(false))
|
||||
|| (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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ use anyhow::{anyhow, Context, Result};
|
|||
use atty::Stream;
|
||||
use globset::GlobBuilder;
|
||||
use lscolors::LsColors;
|
||||
use regex::bytes::{RegexBuilder, RegexSetBuilder};
|
||||
use normpath::PathExt;
|
||||
use regex::bytes::{RegexBuilder, RegexSetBuilder};
|
||||
|
||||
use crate::error::print_error;
|
||||
use crate::exec::CommandTemplate;
|
||||
|
|
22
src/walk.rs
22
src/walk.rs
|
@ -416,27 +416,7 @@ fn spawn_senders(
|
|||
|
||||
// Filter out unwanted file types.
|
||||
if let Some(ref file_types) = config.file_types {
|
||||
if let Some(ref entry_type) = entry.file_type() {
|
||||
if (!file_types.files && entry_type.is_file())
|
||||
|| (!file_types.directories && entry_type.is_dir())
|
||||
|| (!file_types.symlinks && entry_type.is_symlink())
|
||||
|| (!file_types.sockets && filesystem::is_socket(*entry_type))
|
||||
|| (!file_types.pipes && filesystem::is_pipe(*entry_type))
|
||||
|| (file_types.executables_only
|
||||
&& !entry
|
||||
.metadata()
|
||||
.map(|m| filesystem::is_executable(&m))
|
||||
.unwrap_or(false))
|
||||
|| (file_types.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))
|
||||
{
|
||||
return ignore::WalkState::Continue;
|
||||
}
|
||||
} else {
|
||||
if file_types.should_ignore(&entry) {
|
||||
return ignore::WalkState::Continue;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue