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

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

commit 573f7af0088ab073387edd931cbf14c9f49ef795
Author: Xuanwo <[email protected]>
AuthorDate: Thu Nov 23 02:04:30 2023 +0800

    Fix test
    
    Signed-off-by: Xuanwo <[email protected]>
---
 bindings/python/src/capability.rs      | 3 +++
 bindings/python/tests/test_write.py    | 4 ++--
 core/src/services/dashmap/backend.rs   | 2 +-
 core/src/services/memory/backend.rs    | 7 ++++++-
 core/src/services/mini_moka/backend.rs | 2 +-
 core/src/services/moka/backend.rs      | 2 +-
 6 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/bindings/python/src/capability.rs 
b/bindings/python/src/capability.rs
index 533d016fa..7e5e5e817 100644
--- a/bindings/python/src/capability.rs
+++ b/bindings/python/src/capability.rs
@@ -23,6 +23,8 @@ use pyo3::prelude::*;
 pub struct Capability {
     /// If operator supports stat.
     pub stat: bool,
+    /// If operator supports stat a dir.
+    pub stat_dir: bool,
     /// If operator supports stat with if match.
     pub stat_with_if_match: bool,
     /// If operator supports stat with if none match.
@@ -125,6 +127,7 @@ impl Capability {
     pub fn new(capability: opendal::Capability) -> Self {
         Self {
             stat: capability.stat,
+            stat_dir: capability.stat_dir,
             stat_with_if_match: capability.stat_with_if_match,
             stat_with_if_none_match: capability.stat_with_if_none_match,
             read: capability.read,
diff --git a/bindings/python/tests/test_write.py 
b/bindings/python/tests/test_write.py
index e98c6e959..9fcbcbb55 100644
--- a/bindings/python/tests/test_write.py
+++ b/bindings/python/tests/test_write.py
@@ -54,7 +54,7 @@ async def test_async_write(service_name, operator, 
async_operator):
     await async_operator.delete(filename)
 
 
[email protected]_capability("create_dir", "stat")
[email protected]_capability("create_dir", "stat", "stat_dir")
 def test_sync_create_dir(service_name, operator, async_operator):
     path = f"test_dir_{str(uuid4())}/"
     operator.create_dir(path)
@@ -66,7 +66,7 @@ def test_sync_create_dir(service_name, operator, 
async_operator):
 
 
 @pytest.mark.asyncio
[email protected]_capability("create_dir", "stat")
[email protected]_capability("create_dir", "stat", "stat_dir")
 async def test_async_create_dir(service_name, operator, async_operator):
     path = f"test_dir_{str(uuid4())}/"
     await async_operator.create_dir(path)
diff --git a/core/src/services/dashmap/backend.rs 
b/core/src/services/dashmap/backend.rs
index df2c80ea8..f64dd2865 100644
--- a/core/src/services/dashmap/backend.rs
+++ b/core/src/services/dashmap/backend.rs
@@ -122,7 +122,7 @@ impl typed_kv::Adapter for Adapter {
         if path.is_empty() {
             Ok(keys.collect())
         } else {
-            Ok(keys.filter(|k| k.starts_with(path)).collect())
+            Ok(keys.filter(|k| k.starts_with(path) && k != path).collect())
         }
     }
 }
diff --git a/core/src/services/memory/backend.rs 
b/core/src/services/memory/backend.rs
index ad547f9d7..3057d0e46 100644
--- a/core/src/services/memory/backend.rs
+++ b/core/src/services/memory/backend.rs
@@ -131,9 +131,14 @@ impl typed_kv::Adapter for Adapter {
         let keys: Vec<_> = if path.is_empty() {
             inner.keys().cloned().collect()
         } else {
-            let right_range = format!("{}0", &path[..path.len() - 1]);
+            let right_range = if let Some(path) = path.strip_suffix('/') {
+                format!("{}0", path)
+            } else {
+                format!("{}{}", path, std::char::MAX)
+            };
             inner
                 .range(path.to_string()..right_range)
+                .filter(|(k, _)| k.as_str() != path)
                 .map(|(k, _)| k.to_string())
                 .collect()
         };
diff --git a/core/src/services/mini_moka/backend.rs 
b/core/src/services/mini_moka/backend.rs
index bc4e6bc33..e689c3b4f 100644
--- a/core/src/services/mini_moka/backend.rs
+++ b/core/src/services/mini_moka/backend.rs
@@ -192,7 +192,7 @@ impl typed_kv::Adapter for Adapter {
         if path.is_empty() {
             Ok(keys.collect())
         } else {
-            Ok(keys.filter(|k| k.starts_with(path)).collect())
+            Ok(keys.filter(|k| k.starts_with(path) && k != path).collect())
         }
     }
 }
diff --git a/core/src/services/moka/backend.rs 
b/core/src/services/moka/backend.rs
index 8b911de79..fe45d07f9 100644
--- a/core/src/services/moka/backend.rs
+++ b/core/src/services/moka/backend.rs
@@ -238,7 +238,7 @@ impl typed_kv::Adapter for Adapter {
         if path.is_empty() {
             Ok(keys.collect())
         } else {
-            Ok(keys.filter(|k| k.starts_with(path)).collect())
+            Ok(keys.filter(|k| k.starts_with(path) && k != path).collect())
         }
     }
 }

Reply via email to