Skip to content

Commit

Permalink
feat(core/types): blocking remove_all for object storage based servic…
Browse files Browse the repository at this point in the history
…es (#4665)

feat(core/types): blocking remove_all on oss

Signed-off-by: TennyZhuang <zty0826@gmail.com>
  • Loading branch information
TennyZhuang committed Jun 1, 2024
1 parent 1c0c070 commit 38841f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
17 changes: 10 additions & 7 deletions core/src/types/operator/blocking_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,18 +846,21 @@ impl BlockingOperator {
/// # }
/// ```
pub fn remove_all(&self, path: &str) -> Result<()> {
let meta = match self.stat(path) {
Ok(metadata) => metadata,
match self.stat(path) {
Ok(metadata) => {
if metadata.mode() != EntryMode::DIR {
self.delete(path)?;
// There may still be objects prefixed with the path in some backend, so we can't return here.
}
}

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 => {}

Err(e) => return Err(e),
};

if meta.mode() != EntryMode::DIR {
return self.delete(path);
}

let obs = self.lister_with(path).recursive(true).call()?;

for v in obs {
Expand Down
9 changes: 1 addition & 8 deletions core/src/types/operator/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,14 +1416,7 @@ impl Operator {
Err(e) => return Err(e),
};

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),
};
let obs = self.lister_with(path).recursive(true).await?;

if self.info().full_capability().batch {
let mut obs = obs.try_chunks(self.limit());
Expand Down

0 comments on commit 38841f4

Please sign in to comment.