Skip to content
Myr

filetypes.rs

This file

Path

src/filetypes.rs

39 lines · 1.3 KiB · Rust

Last changed by

send DirEntries to output instead of just pathJonathan Gorenbefore adoption813a802

History of this file

Take it

1use crate::entry;2use crate::filesystem;34/// Whether or not to show5#[derive(Default)]6pub struct FileTypes {7    pub files: bool,8    pub directories: bool,9    pub symlinks: bool,10    pub sockets: bool,11    pub pipes: bool,12    pub executables_only: bool,13    pub empty_only: bool,14}1516impl FileTypes {17    pub fn should_ignore(&self, entry: &entry::DirEntry) -> bool {18        if let Some(ref entry_type) = entry.file_type() {19            (!self.files && entry_type.is_file())20                || (!self.directories && entry_type.is_dir())21                || (!self.symlinks && entry_type.is_symlink())22                || (!self.sockets && filesystem::is_socket(*entry_type))23                || (!self.pipes && filesystem::is_pipe(*entry_type))24                || (self.executables_only25                    && !entry26                        .metadata()27                        .map(filesystem::is_executable)28                        .unwrap_or(false))29                || (self.empty_only && !filesystem::is_empty(entry))30                || !(entry_type.is_file()31                    || entry_type.is_dir()32                    || entry_type.is_symlink()33                    || filesystem::is_socket(*entry_type)34                    || filesystem::is_pipe(*entry_type))35        } else {36            true37        }38    }39}