@@ -588,7 +588,7 @@ impl DirListingIterator {
588
588
pub struct ListStatusIterator {
589
589
mount_table : Arc < MountTable > ,
590
590
recursive : bool ,
591
- iters : Vec < DirListingIterator > ,
591
+ iters : Arc < tokio :: sync :: Mutex < Vec < DirListingIterator > > > ,
592
592
}
593
593
594
594
impl ListStatusIterator {
@@ -598,20 +598,21 @@ impl ListStatusIterator {
598
598
ListStatusIterator {
599
599
mount_table,
600
600
recursive,
601
- iters : vec ! [ initial] ,
601
+ iters : Arc :: new ( tokio :: sync :: Mutex :: new ( vec ! [ initial] ) ) ,
602
602
}
603
603
}
604
604
605
- pub async fn next ( & mut self ) -> Option < Result < FileStatus > > {
605
+ pub async fn next ( & self ) -> Option < Result < FileStatus > > {
606
606
let mut next_file: Option < Result < FileStatus > > = None ;
607
+ let mut iters = self . iters . lock ( ) . await ;
607
608
while next_file. is_none ( ) {
608
- if let Some ( iter) = self . iters . last_mut ( ) {
609
+ if let Some ( iter) = iters. last_mut ( ) {
609
610
if let Some ( file_result) = iter. next ( ) . await {
610
611
if let Ok ( file) = file_result {
611
612
// Return the directory as the next result, but start traversing into that directory
612
613
// next if we're doing a recursive listing
613
614
if file. isdir && self . recursive {
614
- self . iters . push ( DirListingIterator :: new (
615
+ iters. push ( DirListingIterator :: new (
615
616
file. path . clone ( ) ,
616
617
& self . mount_table ,
617
618
false ,
@@ -624,7 +625,7 @@ impl ListStatusIterator {
624
625
}
625
626
} else {
626
627
// We've exhausted this directory
627
- self . iters . pop ( ) ;
628
+ iters. pop ( ) ;
628
629
}
629
630
} else {
630
631
// There's nothing left, just return None
@@ -636,7 +637,7 @@ impl ListStatusIterator {
636
637
}
637
638
638
639
pub fn into_stream ( self ) -> BoxStream < ' static , Result < FileStatus > > {
639
- let listing = stream:: unfold ( self , |mut state| async move {
640
+ let listing = stream:: unfold ( self , |state| async move {
640
641
let next = state. next ( ) . await ;
641
642
next. map ( |n| ( n, state) )
642
643
} ) ;
0 commit comments