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(core/types): blocking remove_all for object storage based services #4665

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