Skip to content

Commit

Permalink
cksum: Fix handling of both encodings in a single file
Browse files Browse the repository at this point in the history
  • Loading branch information
RenjiSann committed Aug 31, 2024
1 parent ce63a80 commit 478adeb
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/uucore/src/lib/features/checksum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ impl UError for ChecksumError {

enum LineCheckError {
UError(Box<dyn UError>),
// ImproperlyFormatted,
ImproperlyFormatted,
Skipped,
}

impl From<Box<dyn UError>> for LineCheckError {
Expand Down Expand Up @@ -357,6 +358,11 @@ fn process_checksum_line(
correct_format: &mut usize,
opts: ChecksumOptions,
) -> Result<(), LineCheckError> {
if line.is_empty() || os_str_as_bytes(line)?.starts_with(b"#") {
// Skip empty and comment lines.
return Err(LineCheckError::Skipped);
}

if let Some(caps) =
chosen_regex.captures(os_str_as_bytes(line).expect("UTF-8 decoding failure"))
{
Expand Down Expand Up @@ -463,11 +469,6 @@ fn process_checksum_line(
res.failed_cksum += 1;
}
} else {
if line.is_empty() {
// Don't show any warning for empty lines
// FIXME(dprn): report error in some way ?
return Ok(());
}
if opts.warn {
let algo = if let Some(algo_name_input) = cli_algo_name {
algo_name_input.to_uppercase()
Expand Down Expand Up @@ -542,7 +543,7 @@ fn process_checksum_file(
opts,
) {
Err(UError(e)) => return Err(e.into()),
// Err(_) => todo!(),
Err(Skipped) => continue,
Ok(_) => (),
}
}
Expand Down

0 comments on commit 478adeb

Please sign in to comment.