Skip to content

Commit 2a8811d

Browse files
authored
cksum -c /dev/null 2>/dev/full should not abort (#10643)
1 parent 26498f5 commit 2a8811d

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

src/uucore/src/lib/features/checksum/validate.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

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

8+
use crate::util_name;
9+
810
use std::ffi::OsStr;
911
use std::fmt::Display;
1012
use std::fs::File;
11-
use std::io::{self, BufReader, Read, Write, stdin};
13+
use std::io::{self, BufReader, Read, Write, stderr, stdin};
1214

1315
use os_display::Quotable;
1416

@@ -17,8 +19,7 @@ use crate::error::{FromIo, UError, UResult, USimpleError};
1719
use crate::quoting_style::{QuotingStyle, locale_aware_escape_name};
1820
use crate::sum::DigestOutput;
1921
use crate::{
20-
os_str_as_bytes, os_str_from_bytes, read_os_string_lines, show, show_error, show_warning_caps,
21-
translate,
22+
os_str_as_bytes, os_str_from_bytes, read_os_string_lines, show, show_warning_caps, translate,
2223
};
2324

2425
/// To what level should checksum validation print logging info.
@@ -173,17 +174,21 @@ fn print_cksum_report(res: &ChecksumResult) {
173174
/// Print a "no properly formatted lines" message in stderr
174175
#[inline]
175176
fn log_no_properly_formatted(filename: impl Display) {
176-
show_error!(
177-
"{}",
177+
let _ = writeln!(
178+
stderr(),
179+
"{}: {}",
180+
util_name(),
178181
translate!("checksum-no-properly-formatted", "checksum_file" => filename)
179182
);
180183
}
181184

182185
/// Print a "no file was verified" message in stderr
183186
#[inline]
184187
fn log_no_file_verified(filename: impl Display) {
185-
show_error!(
186-
"{}",
188+
let _ = writeln!(
189+
stderr(),
190+
"{}: {}",
191+
util_name(),
187192
translate!("checksum-no-file-verified", "checksum_file" => filename)
188193
);
189194
}
@@ -839,7 +844,7 @@ fn process_checksum_file(
839844
Ok(f) => f,
840845
Err(e) => {
841846
// Could not read the file, show the error and continue to the next file
842-
show_error!("{e}");
847+
let _ = writeln!(stderr(), "{}: {e}", util_name());
843848
return Err(FileCheckError::CantOpenChecksumFile);
844849
}
845850
}
@@ -891,8 +896,10 @@ fn process_checksum_file(
891896
} else {
892897
"Unknown algorithm"
893898
};
894-
show_error!(
895-
"{}",
899+
let _ = writeln!(
900+
stderr(),
901+
"{}: {}",
902+
util_name(),
896903
translate!("checksum-error-algo-bad-format", "file" => filename_input.maybe_quote(), "line" => i + 1, "algo" => algo)
897904
);
898905
}

0 commit comments

Comments
 (0)