mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
du: make -l/--count-links work
This commit is contained in:
parent
6fa8a6d200
commit
12e61d451c
2 changed files with 32 additions and 0 deletions
|
@ -88,6 +88,7 @@ struct Options {
|
|||
separate_dirs: bool,
|
||||
one_file_system: bool,
|
||||
dereference: Deref,
|
||||
count_links: bool,
|
||||
inodes: bool,
|
||||
verbose: bool,
|
||||
}
|
||||
|
@ -336,6 +337,9 @@ fn du(
|
|||
|
||||
if let Some(inode) = this_stat.inode {
|
||||
if inodes.contains(&inode) {
|
||||
if options.count_links {
|
||||
my_stat.inodes += 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
inodes.insert(inode);
|
||||
|
@ -561,6 +565,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
} else {
|
||||
Deref::None
|
||||
},
|
||||
count_links: matches.get_flag(options::COUNT_LINKS),
|
||||
inodes: matches.get_flag(options::INODES),
|
||||
verbose: matches.get_flag(options::VERBOSE),
|
||||
};
|
||||
|
|
|
@ -441,6 +441,33 @@ fn test_du_inodes() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_du_inodes_with_count_links() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
at.mkdir("dir");
|
||||
at.touch("dir/file");
|
||||
at.hard_link("dir/file", "dir/hard_link_a");
|
||||
at.hard_link("dir/file", "dir/hard_link_b");
|
||||
|
||||
// ensure the hard links are not counted without --count-links
|
||||
ts.ucmd()
|
||||
.arg("--inodes")
|
||||
.arg("dir")
|
||||
.succeeds()
|
||||
.stdout_is("2\tdir\n");
|
||||
|
||||
for arg in ["-l", "--count-links"] {
|
||||
ts.ucmd()
|
||||
.arg("--inodes")
|
||||
.arg(arg)
|
||||
.arg("dir")
|
||||
.succeeds()
|
||||
.stdout_is("4\tdir\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_du_h_flag_empty_file() {
|
||||
new_ucmd!()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue