diff --git a/src/bin/juliaup.rs b/src/bin/juliaup.rs index b585d3b4..d2a2e579 100644 --- a/src/bin/juliaup.rs +++ b/src/bin/juliaup.rs @@ -96,7 +96,7 @@ fn main() -> Result<()> { Juliaup::Remove { channel } => run_command_remove(&channel, &paths), Juliaup::Status {} => run_command_status(&paths), Juliaup::Update { channel } => run_command_update(channel, &paths), - Juliaup::Gc {} => run_command_gc(&paths), + Juliaup::Gc { prune_linked } => run_command_gc(prune_linked, &paths), Juliaup::Link { channel, file, diff --git a/src/cli.rs b/src/cli.rs index 14588c55..d665685f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -33,7 +33,10 @@ pub enum Juliaup { /// Show all installed Julia versions Status {}, /// Garbage collect uninstalled Julia versions - Gc {}, + Gc { + #[clap(long)] + prune_linked: bool, + }, #[clap(subcommand, name = "config")] /// Juliaup configuration Config(ConfigSubCmd), diff --git a/src/command_gc.rs b/src/command_gc.rs index b92eec0d..19c12dd2 100644 --- a/src/command_gc.rs +++ b/src/command_gc.rs @@ -3,11 +3,11 @@ use crate::global_paths::GlobalPaths; use crate::operations::garbage_collect_versions; use anyhow::{Context, Result}; -pub fn run_command_gc(paths: &GlobalPaths) -> Result<()> { +pub fn run_command_gc(prune_linked: bool, paths: &GlobalPaths) -> Result<()> { let mut config_file = load_mut_config_db(paths) .with_context(|| "`gc` command failed to load configuration data.")?; - garbage_collect_versions(&mut config_file.data, paths)?; + garbage_collect_versions(prune_linked, &mut config_file.data, paths)?; save_config_db(&mut config_file) .with_context(|| "`gc` command failed to save configuration db.")?; diff --git a/src/command_remove.rs b/src/command_remove.rs index 7abe52fe..1c743eba 100644 --- a/src/command_remove.rs +++ b/src/command_remove.rs @@ -63,7 +63,7 @@ pub fn run_command_remove(channel: &str, paths: &GlobalPaths) -> Result<()> { #[cfg(not(windows))] remove_symlink(&format!("julia-{}", channel))?; - garbage_collect_versions(&mut config_file.data, paths)?; + garbage_collect_versions(false, &mut config_file.data, paths)?; save_config_db(&mut config_file).with_context(|| { format!( diff --git a/src/command_update.rs b/src/command_update.rs index 37081584..ab0d7ff0 100644 --- a/src/command_update.rs +++ b/src/command_update.rs @@ -138,7 +138,7 @@ pub fn run_command_update(channel: Option, paths: &GlobalPaths) -> Resul } }; - garbage_collect_versions(&mut config_file.data, paths)?; + garbage_collect_versions(false, &mut config_file.data, paths)?; save_config_db(&mut config_file) .with_context(|| "`update` command failed to save configuration db.")?; diff --git a/src/operations.rs b/src/operations.rs index 87aa19db..dde9206b 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -11,6 +11,7 @@ use crate::jsonstructs_versionsdb::JuliaupVersionDB; use crate::utils::get_bin_dir; use crate::utils::get_julianightlies_base_url; use crate::utils::get_juliaserver_base_url; +use crate::utils::is_valid_julia_path; use anyhow::{anyhow, bail, Context, Result}; use bstr::ByteSlice; use bstr::ByteVec; @@ -602,6 +603,7 @@ pub fn install_non_db_version( } pub fn garbage_collect_versions( + prune_linked: bool, config_data: &mut JuliaupConfig, paths: &GlobalPaths, ) -> Result<()> { @@ -635,6 +637,27 @@ pub fn garbage_collect_versions( config_data.installed_versions.remove(&i); } + if prune_linked { + let mut channels_to_uninstall: Vec = Vec::new(); + for (installed_channel, detail) in &config_data.installed_channels { + match &detail { + JuliaupConfigChannel::LinkedChannel { + command: cmd, + args: _, + } => { + if !is_valid_julia_path(&PathBuf::from(cmd)) { + channels_to_uninstall.push(installed_channel.clone()); + } + } + _ => (), + } + } + for channel in channels_to_uninstall { + remove_symlink(&format!("julia-{}", &channel))?; + config_data.installed_channels.remove(&channel); + } + } + Ok(()) }