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

du: fix the count with --inodes

This commit is contained in:
Sylvestre Ledru 2024-11-20 07:46:12 -05:00
parent fb1874bff9
commit 76d14ed484
2 changed files with 36 additions and 2 deletions

View file

@ -346,14 +346,21 @@ fn du(
}
if let Some(inode) = this_stat.inode {
if seen_inodes.contains(&inode) {
if options.count_links {
// Check if the inode has been seen before and if we should skip it
if seen_inodes.contains(&inode)
&& (!options.count_links || !options.all)
{
// If `count_links` is enabled and `all` is not, increment the inode count
if options.count_links && !options.all {
my_stat.inodes += 1;
}
// Skip further processing for this inode
continue;
}
// Mark this inode as seen
seen_inodes.insert(inode);
}
if this_stat.is_dir {
if options.one_file_system {
if let (Some(this_inode), Some(my_inode)) =

View file

@ -546,6 +546,33 @@ fn test_du_inodes_with_count_links() {
}
}
#[cfg(not(target_os = "android"))]
#[test]
fn test_du_inodes_with_count_links_all() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.mkdir("d");
at.mkdir("d/d");
at.touch("d/f");
at.hard_link("d/f", "d/h");
let result = ts.ucmd().arg("--inodes").arg("-al").arg("d").succeeds();
result.no_stderr();
let mut result_seq: Vec<String> = result
.stdout_str()
.split('\n')
.filter(|x| !x.is_empty())
.map(|x| x.parse().unwrap())
.collect();
result_seq.sort_unstable();
#[cfg(windows)]
assert_eq!(result_seq, ["1\td\\d", "1\td\\f", "1\td\\h", "4\td"]);
#[cfg(not(windows))]
assert_eq!(result_seq, ["1\td/d", "1\td/f", "1\td/h", "4\td"]);
}
#[test]
fn test_du_h_flag_empty_file() {
new_ucmd!()