1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

feat(checksum): change process_checksum_line return type to Result<(), LineCheckError>

- Treat digest mismatch as an error
This commit is contained in:
Dorian Péron 2024-11-03 11:57:32 +01:00 committed by Sylvestre Ledru
parent 4ffedcdac6
commit 5309b65867

View file

@ -77,6 +77,7 @@ struct ChecksumResult {
enum LineCheckError { enum LineCheckError {
UError(Box<dyn UError>), UError(Box<dyn UError>),
DigestMismatch,
Skipped, Skipped,
ImproperlyFormatted, ImproperlyFormatted,
CantOpenFile, CantOpenFile,
@ -594,7 +595,7 @@ fn process_checksum_line(
cli_algo_length: Option<usize>, cli_algo_length: Option<usize>,
properly_formatted: &mut bool, properly_formatted: &mut bool,
opts: ChecksumOptions, opts: ChecksumOptions,
) -> Result<bool, LineCheckError> { ) -> Result<(), LineCheckError> {
let line_bytes = os_str_as_bytes(line)?; let line_bytes = os_str_as_bytes(line)?;
if let Some(caps) = chosen_regex.captures(line_bytes) { if let Some(caps) = chosen_regex.captures(line_bytes) {
*properly_formatted = true; *properly_formatted = true;
@ -663,7 +664,12 @@ fn process_checksum_line(
prefix, prefix,
opts, opts,
); );
Ok(checksum_correct)
if checksum_correct {
Ok(())
} else {
Err(LineCheckError::DigestMismatch)
}
} else { } else {
if line.is_empty() || line_bytes.starts_with(b"#") { if line.is_empty() || line_bytes.starts_with(b"#") {
// Don't show any warning for empty or commented lines. // Don't show any warning for empty or commented lines.
@ -740,8 +746,8 @@ fn process_checksum_file(
&mut properly_formatted, &mut properly_formatted,
opts, opts,
) { ) {
Ok(true) => correct_format += 1, Ok(()) => correct_format += 1,
Ok(false) => res.failed_cksum += 1, Err(LineCheckError::DigestMismatch) => res.failed_cksum += 1,
Err(LineCheckError::UError(e)) => return Err(e.into()), Err(LineCheckError::UError(e)) => return Err(e.into()),
Err(LineCheckError::Skipped) => continue, Err(LineCheckError::Skipped) => continue,
Err(LineCheckError::ImproperlyFormatted) => (), Err(LineCheckError::ImproperlyFormatted) => (),