Skip to content

Commit 6d6a991

Browse files
committed
checksum: fix binary flag on windows, ignore test
1 parent c97ce1b commit 6d6a991

5 files changed

Lines changed: 20 additions & 12 deletions

File tree

src/uu/cksum/src/cksum.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
185185
algo_kind: algo,
186186
output_format,
187187
line_ending,
188+
binary: false,
188189
no_names: false,
189190
};
190191

src/uu/hashsum/src/hashsum.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
229229
/* base64: */ false,
230230
),
231231
line_ending,
232+
binary,
232233
no_names,
233234
};
234235

src/uucore/src/lib/features/checksum/compute.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ pub struct ChecksumComputeOptions {
2929
/// Whether to finish lines with '\n' or '\0'.
3030
pub line_ending: LineEnding,
3131

32+
/// On windows, open files as binary instead of text
33+
pub binary: bool,
34+
3235
/// (non-GNU option) Do not print file names
3336
pub no_names: bool,
3437
}
@@ -284,7 +287,7 @@ where
284287
let (sum_hex, sz) = digest_reader(
285288
&mut digest,
286289
&mut file,
287-
false,
290+
options.binary,
288291
options.algo_kind.bitlen(),
289292
)
290293
.map_err_context(|| translate!("cksum-error-failed-to-read-input"))?;

src/uucore/src/lib/features/checksum/validate.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,16 @@ fn compute_and_check_digest_from_file(
644644

645645
// Read the file and calculate the checksum
646646
let mut digest = algo.create_digest();
647-
let (calculated_checksum, _) =
648-
digest_reader(&mut digest, &mut file_reader, false, algo.bitlen()).unwrap();
647+
648+
// TODO: improve function signature to use ReadingMode instead of binary bool
649+
// Set binary to false because --binary is not supported with --check
650+
let (calculated_checksum, _) = digest_reader(
651+
&mut digest,
652+
&mut file_reader,
653+
/* binary */ false,
654+
algo.bitlen(),
655+
)
656+
.unwrap();
649657

650658
// Do the checksum validation
651659
let checksum_correct = expected_checksum == calculated_checksum;

tests/by-util/test_hashsum.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,12 @@ macro_rules! test_digest {
107107
at.write("a", "file1\n");
108108
at.write("c", "file3\n");
109109

110-
#[cfg(unix)]
111-
let file_not_found_str = "No such file or directory";
112-
#[cfg(not(unix))]
113-
let file_not_found_str = "The system cannot find the file specified";
114-
115110
ts.ucmd()
116111
.args(&[DIGEST_ARG, BITS_ARG, "a", "b", "c"])
117112
.fails()
118113
.stdout_contains("a\n")
119114
.stdout_contains("c\n")
120-
.stderr_contains(format!("b: {file_not_found_str}"));
115+
.stderr_contains("b: No such file or directory");
121116
}
122117
}
123118
)*)
@@ -1097,11 +1092,11 @@ fn test_sha256_stdin_binary() {
10971092
);
10981093
}
10991094

1095+
// This test is currently disabled on windows
11001096
#[test]
1097+
#[cfg_attr(windows, ignore = "Discussion is in #9168")]
11011098
fn test_check_sha256_binary() {
1102-
let ts = TestScenario::new(util_name!());
1103-
1104-
ts.ucmd()
1099+
new_ucmd!()
11051100
.args(&[
11061101
"--sha256",
11071102
"--bits=256",

0 commit comments

Comments
 (0)