@@ -198,45 +198,49 @@ impl InProgressTraversal {
198198 /// Recursively traverses a directory and collects file paths, displaying progress
199199 pub fn traverse_path ( & mut self , path : & Path ) -> Result < ( ) > {
200200 if path. is_dir ( ) {
201- self . add_dir ( ) ;
202-
203- // Measure read_dir latency
204- let start_time = Instant :: now ( ) ;
205- let read_dir_result = fs:: read_dir ( path) ;
206- let read_dir_duration = start_time. elapsed ( ) ;
207-
208- let entries = read_dir_result?;
209- let mut entry_count = 0 ;
210-
211- for entry_result in entries {
212- let entry = entry_result?;
213- let path = entry. path ( ) ;
214- let file_type = entry. file_type ( ) ?;
215- entry_count += 1 ;
216-
217- if file_type. is_dir ( ) {
218- if file_type. is_symlink ( ) {
219- if self . follow_symlinks {
220- self . add_traversed_symlink ( ) ;
221- self . traverse_path ( & path) ?;
222- } else {
223- self . add_skipped_symlink ( ) ;
224- }
225- } else {
226- // Regular directory, ie, non symlink
227- self . traverse_path ( & path) ?;
228- }
229- } else if file_type. is_file ( ) {
230- if self . file_count < self . max_files {
231- self . add_file ( path) ;
201+ self . traverse_directory ( path)
202+ } else {
203+ Ok ( ( ) )
204+ }
205+ }
206+
207+ fn traverse_directory ( & mut self , path : & Path ) -> Result < ( ) > {
208+ self . add_dir ( ) ;
209+
210+ let start_time = Instant :: now ( ) ;
211+ let read_dir_result = fs:: read_dir ( path) ;
212+ let read_dir_duration = start_time. elapsed ( ) ;
213+
214+ let entries = read_dir_result?;
215+ let mut entry_count = 0 ;
216+
217+ for entry_result in entries {
218+ let entry = entry_result?;
219+ let path = entry. path ( ) ;
220+ let file_type = entry. file_type ( ) ?;
221+ entry_count += 1 ;
222+
223+ if file_type. is_dir ( ) {
224+ if file_type. is_symlink ( ) {
225+ if self . follow_symlinks {
226+ self . add_traversed_symlink ( ) ;
227+ self . traverse_directory ( & path) ?;
232228 } else {
233- self . add_read_dir_stats ( read_dir_duration, entry_count) ;
234- return Ok ( ( ) ) ;
229+ self . add_skipped_symlink ( ) ;
235230 }
231+ } else {
232+ self . traverse_directory ( & path) ?;
233+ }
234+ } else if file_type. is_file ( ) {
235+ if self . file_count < self . max_files {
236+ self . add_file ( path) ;
237+ } else {
238+ self . add_read_dir_stats ( read_dir_duration, entry_count) ;
239+ return Ok ( ( ) ) ;
236240 }
237241 }
238- self . add_read_dir_stats ( read_dir_duration, entry_count) ;
239242 }
243+ self . add_read_dir_stats ( read_dir_duration, entry_count) ;
240244 Ok ( ( ) )
241245 }
242246}
0 commit comments