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

Merge pull request #5775 from cakebaker/du_ignore_duplicate_files_files0_from

du: ignore duplicate names with `--files0-from`
This commit is contained in:
Sylvestre Ledru 2024-01-03 16:49:40 +01:00 committed by GitHub
commit 78405e6a30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View file

@ -629,7 +629,10 @@ fn read_files_from(file_name: &str) -> Result<Vec<PathBuf>, std::io::Error> {
show_error!("{file_name}:{line_number}: invalid zero-length file name"); show_error!("{file_name}:{line_number}: invalid zero-length file name");
set_exit_code(1); set_exit_code(1);
} else { } else {
paths.push(PathBuf::from(String::from_utf8_lossy(&path).to_string())); let p = PathBuf::from(String::from_utf8_lossy(&path).to_string());
if !paths.contains(&p) {
paths.push(p);
}
} }
} }

View file

@ -1010,6 +1010,21 @@ fn test_du_files0_from() {
.stdout_contains("testdir"); .stdout_contains("testdir");
} }
#[test]
fn test_du_files0_from_ignore_duplicate_file_names() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
let file = "testfile";
at.touch(file);
at.write("filelist", &format!("{file}\0{file}\0"));
ts.ucmd()
.arg("--files0-from=filelist")
.succeeds()
.stdout_is(format!("0\t{file}\n"));
}
#[test] #[test]
fn test_du_files0_from_with_invalid_zero_length_file_names() { fn test_du_files0_from_with_invalid_zero_length_file_names() {
let ts = TestScenario::new(util_name!()); let ts = TestScenario::new(util_name!());
@ -1046,6 +1061,23 @@ fn test_du_files0_from_stdin() {
.stdout_contains("testfile2"); .stdout_contains("testfile2");
} }
#[test]
fn test_du_files0_from_stdin_ignore_duplicate_file_names() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
let file = "testfile";
at.touch(file);
let input = format!("{file}\0{file}");
ts.ucmd()
.arg("--files0-from=-")
.pipe_in(input)
.succeeds()
.stdout_is(format!("0\t{file}\n"));
}
#[test] #[test]
fn test_du_files0_from_stdin_with_invalid_zero_length_file_names() { fn test_du_files0_from_stdin_with_invalid_zero_length_file_names() {
new_ucmd!() new_ucmd!()