diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 7ff0243eb..499fc52c0 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -185,6 +185,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { algo_kind: algo, output_format, line_ending, + binary: false, no_names: false, }; diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index ebe3ac033..d6258210f 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -229,6 +229,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> { /* base64: */ false, ), line_ending, + binary, no_names, }; diff --git a/src/uucore/src/lib/features/checksum/compute.rs b/src/uucore/src/lib/features/checksum/compute.rs index 426b2633e..e91c54166 100644 --- a/src/uucore/src/lib/features/checksum/compute.rs +++ b/src/uucore/src/lib/features/checksum/compute.rs @@ -29,6 +29,9 @@ pub struct ChecksumComputeOptions { /// Whether to finish lines with '\n' or '\0'. pub line_ending: LineEnding, + /// On windows, open files as binary instead of text + pub binary: bool, + /// (non-GNU option) Do not print file names pub no_names: bool, } @@ -284,7 +287,7 @@ where let (sum_hex, sz) = digest_reader( &mut digest, &mut file, - false, + options.binary, options.algo_kind.bitlen(), ) .map_err_context(|| translate!("cksum-error-failed-to-read-input"))?; diff --git a/src/uucore/src/lib/features/checksum/validate.rs b/src/uucore/src/lib/features/checksum/validate.rs index a1d851a05..b68032925 100644 --- a/src/uucore/src/lib/features/checksum/validate.rs +++ b/src/uucore/src/lib/features/checksum/validate.rs @@ -644,8 +644,16 @@ fn compute_and_check_digest_from_file( // Read the file and calculate the checksum let mut digest = algo.create_digest(); - let (calculated_checksum, _) = - digest_reader(&mut digest, &mut file_reader, false, algo.bitlen()).unwrap(); + + // TODO: improve function signature to use ReadingMode instead of binary bool + // Set binary to false because --binary is not supported with --check + let (calculated_checksum, _) = digest_reader( + &mut digest, + &mut file_reader, + /* binary */ false, + algo.bitlen(), + ) + .unwrap(); // Do the checksum validation let checksum_correct = expected_checksum == calculated_checksum; diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index b2eb96879..beaf994e1 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -107,17 +107,12 @@ macro_rules! test_digest { at.write("a", "file1\n"); at.write("c", "file3\n"); - #[cfg(unix)] - let file_not_found_str = "No such file or directory"; - #[cfg(not(unix))] - let file_not_found_str = "The system cannot find the file specified"; - ts.ucmd() .args(&[DIGEST_ARG, BITS_ARG, "a", "b", "c"]) .fails() .stdout_contains("a\n") .stdout_contains("c\n") - .stderr_contains(format!("b: {file_not_found_str}")); + .stderr_contains("b: No such file or directory"); } } )*) @@ -1097,11 +1092,11 @@ fn test_sha256_stdin_binary() { ); } +// This test is currently disabled on windows #[test] +#[cfg_attr(windows, ignore = "Discussion is in #9168")] fn test_check_sha256_binary() { - let ts = TestScenario::new(util_name!()); - - ts.ucmd() + new_ucmd!() .args(&[ "--sha256", "--bits=256",