summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYang Hau <yuanyanghau@gmail.com>2024-07-19 03:30:17 +0800
committerYang Hau <yuanyanghau@gmail.com>2024-07-19 16:05:30 +0800
commite5d765f46cd8c1f56a7863ccf8ffa061f43d73df (patch)
tree751df8b3f915cf02e2dc0376338f7f667b4129b0
parent5882304dcdbdc22fe2b687a7f5478eb023e6b7ec (diff)
hashsum: Return err when only --strict or --quiet is given
-rw-r--r--src/uu/hashsum/src/hashsum.rs6
-rw-r--r--src/uucore/src/lib/features/checksum.rs4
-rw-r--r--tests/by-util/test_hashsum.rs13
3 files changed, 22 insertions, 1 deletions
diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs
index a1e1f0781..f37f8445c 100644
--- a/src/uu/hashsum/src/hashsum.rs
+++ b/src/uu/hashsum/src/hashsum.rs
@@ -209,6 +209,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
let check = matches.get_flag("check");
let status = matches.get_flag("status");
let quiet = matches.get_flag("quiet") || status;
+ let strict = matches.get_flag("strict");
let warn = matches.get_flag("warn") && !status;
let ignore_missing = matches.get_flag("ignore-missing");
@@ -220,7 +221,6 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
if check {
let text_flag = matches.get_flag("text");
let binary_flag = matches.get_flag("binary");
- let strict = matches.get_flag("strict");
if binary_flag || text_flag {
return Err(ChecksumError::BinaryTextConflict.into());
@@ -245,6 +245,10 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
Some(algo.name),
Some(algo.bits),
);
+ } else if quiet {
+ return Err(ChecksumError::QuietNotCheck.into());
+ } else if strict {
+ return Err(ChecksumError::StrictNotCheck.into());
}
let nonames = *matches
diff --git a/src/uucore/src/lib/features/checksum.rs b/src/uucore/src/lib/features/checksum.rs
index c62e268c8..c5366e181 100644
--- a/src/uucore/src/lib/features/checksum.rs
+++ b/src/uucore/src/lib/features/checksum.rs
@@ -81,6 +81,10 @@ pub enum ChecksumError {
RawMultipleFiles,
#[error("the --ignore-missing option is meaningful only when verifying checksums")]
IgnoreNotCheck,
+ #[error("the --strict option is meaningful only when verifying checksums")]
+ StrictNotCheck,
+ #[error("the --quiet option is meaningful only when verifying checksums")]
+ QuietNotCheck,
#[error("Invalid output size for SHA3 (expected 224, 256, 384, or 512)")]
InvalidOutputSizeForSha3,
#[error("--bits required for SHA3")]
diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs
index f91752e25..bdd39b823 100644
--- a/tests/by-util/test_hashsum.rs
+++ b/tests/by-util/test_hashsum.rs
@@ -874,6 +874,19 @@ fn test_check_quiet() {
.fails()
.stdout_contains("f: FAILED")
.stderr_contains("WARNING: 1 computed checksum did NOT match");
+
+ scene
+ .ccmd("md5sum")
+ .arg("--quiet")
+ .arg(at.subdir.join("in.md5"))
+ .fails()
+ .stderr_contains("md5sum: the --quiet option is meaningful only when verifying checksums");
+ scene
+ .ccmd("md5sum")
+ .arg("--strict")
+ .arg(at.subdir.join("in.md5"))
+ .fails()
+ .stderr_contains("md5sum: the --strict option is meaningful only when verifying checksums");
}
#[test]