Skip to content

Commit 8e83b34

Browse files
authored
Merge pull request #5804 from Ato2207/cksum_error
Made cksum return an error if the algorithm blake2b is used on a directory.
2 parents f1499d0 + 0bfd4bb commit 8e83b34

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/uu/cksum/src/cksum.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ where
169169
(ALGORITHM_OPTIONS_CRC, true) => println!("{sum} {sz}"),
170170
(ALGORITHM_OPTIONS_CRC, false) => println!("{sum} {sz} {}", filename.display()),
171171
(ALGORITHM_OPTIONS_BLAKE2B, _) if !options.untagged => {
172+
if filename.is_dir() {
173+
return Err(io::Error::new(
174+
io::ErrorKind::InvalidInput,
175+
format!("{}: Is a directory", filename.display()),
176+
)
177+
.into());
178+
}
172179
if let Some(length) = options.length {
173180
// Multiply by 8 here, as we want to print the length in bits.
174181
println!("BLAKE2b-{} ({}) = {sum}", length * 8, filename.display());

tests/by-util/test_cksum.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,17 @@ fn test_length_is_zero() {
286286
.no_stderr()
287287
.stdout_is_fixture("length_is_zero.expected");
288288
}
289+
290+
#[test]
291+
fn test_blake2b_fail_on_directory() {
292+
let (at, mut ucmd) = at_and_ucmd!();
293+
294+
let folder_name = "a_folder";
295+
at.mkdir(folder_name);
296+
297+
ucmd.arg("--algorithm=blake2b")
298+
.arg(folder_name)
299+
.fails()
300+
.no_stdout()
301+
.stderr_contains(format!("cksum: {folder_name}: Is a directory"));
302+
}

0 commit comments

Comments
 (0)