mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
pr: allow character, block, and fifo devices as input (#9946)
This commit is contained in:
+19
-12
@@ -757,22 +757,29 @@ fn open(path: &str) -> Result<Box<dyn Read>, PrError> {
|
||||
|i| {
|
||||
let path_string = path.to_string();
|
||||
match i.file_type() {
|
||||
#[cfg(unix)]
|
||||
ft if ft.is_block_device() => Err(PrError::UnknownFiletype { file: path_string }),
|
||||
#[cfg(unix)]
|
||||
ft if ft.is_char_device() => Err(PrError::UnknownFiletype { file: path_string }),
|
||||
#[cfg(unix)]
|
||||
ft if ft.is_fifo() => Err(PrError::UnknownFiletype { file: path_string }),
|
||||
#[cfg(unix)]
|
||||
ft if ft.is_socket() => Err(PrError::IsSocket { file: path_string }),
|
||||
ft if ft.is_dir() => Err(PrError::IsDirectory { file: path_string }),
|
||||
ft if ft.is_file() || ft.is_symlink() => {
|
||||
Ok(Box::new(File::open(path).map_err(|e| PrError::Input {
|
||||
source: e,
|
||||
file: path.to_string(),
|
||||
})?) as Box<dyn Read>)
|
||||
|
||||
ft => {
|
||||
#[allow(unused_mut)]
|
||||
let mut is_valid = ft.is_file() || ft.is_symlink();
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
is_valid =
|
||||
is_valid || ft.is_char_device() || ft.is_block_device() || ft.is_fifo();
|
||||
}
|
||||
|
||||
if is_valid {
|
||||
Ok(Box::new(File::open(path).map_err(|e| PrError::Input {
|
||||
source: e,
|
||||
file: path.to_string(),
|
||||
})?) as Box<dyn Read>)
|
||||
} else {
|
||||
Err(PrError::UnknownFiletype { file: path_string })
|
||||
}
|
||||
}
|
||||
_ => Err(PrError::UnknownFiletype { file: path_string }),
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -610,3 +610,9 @@ fn test_help() {
|
||||
fn test_version() {
|
||||
new_ucmd!().arg("--version").succeeds();
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn test_pr_char_device_dev_null() {
|
||||
new_ucmd!().arg("/dev/null").succeeds();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user