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
6 changes: 3 additions & 3 deletions src/uu/du/src/du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let (print_tx, rx) = mpsc::channel::<UResult<StatPrintInfo>>();
let printing_thread = thread::spawn(move || stat_printer.print_stats(&rx));

// Track seen inodes across all arguments to avoid double-counting hard links
let mut seen_inodes: HashSet<FileInfo> = HashSet::new();

'loop_file: for path in files {
// Skip if we don't want to ignore anything
if !&traversal_options.excludes.is_empty() {
Expand All @@ -1098,9 +1101,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
}

// Check existence of path provided in argument
let mut seen_inodes: HashSet<FileInfo> = HashSet::new();

// Determine which traversal method to use
#[cfg(all(unix, not(target_os = "redox")))]
let use_safe_traversal = traversal_options.dereference != Deref::All;
Expand Down
16 changes: 16 additions & 0 deletions tests/by-util/test_du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,22 @@ fn du_hard_link(s: &str) {
}
}

#[cfg(all(unix, not(target_os = "android")))]
#[test]
fn test_du_hard_link_multiple_args() {
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("dir1");
at.mkdir("dir2");
at.write("dir1/file", &"x".repeat(10000));
at.hard_link("dir1/file", "dir2/file");

let result = ucmd.args(&["-b", "dir1", "dir2"]).succeeds();
let lines: Vec<&str> = result.stdout_str().lines().collect();
let size = |i: usize| lines[i].split('\t').next().unwrap().parse::<u64>().unwrap();
assert!(size(0) >= 10000);
assert!(size(1) < 1000);
}

#[test]
#[cfg(not(target_os = "openbsd"))]
fn test_du_d_flag() {
Expand Down
Loading