Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 20 additions & 2 deletions src/uucore/src/lib/features/checksum/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions tests/by-util/test_cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Loading