Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bindings/cpp): rename is_exist to exists as core did #5198

Merged
merged 1 commit into from
Oct 18, 2024
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
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
Loading