Skip to content

Commit c65cbe7

Browse files
authored
Merge branch 'main' into patch-4
2 parents 23da9cc + a738fba commit c65cbe7

File tree

13 files changed

+277
-122
lines changed

13 files changed

+277
-122
lines changed

.github/workflows/GnuTests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
path: |
6060
gnu/config.cache
6161
gnu/src/getlimits
62-
key: ${{ runner.os }}-gnu-config-${{ hashFiles('gnu/NEWS') }}-${{ hashFiles('gnu/configure') }}
62+
key: ${{ runner.os }}-gnu-config-${{ hashFiles('gnu/NEWS') }}-${{ hashFiles('uutils/util/build-gnu.sh') }} # use build-gnu.sh for extremely safe caching
6363

6464
#### Build environment setup
6565
- name: Install dependencies
@@ -111,7 +111,7 @@ jobs:
111111
path: |
112112
gnu/config.cache
113113
gnu/src/getlimits
114-
key: ${{ runner.os }}-gnu-config-${{ hashFiles('gnu/NEWS') }}-${{ hashFiles('gnu/configure') }}
114+
key: ${{ runner.os }}-gnu-config-${{ hashFiles('gnu/NEWS') }}-${{ hashFiles('uutils/util/build-gnu.sh') }}
115115

116116
### Run tests as user
117117
- name: Run GNU tests

src/uu/cat/locales/en-US.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ cat-error-unknown-filetype = unknown filetype: { $ft_debug }
1919
cat-error-is-directory = Is a directory
2020
cat-error-input-file-is-output-file = input file is output file
2121
cat-error-too-many-symbolic-links = Too many levels of symbolic links
22+
cat-error-no-such-device-or-address = No such device or address

src/uu/cat/locales/fr-FR.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ cat-error-unknown-filetype = type de fichier inconnu : { $ft_debug }
1919
cat-error-is-directory = Est un répertoire
2020
cat-error-input-file-is-output-file = le fichier d'entrée est le fichier de sortie
2121
cat-error-too-many-symbolic-links = Trop de niveaux de liens symboliques
22+
cat-error-no-such-device-or-address = Aucun appareil ou adresse de ce type

