Skip to content

Commit b600c25

Browse files
pr: allow character, block, and fifo devices as input (#9946)
1 parent abd581f commit b600c25

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/uu/pr/src/pr.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -757,22 +757,29 @@ fn open(path: &str) -> Result<Box<dyn Read>, PrError> {
757757
|i| {
758758
let path_string = path.to_string();
759759
match i.file_type() {
760-
#[cfg(unix)]
761-
ft if ft.is_block_device() => Err(PrError::UnknownFiletype { file: path_string }),
762-
#[cfg(unix)]
763-
ft if ft.is_char_device() => Err(PrError::UnknownFiletype { file: path_string }),
764-
#[cfg(unix)]
765-
ft if ft.is_fifo() => Err(PrError::UnknownFiletype { file: path_string }),
766760
#[cfg(unix)]
767761
ft if ft.is_socket() => Err(PrError::IsSocket { file: path_string }),
768762
ft if ft.is_dir() => Err(PrError::IsDirectory { file: path_string }),
769-
ft if ft.is_file() || ft.is_symlink() => {
770-
Ok(Box::new(File::open(path).map_err(|e| PrError::Input {
771-
source: e,
772-
file: path.to_string(),
773-
})?) as Box<dyn Read>)
763+
764+
ft => {
765+
#[allow(unused_mut)]
766+
let mut is_valid = ft.is_file() || ft.is_symlink();
767+
768+
#[cfg(unix)]
769+
{
770+
is_valid =
771+
is_valid || ft.is_char_device() || ft.is_block_device() || ft.is_fifo();
772+
}
773+
774+
if is_valid {
775+
Ok(Box::new(File::open(path).map_err(|e| PrError::Input {
776+
source: e,
777+
file: path.to_string(),
778+
})?) as Box<dyn Read>)
779+
} else {
780+
Err(PrError::UnknownFiletype { file: path_string })
781+
}
774782
}
775-
_ => Err(PrError::UnknownFiletype { file: path_string }),
776783
}
777784
},
778785
)

tests/by-util/test_pr.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,3 +610,9 @@ fn test_help() {
610610
fn test_version() {
611611
new_ucmd!().arg("--version").succeeds();
612612
}
613+
614+
#[cfg(unix)]
615+
#[test]
616+
fn test_pr_char_device_dev_null() {
617+
new_ucmd!().arg("/dev/null").succeeds();
618+
}

0 commit comments

Comments
 (0)