@@ -5,7 +5,7 @@ use crate::ops;
5
5
use crate :: util:: errors:: CargoResult ;
6
6
use crate :: util:: interning:: InternedString ;
7
7
use crate :: util:: lev_distance;
8
- use crate :: util:: Config ;
8
+ use crate :: util:: { Config , Progress , ProgressStyle } ;
9
9
10
10
use anyhow:: Context as _;
11
11
use cargo_util:: paths;
@@ -33,8 +33,9 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
33
33
34
34
// If the doc option is set, we just want to delete the doc directory.
35
35
if opts. doc {
36
+ let mut progress = Progress :: with_style ( "Cleaning" , ProgressStyle :: Percentage , config) ;
36
37
target_dir = target_dir. join ( "doc" ) ;
37
- return rm_rf ( & target_dir. into_path_unlocked ( ) , config ) ;
38
+ return rm_rf_with_progress ( & target_dir. into_path_unlocked ( ) , & mut progress ) ;
38
39
}
39
40
40
41
let profiles = Profiles :: new ( ws, opts. requested_profile ) ?;
@@ -53,7 +54,8 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
53
54
// Note that we don't bother grabbing a lock here as we're just going to
54
55
// blow it all away anyway.
55
56
if opts. spec . is_empty ( ) {
56
- return rm_rf ( & target_dir. into_path_unlocked ( ) , config) ;
57
+ let mut progress = Progress :: with_style ( "Cleaning" , ProgressStyle :: Percentage , config) ;
58
+ return rm_rf_with_progress ( & target_dir. into_path_unlocked ( ) , & mut progress) ;
57
59
}
58
60
59
61
// Clean specific packages.
@@ -133,8 +135,10 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
133
135
}
134
136
let packages = pkg_set. get_many ( pkg_ids) ?;
135
137
136
- for pkg in packages {
138
+ let mut progress = Progress :: with_style ( "Cleaning" , ProgressStyle :: Ratio , config) ;
139
+ for ( pkg_idx, pkg) in packages. iter ( ) . enumerate ( ) {
137
140
let pkg_dir = format ! ( "{}-*" , pkg. name( ) ) ;
141
+ progress. tick_now ( pkg_idx + 1 , packages. len ( ) , & format ! ( ": {}" , pkg. name( ) ) ) ?;
138
142
139
143
// Clean fingerprints.
140
144
for ( _, layout) in & layouts_with_host {
@@ -231,6 +235,25 @@ fn rm_rf_glob(pattern: &Path, config: &Config) -> CargoResult<()> {
231
235
Ok ( ( ) )
232
236
}
233
237
238
+ fn rm_rf_with_progress ( path : & Path , progress : & mut Progress < ' _ > ) -> CargoResult < ( ) > {
239
+ let num_paths = walkdir:: WalkDir :: new ( path) . into_iter ( ) . count ( ) ;
240
+ for ( idx, entry) in walkdir:: WalkDir :: new ( path)
241
+ . contents_first ( true )
242
+ . into_iter ( )
243
+ . enumerate ( )
244
+ {
245
+ progress. tick ( std:: cmp:: min ( idx + 1 , num_paths) , num_paths, "" ) ?;
246
+ if let Ok ( entry) = entry {
247
+ if entry. file_type ( ) . is_dir ( ) {
248
+ paths:: remove_dir ( entry. path ( ) ) ?;
249
+ } else {
250
+ paths:: remove_file ( entry. path ( ) ) ?;
251
+ }
252
+ }
253
+ }
254
+ Ok ( ( ) )
255
+ }
256
+
234
257
fn rm_rf ( path : & Path , config : & Config ) -> CargoResult < ( ) > {
235
258
let m = fs:: symlink_metadata ( path) ;
236
259
if m. as_ref ( ) . map ( |s| s. is_dir ( ) ) . unwrap_or ( false ) {
0 commit comments