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

du: fix the size display with --inodes

This commit is contained in:
Sylvestre Ledru 2024-11-20 07:46:53 -05:00
parent 76d14ed484
commit 1b2778b819
2 changed files with 30 additions and 4 deletions

View file

@ -557,9 +557,6 @@ impl StatPrinter {
} }
fn convert_size(&self, size: u64) -> String { fn convert_size(&self, size: u64) -> String {
if self.inodes {
return size.to_string();
}
match self.size_format { match self.size_format {
SizeFormat::HumanDecimal => uucore::format::human::human_readable( SizeFormat::HumanDecimal => uucore::format::human::human_readable(
size, size,
@ -569,7 +566,14 @@ impl StatPrinter {
size, size,
uucore::format::human::SizeFormat::Binary, uucore::format::human::SizeFormat::Binary,
), ),
SizeFormat::BlockSize(block_size) => size.div_ceil(block_size).to_string(), SizeFormat::BlockSize(block_size) => {
if self.inodes {
// we ignore block size (-B) with --inodes
size.to_string()
} else {
size.div_ceil(block_size).to_string()
}
}
} }
} }

View file

@ -1198,3 +1198,25 @@ fn test_invalid_time_style() {
.succeeds() .succeeds()
.stdout_does_not_contain("du: invalid argument 'banana' for 'time style'"); .stdout_does_not_contain("du: invalid argument 'banana' for 'time style'");
} }
#[test]
fn test_human_size() {
use std::fs::File;
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
let dir = at.plus_as_string("d");
at.mkdir(&dir);
for i in 1..=1023 {
let file_path = format!("{dir}/file{i}");
File::create(&file_path).expect("Failed to create file");
}
ts.ucmd()
.arg("--inodes")
.arg("-h")
.arg(&dir)
.succeeds()
.stdout_contains(format!("1.0K {dir}"));
}