diff --git a/bindings/cpp/include/opendal.hpp b/bindings/cpp/include/opendal.hpp index 714cba7b9a9f..cbf96476dd2c 100644 --- a/bindings/cpp/include/opendal.hpp +++ b/bindings/cpp/include/opendal.hpp @@ -137,8 +137,17 @@ class Operator { * @param path The path to check * @return true if the path exists, false otherwise */ + [[deprecated("Use exists() instead.")]] bool is_exist(std::string_view path); + /** + * @brief Check if the path exists + * + * @param path The path to check + * @return true if the path exists, false otherwise + */ + bool exists(std::string_view path); + /** * @brief Create a directory * diff --git a/bindings/cpp/src/lib.rs b/bindings/cpp/src/lib.rs index f8b4a77d2569..a37807c078e6 100644 --- a/bindings/cpp/src/lib.rs +++ b/bindings/cpp/src/lib.rs @@ -80,7 +80,7 @@ mod ffi { fn new_operator(scheme: &str, configs: Vec) -> Result>; fn read(self: &Operator, path: &str) -> Result>; fn write(self: &Operator, path: &str, bs: &'static [u8]) -> Result<()>; - fn is_exist(self: &Operator, path: &str) -> Result; + fn exists(self: &Operator, path: &str) -> Result; fn create_dir(self: &Operator, path: &str) -> Result<()>; fn copy(self: &Operator, src: &str, dst: &str) -> Result<()>; fn rename(self: &Operator, src: &str, dst: &str) -> Result<()>; @@ -125,8 +125,8 @@ impl Operator { Ok(self.0.write(path, bs)?) } - fn is_exist(&self, path: &str) -> Result { - Ok(self.0.is_exist(path)?) + fn exists(&self, path: &str) -> Result { + Ok(self.0.exists(path)?) } fn create_dir(&self, path: &str) -> Result<()> { diff --git a/bindings/cpp/src/opendal.cpp b/bindings/cpp/src/opendal.cpp index 01bb99813d08..c886647cb0ca 100644 --- a/bindings/cpp/src/opendal.cpp +++ b/bindings/cpp/src/opendal.cpp @@ -52,8 +52,12 @@ void Operator::write(std::string_view path, const std::vector &data) { RUST_STR(path), rust::Slice(data.data(), data.size())); } +bool Operator::exists(std::string_view path) { + return operator_.value()->exists(RUST_STR(path)); +} + bool Operator::is_exist(std::string_view path) { - return operator_.value()->is_exist(RUST_STR(path)); + return exists(path); } void Operator::create_dir(std::string_view path) { diff --git a/bindings/cpp/tests/basic_test.cpp b/bindings/cpp/tests/basic_test.cpp index 8e82eb5a931c..9ffd03df3333 100644 --- a/bindings/cpp/tests/basic_test.cpp +++ b/bindings/cpp/tests/basic_test.cpp @@ -62,11 +62,11 @@ TEST_F(OpendalTest, BasicTest) { EXPECT_EQ(res, data); // is_exist - EXPECT_TRUE(op.is_exist(file_path)); + EXPECT_TRUE(op.exists(file_path)); // create_dir op.create_dir(dir_path); - EXPECT_TRUE(op.is_exist(dir_path)); + EXPECT_TRUE(op.exists(dir_path)); // stat auto metadata = op.stat(file_path); @@ -88,7 +88,7 @@ TEST_F(OpendalTest, BasicTest) { // remove op.remove(file_path_renamed); op.remove(dir_path); - EXPECT_FALSE(op.is_exist(file_path_renamed)); + EXPECT_FALSE(op.exists(file_path_renamed)); } TEST_F(OpendalTest, ReaderTest) {