Skip to content

Commit 5b261bc

Browse files
cakebakersylvestre
andauthored
du: handle --files0-from=- with piped in - (#8985)
* du: handle --files0-from=- with piped in '-' * build-gnu.sh: remove incorrect string replacement in tests/du/files0-from.pl --------- Co-authored-by: Sylvestre Ledru <[email protected]>
1 parent 443c201 commit 5b261bc

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ du-error-printing-thread-panicked = Printing thread panicked.
6969
du-error-invalid-suffix = invalid suffix in --{ $option } argument { $value }
7070
du-error-invalid-argument = invalid --{ $option } argument { $value }
7171
du-error-argument-too-large = --{ $option } argument { $value } too large
72+
du-error-hyphen-file-name-not-allowed = when reading file names from standard input, no file name of '-' allowed
7273
7374
# Verbose/status messages
7475
du-verbose-ignored = { $path } ignored

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ du-error-printing-thread-panicked = Le thread d'affichage a paniqué.
6969
du-error-invalid-suffix = suffixe invalide dans l'argument --{ $option } { $value }
7070
du-error-invalid-argument = argument --{ $option } invalide { $value }
7171
du-error-argument-too-large = argument --{ $option } { $value } trop grand
72+
du-error-hyphen-file-name-not-allowed = le nom de fichier '-' n'est pas autorisé lors de la lecture de l'entrée standard
7273
7374
# Messages verbeux/de statut
7475
du-verbose-ignored = { $path } ignoré

src/uu/du/src/du.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
//
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
5+
//
56
// spell-checker:ignore fstatat openat dirfd
67

78
use clap::{Arg, ArgAction, ArgMatches, Command, builder::PossibleValue};
89
use glob::Pattern;
910
use std::collections::HashSet;
1011
use std::env;
11-
use std::ffi::OsStr;
12-
use std::ffi::OsString;
13-
use std::fs::Metadata;
14-
use std::fs::{self, DirEntry, File};
12+
use std::ffi::{OsStr, OsString};
13+
use std::fs::{self, DirEntry, File, Metadata};
1514
use std::io::{BufRead, BufReader, stdout};
1615
#[cfg(not(windows))]
1716
use std::os::unix::fs::MetadataExt;
@@ -942,6 +941,9 @@ fn read_files_from(file_name: &OsStr) -> Result<Vec<PathBuf>, std::io::Error> {
942941
translate!("du-error-invalid-zero-length-file-name", "file" => file_name.to_string_lossy(), "line" => line_number)
943942
);
944943
set_exit_code(1);
944+
} else if path == b"-" && file_name == "-" {
945+
show_error!("{}", translate!("du-error-hyphen-file-name-not-allowed"));
946+
set_exit_code(1);
945947
} else {
946948
let p = PathBuf::from(&*uucore::os_str_from_bytes(&path).unwrap());
947949
if !paths.contains(&p) {

tests/by-util/test_du.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55

66
// spell-checker:ignore (paths) atim sublink subwords azerty azeaze xcwww azeaz amaz azea qzerty tazerty tsublink testfile1 testfile2 filelist fpath testdir testfile
77
// spell-checker:ignore selfref ELOOP smallfile
8+
89
#[cfg(not(windows))]
910
use regex::Regex;
1011

11-
use uutests::at_and_ucmd;
12-
use uutests::new_ucmd;
1312
#[cfg(not(target_os = "windows"))]
1413
use uutests::unwrap_or_return;
1514
use uutests::util::TestScenario;
1615
#[cfg(not(target_os = "windows"))]
1716
use uutests::util::expected_result;
18-
use uutests::util_name;
17+
use uutests::{at_and_ucmd, new_ucmd, util_name};
1918

2019
#[cfg(not(target_os = "openbsd"))]
2120
const SUB_DIR: &str = "subdir/deeper";
@@ -1399,6 +1398,17 @@ fn test_du_files0_from_stdin_with_invalid_zero_length_file_names() {
13991398
.stderr_contains("-:2: invalid zero-length file name");
14001399
}
14011400

1401+
#[test]
1402+
fn test_du_files0_from_stdin_with_stdin_as_input() {
1403+
new_ucmd!()
1404+
.arg("--files0-from=-")
1405+
.pipe_in("-")
1406+
.fails_with_code(1)
1407+
.stderr_is(
1408+
"du: when reading file names from standard input, no file name of '-' allowed\n",
1409+
);
1410+
}
1411+
14021412
#[test]
14031413
fn test_du_files0_from_dir() {
14041414
let ts = TestScenario::new(util_name!());

util/build-gnu.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ test -f "${UU_BUILD_DIR}/getlimits" || cp src/getlimits "${UU_BUILD_DIR}"
285285

286286
# Remove the extra output check
287287
"${SED}" -i -e "s|Try '\$prog --help' for more information.\\\n||" tests/du/files0-from.pl
288-
"${SED}" -i -e "s|when reading file names from stdin, no file name of\"|-: No such file or directory\n\"|" -e "s| '-' allowed\\\n||" tests/du/files0-from.pl
289288
"${SED}" -i -e "s|-: No such file or directory|cannot access '-': No such file or directory|g" tests/du/files0-from.pl
290289

291290
# Skip the move-dir-while-traversing test - our implementation uses safe traversal with openat()

0 commit comments

Comments
 (0)