From 9e080a36840b8bd5f09679b7ead0b969e6d9c8c9 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 20 Apr 2024 21:53:19 +0200 Subject: [PATCH] cksum: handle a corner case --- src/uu/cksum/src/cksum.rs | 16 ++++++++++++---- tests/by-util/test_cksum.rs | 13 ++++++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index b384cd275..4339ff33c 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -377,6 +377,15 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .into()); } + let untagged: bool = matches.get_flag(options::UNTAGGED); + let tag: bool = matches.get_flag(options::TAG); + + let binary = if untagged && tag { + false + } else { + matches.get_flag(options::BINARY) + }; + let (name, algo, bits) = detect_algo(algo_name, length); let output_format = if matches.get_flag(options::RAW) { @@ -392,9 +401,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { digest: algo, output_bits: bits, length, - untagged: matches.get_flag(options::UNTAGGED), + untagged, output_format, - binary: matches.get_flag(options::BINARY), + binary, }; match matches.get_many::(options::FILE) { @@ -442,8 +451,7 @@ pub fn uu_app() -> Command { Arg::new(options::UNTAGGED) .long(options::UNTAGGED) .help("create a reversed style checksum, without digest type") - .action(ArgAction::SetTrue) - .overrides_with(options::TAG), + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::TAG) diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index f25467451..31a3f5274 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -148,7 +148,7 @@ fn test_tag_after_untagged() { .arg("-a=md5") .arg("lorem_ipsum.txt") .succeeds() - .stdout_is_fixture("md5_single_file.expected"); + .stdout_is("cd724690f7dc61775dfac400a71f2caa lorem_ipsum.txt\n"); } #[test] @@ -470,6 +470,17 @@ fn test_binary_file() { .arg(at.subdir.join("f")) .succeeds() .stdout_contains("d41d8cd98f00b204e9800998ecf8427e *"); + + // no "*" in this case + scene + .ucmd() + .arg("--untagged") + .arg("--tag") + .arg("--binary") + .arg("--algorithm=md5") + .arg(at.subdir.join("f")) + .succeeds() + .stdout_contains("d41d8cd98f00b204e9800998ecf8427e "); } #[test]