From 4fb1dc4259521ceeed90346d6f27c2111cb84f2b Mon Sep 17 00:00:00 2001 From: Saathwik Dasari Date: Wed, 31 Dec 2025 14:18:08 +0000 Subject: [PATCH 1/6] pr: allow character, block, and fifo devices as input --- src/uu/pr/src/pr.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index f5c5662aa19..747b50a21b5 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -757,16 +757,16 @@ fn open(path: &str) -> Result, 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() => { + + ft if ft.is_file() + || ft.is_symlink() + || ft.is_char_device() + || ft.is_block_device() + || ft.is_fifo() => + { Ok(Box::new(File::open(path).map_err(|e| PrError::Input { source: e, file: path.to_string(), From 27d4f76f185f39ef3c00d409f60e2cb476588b7c Mon Sep 17 00:00:00 2001 From: Saathwik Dasari Date: Wed, 31 Dec 2025 15:04:02 +0000 Subject: [PATCH 2/6] pr: fix compilation on non-unix platforms --- src/uu/pr/src/pr.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index 747b50a21b5..655a64fb62a 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -761,18 +761,23 @@ fn open(path: &str) -> Result, PrError> { 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() - || ft.is_char_device() - || ft.is_block_device() - || ft.is_fifo() => - { - Ok(Box::new(File::open(path).map_err(|e| PrError::Input { - source: e, - file: path.to_string(), - })?) as Box) + ft => { + 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) + } else { + Err(PrError::UnknownFiletype { file: path_string }) + } } - _ => Err(PrError::UnknownFiletype { file: path_string }), } }, ) From 3c92f4b33b86e5987841f2fbb678f3077de360ba Mon Sep 17 00:00:00 2001 From: Saathwik Dasari Date: Wed, 31 Dec 2025 15:06:38 +0000 Subject: [PATCH 3/6] pr: fix compilation on non-unix platforms after doing cargo fmt --- src/uu/pr/src/pr.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index 655a64fb62a..751d0322163 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -766,7 +766,8 @@ fn open(path: &str) -> Result, PrError> { #[cfg(unix)] { - is_valid = is_valid || ft.is_char_device() || ft.is_block_device() || ft.is_fifo(); + is_valid = + is_valid || ft.is_char_device() || ft.is_block_device() || ft.is_fifo(); } if is_valid { From b43e1e5d382d6e809855905767b2bb54ba1e7d61 Mon Sep 17 00:00:00 2001 From: Saathwik Dasari Date: Wed, 31 Dec 2025 16:12:45 +0000 Subject: [PATCH 4/6] pr: suppress unused mut warning on windows --- src/uu/pr/src/pr.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index 751d0322163..19e9f2a0c89 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -762,6 +762,7 @@ fn open(path: &str) -> Result, PrError> { ft if ft.is_dir() => Err(PrError::IsDirectory { file: path_string }), ft => { + #[allow(unused_mut)] let mut is_valid = ft.is_file() || ft.is_symlink(); #[cfg(unix)] From 6d6ba89beed26ab76312720a9ce3eb5c533f6ac7 Mon Sep 17 00:00:00 2001 From: Saathwik Dasari Date: Wed, 31 Dec 2025 18:38:24 +0000 Subject: [PATCH 5/6] tests: add regression test using /dev/null --- tests/by-util/test_pr.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/by-util/test_pr.rs b/tests/by-util/test_pr.rs index 1fa91dab2e9..26ae1fb30c5 100644 --- a/tests/by-util/test_pr.rs +++ b/tests/by-util/test_pr.rs @@ -610,3 +610,11 @@ 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(); +} \ No newline at end of file From a9e2cdae3dd6ab7696a44cf27ccff70b44de061a Mon Sep 17 00:00:00 2001 From: Saathwik Dasari Date: Wed, 31 Dec 2025 18:45:04 +0000 Subject: [PATCH 6/6] tests: add regression test using /dev/null after cargo fmt --- tests/by-util/test_pr.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/by-util/test_pr.rs b/tests/by-util/test_pr.rs index 26ae1fb30c5..0bb161fb8a8 100644 --- a/tests/by-util/test_pr.rs +++ b/tests/by-util/test_pr.rs @@ -614,7 +614,5 @@ fn test_version() { #[cfg(unix)] #[test] fn test_pr_char_device_dev_null() { - new_ucmd!() - .arg("/dev/null") - .succeeds(); -} \ No newline at end of file + new_ucmd!().arg("/dev/null").succeeds(); +}