mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
cksum: Don't panic when checked file returned EIO (#10534)
This commit is contained in:
@@ -676,8 +676,26 @@ fn compute_and_check_digest_from_file(
|
||||
|
||||
// TODO: improve function signature to use ReadingMode instead of binary bool
|
||||
// Set binary to false because --binary is not supported with --check
|
||||
let (calculated_checksum, _) =
|
||||
digest_reader(&mut digest, &mut file_reader, /* binary */ false).unwrap();
|
||||
|
||||
let (calculated_checksum, _) = match digest_reader(&mut digest, &mut file_reader, false) {
|
||||
Ok(result) => result,
|
||||
Err(err) => {
|
||||
show!(err.map_err_context(|| {
|
||||
locale_aware_escape_name(&real_filename_to_check, QuotingStyle::SHELL_ESCAPE)
|
||||
.to_string_lossy()
|
||||
.to_string()
|
||||
}));
|
||||
|
||||
write_file_report(
|
||||
std::io::stdout(),
|
||||
filename,
|
||||
FileChecksumResult::CantOpen,
|
||||
prefix,
|
||||
opts.verbose,
|
||||
);
|
||||
return Err(LineCheckError::CantOpenFile);
|
||||
}
|
||||
};
|
||||
|
||||
// Do the checksum validation
|
||||
let checksum_correct = match calculated_checksum {
|
||||
|
||||
@@ -3046,3 +3046,17 @@ mod debug_flag {
|
||||
.stderr_contains("pclmul");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
|
||||
fn test_check_file_with_io_error() {
|
||||
// /proc/self/mem causes EIO when read without proper seeking
|
||||
new_ucmd!()
|
||||
.arg("-a")
|
||||
.arg("md5")
|
||||
.arg("--check")
|
||||
.pipe_in("d8e8fca2dc0f896fd7cb4cb0031ba249 /proc/self/mem\n")
|
||||
.fails()
|
||||
.stderr_contains("Input/output error")
|
||||
.stdout_contains("FAILED open or read");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user