@@ -1244,6 +1244,19 @@ impl Config {
12441244 tab_size,
12451245 } )
12461246 }
1247+
1248+ /// Check if leading info (inode and/or block size) should be displayed
1249+ #[ inline]
1250+ fn should_display_leading_info ( & self ) -> bool {
1251+ #[ cfg( unix) ]
1252+ {
1253+ self . inode || self . alloc_size
1254+ }
1255+ #[ cfg( not( unix) ) ]
1256+ {
1257+ self . alloc_size
1258+ }
1259+ }
12471260}
12481261
12491262#[ uucore:: main]
@@ -2687,10 +2700,7 @@ fn display_items(
26872700 let padding_collection = calculate_padding_collection ( items, config, state) ;
26882701
26892702 for item in items {
2690- #[ cfg( unix) ]
2691- let should_display_leading_info = config. inode || config. alloc_size ;
2692- #[ cfg( not( unix) ) ]
2693- let should_display_leading_info = config. alloc_size ;
2703+ let should_display_leading_info = config. should_display_leading_info ( ) ;
26942704
26952705 if should_display_leading_info {
26962706 let more_info = display_additional_leading_info ( item, & padding_collection, config) ?;
@@ -2721,10 +2731,7 @@ fn display_items(
27212731
27222732 let mut names_vec = Vec :: new ( ) ;
27232733
2724- #[ cfg( unix) ]
2725- let should_display_leading_info = config. inode || config. alloc_size ;
2726- #[ cfg( not( unix) ) ]
2727- let should_display_leading_info = config. alloc_size ;
2734+ let should_display_leading_info = config. should_display_leading_info ( ) ;
27282735
27292736 for i in items {
27302737 let more_info = if should_display_leading_info {
@@ -3587,20 +3594,22 @@ fn get_security_context<'a>(
35873594 Cow :: Borrowed ( SUBSTITUTE_STRING )
35883595}
35893596
3590- #[ cfg( unix) ]
35913597fn calculate_padding_collection (
35923598 items : & [ PathData ] ,
35933599 config : & Config ,
35943600 state : & mut ListState ,
35953601) -> PaddingCollection {
35963602 let mut padding_collections = PaddingCollection {
3603+ #[ cfg( unix) ]
35973604 inode : 1 ,
35983605 link_count : 1 ,
35993606 uname : 1 ,
36003607 group : 1 ,
36013608 context : 1 ,
36023609 size : 1 ,
3610+ #[ cfg( unix) ]
36033611 major : 1 ,
3612+ #[ cfg( unix) ]
36043613 minor : 1 ,
36053614 block_size : 1 ,
36063615 } ;
@@ -3646,56 +3655,25 @@ fn calculate_padding_collection(
36463655 }
36473656 }
36483657
3649- if items. len ( ) == 1usize {
3650- padding_collections. size = 0usize ;
3651- padding_collections. major = 0usize ;
3652- padding_collections. minor = 0usize ;
3653- } else {
3654- padding_collections. major = major_len. max ( padding_collections. major ) ;
3655- padding_collections. minor = minor_len. max ( padding_collections. minor ) ;
3656- padding_collections. size = size_len
3657- . max ( padding_collections. size )
3658- . max ( padding_collections. major ) ;
3658+ #[ cfg( unix) ]
3659+ {
3660+ if items. len ( ) == 1usize {
3661+ padding_collections. size = 0usize ;
3662+ padding_collections. major = 0usize ;
3663+ padding_collections. minor = 0usize ;
3664+ } else {
3665+ padding_collections. major = major_len. max ( padding_collections. major ) ;
3666+ padding_collections. minor = minor_len. max ( padding_collections. minor ) ;
3667+ padding_collections. size = size_len
3668+ . max ( padding_collections. size )
3669+ . max ( padding_collections. major ) ;
3670+ }
36593671 }
3660- }
3661- }
3662-
3663- padding_collections
3664- }
3665-
3666- #[ cfg( not( unix) ) ]
3667- fn calculate_padding_collection (
3668- items : & [ PathData ] ,
3669- config : & Config ,
3670- state : & mut ListState ,
3671- ) -> PaddingCollection {
3672- let mut padding_collections = PaddingCollection {
3673- link_count : 1 ,
3674- uname : 1 ,
3675- group : 1 ,
3676- context : 1 ,
3677- size : 1 ,
3678- block_size : 1 ,
3679- } ;
3680-
3681- for item in items {
3682- if config. alloc_size {
3683- if let Some ( md) = item. metadata ( ) {
3684- let block_size_len = display_size ( get_block_size ( md, config) , config) . len ( ) ;
3685- padding_collections. block_size = block_size_len. max ( padding_collections. block_size ) ;
3672+ #[ cfg( not( unix) ) ]
3673+ {
3674+ padding_collections. size = size_len. max ( padding_collections. size ) ;
36863675 }
36873676 }
3688-
3689- let context_len = item. security_context ( config) . len ( ) ;
3690- let ( link_count_len, uname_len, group_len, size_len, _major_len, _minor_len) =
3691- display_dir_entry_size ( item, config, state) ;
3692- padding_collections. link_count = link_count_len. max ( padding_collections. link_count ) ;
3693- padding_collections. uname = uname_len. max ( padding_collections. uname ) ;
3694- padding_collections. group = group_len. max ( padding_collections. group ) ;
3695- if config. context {
3696- padding_collections. context = context_len. max ( padding_collections. context ) ;
3697- }
3698- padding_collections. size = size_len. max ( padding_collections. size ) ;
36993677 }
37003678
37013679 padding_collections
0 commit comments