@@ -103,17 +103,18 @@ where
103103 . run ( ) ;
104104 } ;
105105
106- // ExactSizeIterator::is_empty is unstable
107- let data_tree = if iter . len ( ) == 0 {
106+ let only_one_arg = iter . len ( ) == 0 ; // ExactSizeIterator::is_empty is unstable
107+ let data_tree = if only_one_arg {
108108 data_tree
109109 } else {
110110 let children: Vec < _ > = once ( data_tree) . chain ( iter) . collect ( ) ;
111- DataTree :: dir (
112- OsStringDisplay :: os_string_from ( "(total)" ) ,
113- Size :: default ( ) ,
114- children,
115- )
116- . into_par_retained ( |_, depth| depth + 1 < max_depth)
111+
112+ // This name is for hardlinks deduplication to work correctly as empty string is considered to be the start of any path.
113+ // It would be changed into "(total)" later.
114+ let fake_root_name = OsStringDisplay :: os_string_from ( "" ) ;
115+
116+ DataTree :: dir ( fake_root_name, Size :: default ( ) , children)
117+ . into_par_retained ( |_, depth| depth + 1 < max_depth)
117118 } ;
118119
119120 if reporter. destroy ( ) . is_err ( ) {
@@ -130,6 +131,10 @@ where
130131 data_tree. par_sort_by ( |left, right| left. size ( ) . cmp ( & right. size ( ) ) . reverse ( ) ) ;
131132 }
132133 let deduplication_record = hardlinks_handler. deduplicate ( & mut data_tree) ;
134+ if !only_one_arg {
135+ assert_eq ! ( data_tree. name( ) . as_os_str( ) . to_str( ) , Some ( "" ) ) ;
136+ * data_tree. name_mut ( ) = OsStringDisplay :: os_string_from ( "(total)" ) ;
137+ }
133138 ( data_tree, deduplication_record)
134139 } ;
135140
0 commit comments