This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch polish-lister
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git

commit 6ab30ca31fcb529c9420c3ee57e065d414b816d3
Author: Xuanwo <[email protected]>
AuthorDate: Wed Nov 15 23:42:16 2023 +0800

    Polish flat lister
    
    Signed-off-by: Xuanwo <[email protected]>
---
 core/src/layers/complete.rs                        |  6 +--
 .../oio/list/{into_flat_page.rs => flat_list.rs}   | 47 ++++++++++++----------
 core/src/raw/oio/list/mod.rs                       |  5 +--
 3 files changed, 31 insertions(+), 27 deletions(-)

diff --git a/core/src/layers/complete.rs b/core/src/layers/complete.rs
index 6a7e665ce..68af92d2d 100644
--- a/core/src/layers/complete.rs
+++ b/core/src/layers/complete.rs
@@ -27,11 +27,11 @@ use std::task::Poll;
 use async_trait::async_trait;
 use bytes::Bytes;
 
+use crate::raw::oio::FileReader;
 use crate::raw::oio::FlatLister;
 use crate::raw::oio::HierarchyLister;
 use crate::raw::oio::RangeReader;
 use crate::raw::oio::StreamableReader;
-use crate::raw::oio::{into_flat_page, FileReader};
 use crate::raw::oio::{into_hierarchy_page, LazyReader};
 use crate::raw::*;
 use crate::*;
@@ -249,7 +249,7 @@ impl<A: Accessor> CompleteAccessor<A> {
             (_, false, false) => 
Err(self.new_unsupported_error(Operation::List)),
             // If recursive is true but service can't list_with_recursive
             (true, false, true) => {
-                let p = into_flat_page(self.inner.clone(), path);
+                let p = FlatLister::new(self.inner.clone(), path);
                 Ok((RpList::default(), CompleteLister::NeedFlat(p)))
             }
             // If recursive is false but service can't list_without_recursive
@@ -291,7 +291,7 @@ impl<A: Accessor> CompleteAccessor<A> {
             (_, false, false) => 
Err(self.new_unsupported_error(Operation::List)),
             // If recursive is true but service can't list_with_recursive
             (true, false, true) => {
-                let p = into_flat_page(self.inner.clone(), path);
+                let p = FlatLister::new(self.inner.clone(), path);
                 Ok((RpList::default(), CompleteLister::NeedFlat(p)))
             }
             // If recursive is false but service can't list_without_recursive
diff --git a/core/src/raw/oio/list/into_flat_page.rs 
b/core/src/raw/oio/list/flat_list.rs
similarity index 92%
rename from core/src/raw/oio/list/into_flat_page.rs
rename to core/src/raw/oio/list/flat_list.rs
index 5ec6fbe0f..2d40b13fd 100644
--- a/core/src/raw/oio/list/into_flat_page.rs
+++ b/core/src/raw/oio/list/flat_list.rs
@@ -27,26 +27,6 @@ use crate::*;
 /// ListFuture is the future returned while calling async list.
 type ListFuture<A, L> = BoxFuture<'static, (A, oio::Entry, Result<(RpList, 
L)>)>;
 
-/// to_flat_lister is used to make a hierarchy lister flat.
-pub fn into_flat_page<A: Accessor, P>(acc: A, path: &str) -> FlatLister<A, P> {
-    #[cfg(debug_assertions)]
-    {
-        let meta = acc.info();
-        debug_assert!(
-            meta.full_capability().list_without_recursive,
-            "service doesn't support list hierarchy, it must be a bug"
-        );
-    }
-
-    FlatLister {
-        acc: Some(acc),
-        root: path.to_string(),
-        next_dir: Some(oio::Entry::new(path, Metadata::new(EntryMode::DIR))),
-        active_lister: vec![],
-        list_future: None,
-    }
-}
-
 /// ToFlatLister will walk dir in bottom up way:
 ///
 /// - List nested dir first
@@ -97,6 +77,31 @@ pub struct FlatLister<A: Accessor, L> {
 /// We will only take `&mut Self` reference for FsLister.
 unsafe impl<A: Accessor, L> Sync for FlatLister<A, L> {}
 
+impl<A, L> FlatLister<A, L>
+where
+    A: Accessor,
+{
+    /// Create a new flat lister
+    pub fn new(acc: A, path: &str) -> FlatLister<A, L> {
+        #[cfg(debug_assertions)]
+        {
+            let meta = acc.info();
+            debug_assert!(
+                meta.full_capability().list_without_recursive,
+                "service doesn't support list hierarchy, it must be a bug"
+            );
+        }
+
+        FlatLister {
+            acc: Some(acc),
+            root: path.to_string(),
+            next_dir: Some(oio::Entry::new(path, 
Metadata::new(EntryMode::DIR))),
+            active_lister: vec![],
+            list_future: None,
+        }
+    }
+}
+
 #[async_trait]
 impl<A, L> oio::List for FlatLister<A, L>
 where
@@ -280,7 +285,7 @@ mod tests {
         let _ = tracing_subscriber::fmt().with_test_writer().try_init();
 
         let acc = MockService::new();
-        let mut lister = into_flat_page(acc, "x/");
+        let mut lister = FlatLister::new(acc, "x/");
 
         let mut entries = Vec::default();
 
diff --git a/core/src/raw/oio/list/mod.rs b/core/src/raw/oio/list/mod.rs
index 63fe41292..30c117333 100644
--- a/core/src/raw/oio/list/mod.rs
+++ b/core/src/raw/oio/list/mod.rs
@@ -27,9 +27,8 @@ pub use page_list::PageContext;
 pub use page_list::PageList;
 pub use page_list::PageLister;
 
-mod into_flat_page;
-pub use into_flat_page::into_flat_page;
-pub use into_flat_page::FlatLister;
+mod flat_list;
+pub use flat_list::FlatLister;
 
 mod into_hierarchy_pager;
 pub use into_hierarchy_pager::into_hierarchy_page;

Reply via email to