mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
checksum: fix binary flag on windows, ignore test
This commit is contained in:
@@ -185,6 +185,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
algo_kind: algo,
|
||||
output_format,
|
||||
line_ending,
|
||||
binary: false,
|
||||
no_names: false,
|
||||
};
|
||||
|
||||
|
||||
@@ -229,6 +229,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
|
||||
/* base64: */ false,
|
||||
),
|
||||
line_ending,
|
||||
binary,
|
||||
no_names,
|
||||
};
|
||||
|
||||
|
||||
@@ -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"))?;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user