Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/uu/cksum/src/cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ where
(ALGORITHM_OPTIONS_CRC, true) => println!("{sum} {sz}"),
(ALGORITHM_OPTIONS_CRC, false) => println!("{sum} {sz} {}", filename.display()),
(ALGORITHM_OPTIONS_BLAKE2B, _) if !options.untagged => {
if filename.is_dir() {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("{}: Is a directory", filename.display()),
)
.into());
}
if let Some(length) = options.length {
// Multiply by 8 here, as we want to print the length in bits.
println!("BLAKE2b-{} ({}) = {sum}", length * 8, filename.display());
Expand Down
14 changes: 14 additions & 0 deletions tests/by-util/test_cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,17 @@ fn test_length_is_zero() {
.no_stderr()
.stdout_is_fixture("length_is_zero.expected");
}

#[test]
fn test_blake2b_fail_on_directory() {
let (at, mut ucmd) = at_and_ucmd!();

let folder_name = "a_folder";
at.mkdir(folder_name);

ucmd.arg("--algorithm=blake2b")
.arg(folder_name)
.fails()
.no_stdout()
.stderr_contains(format!("cksum: {folder_name}: Is a directory"));
}