1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-13 10:37:58 +00:00

Merge pull request #5804 from Ato2207/cksum_error

Made cksum return an error if the algorithm blake2b is used on a directory.
This commit is contained in:
Daniel Hofstetter 2024-01-08 08:38:48 +01:00 committed by GitHub
commit 8e83b347c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -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());

View file

@ -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"));
}