Skip to content

Commit

Permalink
cksum: handle a corner case
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Apr 21, 2024
1 parent 88d8e37 commit 6198173
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/uu/cksum/src/cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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::<String>(options::FILE) {
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion tests/by-util/test_cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 6198173

Please sign in to comment.