Skip to content

Commit

Permalink
Add --prune-linked option for garbage collection
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangnrd committed Sep 3, 2024
1 parent f160605 commit 040011c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/bin/juliaup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/command_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")?;
Expand Down
2 changes: 1 addition & 1 deletion src/command_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion src/command_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub fn run_command_update(channel: Option<String>, 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.")?;
Expand Down
23 changes: 23 additions & 0 deletions src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<()> {
Expand Down Expand Up @@ -635,6 +637,27 @@ pub fn garbage_collect_versions(
config_data.installed_versions.remove(&i);
}

if prune_linked {
let mut channels_to_uninstall: Vec<String> = 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(())
}

Expand Down

0 comments on commit 040011c

Please sign in to comment.