pr: allow character, block, and fifo devices as input (#9946)

This commit is contained in:
Saathwik Dasari
2026-01-01 12:36:58 +01:00
committed by GitHub
parent abd581f62e
commit b600c257ef
2 changed files with 25 additions and 12 deletions
+19 -12
View File
@@ -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 }),
}
},
)
+6
View File
@@ -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();
}