@@ -320,8 +320,8 @@ impl Cache {
320320 }
321321
322322 /// 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 )
325325 }
326326
327327 /// Remove a package from the cache.
@@ -379,7 +379,7 @@ impl Cache {
379379 let path = fs_err:: canonicalize ( entry. path ( ) ) ?;
380380 if !after. contains ( & path) && before. contains ( & path) {
381381 debug ! ( "Removing dangling cache entry: {}" , path. display( ) ) ;
382- summary += rm_rf ( path) ?;
382+ summary += rm_rf ( path, None ) ?;
383383 }
384384 }
385385 }
@@ -409,13 +409,13 @@ impl Cache {
409409 if CacheBucket :: iter ( ) . all ( |bucket| entry. file_name ( ) != bucket. to_str ( ) ) {
410410 let path = entry. path ( ) ;
411411 debug ! ( "Removing dangling cache bucket: {}" , path. display( ) ) ;
412- summary += rm_rf ( path) ?;
412+ summary += rm_rf ( path, None ) ?;
413413 }
414414 } else {
415415 // If the file is not a marker file, remove it.
416416 let path = entry. path ( ) ;
417417 debug ! ( "Removing dangling cache bucket: {}" , path. display( ) ) ;
418- summary += rm_rf ( path) ?;
418+ summary += rm_rf ( path, None ) ?;
419419 }
420420 }
421421
@@ -427,7 +427,7 @@ impl Cache {
427427 let entry = entry?;
428428 let path = fs_err:: canonicalize ( entry. path ( ) ) ?;
429429 debug ! ( "Removing dangling cache environment: {}" , path. display( ) ) ;
430- summary += rm_rf ( path) ?;
430+ summary += rm_rf ( path, None ) ?;
431431 }
432432 }
433433 Err ( err) if err. kind ( ) == io:: ErrorKind :: NotFound => ( ) ,
@@ -444,7 +444,7 @@ impl Cache {
444444 let path = fs_err:: canonicalize ( entry. path ( ) ) ?;
445445 if path. is_dir ( ) {
446446 debug ! ( "Removing unzipped wheel entry: {}" , path. display( ) ) ;
447- summary += rm_rf ( path) ?;
447+ summary += rm_rf ( path, None ) ?;
448448 }
449449 }
450450 }
@@ -472,10 +472,10 @@ impl Cache {
472472
473473 if path. is_dir ( ) {
474474 debug ! ( "Removing unzipped built wheel entry: {}" , path. display( ) ) ;
475- summary += rm_rf ( path) ?;
475+ summary += rm_rf ( path, None ) ?;
476476 } else if path. is_symlink ( ) {
477477 debug ! ( "Removing unzipped built wheel entry: {}" , path. display( ) ) ;
478- summary += rm_rf ( path) ?;
478+ summary += rm_rf ( path, None ) ?;
479479 }
480480 }
481481 }
@@ -505,7 +505,7 @@ impl Cache {
505505 let path = fs_err:: canonicalize ( entry. path ( ) ) ?;
506506 if !references. contains ( & path) {
507507 debug ! ( "Removing dangling cache archive: {}" , path. display( ) ) ;
508- summary += rm_rf ( path) ?;
508+ summary += rm_rf ( path, None ) ?;
509509 }
510510 }
511511 }
@@ -517,6 +517,15 @@ impl Cache {
517517 }
518518}
519519
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+
520529/// The different kinds of data in the cache are stored in different bucket, which in our case
521530/// are subdirectories of the cache root.
522531#[ derive( Debug , Clone , Copy , Eq , PartialEq , Hash ) ]
@@ -800,32 +809,32 @@ impl CacheBucket {
800809 Self :: Wheels => {
801810 // For `pypi` wheels, we expect a directory per package (indexed by name).
802811 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 ) ?;
804813
805814 // For alternate indices, we expect a directory for every index (under an `index`
806815 // subdirectory), followed by a directory per package (indexed by name).
807816 let root = cache. bucket ( self ) . join ( WheelCacheKind :: Index ) ;
808817 for directory in directories ( root) {
809- summary += rm_rf ( directory. join ( name. to_string ( ) ) ) ?;
818+ summary += rm_rf ( directory. join ( name. to_string ( ) ) , None ) ?;
810819 }
811820
812821 // For direct URLs, we expect a directory for every URL, followed by a
813822 // directory per package (indexed by name).
814823 let root = cache. bucket ( self ) . join ( WheelCacheKind :: Url ) ;
815824 for directory in directories ( root) {
816- summary += rm_rf ( directory. join ( name. to_string ( ) ) ) ?;
825+ summary += rm_rf ( directory. join ( name. to_string ( ) ) , None ) ?;
817826 }
818827 }
819828 Self :: SourceDistributions => {
820829 // For `pypi` wheels, we expect a directory per package (indexed by name).
821830 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 ) ?;
823832
824833 // For alternate indices, we expect a directory for every index (under an `index`
825834 // subdirectory), followed by a directory per package (indexed by name).
826835 let root = cache. bucket ( self ) . join ( WheelCacheKind :: Index ) ;
827836 for directory in directories ( root) {
828- summary += rm_rf ( directory. join ( name. to_string ( ) ) ) ?;
837+ summary += rm_rf ( directory. join ( name. to_string ( ) ) , None ) ?;
829838 }
830839
831840 // For direct URLs, we expect a directory for every URL, followed by a
@@ -834,7 +843,7 @@ impl CacheBucket {
834843 let root = cache. bucket ( self ) . join ( WheelCacheKind :: Url ) ;
835844 for url in directories ( root) {
836845 if directories ( & url) . any ( |version| is_match ( & version, name) ) {
837- summary += rm_rf ( url) ?;
846+ summary += rm_rf ( url, None ) ?;
838847 }
839848 }
840849
@@ -844,7 +853,7 @@ impl CacheBucket {
844853 let root = cache. bucket ( self ) . join ( WheelCacheKind :: Path ) ;
845854 for path in directories ( root) {
846855 if directories ( & path) . any ( |version| is_match ( & version, name) ) {
847- summary += rm_rf ( path) ?;
856+ summary += rm_rf ( path, None ) ?;
848857 }
849858 }
850859
@@ -855,28 +864,28 @@ impl CacheBucket {
855864 for repository in directories ( root) {
856865 for sha in directories ( repository) {
857866 if is_match ( & sha, name) {
858- summary += rm_rf ( sha) ?;
867+ summary += rm_rf ( sha, None ) ?;
859868 }
860869 }
861870 }
862871 }
863872 Self :: Simple => {
864873 // For `pypi` wheels, we expect a rkyv file per package, indexed by name.
865874 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 ) ?;
867876
868877 // For alternate indices, we expect a directory for every index (under an `index`
869878 // subdirectory), followed by a directory per package (indexed by name).
870879 let root = cache. bucket ( self ) . join ( WheelCacheKind :: Index ) ;
871880 for directory in directories ( root) {
872- summary += rm_rf ( directory. join ( format ! ( "{name}.rkyv" ) ) ) ?;
881+ summary += rm_rf ( directory. join ( format ! ( "{name}.rkyv" ) ) , None ) ?;
873882 }
874883 }
875884 Self :: FlatIndex => {
876885 // We can't know if the flat index includes a package, so we just remove the entire
877886 // cache entry.
878887 let root = cache. bucket ( self ) ;
879- summary += rm_rf ( root) ?;
888+ summary += rm_rf ( root, None ) ?;
880889 }
881890 Self :: Git => {
882891 // Nothing to do.
0 commit comments