(client: &aws_sdk_s3::Client, bucket: &str, prefix: &str)
| 202 | } |
| 203 | |
| 204 | async 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 | } |
no test coverage detected