File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -557,9 +557,6 @@ impl StatPrinter {
557557 }
558558
559559 fn convert_size ( & self , size : u64 ) -> String {
560- if self . inodes {
561- return size. to_string ( ) ;
562- }
563560 match self . size_format {
564561 SizeFormat :: HumanDecimal => uucore:: format:: human:: human_readable (
565562 size,
@@ -569,7 +566,14 @@ impl StatPrinter {
569566 size,
570567 uucore:: format:: human:: SizeFormat :: Binary ,
571568 ) ,
572- SizeFormat :: BlockSize ( block_size) => size. div_ceil ( block_size) . to_string ( ) ,
569+ SizeFormat :: BlockSize ( block_size) => {
570+ if self . inodes {
571+ // we ignore block size (-B) with --inodes
572+ size. to_string ( )
573+ } else {
574+ size. div_ceil ( block_size) . to_string ( )
575+ }
576+ }
573577 }
574578 }
575579
Original file line number Diff line number Diff line change @@ -1198,3 +1198,25 @@ fn test_invalid_time_style() {
11981198 . succeeds ( )
11991199 . stdout_does_not_contain ( "du: invalid argument 'banana' for 'time style'" ) ;
12001200}
1201+
1202+ #[ test]
1203+ fn test_human_size ( ) {
1204+ use std:: fs:: File ;
1205+
1206+ let ts = TestScenario :: new ( util_name ! ( ) ) ;
1207+ let at = & ts. fixtures ;
1208+ let dir = at. plus_as_string ( "d" ) ;
1209+ at. mkdir ( & dir) ;
1210+
1211+ for i in 1 ..=1023 {
1212+ let file_path = format ! ( "{dir}/file{i}" ) ;
1213+ File :: create ( & file_path) . expect ( "Failed to create file" ) ;
1214+ }
1215+
1216+ ts. ucmd ( )
1217+ . arg ( "--inodes" )
1218+ . arg ( "-h" )
1219+ . arg ( & dir)
1220+ . succeeds ( )
1221+ . stdout_contains ( format ! ( "1.0K {dir}" ) ) ;
1222+ }
You can’t perform that action at this time.
0 commit comments