Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/uucore/src/lib/features/checksum/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

// spell-checker:ignore rsplit hexdigit bitlen invalidchecksum inva idchecksum xffname

use crate::util_name;

use std::ffi::OsStr;
use std::fmt::Display;
use std::fs::File;
use std::io::{self, BufReader, Read, Write, stdin};
use std::io::{self, BufReader, Read, Write, stderr, stdin};

use os_display::Quotable;

Expand All @@ -17,8 +19,7 @@ use crate::error::{FromIo, UError, UResult, USimpleError};
use crate::quoting_style::{QuotingStyle, locale_aware_escape_name};
use crate::sum::DigestOutput;
use crate::{
os_str_as_bytes, os_str_from_bytes, read_os_string_lines, show, show_error, show_warning_caps,
translate,
os_str_as_bytes, os_str_from_bytes, read_os_string_lines, show, show_warning_caps, translate,
};

/// To what level should checksum validation print logging info.
Expand Down Expand Up @@ -173,17 +174,21 @@ fn print_cksum_report(res: &ChecksumResult) {
/// Print a "no properly formatted lines" message in stderr
#[inline]
fn log_no_properly_formatted(filename: impl Display) {
show_error!(
"{}",
let _ = writeln!(
stderr(),
"{}: {}",
util_name(),
translate!("checksum-no-properly-formatted", "checksum_file" => filename)
);
}

/// Print a "no file was verified" message in stderr
#[inline]
fn log_no_file_verified(filename: impl Display) {
show_error!(
"{}",
let _ = writeln!(
stderr(),
"{}: {}",
util_name(),
translate!("checksum-no-file-verified", "checksum_file" => filename)
);
}
Expand Down Expand Up @@ -839,7 +844,7 @@ fn process_checksum_file(
Ok(f) => f,
Err(e) => {
// Could not read the file, show the error and continue to the next file
show_error!("{e}");
let _ = writeln!(stderr(), "{}: {e}", util_name());
return Err(FileCheckError::CantOpenChecksumFile);
}
}
Expand Down Expand Up @@ -891,8 +896,10 @@ fn process_checksum_file(
} else {
"Unknown algorithm"
};
show_error!(
"{}",
let _ = writeln!(
stderr(),
"{}: {}",
util_name(),
translate!("checksum-error-algo-bad-format", "file" => filename_input.maybe_quote(), "line" => i + 1, "algo" => algo)
);
}
Expand Down
Loading