Skip to content

Commit 79f09a6

Browse files
authored
Merge pull request #9695 from RenjiSann/checksum-ignore-binary
Checksum ignore binary
2 parents 7c7f1fc + 34c41df commit 79f09a6

File tree

4 files changed

+14
-33
lines changed

4 files changed

+14
-33
lines changed

src/uu/cksum/src/cksum.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
216216
algo_kind: algo,
217217
output_format,
218218
line_ending,
219-
binary: false,
220219
no_names: false,
221220
};
222221

src/uu/hashsum/src/hashsum.rs

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

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ use crate::{show, translate};
2020
/// from it: 32 KiB.
2121
const READ_BUFFER_SIZE: usize = 32 * 1024;
2222

23+
/// Necessary options when computing a checksum. Historically, these options
24+
/// included a `binary` field to differentiate `--binary` and `--text` modes on
25+
/// windows. Since the support for this feature is approximate in GNU, and it's
26+
/// deprecated anyway, it was decided in #9168 to ignore the difference when
27+
/// computing the checksum.
2328
pub struct ChecksumComputeOptions {
2429
/// Which algorithm to use to compute the digest.
2530
pub algo_kind: SizedAlgoKind,
@@ -30,9 +35,6 @@ pub struct ChecksumComputeOptions {
3035
/// Whether to finish lines with '\n' or '\0'.
3136
pub line_ending: LineEnding,
3237

33-
/// On windows, open files as binary instead of text
34-
pub binary: bool,
35-
3638
/// (non-GNU option) Do not print file names
3739
pub no_names: bool,
3840
}
@@ -42,6 +44,12 @@ pub struct ChecksumComputeOptions {
4244
/// On most linux systems, this is irrelevant, as there is no distinction
4345
/// between text and binary files. Refer to GNU's cksum documentation for more
4446
/// information.
47+
///
48+
/// As discussed in #9168, we decide to ignore the reading mode to compute the
49+
/// digest, both on Windows and UNIX. The reason for that is that this is a
50+
/// legacy feature that is poorly documented and used. This enum is kept
51+
/// nonetheless to still take into account the flags passed to cksum when
52+
/// generating untagged lines.
4553
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4654
pub enum ReadingMode {
4755
Binary,
@@ -280,7 +288,9 @@ where
280288

281289
let mut digest = options.algo_kind.create_digest();
282290

283-
let (digest_output, sz) = digest_reader(&mut digest, &mut file, options.binary)
291+
// Always compute the "binary" version of the digest, i.e. on Windows,
292+
// never handle CRLFs specifically.
293+
let (digest_output, sz) = digest_reader(&mut digest, &mut file, /* binary: */ true)
284294
.map_err_context(|| translate!("checksum-error-failed-to-read-input"))?;
285295

286296
// Encodes the sum if df is Base64, leaves as-is otherwise.

tests/by-util/test_hashsum.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,33 +74,6 @@ macro_rules! test_digest {
7474
get_hash!(ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).arg("--zero").arg(INPUT_FILE).succeeds().no_stderr().stdout_str()));
7575
}
7676

77-
78-
#[cfg(windows)]
79-
#[test]
80-
fn test_text_mode() {
81-
use uutests::new_ucmd;
82-
83-
// TODO Replace this with hard-coded files that store the
84-
// expected output of text mode on an input file that has
85-
// "\r\n" line endings.
86-
let result = new_ucmd!()
87-
.args(&[DIGEST_ARG, BITS_ARG, "-b"])
88-
.pipe_in("a\nb\nc\n")
89-
.succeeds();
90-
let expected = result.no_stderr().stdout();
91-
// Replace the "*-\n" at the end of the output with " -\n".
92-
// The asterisk indicates that the digest was computed in
93-
// binary mode.
94-
let n = expected.len();
95-
let expected = [&expected[..n - 3], b" -\n"].concat();
96-
new_ucmd!()
97-
.args(&[DIGEST_ARG, BITS_ARG, "-t"])
98-
.pipe_in("a\r\nb\r\nc\r\n")
99-
.succeeds()
100-
.no_stderr()
101-
.stdout_is(std::str::from_utf8(&expected).unwrap());
102-
}
103-
10477
#[test]
10578
fn test_missing_file() {
10679
let ts = TestScenario::new(util_name!());

0 commit comments

Comments
 (0)