From 5309b65867d4899cce7ef27ca4af348c24eb8da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20P=C3=A9ron?= Date: Sun, 3 Nov 2024 11:57:32 +0100 Subject: [PATCH] feat(checksum): change process_checksum_line return type to Result<(), LineCheckError> - Treat digest mismatch as an error --- src/uucore/src/lib/features/checksum.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/uucore/src/lib/features/checksum.rs b/src/uucore/src/lib/features/checksum.rs index 1de41232e..333c76d2a 100644 --- a/src/uucore/src/lib/features/checksum.rs +++ b/src/uucore/src/lib/features/checksum.rs @@ -77,6 +77,7 @@ struct ChecksumResult { enum LineCheckError { UError(Box), + DigestMismatch, Skipped, ImproperlyFormatted, CantOpenFile, @@ -594,7 +595,7 @@ fn process_checksum_line( cli_algo_length: Option, properly_formatted: &mut bool, opts: ChecksumOptions, -) -> Result { +) -> Result<(), LineCheckError> { let line_bytes = os_str_as_bytes(line)?; if let Some(caps) = chosen_regex.captures(line_bytes) { *properly_formatted = true; @@ -663,7 +664,12 @@ fn process_checksum_line( prefix, opts, ); - Ok(checksum_correct) + + if checksum_correct { + Ok(()) + } else { + Err(LineCheckError::DigestMismatch) + } } else { if line.is_empty() || line_bytes.starts_with(b"#") { // Don't show any warning for empty or commented lines. @@ -740,8 +746,8 @@ fn process_checksum_file( &mut properly_formatted, opts, ) { - Ok(true) => correct_format += 1, - Ok(false) => res.failed_cksum += 1, + Ok(()) => correct_format += 1, + Err(LineCheckError::DigestMismatch) => res.failed_cksum += 1, Err(LineCheckError::UError(e)) => return Err(e.into()), Err(LineCheckError::Skipped) => continue, Err(LineCheckError::ImproperlyFormatted) => (),