2021-11-09 11:01:09 +01:00
|
|
|
use crate::entry;
|
2021-08-10 09:46:12 +02:00
|
|
|
use crate::filesystem;
|
|
|
|
|
2018-10-12 09:06:14 +02:00
|
|
|
/// Whether or not to show
|
2021-12-07 18:04:17 +01:00
|
|
|
#[derive(Default)]
|
2018-10-12 09:06:14 +02:00
|
|
|
pub struct FileTypes {
|
|
|
|
pub files: bool,
|
|
|
|
pub directories: bool,
|
|
|
|
pub symlinks: bool,
|
2020-04-16 09:41:24 +02:00
|
|
|
pub sockets: bool,
|
|
|
|
pub pipes: bool,
|
2018-10-12 09:06:14 +02:00
|
|
|
pub executables_only: bool,
|
|
|
|
pub empty_only: bool,
|
|
|
|
}
|
|
|
|
|
2021-08-10 09:46:12 +02:00
|
|
|
impl FileTypes {
|
2021-11-09 11:01:09 +01:00
|
|
|
pub fn should_ignore(&self, entry: &entry::DirEntry) -> bool {
|
2021-08-10 09:46:12 +02:00
|
|
|
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()
|
2021-12-07 18:04:17 +01:00
|
|
|
.map(filesystem::is_executable)
|
2021-08-10 09:46:12 +02:00
|
|
|
.unwrap_or(false))
|
2021-10-12 08:46:15 +02:00
|
|
|
|| (self.empty_only && !filesystem::is_empty(entry))
|
2021-08-10 09:46:12 +02:00
|
|
|
|| !(entry_type.is_file()
|
|
|
|
|| entry_type.is_dir()
|
|
|
|
|| entry_type.is_symlink()
|
|
|
|
|| filesystem::is_socket(*entry_type)
|
|
|
|
|| filesystem::is_pipe(*entry_type))
|
|
|
|
} else {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|