You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2024/05/31 16:16:19 UTC
(opendal) branch main updated: fix(core/types): remove_all not work under object-store backend (#4659)
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 1c0c070129 fix(core/types): remove_all not work under object-store backend (#4659)
1c0c070129 is described below
commit 1c0c070129c5e4b8a40dcd89ac02d8dc5b9c156b
Author: TennyZhuang <zt...@gmail.com>
AuthorDate: Sat Jun 1 00:16:14 2024 +0800
fix(core/types): remove_all not work under object-store backend (#4659)
Signed-off-by: TennyZhuang <zt...@gmail.com>
---
core/src/types/operator/operator.rs | 28 +++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/core/src/types/operator/operator.rs b/core/src/types/operator/operator.rs
index 4685bb64e2..3984634904 100644
--- a/core/src/types/operator/operator.rs
+++ b/core/src/types/operator/operator.rs
@@ -1398,22 +1398,32 @@ impl Operator {
/// # }
/// ```
pub async fn remove_all(&self, path: &str) -> Result<()> {
- let meta = match self.stat(path).await {
+ match self.stat(path).await {
// If object exists.
- Ok(metadata) => metadata,
+ Ok(metadata) => {
+ // If the object is a file, we can delete it.
+ if metadata.mode() != EntryMode::DIR {
+ self.delete(path).await?;
+ // There may still be objects prefixed with the path in some backend, so we can't return here.
+ }
+ }
- // If object not found, return success.
- Err(e) if e.kind() == ErrorKind::NotFound => return Ok(()),
+ // If dir not found, it may be a prefix in object store like S3,
+ // and we still need to delete objects under the prefix.
+ Err(e) if e.kind() == ErrorKind::NotFound => {}
// Pass on any other error.
Err(e) => return Err(e),
};
- if meta.mode() != EntryMode::DIR {
- return self.delete(path).await;
- }
-
- let obs = self.lister_with(path).recursive(true).await?;
+ let obs = match self.lister_with(path).recursive(true).await {
+ Ok(obs) => obs,
+ Err(e) if e.kind() == ErrorKind::NotFound => {
+ // If lister still returns NotFound, we can confirm there are no objects under the prefix in any backend.
+ return Ok(());
+ }
+ Err(e) => return Err(e),
+ };
if self.info().full_capability().batch {
let mut obs = obs.try_chunks(self.limit());