You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "jiaoew1991 (via GitHub)" <gi...@apache.org> on 2023/06/05 08:53:46 UTC

[GitHub] [incubator-opendal] jiaoew1991 commented on a diff in pull request #2416: feat(bindings/c): add opendal_operator_blocking_delete method

jiaoew1991 commented on code in PR #2416:
URL: https://github.com/apache/incubator-opendal/pull/2416#discussion_r1217747536


##########
bindings/c/src/lib.rs:
##########
@@ -235,6 +235,56 @@ pub unsafe extern "C" fn opendal_operator_blocking_read(
     }
 }
 
+/// \brief Blockingly delete `path`.
+///
+/// Write the `bytes` into the `path` blockingly by `op_ptr`, returns the opendal_code OPENDAL_OK
+/// if succeeds, others otherwise
+///
+/// @param ptr The opendal_operator_ptr created previously
+/// @param path The designated path you want to delete
+/// @see opendal_operator_ptr
+/// @see opendal_code
+/// @return OPENDAL_OK if succeeds others otherwise
+///
+/// # Example
+///
+/// Following is an example
+/// ```C
+/// //...prepare your opendal_operator_ptr, named ptr for example
+///
+/// // now you can delete!
+/// opendal_code code = opendal_operator_blocking_delete(ptr, "/testpath");
+///
+/// // Assert that this succeeds
+/// assert(code == OPENDAL_OK)
+/// ```
+///
+/// # Safety
+///
+/// It is **safe** under the cases below
+/// * The memory pointed to by `path` must contain a valid nul terminator at the end of
+///   the string.
+///
+/// # Panic
+///
+/// * If the `path` points to NULL, this function panics, i.e. exits with information
+#[no_mangle]
+pub unsafe extern "C" fn opendal_operator_blocking_delete(
+    ptr: opendal_operator_ptr,
+    path: *const c_char,
+) -> opendal_code {
+    if path.is_null() {
+        panic!("The path given is pointing at NULL");
+    }
+
+    let op = ptr.as_ref();
+    let path = unsafe { std::ffi::CStr::from_ptr(path).to_str().unwrap() };
+    match op.delete(path) {
+        Ok(_) => opendal_code::OPENDAL_OK,

Review Comment:
   👌🏻



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org