diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index 4b049e8cf..7742358a5 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -348,6 +348,11 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> { let zero = matches.get_flag("zero"); let ignore_missing = matches.get_flag("ignore-missing"); + if ignore_missing && !check { + // --ignore-missing needs -c + return Err(HashsumError::IgnoreNotCheck.into()); + } + let opts = Options { algoname: name, digest: algo, @@ -573,6 +578,7 @@ fn uu_app(binary_name: &str) -> Command { enum HashsumError { InvalidRegex, InvalidFormat, + IgnoreNotCheck, } impl Error for HashsumError {} @@ -583,6 +589,10 @@ impl std::fmt::Display for HashsumError { match self { Self::InvalidRegex => write!(f, "invalid regular expression"), Self::InvalidFormat => Ok(()), + Self::IgnoreNotCheck => write!( + f, + "the --ignore-missing option is meaningful only when verifying checksums" + ), } } } @@ -715,7 +725,7 @@ where let f = match File::open(ck_filename_unescaped) { Err(_) => { if options.ignore_missing { - // No need to show an error + // No need to show or return an error. continue; } diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index 4e590902d..e5e3e1e98 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -154,6 +154,13 @@ fn test_check_md5_ignore_missing() { .succeeds() .stdout_is("testf: OK\n") .stderr_is(""); + + scene + .ccmd("md5sum") + .arg("--ignore-missing") + .arg(at.subdir.join("testf.sha1")) + .fails() + .stderr_contains("the --ignore-missing option is meaningful only when verifying checksums"); } #[test]