mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
checksum: move line warning display to process_line loop
This commit is contained in:
parent
58e4e4bb70
commit
11a0b1b505
1 changed files with 30 additions and 30 deletions
|
@ -789,7 +789,6 @@ fn process_non_algo_based_line(
|
||||||
/// matched the expected.
|
/// matched the expected.
|
||||||
/// If the comparison didn't happen, return a `LineChecksumError`.
|
/// If the comparison didn't happen, return a `LineChecksumError`.
|
||||||
fn process_checksum_line(
|
fn process_checksum_line(
|
||||||
filename_input: &OsStr,
|
|
||||||
line: &OsStr,
|
line: &OsStr,
|
||||||
i: usize,
|
i: usize,
|
||||||
cli_algo_name: Option<&str>,
|
cli_algo_name: Option<&str>,
|
||||||
|
@ -806,34 +805,19 @@ fn process_checksum_line(
|
||||||
|
|
||||||
// Use `LineInfo` to extract the data of a line.
|
// Use `LineInfo` to extract the data of a line.
|
||||||
// Then, depending on its format, apply a different pre-treatment.
|
// Then, depending on its format, apply a different pre-treatment.
|
||||||
if let Some(line_info) = LineInfo::parse(line, cached_regex) {
|
let Some(line_info) = LineInfo::parse(line, cached_regex) else {
|
||||||
if line_info.format == LineFormat::AlgoBased {
|
return Err(LineCheckError::ImproperlyFormatted);
|
||||||
process_algo_based_line(&line_info, cli_algo_name, opts)
|
};
|
||||||
} else if let Some(cli_algo) = cli_algo_name {
|
|
||||||
// If we match a non-algo based regex, we expect a cli argument
|
|
||||||
// to give us the algorithm to use
|
|
||||||
process_non_algo_based_line(i, &line_info, cli_algo, cli_algo_length, opts)
|
|
||||||
} else {
|
|
||||||
// We have no clue of what algorithm to use
|
|
||||||
return Err(LineCheckError::ImproperlyFormatted);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if opts.warn {
|
|
||||||
let algo = if let Some(algo_name_input) = cli_algo_name {
|
|
||||||
algo_name_input.to_uppercase()
|
|
||||||
} else {
|
|
||||||
"Unknown algorithm".to_string()
|
|
||||||
};
|
|
||||||
eprintln!(
|
|
||||||
"{}: {}: {}: improperly formatted {} checksum line",
|
|
||||||
util_name(),
|
|
||||||
&filename_input.maybe_quote(),
|
|
||||||
i + 1,
|
|
||||||
algo
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Err(LineCheckError::ImproperlyFormatted)
|
if line_info.format == LineFormat::AlgoBased {
|
||||||
|
process_algo_based_line(&line_info, cli_algo_name, opts)
|
||||||
|
} else if let Some(cli_algo) = cli_algo_name {
|
||||||
|
// If we match a non-algo based regex, we expect a cli argument
|
||||||
|
// to give us the algorithm to use
|
||||||
|
process_non_algo_based_line(i, &line_info, cli_algo, cli_algo_length, opts)
|
||||||
|
} else {
|
||||||
|
// We have no clue of what algorithm to use
|
||||||
|
return Err(LineCheckError::ImproperlyFormatted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -871,7 +855,6 @@ fn process_checksum_file(
|
||||||
|
|
||||||
for (i, line) in lines.iter().enumerate() {
|
for (i, line) in lines.iter().enumerate() {
|
||||||
let line_result = process_checksum_line(
|
let line_result = process_checksum_line(
|
||||||
filename_input,
|
|
||||||
line,
|
line,
|
||||||
i,
|
i,
|
||||||
cli_algo_name,
|
cli_algo_name,
|
||||||
|
@ -893,7 +876,24 @@ fn process_checksum_file(
|
||||||
match line_result {
|
match line_result {
|
||||||
Ok(()) => res.correct += 1,
|
Ok(()) => res.correct += 1,
|
||||||
Err(DigestMismatch) => res.failed_cksum += 1,
|
Err(DigestMismatch) => res.failed_cksum += 1,
|
||||||
Err(ImproperlyFormatted) => res.bad_format += 1,
|
Err(ImproperlyFormatted) => {
|
||||||
|
res.bad_format += 1;
|
||||||
|
|
||||||
|
if opts.warn {
|
||||||
|
let algo = if let Some(algo_name_input) = cli_algo_name {
|
||||||
|
Cow::Owned(algo_name_input.to_uppercase())
|
||||||
|
} else {
|
||||||
|
Cow::Borrowed("Unknown algorithm")
|
||||||
|
};
|
||||||
|
eprintln!(
|
||||||
|
"{}: {}: {}: improperly formatted {} checksum line",
|
||||||
|
util_name(),
|
||||||
|
&filename_input.maybe_quote(),
|
||||||
|
i + 1,
|
||||||
|
algo
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(CantOpenFile | FileIsDirectory) => res.failed_open_file += 1,
|
Err(CantOpenFile | FileIsDirectory) => res.failed_open_file += 1,
|
||||||
Err(FileNotFound) if !opts.ignore_missing => res.failed_open_file += 1,
|
Err(FileNotFound) if !opts.ignore_missing => res.failed_open_file += 1,
|
||||||
_ => continue,
|
_ => continue,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue