mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
du: fix the size display with --inodes
This commit is contained in:
parent
76d14ed484
commit
1b2778b819
2 changed files with 30 additions and 4 deletions
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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}"));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue