Addresses #246
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Some implementation to search by filetype `executables`
authored by Pramod Bisht · committed by David Peter · parent ab3ded8 · Browse files · 5 files·+9 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+9 added−4 removed
- other:+9 added−4 removed
Provenance
- Commit
b1e48ef- Tree
0a9e43e- Author
Pramod Bisht <pramodpsb@outlook.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
ab3ded8
5 files changed+9 added−4 removed
modified:src/app.rs+3 added-2 removed
81 unmodified lines82 .multiple(true)83 .number_of_values(1)84 .takes_value(true)85 .value_name("filetype")86- .possible_values(&["f", "file", "d", "directory", "l", "symlink"])86+ .possible_values(&["f", "file", "d", "directory", "l", "symlink", "x", "executable"])87 .hide_possible_values(true),88 )89 .arg(90 arg("extension")97 unmodified lines188 , "Filter by type: f(ile), d(irectory), (sym)l(ink)"189 , "Filter the search by type (multiple allowable filetypes can be specified):\n \190 'f' or 'file': regular files\n \191 'd' or 'directory': directories\n \192- 'l' or 'symlink': symbolic links");192+ 'l' or 'symlink': symbolic links\n \193+ 'x' or 'executable': executables");194 doc!(h, "extension"195 , "Filter by file extension"196 , "(Additionally) filter search results by their file extension. Multiple allowable file \197 extensions can be specified.");42 unmodified linesmodified:src/internal.rs+2 added
20 unmodified lines21 pub struct FileTypes {22 pub files: bool,23 pub directories: bool,24 pub symlinks: bool,25+ pub executables: bool,26 }27 28 impl Default for FileTypes {29 fn default() -> FileTypes {30 FileTypes {31 files: false,32 directories: false,33 symlinks: false,34+ executables: false,35 }36 }37 }38 215 unmodified linesmodified:src/main.rs+1 added
159 unmodified lines160 match value {161 "f" | "file" => file_types.files = true,162 "d" | "directory" => file_types.directories = true,163 "l" | "symlink" => file_types.symlinks = true,164+ "x" | "executable" => file_types.executables = true,165 _ => unreachable!(),166 }167 }168 file_types34 unmodified linesmodified:src/output.rs+2 added-2 removed
133 unmodified lines134 }135 }136 137 #[cfg(any(unix, target_os = "redox"))]138-fn is_executable(md: &fs::Metadata) -> bool {138+pub fn is_executable(md: &fs::Metadata) -> bool {139 md.permissions().mode() & 0o111 != 0140 }141 142 #[cfg(windows)]143-fn is_executable(_: &fs::Metadata) -> bool {143+pub fn is_executable(_: &fs::Metadata) -> bool {144 false145 }modified:src/walk.rs+1 added
199 unmodified lines200 if let Some(ref entry_type) = entry.file_type() {201 if (entry_type.is_file() && !file_types.files)202 || (entry_type.is_dir() && !file_types.directories)203 || (entry_type.is_symlink() && !file_types.symlinks)204+ || (output::is_executable(&entry.metadata().unwrap()) && !file_types.executables)205 {206 return ignore::WalkState::Continue;207 } else if !(entry_type.is_file() || entry_type.is_dir()208 || entry_type.is_symlink())53 unmodified lines