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

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 8c72db973 feat(bindings/c): add opendal_operator_check (#5851)
8c72db973 is described below

commit 8c72db973a97cf94b3acbb9744933b8e0d635815
Author: Asuka Minato <[email protected]>
AuthorDate: Tue Mar 25 21:21:26 2025 +0900

    feat(bindings/c): add opendal_operator_check (#5851)
    
    * add opendal_operator_remove && opendal_operator_remove_all
    
    * clippy
    
    * add header
    
    * try add test
    
    * error: cannot convert ‘<brace-enclosed initializer list>’ to ‘const char* 
const*’
    
    * error: scalar object ‘paths’ requires one element in initializer
    
    * ERROR: LeakSanitizer: detected memory leaks
    
    * error: too few arguments to function ‘opendal_error* 
opendal_operator_write(const opendal_operator*, const char*, const 
opendal_bytes*)’
    
    * add check
    
    * add check for BlockingOperator
    
    * add doc
    
    * fix doc test
    
    * remove remove api
---
 bindings/c/include/opendal.h                 |  2 ++
 bindings/c/src/operator.rs                   |  9 +++++++++
 bindings/c/tests/bdd.cpp                     |  5 ++++-
 core/src/types/operator/blocking_operator.rs | 24 ++++++++++++++++++++++++
 4 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/bindings/c/include/opendal.h b/bindings/c/include/opendal.h
index 53bc1b0e7..73953d04e 100644
--- a/bindings/c/include/opendal.h
+++ b/bindings/c/include/opendal.h
@@ -1300,6 +1300,8 @@ struct opendal_error *opendal_operator_copy(const struct 
opendal_operator *op,
                                             const char *src,
                                             const char *dest);
 
+struct opendal_error *opendal_operator_check(const struct opendal_operator 
*op);
+
 /**
  * \brief Get information of underlying accessor.
  *
diff --git a/bindings/c/src/operator.rs b/bindings/c/src/operator.rs
index 6545c6a52..84751fc49 100644
--- a/bindings/c/src/operator.rs
+++ b/bindings/c/src/operator.rs
@@ -893,3 +893,12 @@ pub unsafe extern "C" fn opendal_operator_copy(
         std::ptr::null_mut()
     }
 }
+
+#[no_mangle]
+pub unsafe extern "C" fn opendal_operator_check(op: &opendal_operator) -> *mut 
opendal_error {
+    if let Err(err) = op.deref().check() {
+        opendal_error::new(err)
+    } else {
+        std::ptr::null_mut()
+    }
+}
diff --git a/bindings/c/tests/bdd.cpp b/bindings/c/tests/bdd.cpp
index be218cf6b..93b514845 100644
--- a/bindings/c/tests/bdd.cpp
+++ b/bindings/c/tests/bdd.cpp
@@ -61,7 +61,10 @@ TEST_F(OpendalBddTest, FeatureTest)
         .data = (uint8_t*)this->content.c_str(),
         .len = this->content.length(),
     };
-    opendal_error* error = opendal_operator_write(this->p, this->path.c_str(), 
&data);
+    opendal_error* error = opendal_operator_check(this->p);
+    EXPECT_EQ(error, nullptr);
+
+    error = opendal_operator_write(this->p, this->path.c_str(), &data);
     EXPECT_EQ(error, nullptr);
 
     // The blocking file "test" should exist
diff --git a/core/src/types/operator/blocking_operator.rs 
b/core/src/types/operator/blocking_operator.rs
index b7d4e24b2..b90c74f66 100644
--- a/core/src/types/operator/blocking_operator.rs
+++ b/core/src/types/operator/blocking_operator.rs
@@ -1109,6 +1109,30 @@ impl BlockingOperator {
             |inner, path, args| BlockingLister::create(inner, &path, args),
         ))
     }
+
+    /// Check if this operator can work correctly.
+    ///
+    /// We will send a `list` request to path and return any errors we met.
+    ///
+    /// ```
+    /// # use std::sync::Arc;
+    /// # use anyhow::Result;
+    /// use opendal::BlockingOperator;
+    /// use opendal::ErrorKind;
+    ///
+    /// # fn test(op: BlockingOperator) -> Result<()> {
+    /// op.check()?;
+    /// # Ok(())
+    /// # }
+    /// ```
+    pub fn check(&self) -> Result<()> {
+        let mut ds = self.lister("/")?;
+
+        match ds.next() {
+            Some(Err(e)) if e.kind() != ErrorKind::NotFound => Err(e),
+            _ => Ok(()),
+        }
+    }
 }
 
 impl From<BlockingOperator> for Operator {

Reply via email to