1818use std:: sync:: Arc ;
1919use std:: vec:: IntoIter ;
2020
21- use super :: Adapter ;
21+ use super :: { Adapter , Scan } ;
2222use crate :: raw:: oio:: HierarchyLister ;
2323use crate :: raw:: oio:: QueueBuf ;
2424use crate :: raw:: * ;
@@ -68,8 +68,8 @@ impl<S: Adapter> Access for Backend<S> {
6868 type BlockingReader = Buffer ;
6969 type Writer = KvWriter < S > ;
7070 type BlockingWriter = KvWriter < S > ;
71- type Lister = HierarchyLister < KvLister > ;
72- type BlockingLister = HierarchyLister < KvLister > ;
71+ type Lister = HierarchyLister < KvLister < S :: Scanner > > ;
72+ type BlockingLister = HierarchyLister < BlockingKvLister > ;
7373
7474 fn info ( & self ) -> Arc < AccessorInfo > {
7575 let mut am: AccessorInfo = self . kv . metadata ( ) . into ( ) ;
@@ -182,19 +182,60 @@ impl<S: Adapter> Access for Backend<S> {
182182 fn blocking_list ( & self , path : & str , args : OpList ) -> Result < ( RpList , Self :: BlockingLister ) > {
183183 let p = build_abs_path ( & self . root , path) ;
184184 let res = self . kv . blocking_scan ( & p) ?;
185- let lister = KvLister :: new ( & self . root , res) ;
185+ let lister = BlockingKvLister :: new ( & self . root , res) ;
186186 let lister = HierarchyLister :: new ( lister, path, args. recursive ( ) ) ;
187187
188188 Ok ( ( RpList :: default ( ) , lister) )
189189 }
190190}
191191
192- pub struct KvLister {
192+ pub struct KvLister < Iter > {
193+ root : String ,
194+ inner : Iter ,
195+ }
196+
197+ impl < Iter > KvLister < Iter >
198+ where
199+ Iter : Scan ,
200+ {
201+ fn new ( root : & str , inner : Iter ) -> Self {
202+ Self {
203+ root : root. to_string ( ) ,
204+ inner,
205+ }
206+ }
207+
208+ async fn inner_next ( & mut self ) -> Result < Option < oio:: Entry > > {
209+ Ok ( self . inner . next ( ) . await ?. map ( |v| {
210+ let mode = if v. ends_with ( '/' ) {
211+ EntryMode :: DIR
212+ } else {
213+ EntryMode :: FILE
214+ } ;
215+ let mut path = build_rel_path ( & self . root , & v) ;
216+ if path. is_empty ( ) {
217+ path = "/" . to_string ( ) ;
218+ }
219+ oio:: Entry :: new ( & path, Metadata :: new ( mode) )
220+ } ) )
221+ }
222+ }
223+
224+ impl < Iter > oio:: List for KvLister < Iter >
225+ where
226+ Iter : Scan ,
227+ {
228+ async fn next ( & mut self ) -> Result < Option < oio:: Entry > > {
229+ self . inner_next ( ) . await
230+ }
231+ }
232+
233+ pub struct BlockingKvLister {
193234 root : String ,
194235 inner : IntoIter < String > ,
195236}
196237
197- impl KvLister {
238+ impl BlockingKvLister {
198239 fn new ( root : & str , inner : Vec < String > ) -> Self {
199240 Self {
200241 root : root. to_string ( ) ,
@@ -218,13 +259,7 @@ impl KvLister {
218259 }
219260}
220261
221- impl oio:: List for KvLister {
222- async fn next ( & mut self ) -> Result < Option < oio:: Entry > > {
223- Ok ( self . inner_next ( ) )
224- }
225- }
226-
227- impl oio:: BlockingList for KvLister {
262+ impl oio:: BlockingList for BlockingKvLister {
228263 fn next ( & mut self ) -> Result < Option < oio:: Entry > > {
229264 Ok ( self . inner_next ( ) )
230265 }
0 commit comments