src/uu/cat/src/cat.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,10 @@ use memchr::memchr2;
1313
use std::ffi::OsString;
1414
use std::fs::{File, metadata};
1515
use std::io::{self, BufWriter, ErrorKind, IsTerminal, Read, Write};
16-
/// Unix domain socket support
17-
#[cfg(unix)]
18-
use std::net::Shutdown;
1916
#[cfg(unix)]
2017
use std::os::fd::AsFd;
2118
#[cfg(unix)]
2219
use std::os::unix::fs::FileTypeExt;
23-
#[cfg(unix)]
24-
use std::os::unix::net::UnixStream;
2520
use thiserror::Error;
2621
use uucore::display::Quotable;
2722
use uucore::error::UResult;
@@ -103,6 +98,9 @@ enum CatError {
10398
},
10499
#[error("{}", translate!("cat-error-is-directory"))]
105100
IsDirectory,
101+
#[cfg(unix)]
102+
#[error("{}", translate!("cat-error-no-such-device-or-address"))]
103+
NoSuchDeviceOrAddress,
106104
#[error("{}", translate!("cat-error-input-file-is-output-file"))]
107105
OutputIsInput,
108106
#[error("{}", translate!("cat-error-too-many-symbolic-links"))]
@@ -395,15 +393,7 @@ fn cat_path(path: &OsString, options: &OutputOptions, state: &mut OutputState) -
395393
}
396394
InputType::Directory => Err(CatError::IsDirectory),
397395
#[cfg(unix)]
398-
InputType::Socket => {
399-
let socket = UnixStream::connect(path)?;
400-
socket.shutdown(Shutdown::Write)?;
401-
let mut handle = InputHandle {
402-
reader: socket,
403-
is_interactive: false,
404-
};
405-
cat_handle(&mut handle, options, state)
406-
}
396+
InputType::Socket => Err(CatError::NoSuchDeviceOrAddress),
407397
_ => {
408398
let file = File::open(path)?;
409399
if is_unsafe_overwrite(&file, &io::stdout()) {

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/uu/head/src/parse.rs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
// file that was distributed with this source code.
55

66
use std::ffi::OsString;
7-
use uucore::parser::parse_size::{ParseSizeError, parse_size_u64_max};
7+
use uucore::parser::parse_signed_num::{SignPrefix, parse_signed_num_max};
8+
use uucore::parser::parse_size::ParseSizeError;
89

910
#[derive(PartialEq, Eq, Debug)]
1011
pub struct ParseError;
@@ -107,30 +108,12 @@ fn process_num_block(
107108
}
108109

109110
/// Parses an -c or -n argument,
110-
/// the bool specifies whether to read from the end
111+
/// the bool specifies whether to read from the end (all but last N)
111112
pub fn parse_num(src: &str) -> Result<(u64, bool), ParseSizeError> {
112-
let mut size_string = src.trim();
113-
let mut all_but_last = false;
114-
115-
if let Some(c) = size_string.chars().next() {
116-
if c == '+' || c == '-' {
117-
// head: '+' is not documented (8.32 man pages)
118-
size_string = &size_string[1..];
119-
if c == '-' {
120-
all_but_last = true;
121-
}
122-
}
123-
} else {
124-
return Err(ParseSizeError::ParseFailure(src.to_string()));
125-
}
126-
127-
// remove leading zeros so that size is interpreted as decimal, not octal
128-
let trimmed_string = size_string.trim_start_matches('0');
129-
if trimmed_string.is_empty() {
130-
Ok((0, all_but_last))
131-
} else {
132-
parse_size_u64_max(trimmed_string).map(|n| (n, all_but_last))
133-
}
113+
let result = parse_signed_num_max(src)?;
114+
// head: '-' means "all but last N"
115+
let all_but_last = result.sign == Some(SignPrefix::Minus);
116+
Ok((result.value, all_but_last))
134117
}
135118

136119
#[cfg(test)]

src/uu/tail/src/args.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use std::ffi::OsString;
1313
use std::io::IsTerminal;
1414
use std::time::Duration;
1515
use uucore::error::{UResult, USimpleError, UUsageError};
16-
use uucore::parser::parse_size::{ParseSizeError, parse_size_u64};
16+
use uucore::parser::parse_signed_num::{SignPrefix, parse_signed_num};
17+
use uucore::parser::parse_size::ParseSizeError;
1718
use uucore::parser::parse_time;
1819
use uucore::parser::shortcut_value_parser::ShortcutValueParser;
1920
use uucore::translate;
@@ -386,27 +387,15 @@ pub fn parse_obsolete(arg: &OsString, input: Option<&OsString>) -> UResult<Optio
386387
}
387388

388389
fn parse_num(src: &str) -> Result<Signum, ParseSizeError> {
389-
let mut size_string = src.trim();
390-
let mut starting_with = false;
391-
392-
if let Some(c) = size_string.chars().next() {
393-
if c == '+' || c == '-' {
394-
// tail: '-' is not documented (8.32 man pages)
395-
size_string = &size_string[1..];
396-
if c == '+' {
397-
starting_with = true;
398-
}
399-
}
400-
}
401-
402-
match parse_size_u64(size_string) {
403-
Ok(n) => match (n, starting_with) {
404-
(0, true) => Ok(Signum::PlusZero),
405-
(0, false) => Ok(Signum::MinusZero),
406-
(n, true) => Ok(Signum::Positive(n)),
407-
(n, false) => Ok(Signum::Negative(n)),
408-
},
409-
Err(_) => Err(ParseSizeError::ParseFailure(size_string.to_string())),
390+
let result = parse_signed_num(src)?;
391+
// tail: '+' means "starting from line/byte N", default/'-' means "last N"
392+
let is_plus = result.sign == Some(SignPrefix::Plus);
393+
394+
match (result.value, is_plus) {
395+
(0, true) => Ok(Signum::PlusZero),
396+
(0, false) => Ok(Signum::MinusZero),
397+
(n, true) => Ok(Signum::Positive(n)),
398+
(n, false) => Ok(Signum::Negative(n)),
410399
}
411400
}
412401

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.

src/uucore/src/lib/features/parser/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub mod num_parser;
99
#[cfg(any(feature = "parser", feature = "parser-glob"))]
1010
pub mod parse_glob;
1111
#[cfg(any(feature = "parser", feature = "parser-size"))]
12+
pub mod parse_signed_num;
13+
#[cfg(any(feature = "parser", feature = "parser-size"))]
1214
pub mod parse_size;
1315
#[cfg(any(feature = "parser", feature = "parser-num"))]
1416
pub mod parse_time;

0 commit comments

Comments
 (0)