You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/04/12 11:11:15 UTC

[incubator-opendal] branch add-docs-for-scan created (now 34849c34)

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

xuanwo pushed a change to branch add-docs-for-scan
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


      at 34849c34 refactor: Polish the behavior of scan

This branch includes the following new commits:

     new 34849c34 refactor: Polish the behavior of scan

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-opendal] 01/01: refactor: Polish the behavior of scan

Posted by xu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch add-docs-for-scan
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git

commit 34849c34aed96d64bec948a4b6a0ef91e6dcdc2a
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Wed Apr 12 19:10:57 2023 +0800

    refactor: Polish the behavior of scan
    
    Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
 core/src/raw/oio/to_flat_pager.rs            | 12 ++++++++++--
 core/src/types/operator/blocking_operator.rs |  6 +++++-
 core/src/types/operator/operator.rs          |  9 ++++++++-
 core/tests/behavior/list.rs                  | 14 ++++++++++++++
 4 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/core/src/raw/oio/to_flat_pager.rs b/core/src/raw/oio/to_flat_pager.rs
index 8f20093c..6cbce7b3 100644
--- a/core/src/raw/oio/to_flat_pager.rs
+++ b/core/src/raw/oio/to_flat_pager.rs
@@ -42,6 +42,7 @@ pub fn to_flat_pager<A: Accessor, P>(acc: A, path: &str, size: usize) -> ToFlatP
     ToFlatPager {
         acc,
         size,
+        root: path.to_string(),
         dirs: VecDeque::from([oio::Entry::new(path, Metadata::new(EntryMode::DIR))]),
         pagers: vec![],
         res: Vec::with_capacity(size),
@@ -87,6 +88,7 @@ pub fn to_flat_pager<A: Accessor, P>(acc: A, path: &str, size: usize) -> ToFlatP
 pub struct ToFlatPager<A: Accessor, P> {
     acc: A,
     size: usize,
+    root: String,
     dirs: VecDeque<oio::Entry>,
     pagers: Vec<(P, oio::Entry, Vec<oio::Entry>)>,
     res: Vec<oio::Entry>,
@@ -121,7 +123,10 @@ where
                         buf = v;
                     }
                     None => {
-                        self.res.push(de);
+                        // Only push entry if it's not root dir
+                        if de.path() != self.root {
+                            self.res.push(de);
+                        }
                         continue;
                     }
                 }
@@ -178,7 +183,10 @@ where
                         buf = v;
                     }
                     None => {
-                        self.res.push(de);
+                        // Only push entry if it's not root dir
+                        if de.path() != self.root {
+                            self.res.push(de);
+                        }
                         continue;
                     }
                 }
diff --git a/core/src/types/operator/blocking_operator.rs b/core/src/types/operator/blocking_operator.rs
index fe52d3b6..a2503ed6 100644
--- a/core/src/types/operator/blocking_operator.rs
+++ b/core/src/types/operator/blocking_operator.rs
@@ -718,10 +718,14 @@ impl BlockingOperator {
 
     /// List dir in flat way.
     ///
-    /// This function will create a new handle to list entries.
+    /// Also, this function can be used to list a prefix.
     ///
     /// An error will be returned if given path doesn't end with `/`.
     ///
+    /// # Notes
+    ///
+    /// - `scan` will not return the prefix itself.
+    ///
     /// # Examples
     ///
     /// ```no_run
diff --git a/core/src/types/operator/operator.rs b/core/src/types/operator/operator.rs
index b33b0638..a85b963e 100644
--- a/core/src/types/operator/operator.rs
+++ b/core/src/types/operator/operator.rs
@@ -944,6 +944,9 @@ impl Operator {
                 .await?;
         }
 
+        // Remove the directory itself.
+        self.delete(path).await?;
+
         Ok(())
     }
 
@@ -1000,10 +1003,14 @@ impl Operator {
 
     /// List dir in flat way.
     ///
-    /// This function will create a new handle to list entries.
+    /// Also, this function can be used to list a prefix.
     ///
     /// An error will be returned if given path doesn't end with `/`.
     ///
+    /// # Notes
+    ///
+    /// - `scan` will not return the prefix itself.
+    ///
     /// # Examples
     ///
     /// ```no_run
diff --git a/core/tests/behavior/list.rs b/core/tests/behavior/list.rs
index 85e023f8..2b908598 100644
--- a/core/tests/behavior/list.rs
+++ b/core/tests/behavior/list.rs
@@ -82,6 +82,7 @@ macro_rules! behavior_list_tests {
                 test_list_nested_dir,
                 test_list_dir_with_file_path,
                 test_scan,
+                test_scan_root,
                 test_remove_all,
             );
         )*
@@ -279,6 +280,19 @@ pub async fn test_list_dir_with_file_path(op: Operator) -> Result<()> {
     Ok(())
 }
 
+pub async fn test_scan_root(op: Operator) -> Result<()> {
+    let w = op.scan("").await?;
+    let actual = w
+        .try_collect::<Vec<_>>()
+        .await?
+        .into_iter()
+        .map(|v| v.path().to_string())
+        .collect::<HashSet<_>>();
+
+    assert!(actual.is_empty(), "empty root should return empty");
+    Ok(())
+}
+
 // Walk top down should output as expected
 pub async fn test_scan(op: Operator) -> Result<()> {
     let expected = vec![