Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prune linked versions that no longer exist with --prune-linked option. #1030

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading