Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/uu/du/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ du-error-printing-thread-panicked = Printing thread panicked.
du-error-invalid-suffix = invalid suffix in --{ $option } argument { $value }
du-error-invalid-argument = invalid --{ $option } argument { $value }
du-error-argument-too-large = --{ $option } argument { $value } too large
du-error-hyphen-file-name-not-allowed = when reading file names from standard input, no file name of '-' allowed
# Verbose/status messages
du-verbose-ignored = { $path } ignored
Expand Down
1 change: 1 addition & 0 deletions src/uu/du/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ du-error-printing-thread-panicked = Le thread d'affichage a paniqué.
du-error-invalid-suffix = suffixe invalide dans l'argument --{ $option } { $value }
du-error-invalid-argument = argument --{ $option } invalide { $value }
du-error-argument-too-large = argument --{ $option } { $value } trop grand
du-error-hyphen-file-name-not-allowed = le nom de fichier '-' n'est pas autorisé lors de la lecture de l'entrée standard
# Messages verbeux/de statut
du-verbose-ignored = { $path } ignoré
Expand Down
10 changes: 6 additions & 4 deletions src/uu/du/src/du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
//
// spell-checker:ignore fstatat openat dirfd

use clap::{Arg, ArgAction, ArgMatches, Command, builder::PossibleValue};
use glob::Pattern;
use std::collections::HashSet;
use std::env;
use std::ffi::OsStr;
use std::ffi::OsString;
use std::fs::Metadata;
use std::fs::{self, DirEntry, File};
use std::ffi::{OsStr, OsString};
use std::fs::{self, DirEntry, File, Metadata};
use std::io::{BufRead, BufReader, stdout};
#[cfg(not(windows))]
use std::os::unix::fs::MetadataExt;
Expand Down Expand Up @@ -942,6 +941,9 @@ fn read_files_from(file_name: &OsStr) -> Result<Vec<PathBuf>, std::io::Error> {
translate!("du-error-invalid-zero-length-file-name", "file" => file_name.to_string_lossy(), "line" => line_number)
);
set_exit_code(1);
} else if path == b"-" && file_name == "-" {
show_error!("{}", translate!("du-error-hyphen-file-name-not-allowed"));
set_exit_code(1);
} else {
let p = PathBuf::from(&*uucore::os_str_from_bytes(&path).unwrap());
if !paths.contains(&p) {
Expand Down
16 changes: 13 additions & 3 deletions tests/by-util/test_du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@

// spell-checker:ignore (paths) atim sublink subwords azerty azeaze xcwww azeaz amaz azea qzerty tazerty tsublink testfile1 testfile2 filelist fpath testdir testfile
// spell-checker:ignore selfref ELOOP smallfile

#[cfg(not(windows))]
use regex::Regex;

use uutests::at_and_ucmd;
use uutests::new_ucmd;
#[cfg(not(target_os = "windows"))]
use uutests::unwrap_or_return;
use uutests::util::TestScenario;
#[cfg(not(target_os = "windows"))]
use uutests::util::expected_result;
use uutests::util_name;
use uutests::{at_and_ucmd, new_ucmd, util_name};

#[cfg(not(target_os = "openbsd"))]
const SUB_DIR: &str = "subdir/deeper";
Expand Down Expand Up @@ -1392,6 +1391,17 @@ fn test_du_files0_from_stdin_with_invalid_zero_length_file_names() {
.stderr_contains("-:2: invalid zero-length file name");
}

#[test]
fn test_du_files0_from_stdin_with_stdin_as_input() {
new_ucmd!()
.arg("--files0-from=-")
.pipe_in("-")
.fails_with_code(1)
.stderr_is(
"du: when reading file names from standard input, no file name of '-' allowed\n",
);
}

#[test]
fn test_du_files0_from_dir() {
let ts = TestScenario::new(util_name!());
Expand Down
1 change: 0 additions & 1 deletion util/build-gnu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ sed -i -e "s/du: invalid -t argument/du: invalid --threshold argument/" -e "s/du

# Remove the extra output check
sed -i -e "s|Try '\$prog --help' for more information.\\\n||" tests/du/files0-from.pl
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
sed -i -e "s|-: No such file or directory|cannot access '-': No such file or directory|g" tests/du/files0-from.pl

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