MCPcopy Create free account
hub / github.com/AI45Lab/Code / cleanup_prefix

Function cleanup_prefix

core/tests/test_s3_backend.rs:204–237  ·  view source on GitHub ↗
(client: &aws_sdk_s3::Client, bucket: &str, prefix: &str)

Source from the content-addressed store, hash-verified

202}
203
204async fn cleanup_prefix(client: &aws_sdk_s3::Client, bucket: &str, prefix: &str) {
205 let prefix = if prefix.ends_with('/') {
206 prefix.to_string()
207 } else {
208 format!("{prefix}/")
209 };
210 let mut continuation: Option<String> = None;
211 loop {
212 let mut req = client.list_objects_v2().bucket(bucket).prefix(&prefix);
213 if let Some(ref token) = continuation {
214 req = req.continuation_token(token);
215 }
216 let resp = match req.send().await {
217 Ok(r) => r,
218 Err(e) => {
219 eprintln!("cleanup list_objects_v2 failed: {e}");
220 return;
221 }
222 };
223 for obj in resp.contents() {
224 if let Some(key) = obj.key() {
225 let _ = client.delete_object().bucket(bucket).key(key).send().await;
226 }
227 }
228 if resp.is_truncated().unwrap_or(false) {
229 continuation = resp.next_continuation_token().map(|s| s.to_string());
230 if continuation.is_none() {
231 break;
232 }
233 } else {
234 break;
235 }
236 }
237}

Calls 3

prefixMethod · 0.80
bucketMethod · 0.80
sendMethod · 0.45

Tested by

no test coverage detected