Skip to content

Commit

Permalink
feat(bindings/cpp): rename is_exist to exists as core did
Browse files Browse the repository at this point in the history
  • Loading branch information
PragmaTwice committed Oct 17, 2024
1 parent 926e351 commit 5b8492c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
9 changes: 9 additions & 0 deletions bindings/cpp/include/opendal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
6 changes: 3 additions & 3 deletions bindings/cpp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mod ffi {
fn new_operator(scheme: &str, configs: Vec<HashMapValue>) -> Result<Box<Operator>>;
fn read(self: &Operator, path: &str) -> Result<Vec<u8>>;
fn write(self: &Operator, path: &str, bs: &'static [u8]) -> Result<()>;
fn is_exist(self: &Operator, path: &str) -> Result<bool>;
fn exists(self: &Operator, path: &str) -> Result<bool>;
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<()>;
Expand Down Expand Up @@ -125,8 +125,8 @@ impl Operator {
Ok(self.0.write(path, bs)?)
}

fn is_exist(&self, path: &str) -> Result<bool> {
Ok(self.0.is_exist(path)?)
fn exists(&self, path: &str) -> Result<bool> {
Ok(self.0.exists(path)?)
}

fn create_dir(&self, path: &str) -> Result<()> {
Expand Down
6 changes: 5 additions & 1 deletion bindings/cpp/src/opendal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ void Operator::write(std::string_view path, const std::vector<uint8_t> &data) {
RUST_STR(path), rust::Slice<const uint8_t>(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) {
Expand Down
6 changes: 3 additions & 3 deletions bindings/cpp/tests/basic_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit 5b8492c

Please sign in to comment.