Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bindings/c/include/opendal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
9 changes: 9 additions & 0 deletions bindings/c/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
5 changes: 4 additions & 1 deletion bindings/c/tests/bdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions core/src/types/operator/blocking_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading