From 6009543fc35874936848bddcbcf8a2ce44d40c28 Mon Sep 17 00:00:00 2001 From: Dorian Peron Date: Mon, 1 Dec 2025 01:58:19 +0100 Subject: [PATCH] checksum(validate): Remove called-once simple functions, fix standard-input filename print --- .../src/lib/features/checksum/validate.rs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/uucore/src/lib/features/checksum/validate.rs b/src/uucore/src/lib/features/checksum/validate.rs index c36baca87..e91a07cae 100644 --- a/src/uucore/src/lib/features/checksum/validate.rs +++ b/src/uucore/src/lib/features/checksum/validate.rs @@ -170,10 +170,16 @@ fn print_cksum_report(res: &ChecksumResult) { /// Print a "no properly formatted lines" message in stderr #[inline] -fn log_no_properly_formatted(filename: String) { +fn log_no_properly_formatted(filename: impl Display) { show_error!("{filename}: no properly formatted checksum lines found"); } +/// Print a "no file was verified" message in stderr +#[inline] +fn log_no_file_verified(filename: impl Display) { + show_error!("{filename}: no file was verified"); +} + /// Represents the different outcomes that can happen to a file /// that is being checked. #[derive(Debug, Clone, Copy)] @@ -467,16 +473,6 @@ impl LineInfo { } } -fn get_filename_for_output(filename: &OsStr, input_is_stdin: bool) -> String { - if input_is_stdin { - "standard input" - } else { - filename.to_str().unwrap() - } - .maybe_quote() - .to_string() -} - /// Extract the expected digest from the checksum string and decode it fn get_raw_expected_digest(checksum: &str, byte_len_hint: Option) -> Option> { // If the length of the digest is not a multiple of 2, then it must be @@ -882,11 +878,19 @@ fn process_checksum_file( } } + let filename_display = || { + if input_is_stdin { + "standard input".maybe_quote() + } else { + filename_input.maybe_quote() + } + }; + // not a single line correctly formatted found // return an error if res.total_properly_formatted() == 0 { if opts.verbose.over_status() { - log_no_properly_formatted(get_filename_for_output(filename_input, input_is_stdin)); + log_no_properly_formatted(filename_display()); } return Err(FileCheckError::Failed); } @@ -900,11 +904,7 @@ fn process_checksum_file( // we have only bad format // and we had ignore-missing if opts.verbose.over_status() { - eprintln!( - "{}: {}: no file was verified", - util_name(), - filename_input.maybe_quote(), - ); + log_no_file_verified(filename_display()); } return Err(FileCheckError::Failed); }