Skip to content

Commit cda25cb

Browse files
committed
storage: return deleted paths from mass deletion methods
1 parent 86c52ae commit cda25cb

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

src/storage.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,16 @@ impl Storage {
213213
apply_cdn_prefix(&self.cdn_prefix, &feed_id.into()).replace('+', "%2B")
214214
}
215215

216+
/// Deletes all crate files for the given crate, returning the paths that were deleted.
216217
#[instrument(skip(self))]
217-
pub async fn delete_all_crate_files(&self, name: &str) -> Result<()> {
218+
pub async fn delete_all_crate_files(&self, name: &str) -> Result<Vec<Path>> {
218219
let prefix = format!("{PREFIX_CRATES}/{name}").into();
219220
self.delete_all_with_prefix(&prefix).await
220221
}
221222

223+
/// Deletes all READMEs for the given crate, returning the paths that were deleted.
222224
#[instrument(skip(self))]
223-
pub async fn delete_all_readmes(&self, name: &str) -> Result<()> {
225+
pub async fn delete_all_readmes(&self, name: &str) -> Result<Vec<Path>> {
224226
let prefix = format!("{PREFIX_READMES}/{name}").into();
225227
self.delete_all_with_prefix(&prefix).await
226228
}
@@ -333,16 +335,24 @@ impl Storage {
333335
self.store.clone()
334336
}
335337

336-
async fn delete_all_with_prefix(&self, prefix: &Path) -> Result<()> {
338+
async fn delete_all_with_prefix(&self, prefix: &Path) -> Result<Vec<Path>> {
337339
let objects = self.store.list(Some(prefix));
338-
let locations = objects.map(|meta| meta.map(|m| m.location)).boxed();
340+
let mut paths = Vec::new();
341+
let locations = objects
342+
.map(|meta| meta.map(|m| m.location))
343+
.inspect(|r| {
344+
if let Ok(path) = r {
345+
paths.push(path.clone());
346+
}
347+
})
348+
.boxed();
339349

340350
self.store
341351
.delete_stream(locations)
342352
.try_collect::<Vec<_>>()
343353
.await?;
344354

345-
Ok(())
355+
Ok(paths)
346356
}
347357

348358
fn attrs(&self, slice: impl IntoIterator<Item = (Attribute, &'static str)>) -> Attributes {
@@ -505,7 +515,14 @@ mod tests {
505515
async fn delete_all_crate_files() {
506516
let storage = prepare().await;
507517

508-
storage.delete_all_crate_files("foo").await.unwrap();
518+
let deleted_files = storage.delete_all_crate_files("foo").await.unwrap();
519+
assert_eq!(
520+
deleted_files,
521+
vec![
522+
"crates/foo/foo-1.0.0.crate".into(),
523+
"crates/foo/foo-1.2.3.crate".into(),
524+
]
525+
);
509526

510527
let expected_files = vec![
511528
"crates/bar/bar-2.0.0.crate",
@@ -520,7 +537,14 @@ mod tests {
520537
async fn delete_all_readmes() {
521538
let storage = prepare().await;
522539

523-
storage.delete_all_readmes("foo").await.unwrap();
540+
let deleted_files = storage.delete_all_readmes("foo").await.unwrap();
541+
assert_eq!(
542+
deleted_files,
543+
vec![
544+
"readmes/foo/foo-1.0.0.html".into(),
545+
"readmes/foo/foo-1.2.3.html".into(),
546+
]
547+
);
524548

525549
let expected_files = vec![
526550
"crates/bar/bar-2.0.0.crate",

0 commit comments

Comments
 (0)