Support character and block device file types
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Christian Göttsche · committed by David Peter · parent 3ed4ea7 · Browse files · 7 files·+44 added−2 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+44 added−2 removed
- other:+44 added−2 removed
Provenance
- Commit
36bc840- Tree
372e7f4- Author
Christian Göttsche <cgzones@googlemail.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
3ed4ea7
7 files changed+44 added−2 removed
modified:contrib/completion/_fd+2 added
24 unmodified lines25 {d,directory}'\:"directories"'26 {l,symlink}'\:"symbolic links"'27 {e,empty}'\:"empty files or directories"'28 {x,executable}'\:"executable (files)"'29+ {b,block-device}'\:"block devices"'30+ {c,char-device}'\:"character devices"'31 {s,socket}'\:"sockets"'32 {p,pipe}'\:"named pipes (FIFOs)"'33 )34 249 unmodified linesmodified:doc/fd.1+4 added
182 unmodified lines183 .IP "d, directory"184 directories185 .IP "l, symlink"186 symbolic links187+.IP "b, block-device"188+block devices189+.IP "c, char-device"190+character devices191 .IP "s, socket"192 sockets193 .IP "p, pipe"194 named pipes (FIFOs)290 unmodified linesmodified:src/cli.rs+8 added-1 removed
311 unmodified lines312 /// {n} 'd' or 'directory': directories313 /// {n} 'l' or 'symlink': symbolic links314 /// {n} 's' or 'socket': socket315 /// {n} 'p' or 'pipe': named pipe (FIFO)316+ /// {n} 'b' or 'block-device': block device317+ /// {n} 'c' or 'char-device': character device318 /// {n}{n} 'x' or 'executable': executables319 /// {n} 'e' or 'empty': empty files or directories320 ///321 /// This option can be specified more than once to include multiple file types.25 unmodified lines347 value_name = "filetype",348 hide_possible_values = true,349 value_enum,350 help = "Filter by type: file (f), directory (d), symlink (l), \349- executable (x), empty (e), socket (s), pipe (p)",351+ executable (x), empty (e), socket (s), pipe (p), \352+ char-device (c), block-device (b)",353 long_help354 )]355 pub filetype: Option<Vec<FileType>>,356 365 unmodified lines722 #[value(alias = "d")]723 Directory,724 #[value(alias = "l")]725 Symlink,726+ #[value(alias = "b")]727+ BlockDevice,728+ #[value(alias = "c")]729+ CharDevice,730 /// A file which is executable by the current effective user731 #[value(alias = "x")]732 Executable,733 #[value(alias = "e")]136 unmodified linesmodified:src/filesystem.rs+20 added
58 unmodified lines59 }60 }61 62 #[cfg(any(unix, target_os = "redox"))]63+pub fn is_block_device(ft: fs::FileType) -> bool {64+ ft.is_block_device()65+}66+67+#[cfg(windows)]68+pub fn is_block_device(_: fs::FileType) -> bool {69+ false70+}71+72+#[cfg(any(unix, target_os = "redox"))]73+pub fn is_char_device(ft: fs::FileType) -> bool {74+ ft.is_char_device()75+}76+77+#[cfg(windows)]78+pub fn is_char_device(_: fs::FileType) -> bool {79+ false80+}81+82+#[cfg(any(unix, target_os = "redox"))]83 pub fn is_socket(ft: fs::FileType) -> bool {84 ft.is_socket()85 }86 72 unmodified linesmodified:src/filetypes.rs+6 added
7 unmodified lines8 pub struct FileTypes {9 pub files: bool,10 pub directories: bool,11 pub symlinks: bool,12+ pub block_devices: bool,13+ pub char_devices: bool,14 pub sockets: bool,15 pub pipes: bool,16 pub executables_only: bool,17 pub empty_only: bool,4 unmodified lines22 if let Some(ref entry_type) = entry.file_type() {23 (!self.files && entry_type.is_file())24 || (!self.directories && entry_type.is_dir())25 || (!self.symlinks && entry_type.is_symlink())26+ || (!self.block_devices && filesystem::is_block_device(*entry_type))27+ || (!self.char_devices && filesystem::is_char_device(*entry_type))28 || (!self.sockets && filesystem::is_socket(*entry_type))29 || (!self.pipes && filesystem::is_pipe(*entry_type))30 || (self.executables_only && !entry.path().executable())31 || (self.empty_only && !filesystem::is_empty(entry))32 || !(entry_type.is_file()33 || entry_type.is_dir()34 || entry_type.is_symlink()35+ || filesystem::is_block_device(*entry_type)36+ || filesystem::is_char_device(*entry_type)37 || filesystem::is_socket(*entry_type)38 || filesystem::is_pipe(*entry_type))39 } else {40 true3 unmodified linesmodified:src/main.rs+2 added
267 unmodified lines268 file_types.executables_only = true;269 file_types.files = true;270 }271 Empty => file_types.empty_only = true,272+ BlockDevice => file_types.block_devices = true,273+ CharDevice => file_types.char_devices = true,274 Socket => file_types.sockets = true,275 Pipe => file_types.pipes = true,276 }277 }196 unmodified linesmodified:README.md+2 added-1 removed
312 unmodified lines313 -p, --full-path Search full abs. path (default: filename only)314 -d, --max-depth <depth> Set maximum search depth (default: none)315 -E, --exclude <pattern> Exclude entries that match the given glob pattern316 -t, --type <filetype> Filter by type: file (f), directory (d), symlink (l),317- executable (x), empty (e), socket (s), pipe (p)317+ executable (x), empty (e), socket (s), pipe (p),318+ block-device (b), char-device (c)319 -e, --extension <ext> Filter by file extension320 -S, --size <size> Limit results based on the size of files321 --changed-within <date|dur> Filter by file modification time (newer than)322 --changed-before <date|dur> Filter by file modification time (older than)393 unmodified lines