This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 926e351b0d refactor(types/operator): rename is_exist to exists (#5193)
926e351b0d is described below
commit 926e351b0d1f0d81368274511eef546093d4c979
Author: Zan Pan <[email protected]>
AuthorDate: Thu Oct 17 15:17:43 2024 +0800
refactor(types/operator): rename is_exist to exists (#5193)
---
.../src/main.rs | 2 +-
core/src/types/operator/blocking_operator.rs | 25 ++++++++++++++++++++
core/src/types/operator/operator.rs | 27 ++++++++++++++++++++++
core/tests/behavior/async_delete.rs | 12 +++++-----
core/tests/behavior/async_list.rs | 2 +-
core/tests/behavior/async_write.rs | 4 ++--
core/tests/behavior/blocking_delete.rs | 4 ++--
core/tests/behavior/blocking_list.rs | 2 +-
integrations/dav-server/src/fs.rs | 4 ++--
integrations/parquet/src/async_writer.rs | 2 +-
10 files changed, 68 insertions(+), 16 deletions(-)
diff --git a/core/edge/s3_aws_assume_role_with_web_identity/src/main.rs
b/core/edge/s3_aws_assume_role_with_web_identity/src/main.rs
index b5a5bc6488..367e786ce2 100644
--- a/core/edge/s3_aws_assume_role_with_web_identity/src/main.rs
+++ b/core/edge/s3_aws_assume_role_with_web_identity/src/main.rs
@@ -25,7 +25,7 @@ async fn main() -> Result<()> {
assert_eq!(op.info().scheme(), Scheme::S3);
let result = op
- .is_exist(&uuid::Uuid::new_v4().to_string())
+ .exists(&uuid::Uuid::new_v4().to_string())
.await
.expect("this operation should never return error");
assert!(!result, "the file must be not exist");
diff --git a/core/src/types/operator/blocking_operator.rs
b/core/src/types/operator/blocking_operator.rs
index 3e5c5bab8f..47f48d0165 100644
--- a/core/src/types/operator/blocking_operator.rs
+++ b/core/src/types/operator/blocking_operator.rs
@@ -267,6 +267,30 @@ impl BlockingOperator {
))
}
+ /// Check if this path exists or not.
+ ///
+ /// # Example
+ ///
+ /// ```no_run
+ /// use anyhow::Result;
+ /// use opendal::BlockingOperator;
+ /// fn test(op: BlockingOperator) -> Result<()> {
+ /// let _ = op.exists("test")?;
+ ///
+ /// Ok(())
+ /// }
+ /// ```
+ pub fn exists(&self, path: &str) -> Result<bool> {
+ let r = self.stat(path);
+ match r {
+ Ok(_) => Ok(true),
+ Err(err) => match err.kind() {
+ ErrorKind::NotFound => Ok(false),
+ _ => Err(err),
+ },
+ }
+ }
+
/// Check if this path exists or not.
///
/// # Example
@@ -280,6 +304,7 @@ impl BlockingOperator {
/// Ok(())
/// }
/// ```
+ #[deprecated(note = "rename to `exists` for consistence with
`std::fs::exists`")]
pub fn is_exist(&self, path: &str) -> Result<bool> {
let r = self.stat(path);
match r {
diff --git a/core/src/types/operator/operator.rs
b/core/src/types/operator/operator.rs
index e2451a3ad2..e58c60303f 100644
--- a/core/src/types/operator/operator.rs
+++ b/core/src/types/operator/operator.rs
@@ -330,6 +330,32 @@ impl Operator {
)
}
+ /// Check if this path exists or not.
+ ///
+ /// # Example
+ ///
+ /// ```
+ /// use anyhow::Result;
+ /// use futures::io;
+ /// use opendal::Operator;
+ ///
+ /// async fn test(op: Operator) -> Result<()> {
+ /// let _ = op.exists("test").await?;
+ ///
+ /// Ok(())
+ /// }
+ /// ```
+ pub async fn exists(&self, path: &str) -> Result<bool> {
+ let r = self.stat(path).await;
+ match r {
+ Ok(_) => Ok(true),
+ Err(err) => match err.kind() {
+ ErrorKind::NotFound => Ok(false),
+ _ => Err(err),
+ },
+ }
+ }
+
/// Check if this path exists or not.
///
/// # Example
@@ -345,6 +371,7 @@ impl Operator {
/// Ok(())
/// }
/// ```
+ #[deprecated(note = "rename to `exists` for consistence with
`std::fs::exists`")]
pub async fn is_exist(&self, path: &str) -> Result<bool> {
let r = self.stat(path).await;
match r {
diff --git a/core/tests/behavior/async_delete.rs
b/core/tests/behavior/async_delete.rs
index 0225f50ab6..9f055b67a4 100644
--- a/core/tests/behavior/async_delete.rs
+++ b/core/tests/behavior/async_delete.rs
@@ -55,7 +55,7 @@ pub async fn test_delete_file(op: Operator) -> Result<()> {
op.delete(&path).await?;
// Stat it again to check.
- assert!(!op.is_exist(&path).await?);
+ assert!(!op.exists(&path).await?);
Ok(())
}
@@ -96,7 +96,7 @@ pub async fn test_delete_with_special_chars(op: Operator) ->
Result<()> {
op.delete(&path).await?;
// Stat it again to check.
- assert!(!op.is_exist(&path).await?);
+ assert!(!op.exists(&path).await?);
Ok(())
}
@@ -121,7 +121,7 @@ pub async fn test_remove_one_file(op: Operator) ->
Result<()> {
op.remove(vec![path.clone()]).await?;
// Stat it again to check.
- assert!(!op.is_exist(&path).await?);
+ assert!(!op.exists(&path).await?);
op.write(&format!("/{path}"), content)
.await
@@ -130,7 +130,7 @@ pub async fn test_remove_one_file(op: Operator) ->
Result<()> {
op.remove(vec![path.clone()]).await?;
// Stat it again to check.
- assert!(!op.is_exist(&path).await?);
+ assert!(!op.exists(&path).await?);
Ok(())
}
@@ -163,7 +163,7 @@ pub async fn test_delete_stream(op: Operator) -> Result<()>
{
// Stat it again to check.
for path in expected.iter() {
assert!(
- !op.is_exist(&format!("{dir}/{path}")).await?,
+ !op.exists(&format!("{dir}/{path}")).await?,
"{path} should be removed"
)
}
@@ -229,7 +229,7 @@ pub async fn test_delete_with_version(op: Operator) ->
Result<()> {
let version = meta.version().expect("must have version");
op.delete(path.as_str()).await.expect("delete must success");
- assert!(!op.is_exist(path.as_str()).await?);
+ assert!(!op.exists(path.as_str()).await?);
// After a simple delete, the data can still be accessed using its version.
let meta = op
diff --git a/core/tests/behavior/async_list.rs
b/core/tests/behavior/async_list.rs
index ba862f7025..69157cdc15 100644
--- a/core/tests/behavior/async_list.rs
+++ b/core/tests/behavior/async_list.rs
@@ -655,7 +655,7 @@ pub async fn test_remove_all(op: Operator) -> Result<()> {
continue;
}
assert!(
- !op.is_exist(&format!("{parent}/{path}")).await?,
+ !op.exists(&format!("{parent}/{path}")).await?,
"{parent}/{path} should be removed"
)
}
diff --git a/core/tests/behavior/async_write.rs
b/core/tests/behavior/async_write.rs
index 9bfdc15059..3ccf42e715 100644
--- a/core/tests/behavior/async_write.rs
+++ b/core/tests/behavior/async_write.rs
@@ -255,7 +255,7 @@ pub async fn test_writer_abort(op: Operator) -> Result<()> {
}
// Aborted writer should not write actual file.
- assert!(!op.is_exist(&path).await?);
+ assert!(!op.exists(&path).await?);
Ok(())
}
@@ -282,7 +282,7 @@ pub async fn test_writer_abort_with_concurrent(op:
Operator) -> Result<()> {
}
// Aborted writer should not write actual file.
- assert!(!op.is_exist(&path).await?);
+ assert!(!op.exists(&path).await?);
Ok(())
}
diff --git a/core/tests/behavior/blocking_delete.rs
b/core/tests/behavior/blocking_delete.rs
index f5d1dd3169..79e0ef24db 100644
--- a/core/tests/behavior/blocking_delete.rs
+++ b/core/tests/behavior/blocking_delete.rs
@@ -52,7 +52,7 @@ pub fn test_blocking_delete_file(op: BlockingOperator) ->
Result<()> {
op.delete(&path)?;
// Stat it again to check.
- assert!(!op.is_exist(&path)?);
+ assert!(!op.exists(&path)?);
Ok(())
}
@@ -67,7 +67,7 @@ pub fn test_blocking_remove_one_file(op: BlockingOperator) ->
Result<()> {
op.remove(vec![path.clone()])?;
// Stat it again to check.
- assert!(!op.is_exist(&path)?);
+ assert!(!op.exists(&path)?);
Ok(())
}
diff --git a/core/tests/behavior/blocking_list.rs
b/core/tests/behavior/blocking_list.rs
index dd0647090e..225d19cad4 100644
--- a/core/tests/behavior/blocking_list.rs
+++ b/core/tests/behavior/blocking_list.rs
@@ -196,7 +196,7 @@ pub fn test_blocking_remove_all(op: BlockingOperator) ->
Result<()> {
continue;
}
assert!(
- !op.is_exist(&format!("{parent}/{path}"))?,
+ !op.exists(&format!("{parent}/{path}"))?,
"{parent}/{path} should be removed"
)
}
diff --git a/integrations/dav-server/src/fs.rs
b/integrations/dav-server/src/fs.rs
index a1096bf47a..80444d8c67 100644
--- a/integrations/dav-server/src/fs.rs
+++ b/integrations/dav-server/src/fs.rs
@@ -119,7 +119,7 @@ impl DavFileSystem for OpendalFs {
// During MKCOL processing, a server MUST make the Request-URI a
member of its parent collection, unless the Request-URI is "/". If no such
ancestor exists, the method MUST fail.
// refer to
https://datatracker.ietf.org/doc/html/rfc2518#section-8.3.1
let parent = Path::new(&path).parent().unwrap();
- match self.op.is_exist(parent.to_str().unwrap()).await {
+ match self.op.exists(parent.to_str().unwrap()).await {
Ok(exist) => {
if !exist && parent != Path::new("/") {
return Err(FsError::NotFound);
@@ -132,7 +132,7 @@ impl DavFileSystem for OpendalFs {
let path = path.as_str();
// check if the given path is exist (MKCOL on existing collection
should fail (RFC2518:8.3.1))
- let exist = self.op.is_exist(path).await;
+ let exist = self.op.exists(path).await;
match exist {
Ok(exist) => match exist {
true => Err(FsError::Exists),
diff --git a/integrations/parquet/src/async_writer.rs
b/integrations/parquet/src/async_writer.rs
index 47266564c3..7f4ab16e5c 100644
--- a/integrations/parquet/src/async_writer.rs
+++ b/integrations/parquet/src/async_writer.rs
@@ -137,7 +137,7 @@ mod tests {
writer.write(bytes).await.unwrap();
drop(writer);
- let exist = op.is_exist(path).await.unwrap();
+ let exist = op.exists(path).await.unwrap();
assert!(!exist);
}