Skip to content

Commit d4c83ee

Browse files
committed
Do not call rm_rf_glob in a loop for paths that do not depend on file_types
1 parent eee4ea2 commit d4c83ee

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/cargo/ops/cargo_clean.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,28 +212,15 @@ fn clean_specs(
212212
TargetKind::Test | TargetKind::Bench => (layout.deps(), None),
213213
_ => (layout.deps(), Some(layout.dest())),
214214
};
215+
let dir_glob = escape_glob_path(dir)?;
216+
let dir_glob = Path::new(&dir_glob);
215217
for file_type in file_types {
216218
// Some files include a hash in the filename, some don't.
217219
let hashed_name = file_type.output_filename(target, Some("*"));
218220
let unhashed_name = file_type.output_filename(target, None);
219-
let dir_glob = escape_glob_path(dir)?;
220-
let dir_glob = Path::new(&dir_glob);
221221

222222
clean_ctx.rm_rf_glob(&dir_glob.join(&hashed_name))?;
223223
clean_ctx.rm_rf(&dir.join(&unhashed_name))?;
224-
// Remove dep-info file generated by rustc. It is not tracked in
225-
// file_types. It does not have a prefix.
226-
let hashed_dep_info = dir_glob.join(format!("{}-*.d", crate_name));
227-
clean_ctx.rm_rf_glob(&hashed_dep_info)?;
228-
let unhashed_dep_info = dir.join(format!("{}.d", crate_name));
229-
clean_ctx.rm_rf(&unhashed_dep_info)?;
230-
// Remove split-debuginfo files generated by rustc.
231-
let split_debuginfo_obj = dir_glob.join(format!("{}.*.o", crate_name));
232-
clean_ctx.rm_rf_glob(&split_debuginfo_obj)?;
233-
let split_debuginfo_dwo = dir_glob.join(format!("{}.*.dwo", crate_name));
234-
clean_ctx.rm_rf_glob(&split_debuginfo_dwo)?;
235-
let split_debuginfo_dwp = dir_glob.join(format!("{}.*.dwp", crate_name));
236-
clean_ctx.rm_rf_glob(&split_debuginfo_dwp)?;
237224

238225
// Remove the uplifted copy.
239226
if let Some(uplift_dir) = uplift_dir {
@@ -244,6 +231,20 @@ fn clean_specs(
244231
clean_ctx.rm_rf(&dep_info)?;
245232
}
246233
}
234+
// Remove dep-info file generated by rustc. It is not tracked in
235+
// file_types. It does not have a prefix.
236+
let hashed_dep_info = dir_glob.join(format!("{}-*.d", crate_name));
237+
clean_ctx.rm_rf_glob(&hashed_dep_info)?;
238+
let unhashed_dep_info = dir.join(format!("{}.d", crate_name));
239+
clean_ctx.rm_rf(&unhashed_dep_info)?;
240+
// Remove split-debuginfo files generated by rustc.
241+
let split_debuginfo_obj = dir_glob.join(format!("{}.*.o", crate_name));
242+
clean_ctx.rm_rf_glob(&split_debuginfo_obj)?;
243+
let split_debuginfo_dwo = dir_glob.join(format!("{}.*.dwo", crate_name));
244+
clean_ctx.rm_rf_glob(&split_debuginfo_dwo)?;
245+
let split_debuginfo_dwp = dir_glob.join(format!("{}.*.dwp", crate_name));
246+
clean_ctx.rm_rf_glob(&split_debuginfo_dwp)?;
247+
247248
// TODO: what to do about build_script_build?
248249
let dir = escape_glob_path(layout.incremental())?;
249250
let incremental = Path::new(&dir).join(format!("{}-*", crate_name));

0 commit comments

Comments
 (0)