Skip to content

Commit ee2eb35

Browse files
authored
Merge pull request #1205 from ghyatzo/patch-fixgc
Don't orphan old julia versions when failing to delete them.
2 parents fbd0463 + a7b45c4 commit ee2eb35

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/operations.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -767,18 +767,29 @@ pub fn garbage_collect_versions(
767767
version: _,
768768
} => true,
769769
}) {
770-
let path_to_delete = paths.juliauphome.join(&detail.path);
770+
let path_to_delete = paths.juliauphome.join(&detail.path).canonicalize()?;
771771
let display = path_to_delete.display();
772772

773-
if std::fs::remove_dir_all(&path_to_delete).is_err() {
774-
eprintln!("WARNING: Failed to delete {}. You can try to delete at a later point by running `juliaup gc`.", display)
773+
match std::fs::remove_dir_all(&path_to_delete) {
774+
Ok(_) => versions_to_uninstall.push(installed_version.clone()),
775+
Err(_) => eprintln!(
776+
"{}: Failed to delete {}. \
777+
Make sure to close any old julia version still running.\n\
778+
You can try to delete at a later point by running `juliaup gc`.",
779+
style("WARNING").yellow().bold(),
780+
display
781+
),
775782
}
776-
versions_to_uninstall.push(installed_version.clone());
777783
}
778784
}
779785

780-
for i in versions_to_uninstall {
781-
config_data.installed_versions.remove(&i);
786+
if versions_to_uninstall.is_empty() {
787+
eprintln!("Nothing to remove.");
788+
} else {
789+
for i in versions_to_uninstall {
790+
eprintln!("{} Julia {}", style("Removed").green().bold(), &i);
791+
config_data.installed_versions.remove(&i);
792+
}
782793
}
783794

784795
if prune_linked {

0 commit comments

Comments
 (0)