@@ -522,7 +522,7 @@ impl FileSystemService {
522522 max_depth : Option < usize > ,
523523 max_files : Option < usize > ,
524524 current_count : & mut usize ,
525- ) -> ServiceResult < Value > {
525+ ) -> ServiceResult < ( Value , bool ) > {
526526 let valid_path = self . validate_path ( root_path. as_ref ( ) ) ?;
527527
528528 let metadata = fs:: metadata ( & valid_path) ?;
@@ -533,6 +533,7 @@ impl FileSystemService {
533533 }
534534
535535 let mut children = Vec :: new ( ) ;
536+ let mut reached_max_depth = false ;
536537
537538 if max_depth != Some ( 0 ) {
538539 for entry in WalkDir :: new ( valid_path)
@@ -568,17 +569,21 @@ impl FileSystemService {
568569
569570 if metadata. is_dir ( ) {
570571 let next_depth = max_depth. map ( |d| d - 1 ) ;
571- let child_children =
572+ let ( child_children, child_reached_max_depth ) =
572573 self . directory_tree ( child_path, next_depth, max_files, current_count) ?;
573574 json_entry
574575 . as_object_mut ( )
575576 . unwrap ( )
576577 . insert ( "children" . to_string ( ) , child_children) ;
578+ reached_max_depth |= child_reached_max_depth;
577579 }
578580 children. push ( json_entry) ;
579581 }
582+ } else {
583+ // If max_depth is 0, we skip processing this directory's children
584+ reached_max_depth = true ;
580585 }
581- Ok ( Value :: Array ( children) )
586+ Ok ( ( Value :: Array ( children) , reached_max_depth ) )
582587 }
583588
584589 pub fn create_unified_diff (
0 commit comments