@@ -20,6 +20,7 @@ use walkdir::WalkDir;
20
20
21
21
#[ cfg( any( feature = "async-std" , feature = "tokio" ) ) ]
22
22
use crate :: async_lib:: { AsyncBufReadExt , AsyncWriteExt } ;
23
+ use crate :: content:: path:: content_path;
23
24
use crate :: errors:: { IoErrorExt , Result } ;
24
25
use crate :: put:: WriteOpts ;
25
26
@@ -407,6 +408,11 @@ impl RemoveOpts {
407
408
if !self . remove_fully {
408
409
delete ( cache. as_ref ( ) , key. as_ref ( ) )
409
410
} else {
411
+ if let Some ( meta) = crate :: metadata_sync ( cache. as_ref ( ) , key. as_ref ( ) ) ? {
412
+ let content = content_path ( cache. as_ref ( ) , & meta. integrity ) ;
413
+ fs:: remove_file ( & content)
414
+ . with_context ( || format ! ( "Failed to remove content at {content:?}" ) ) ?;
415
+ }
410
416
let bucket = bucket_path ( cache. as_ref ( ) , key. as_ref ( ) ) ;
411
417
fs:: remove_file ( & bucket)
412
418
. with_context ( || format ! ( "Failed to remove bucket at {bucket:?}" ) )
@@ -423,6 +429,12 @@ impl RemoveOpts {
423
429
if !self . remove_fully {
424
430
delete_async ( cache. as_ref ( ) , key. as_ref ( ) ) . await
425
431
} else {
432
+ if let Some ( meta) = crate :: metadata ( cache. as_ref ( ) , key. as_ref ( ) ) . await ? {
433
+ let content = content_path ( cache. as_ref ( ) , & meta. integrity ) ;
434
+ crate :: async_lib:: remove_file ( & content)
435
+ . await
436
+ . with_context ( || format ! ( "Failed to remove content at {content:?}" ) ) ?;
437
+ }
426
438
let bucket = bucket_path ( cache. as_ref ( ) , key. as_ref ( ) ) ;
427
439
crate :: async_lib:: remove_file ( & bucket)
428
440
. await
@@ -536,6 +548,44 @@ mod tests {
536
548
assert_eq ! ( find( & dir, "hello" ) . unwrap( ) , None ) ;
537
549
}
538
550
551
+ #[ test]
552
+ fn delete_fully ( ) {
553
+ let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
554
+ let dir = tmp. path ( ) . to_owned ( ) ;
555
+ let content = content_path ( & dir, & "sha1-deadbeef" . parse ( ) . unwrap ( ) ) ;
556
+ fs:: create_dir_all ( content. parent ( ) . unwrap ( ) ) . unwrap ( ) ;
557
+ fs:: write ( content. as_path ( ) , "hello" ) . unwrap ( ) ;
558
+ let sri: Integrity = "sha1-deadbeef" . parse ( ) . unwrap ( ) ;
559
+ let time = 1_234_567 ;
560
+ insert ( & dir, "hello" , WriteOpts :: new ( ) . integrity ( sri) . time ( time) ) . unwrap ( ) ;
561
+ RemoveOpts :: new ( )
562
+ . remove_fully ( true )
563
+ . remove_sync ( & dir, "hello" )
564
+ . unwrap ( ) ;
565
+ assert_eq ! ( find( & dir, "hello" ) . unwrap( ) , None ) ;
566
+ assert ! ( !content. exists( ) ) ;
567
+ }
568
+
569
+ #[ cfg( any( feature = "async-std" , feature = "tokio" ) ) ]
570
+ #[ async_test]
571
+ async fn delete_fully_async ( ) {
572
+ let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
573
+ let dir = tmp. path ( ) . to_owned ( ) ;
574
+ let content = content_path ( & dir, & "sha1-deadbeef" . parse ( ) . unwrap ( ) ) ;
575
+ fs:: create_dir_all ( content. parent ( ) . unwrap ( ) ) . unwrap ( ) ;
576
+ fs:: write ( content. as_path ( ) , "hello" ) . unwrap ( ) ;
577
+ let sri: Integrity = "sha1-deadbeef" . parse ( ) . unwrap ( ) ;
578
+ let time = 1_234_567 ;
579
+ insert ( & dir, "hello" , WriteOpts :: new ( ) . integrity ( sri) . time ( time) ) . unwrap ( ) ;
580
+ RemoveOpts :: new ( )
581
+ . remove_fully ( true )
582
+ . remove ( & dir, "hello" )
583
+ . await
584
+ . unwrap ( ) ;
585
+ assert_eq ! ( find( & dir, "hello" ) . unwrap( ) , None ) ;
586
+ assert ! ( !content. exists( ) ) ;
587
+ }
588
+
539
589
#[ test]
540
590
fn round_trip ( ) {
541
591
let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
0 commit comments