mirror of
https://github.com/uutils/coreutils.git
synced 2025-12-23 08:47:37 +00:00
Merge pull request #8930 from Ada-Armstrong/hashsum_continue_on_dirs
hashsum: don't fail on dirs
This commit is contained in:
parent
fd83181ac2
commit
f7e639f8a2
2 changed files with 51 additions and 6 deletions
|
|
@ -25,7 +25,7 @@ use uucore::checksum::detect_algo;
|
|||
use uucore::checksum::digest_reader;
|
||||
use uucore::checksum::escape_filename;
|
||||
use uucore::checksum::perform_checksum_validation;
|
||||
use uucore::error::{FromIo, UResult};
|
||||
use uucore::error::{UResult, strip_errno};
|
||||
use uucore::format_usage;
|
||||
use uucore::sum::{Digest, Sha3_224, Sha3_256, Sha3_384, Sha3_512, Shake128, Shake256};
|
||||
use uucore::translate;
|
||||
|
|
@ -552,9 +552,10 @@ where
|
|||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
eprintln!(
|
||||
"{}: {}: {e}",
|
||||
"{}: {}: {}",
|
||||
options.binary_name,
|
||||
filename.to_string_lossy()
|
||||
filename.to_string_lossy(),
|
||||
strip_errno(&e)
|
||||
);
|
||||
err_found = Some(ChecksumError::Io(e));
|
||||
continue;
|
||||
|
|
@ -564,13 +565,25 @@ where
|
|||
},
|
||||
);
|
||||
|
||||
let (sum, _) = digest_reader(
|
||||
let sum = match digest_reader(
|
||||
&mut options.digest,
|
||||
&mut file,
|
||||
options.binary,
|
||||
options.output_bits,
|
||||
)
|
||||
.map_err_context(|| translate!("hashsum-error-failed-to-read-input"))?;
|
||||
) {
|
||||
Ok((sum, _)) => sum,
|
||||
Err(e) => {
|
||||
eprintln!(
|
||||
"{}: {}: {}",
|
||||
options.binary_name,
|
||||
filename.to_string_lossy(),
|
||||
strip_errno(&e)
|
||||
);
|
||||
err_found = Some(ChecksumError::Io(e));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let (escaped_filename, prefix) = escape_filename(filename);
|
||||
if options.tag {
|
||||
if options.algoname == "blake2b" {
|
||||
|
|
|
|||
|
|
@ -872,6 +872,38 @@ fn test_check_directory_error() {
|
|||
.stderr_contains(err_msg);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn test_continue_after_directory_error() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.mkdir("d");
|
||||
at.touch("file");
|
||||
at.touch("no_read_perms");
|
||||
at.set_mode("no_read_perms", 200);
|
||||
|
||||
let (out, err_msg) = (
|
||||
"d41d8cd98f00b204e9800998ecf8427e file\n",
|
||||
[
|
||||
"md5sum: d: Is a directory",
|
||||
"md5sum: dne: No such file or directory",
|
||||
"md5sum: no_read_perms: Permission denied\n",
|
||||
]
|
||||
.join("\n"),
|
||||
);
|
||||
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("d")
|
||||
.arg("dne")
|
||||
.arg("no_read_perms")
|
||||
.arg("file")
|
||||
.fails()
|
||||
.stdout_is(out)
|
||||
.stderr_is(err_msg);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_quiet() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue