1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

cksum: fix error message when the flags length and an algorithm different from blake2b are present (#7071)

test length and blake2b algorithm before testing supported algorithms
This commit is contained in:
Tommaso Fellegara 2025-01-04 21:53:10 +01:00 committed by GitHub
parent fbea7c41ca
commit b15bc8440c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View file

@ -276,10 +276,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
};
if ["bsd", "crc", "sysv"].contains(&algo_name) && check {
return Err(ChecksumError::AlgorithmNotSupportedWithCheck.into());
}
let input_length = matches.get_one::<usize>(options::LENGTH);
let length = match input_length {
@ -293,6 +289,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
None => None,
};
if ["bsd", "crc", "sysv"].contains(&algo_name) && check {
return Err(ChecksumError::AlgorithmNotSupportedWithCheck.into());
}
if check {
let text_flag = matches.get_flag(options::TEXT);
let binary_flag = matches.get_flag(options::BINARY);

View file

@ -352,6 +352,18 @@ fn test_length_not_supported() {
.no_stdout()
.stderr_contains("--length is only supported with --algorithm=blake2b")
.code_is(1);
new_ucmd!()
.arg("-l")
.arg("158")
.arg("-c")
.arg("-a")
.arg("crc")
.arg("/tmp/xxx")
.fails()
.no_stdout()
.stderr_contains("--length is only supported with --algorithm=blake2b")
.code_is(1);
}
#[test]