@@ -171,6 +171,8 @@ fn clean_specs(
171
171
172
172
clean_ctx. progress = Box :: new ( CleaningPackagesBar :: new ( clean_ctx. gctx , packages. len ( ) ) ) ;
173
173
174
+ // Try to reduce the amount of times we iterate over the same target directory by storing away
175
+ // the directories we've iterated over (and cleaned for a given package).
174
176
let mut cleaned_packages: HashMap < _ , HashSet < _ > > = HashMap :: default ( ) ;
175
177
for pkg in packages {
176
178
let pkg_dir = format ! ( "{}-*" , pkg. name( ) ) ;
@@ -236,11 +238,8 @@ fn clean_specs(
236
238
clean_ctx. rm_rf ( & dep_info) ?;
237
239
}
238
240
}
239
- // Remove dep-info file generated by rustc. It is not tracked in
240
- // file_types. It does not have a prefix.
241
241
let unhashed_dep_info = dir. join ( format ! ( "{}.d" , crate_name) ) ;
242
242
clean_ctx. rm_rf ( & unhashed_dep_info) ?;
243
- // Remove split-debuginfo files generated by rustc.
244
243
245
244
if !dir_glob_str. ends_with ( std:: path:: MAIN_SEPARATOR ) {
246
245
dir_glob_str. push ( std:: path:: MAIN_SEPARATOR ) ;
@@ -253,7 +252,10 @@ fn clean_specs(
253
252
. insert ( crate_name. clone ( ) )
254
253
{
255
254
let paths = [
255
+ // Remove dep-info file generated by rustc. It is not tracked in
256
+ // file_types. It does not have a prefix.
256
257
( path_dash. clone ( ) , ".d" ) ,
258
+ // Remove split-debuginfo files generated by rustc.
257
259
( path_dot. clone ( ) , ".o" ) ,
258
260
( path_dot. clone ( ) , ".dwo" ) ,
259
261
( path_dot. clone ( ) , ".dwp" ) ,
@@ -339,13 +341,14 @@ impl<'gctx> CleanContext<'gctx> {
339
341
Ok ( ( ) )
340
342
}
341
343
344
+ /// Iterates over files matching a glob (`pattern`), removing any files whose filenames start and end with provided prefix/suffix pair.
345
+ /// Compared to multiple separate calls to [`Self::rm_rf_glob`], this method iterates over the directory just once, which is why
346
+ /// it may be preferable for working with multiple prefix/suffix pairs.
342
347
fn rm_rf_prefix_list (
343
348
& mut self ,
344
349
pattern : & str ,
345
350
path_matchers : & [ ( Rc < str > , & str ) ] ,
346
351
) -> CargoResult < ( ) > {
347
- // TODO: Display utf8 warning to user? Or switch to globset?
348
-
349
352
for path in glob:: glob ( pattern) ? {
350
353
let path = path?;
351
354
let filename = path. file_name ( ) . and_then ( |name| name. to_str ( ) ) . unwrap ( ) ;
0 commit comments