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:
commit
78405e6a30
2 changed files with 36 additions and 1 deletions
|
@ -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");
|
||||
set_exit_code(1);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1010,6 +1010,21 @@ fn test_du_files0_from() {
|
|||
.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]
|
||||
fn test_du_files0_from_with_invalid_zero_length_file_names() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
|
@ -1046,6 +1061,23 @@ fn test_du_files0_from_stdin() {
|
|||
.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]
|
||||
fn test_du_files0_from_stdin_with_invalid_zero_length_file_names() {
|
||||
new_ucmd!()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue