summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2023-06-14 15:28:24 +0200
committerDavid Peter <sharkdp@users.noreply.github.com>2023-10-21 13:56:33 +0200
commit36bc84041b0e4bca758abb248e18538b75c4774a (patch)
tree372e7f40a591eba45909ed26e47a59e3195a4668 /src
parent3ed4ea7538fee17d6b3a00eb89f16737225f42f3 (diff)
Support character and block device file types
Diffstat (limited to 'src')
-rw-r--r--src/cli.rs9
-rw-r--r--src/filesystem.rs20
-rw-r--r--src/filetypes.rs6
-rw-r--r--src/main.rs2
4 files changed, 36 insertions, 1 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 53d0cbb..af9bcce 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -313,6 +313,8 @@ pub struct Opts {
/// {n} 'l' or 'symlink': symbolic links
/// {n} 's' or 'socket': socket
/// {n} 'p' or 'pipe': named pipe (FIFO)
+ /// {n} 'b' or 'block-device': block device
+ /// {n} 'c' or 'char-device': character device
/// {n}{n} 'x' or 'executable': executables
/// {n} 'e' or 'empty': empty files or directories
///
@@ -346,7 +348,8 @@ pub struct Opts {
hide_possible_values = true,
value_enum,
help = "Filter by type: file (f), directory (d), symlink (l), \
- executable (x), empty (e), socket (s), pipe (p)",
+ executable (x), empty (e), socket (s), pipe (p), \
+ char-device (c), block-device (b)",
long_help
)]
pub filetype: Option<Vec<FileType>>,
@@ -720,6 +723,10 @@ pub enum FileType {
Directory,
#[value(alias = "l")]
Symlink,
+ #[value(alias = "b")]
+ BlockDevice,
+ #[value(alias = "c")]
+ CharDevice,
/// A file which is executable by the current effective user
#[value(alias = "x")]
Executable,
diff --git a/src/filesystem.rs b/src/filesystem.rs
index b7895c0..b9df0ba 100644
--- a/src/filesystem.rs
+++ b/src/filesystem.rs
@@ -60,6 +60,26 @@ pub fn is_empty(entry: &dir_entry::DirEntry) -> bool {
}
#[cfg(any(unix, target_os = "redox"))]
+pub fn is_block_device(ft: fs::FileType) -> bool {
+ ft.is_block_device()
+}
+
+#[cfg(windows)]
+pub fn is_block_device(_: fs::FileType) -> bool {
+ false
+}
+
+#[cfg(any(unix, target_os = "redox"))]
+pub fn is_char_device(ft: fs::FileType) -> bool {
+ ft.is_char_device()
+}
+
+#[cfg(windows)]
+pub fn is_char_device(_: fs::FileType) -> bool {
+ false
+}
+
+#[cfg(any(unix, target_os = "redox"))]
pub fn is_socket(ft: fs::FileType) -> bool {
ft.is_socket()
}
diff --git a/src/filetypes.rs b/src/filetypes.rs
index c34cc49..a10924b 100644
--- a/src/filetypes.rs
+++ b/src/filetypes.rs
@@ -9,6 +9,8 @@ pub struct FileTypes {
pub files: bool,
pub directories: bool,
pub symlinks: bool,
+ pub block_devices: bool,
+ pub char_devices: bool,
pub sockets: bool,
pub pipes: bool,
pub executables_only: bool,
@@ -21,6 +23,8 @@ impl FileTypes {
(!self.files && entry_type.is_file())
|| (!self.directories && entry_type.is_dir())
|| (!self.symlinks && entry_type.is_symlink())
+ || (!self.block_devices && filesystem::is_block_device(*entry_type))
+ || (!self.char_devices && filesystem::is_char_device(*entry_type))
|| (!self.sockets && filesystem::is_socket(*entry_type))
|| (!self.pipes && filesystem::is_pipe(*entry_type))
|| (self.executables_only && !entry.path().executable())
@@ -28,6 +32,8 @@ impl FileTypes {
|| !(entry_type.is_file()
|| entry_type.is_dir()
|| entry_type.is_symlink()
+ || filesystem::is_block_device(*entry_type)
+ || filesystem::is_char_device(*entry_type)
|| filesystem::is_socket(*entry_type)
|| filesystem::is_pipe(*entry_type))
} else {
diff --git a/src/main.rs b/src/main.rs
index 8c39a1e..a1bad2b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -269,6 +269,8 @@ fn construct_config(mut opts: Opts, pattern_regexps: &[String]) -> Result<Config
file_types.files = true;
}
Empty => file_types.empty_only = true,
+ BlockDevice => file_types.block_devices = true,
+ CharDevice => file_types.char_devices = true,
Socket => file_types.sockets = true,
Pipe => file_types.pipes = true,
}