1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

du: an error code when done on a non existing file

This commit is contained in:
Sylvestre Ledru 2023-04-09 21:10:31 +02:00
parent dd3c0f7fe9
commit 5a1d9cec7e
2 changed files with 26 additions and 2 deletions

View file

@ -33,7 +33,7 @@ use std::time::{Duration, UNIX_EPOCH};
use std::{error::Error, fmt::Display}; use std::{error::Error, fmt::Display};
use uucore::display::{print_verbatim, Quotable}; use uucore::display::{print_verbatim, Quotable};
use uucore::error::FromIo; use uucore::error::FromIo;
use uucore::error::{UError, UResult}; use uucore::error::{set_exit_code, UError, UResult};
use uucore::parse_glob; use uucore::parse_glob;
use uucore::parse_size::{parse_size, ParseSizeError}; use uucore::parse_size::{parse_size, ParseSizeError};
use uucore::{ use uucore::{
@ -655,6 +655,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
path_string.maybe_quote(), path_string.maybe_quote(),
"No such file or directory" "No such file or directory"
); );
set_exit_code(1);
} }
} }

View file

@ -6,7 +6,6 @@
// spell-checker:ignore (paths) sublink subwords azerty azeaze xcwww azeaz amaz azea qzerty tazerty // spell-checker:ignore (paths) sublink subwords azerty azeaze xcwww azeaz amaz azea qzerty tazerty
#[cfg(not(windows))] #[cfg(not(windows))]
use regex::Regex; use regex::Regex;
#[cfg(not(windows))]
use std::io::Write; use std::io::Write;
#[cfg(any(target_os = "linux", target_os = "android"))] #[cfg(any(target_os = "linux", target_os = "android"))]
@ -851,3 +850,27 @@ fn test_du_exclude_invalid_syntax() {
.fails() .fails()
.stderr_contains("du: Invalid exclude syntax"); .stderr_contains("du: Invalid exclude syntax");
} }
#[test]
fn test_du_symlink_fail() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.symlink_file("non-existing.txt", "target.txt");
ts.ucmd().arg("-L").arg("target.txt").fails().code_is(1);
}
#[test]
fn test_du_symlink_multiple_fail() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.symlink_file("non-existing.txt", "target.txt");
let mut file1 = at.make_file("file1");
file1.write_all(b"azeaze").unwrap();
let result = ts.ucmd().arg("-L").arg("target.txt").arg("file1").fails();
assert_eq!(result.code(), 1);
result.stdout_contains("4\tfile1\n");
}