Skip to content

Commit a8803d3

Browse files
committed
Delete files immediately, instead of collecting into vector
1 parent 2fa3598 commit a8803d3

File tree

1 file changed

+17
-20
lines changed
  • compiler/rustc_incremental/src/persist

1 file changed

+17
-20
lines changed

compiler/rustc_incremental/src/persist/fs.rs

+17-20
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,6 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
765765

766766
// Now garbage collect the valid session directories.
767767
let mut deletion_candidates = vec![];
768-
let mut definitely_delete = vec![];
769768

770769
for (lock_file_name, directory_name) in &lock_file_to_session_dir {
771770
debug!("garbage_collect_session_directories() - inspecting: {}", directory_name);
@@ -842,8 +841,11 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
842841
successfully acquired lock"
843842
);
844843

845-
// Note that we are holding on to the lock
846-
definitely_delete.push((crate_directory.join(directory_name), Some(lock)));
844+
delete_old(sess, &crate_directory.join(directory_name));
845+
846+
// Let's make it explicit that the file lock is released at this point,
847+
// or rather, that we held on to it until here
848+
mem::drop(lock);
847849
}
848850
Err(_) => {
849851
debug!(
@@ -880,26 +882,21 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
880882
mem::drop(lock);
881883
}
882884

883-
for (path, lock) in definitely_delete {
884-
debug!("garbage_collect_session_directories() - deleting `{}`", path.display());
885+
Ok(())
886+
}
885887

886-
if let Err(err) = safe_remove_dir_all(&path) {
887-
sess.warn(&format!(
888-
"Failed to garbage collect incremental \
889-
compilation session directory `{}`: {}",
890-
path.display(),
891-
err
892-
));
893-
} else {
894-
delete_session_dir_lock_file(sess, &lock_file_path(&path));
895-
}
888+
fn delete_old(sess: &Session, path: &Path) {
889+
debug!("garbage_collect_session_directories() - deleting `{}`", path.display());
896890

897-
// Let's make it explicit that the file lock is released at this point,
898-
// or rather, that we held on to it until here
899-
mem::drop(lock);
891+
if let Err(err) = safe_remove_dir_all(&path) {
892+
sess.warn(&format!(
893+
"Failed to garbage collect incremental compilation session directory `{}`: {}",
894+
path.display(),
895+
err
896+
));
897+
} else {
898+
delete_session_dir_lock_file(sess, &lock_file_path(&path));
900899
}
901-
902-
Ok(())
903900
}
904901

905902
fn all_except_most_recent(

0 commit comments

Comments
 (0)