mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
hashsum: --ignore-missing needs -c
This commit is contained in:
parent
b977d61f67
commit
f817018f90
2 changed files with 18 additions and 1 deletions
|
@ -348,6 +348,11 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
|
||||||
let zero = matches.get_flag("zero");
|
let zero = matches.get_flag("zero");
|
||||||
let ignore_missing = matches.get_flag("ignore-missing");
|
let ignore_missing = matches.get_flag("ignore-missing");
|
||||||
|
|
||||||
|
if ignore_missing && !check {
|
||||||
|
// --ignore-missing needs -c
|
||||||
|
return Err(HashsumError::IgnoreNotCheck.into());
|
||||||
|
}
|
||||||
|
|
||||||
let opts = Options {
|
let opts = Options {
|
||||||
algoname: name,
|
algoname: name,
|
||||||
digest: algo,
|
digest: algo,
|
||||||
|
@ -573,6 +578,7 @@ fn uu_app(binary_name: &str) -> Command {
|
||||||
enum HashsumError {
|
enum HashsumError {
|
||||||
InvalidRegex,
|
InvalidRegex,
|
||||||
InvalidFormat,
|
InvalidFormat,
|
||||||
|
IgnoreNotCheck,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for HashsumError {}
|
impl Error for HashsumError {}
|
||||||
|
@ -583,6 +589,10 @@ impl std::fmt::Display for HashsumError {
|
||||||
match self {
|
match self {
|
||||||
Self::InvalidRegex => write!(f, "invalid regular expression"),
|
Self::InvalidRegex => write!(f, "invalid regular expression"),
|
||||||
Self::InvalidFormat => Ok(()),
|
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) {
|
let f = match File::open(ck_filename_unescaped) {
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
if options.ignore_missing {
|
if options.ignore_missing {
|
||||||
// No need to show an error
|
// No need to show or return an error.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,6 +154,13 @@ fn test_check_md5_ignore_missing() {
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_is("testf: OK\n")
|
.stdout_is("testf: OK\n")
|
||||||
.stderr_is("");
|
.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]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue