@@ -320,8 +320,8 @@ impl Cache {
320
320
}
321
321
322
322
/// Clear the cache, removing all entries.
323
- pub fn clear ( & self ) -> Result < Removal , io:: Error > {
324
- rm_rf ( & self . root )
323
+ pub fn clear ( & self , reporter : Option < & dyn CleanReporter > ) -> Result < Removal , io:: Error > {
324
+ rm_rf ( & self . root , reporter )
325
325
}
326
326
327
327
/// Remove a package from the cache.
@@ -379,7 +379,7 @@ impl Cache {
379
379
let path = fs_err:: canonicalize ( entry. path ( ) ) ?;
380
380
if !after. contains ( & path) && before. contains ( & path) {
381
381
debug ! ( "Removing dangling cache entry: {}" , path. display( ) ) ;
382
- summary += rm_rf ( path) ?;
382
+ summary += rm_rf ( path, None ) ?;
383
383
}
384
384
}
385
385
}
@@ -409,13 +409,13 @@ impl Cache {
409
409
if CacheBucket :: iter ( ) . all ( |bucket| entry. file_name ( ) != bucket. to_str ( ) ) {
410
410
let path = entry. path ( ) ;
411
411
debug ! ( "Removing dangling cache bucket: {}" , path. display( ) ) ;
412
- summary += rm_rf ( path) ?;
412
+ summary += rm_rf ( path, None ) ?;
413
413
}
414
414
} else {
415
415
// If the file is not a marker file, remove it.
416
416
let path = entry. path ( ) ;
417
417
debug ! ( "Removing dangling cache bucket: {}" , path. display( ) ) ;
418
- summary += rm_rf ( path) ?;
418
+ summary += rm_rf ( path, None ) ?;
419
419
}
420
420
}
421
421
@@ -427,7 +427,7 @@ impl Cache {
427
427
let entry = entry?;
428
428
let path = fs_err:: canonicalize ( entry. path ( ) ) ?;
429
429
debug ! ( "Removing dangling cache environment: {}" , path. display( ) ) ;
430
- summary += rm_rf ( path) ?;
430
+ summary += rm_rf ( path, None ) ?;
431
431
}
432
432
}
433
433
Err ( err) if err. kind ( ) == io:: ErrorKind :: NotFound => ( ) ,
@@ -444,7 +444,7 @@ impl Cache {
444
444
let path = fs_err:: canonicalize ( entry. path ( ) ) ?;
445
445
if path. is_dir ( ) {
446
446
debug ! ( "Removing unzipped wheel entry: {}" , path. display( ) ) ;
447
- summary += rm_rf ( path) ?;
447
+ summary += rm_rf ( path, None ) ?;
448
448
}
449
449
}
450
450
}
@@ -472,10 +472,10 @@ impl Cache {
472
472
473
473
if path. is_dir ( ) {
474
474
debug ! ( "Removing unzipped built wheel entry: {}" , path. display( ) ) ;
475
- summary += rm_rf ( path) ?;
475
+ summary += rm_rf ( path, None ) ?;
476
476
} else if path. is_symlink ( ) {
477
477
debug ! ( "Removing unzipped built wheel entry: {}" , path. display( ) ) ;
478
- summary += rm_rf ( path) ?;
478
+ summary += rm_rf ( path, None ) ?;
479
479
}
480
480
}
481
481
}
@@ -505,7 +505,7 @@ impl Cache {
505
505
let path = fs_err:: canonicalize ( entry. path ( ) ) ?;
506
506
if !references. contains ( & path) {
507
507
debug ! ( "Removing dangling cache archive: {}" , path. display( ) ) ;
508
- summary += rm_rf ( path) ?;
508
+ summary += rm_rf ( path, None ) ?;
509
509
}
510
510
}
511
511
}
@@ -517,6 +517,15 @@ impl Cache {
517
517
}
518
518
}
519
519
520
+ pub trait CleanReporter : Send + Sync {
521
+ /// Called after one file or directory is removed.
522
+ fn on_clean ( & self ) ;
523
+ /// Called after a package is cleaned.
524
+ fn on_clean_package ( & self , _package : & str , _removal : & Removal ) { }
525
+ /// Called after all files and directories are removed.
526
+ fn on_complete ( & self ) ;
527
+ }
528
+
520
529
/// The different kinds of data in the cache are stored in different bucket, which in our case
521
530
/// are subdirectories of the cache root.
522
531
#[ derive( Debug , Clone , Copy , Eq , PartialEq , Hash ) ]
@@ -800,32 +809,32 @@ impl CacheBucket {
800
809
Self :: Wheels => {
801
810
// For `pypi` wheels, we expect a directory per package (indexed by name).
802
811
let root = cache. bucket ( self ) . join ( WheelCacheKind :: Pypi ) ;
803
- summary += rm_rf ( root. join ( name. to_string ( ) ) ) ?;
812
+ summary += rm_rf ( root. join ( name. to_string ( ) ) , None ) ?;
804
813
805
814
// For alternate indices, we expect a directory for every index (under an `index`
806
815
// subdirectory), followed by a directory per package (indexed by name).
807
816
let root = cache. bucket ( self ) . join ( WheelCacheKind :: Index ) ;
808
817
for directory in directories ( root) {
809
- summary += rm_rf ( directory. join ( name. to_string ( ) ) ) ?;
818
+ summary += rm_rf ( directory. join ( name. to_string ( ) ) , None ) ?;
810
819
}
811
820
812
821
// For direct URLs, we expect a directory for every URL, followed by a
813
822
// directory per package (indexed by name).
814
823
let root = cache. bucket ( self ) . join ( WheelCacheKind :: Url ) ;
815
824
for directory in directories ( root) {
816
- summary += rm_rf ( directory. join ( name. to_string ( ) ) ) ?;
825
+ summary += rm_rf ( directory. join ( name. to_string ( ) ) , None ) ?;
817
826
}
818
827
}
819
828
Self :: SourceDistributions => {
820
829
// For `pypi` wheels, we expect a directory per package (indexed by name).
821
830
let root = cache. bucket ( self ) . join ( WheelCacheKind :: Pypi ) ;
822
- summary += rm_rf ( root. join ( name. to_string ( ) ) ) ?;
831
+ summary += rm_rf ( root. join ( name. to_string ( ) ) , None ) ?;
823
832
824
833
// For alternate indices, we expect a directory for every index (under an `index`
825
834
// subdirectory), followed by a directory per package (indexed by name).
826
835
let root = cache. bucket ( self ) . join ( WheelCacheKind :: Index ) ;
827
836
for directory in directories ( root) {
828
- summary += rm_rf ( directory. join ( name. to_string ( ) ) ) ?;
837
+ summary += rm_rf ( directory. join ( name. to_string ( ) ) , None ) ?;
829
838
}
830
839
831
840
// For direct URLs, we expect a directory for every URL, followed by a
@@ -834,7 +843,7 @@ impl CacheBucket {
834
843
let root = cache. bucket ( self ) . join ( WheelCacheKind :: Url ) ;
835
844
for url in directories ( root) {
836
845
if directories ( & url) . any ( |version| is_match ( & version, name) ) {
837
- summary += rm_rf ( url) ?;
846
+ summary += rm_rf ( url, None ) ?;
838
847
}
839
848
}
840
849
@@ -844,7 +853,7 @@ impl CacheBucket {
844
853
let root = cache. bucket ( self ) . join ( WheelCacheKind :: Path ) ;
845
854
for path in directories ( root) {
846
855
if directories ( & path) . any ( |version| is_match ( & version, name) ) {
847
- summary += rm_rf ( path) ?;
856
+ summary += rm_rf ( path, None ) ?;
848
857
}
849
858
}
850
859
@@ -855,28 +864,28 @@ impl CacheBucket {
855
864
for repository in directories ( root) {
856
865
for sha in directories ( repository) {
857
866
if is_match ( & sha, name) {
858
- summary += rm_rf ( sha) ?;
867
+ summary += rm_rf ( sha, None ) ?;
859
868
}
860
869
}
861
870
}
862
871
}
863
872
Self :: Simple => {
864
873
// For `pypi` wheels, we expect a rkyv file per package, indexed by name.
865
874
let root = cache. bucket ( self ) . join ( WheelCacheKind :: Pypi ) ;
866
- summary += rm_rf ( root. join ( format ! ( "{name}.rkyv" ) ) ) ?;
875
+ summary += rm_rf ( root. join ( format ! ( "{name}.rkyv" ) ) , None ) ?;
867
876
868
877
// For alternate indices, we expect a directory for every index (under an `index`
869
878
// subdirectory), followed by a directory per package (indexed by name).
870
879
let root = cache. bucket ( self ) . join ( WheelCacheKind :: Index ) ;
871
880
for directory in directories ( root) {
872
- summary += rm_rf ( directory. join ( format ! ( "{name}.rkyv" ) ) ) ?;
881
+ summary += rm_rf ( directory. join ( format ! ( "{name}.rkyv" ) ) , None ) ?;
873
882
}
874
883
}
875
884
Self :: FlatIndex => {
876
885
// We can't know if the flat index includes a package, so we just remove the entire
877
886
// cache entry.
878
887
let root = cache. bucket ( self ) ;
879
- summary += rm_rf ( root) ?;
888
+ summary += rm_rf ( root, None ) ?;
880
889
}
881
890
Self :: Git => {
882
891
// Nothing to do.
0 commit comments