@@ -213,14 +213,16 @@ impl Storage {
213
213
apply_cdn_prefix ( & self . cdn_prefix , & feed_id. into ( ) ) . replace ( '+' , "%2B" )
214
214
}
215
215
216
+ /// Deletes all crate files for the given crate, returning the paths that were deleted.
216
217
#[ 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 > > {
218
219
let prefix = format ! ( "{PREFIX_CRATES}/{name}" ) . into ( ) ;
219
220
self . delete_all_with_prefix ( & prefix) . await
220
221
}
221
222
223
+ /// Deletes all READMEs for the given crate, returning the paths that were deleted.
222
224
#[ 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 > > {
224
226
let prefix = format ! ( "{PREFIX_READMES}/{name}" ) . into ( ) ;
225
227
self . delete_all_with_prefix ( & prefix) . await
226
228
}
@@ -333,16 +335,24 @@ impl Storage {
333
335
self . store . clone ( )
334
336
}
335
337
336
- async fn delete_all_with_prefix ( & self , prefix : & Path ) -> Result < ( ) > {
338
+ async fn delete_all_with_prefix ( & self , prefix : & Path ) -> Result < Vec < Path > > {
337
339
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 ( ) ;
339
349
340
350
self . store
341
351
. delete_stream ( locations)
342
352
. try_collect :: < Vec < _ > > ( )
343
353
. await ?;
344
354
345
- Ok ( ( ) )
355
+ Ok ( paths )
346
356
}
347
357
348
358
fn attrs ( & self , slice : impl IntoIterator < Item = ( Attribute , & ' static str ) > ) -> Attributes {
@@ -505,7 +515,14 @@ mod tests {
505
515
async fn delete_all_crate_files ( ) {
506
516
let storage = prepare ( ) . await ;
507
517
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
+ ) ;
509
526
510
527
let expected_files = vec ! [
511
528
"crates/bar/bar-2.0.0.crate" ,
@@ -520,7 +537,14 @@ mod tests {
520
537
async fn delete_all_readmes ( ) {
521
538
let storage = prepare ( ) . await ;
522
539
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
+ ) ;
524
548
525
549
let expected_files = vec ! [
526
550
"crates/bar/bar-2.0.0.crate" ,
0 commit comments