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

Make check channel up-to-date in julialauncher optional #706

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 8 additions & 6 deletions src/bin/julialauncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,14 @@ fn get_julia_path_from_channel(
.installed_versions.get(version)
.ok_or_else(|| anyhow!("The juliaup configuration is in an inconsistent state, the channel {} is pointing to Julia version {}, which is not installed.", channel, version))?.path;

check_channel_uptodate(channel, version, versions_db).with_context(|| {
format!(
"The Julia launcher failed while checking whether the channe {} is up-to-date.",
channel
)
})?;
if config_data.settings.should_check_channel_uptodate {
check_channel_uptodate(channel, version, versions_db).with_context(|| {
format!(
"The Julia launcher failed while checking whether the channel {} is up-to-date.",
channel
)
})?;
}
let absolute_path = juliaupconfig_path
.parent()
.unwrap() // unwrap OK because there should always be a parent
Expand Down
10 changes: 10 additions & 0 deletions src/bin/juliaup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use juliaup::command_api::run_command_api;
#[cfg(not(windows))]
use juliaup::command_config_symlinks::run_command_config_symlinks;
use juliaup::command_config_versionsdbupdate::run_command_config_versionsdbupdate;
use juliaup::command_config_checkchanneluptodate::run_command_config_checkchanneluptodate;
use juliaup::command_default::run_command_default;
use juliaup::command_gc::run_command_gc;
use juliaup::command_info::run_command_info;
Expand Down Expand Up @@ -147,6 +148,12 @@ enum ConfigSubCmd {
/// New value
value: Option<i64>,
},
#[clap(name = "checkchanneluptodate")]
/// Check for updates to the default channel on startup
ShouldCheckChannelUptodate {
/// New Value
value: Option<bool>,
},
}

fn main() -> Result<()> {
Expand Down Expand Up @@ -200,6 +207,9 @@ fn main() -> Result<()> {
ConfigSubCmd::VersionsDbUpdateInterval { value } => {
run_command_config_versionsdbupdate(value, false, &paths)
}
ConfigSubCmd::ShouldCheckChannelUptodate { value } => {
run_command_config_checkchanneluptodate(value, false, &paths)
}
},
Juliaup::Api { command } => run_command_api(&command, &paths),
Juliaup::InitialSetupFromLauncher {} => run_command_initial_setup_from_launcher(&paths),
Expand Down
51 changes: 51 additions & 0 deletions src/command_config_checkchanneluptodate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use anyhow::Result;

pub fn run_command_config_checkchanneluptodate(
value: Option<bool>,
quiet: bool,
paths: &crate::global_paths::GlobalPaths,
) -> Result<()> {
use crate::config_file::{load_config_db, load_mut_config_db, save_config_db};
use anyhow::Context;

match value {
Some(value) => {
let mut config_file = load_mut_config_db(paths)
.with_context(|| "`config` command failed to load configuration data.")?;

let mut value_changed = false;

if value != config_file.data.settings.should_check_channel_uptodate {
config_file.data.settings.should_check_channel_uptodate = value;
value_changed = true;
}

save_config_db(&mut config_file)
.with_context(|| "Failed to save configuration file from `config` command.")?;

if !quiet {
if value_changed {
eprintln!("Property 'checkchanneluptodate' set to '{}'", value);
} else {
eprintln!(
"Property 'checkchanneluptodate' is already set to '{}'",
value
);
}
}
}
None => {
let config_file = load_config_db(paths)
.with_context(|| "`config` command failed to load configuration data.")?;

if !quiet {
eprintln!(
"Property 'checkchanneluptodate' set to '{}'",
config_file.data.settings.should_check_channel_uptodate
);
}
}
};

Ok(())
}
13 changes: 13 additions & 0 deletions src/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ fn is_default_versionsdb_update_interval(i: &i64) -> bool {
*i == default_versionsdb_update_interval()
}

fn default_should_check_channel_uptodate() -> bool {
true
}

#[derive(Serialize, Deserialize, Clone)]
pub struct JuliaupConfigVersion {
#[serde(rename = "Path")]
Expand Down Expand Up @@ -55,13 +59,20 @@ pub struct JuliaupConfigSettings {
skip_serializing_if = "is_default_versionsdb_update_interval"
)]
pub versionsdb_update_interval: i64,
#[serde(
rename = "ShouldCheckChannelUptodate",
default = "default_should_check_channel_uptodate",
skip_serializing_if = "is_default"
)]
pub should_check_channel_uptodate: bool,
}

impl Default for JuliaupConfigSettings {
fn default() -> Self {
JuliaupConfigSettings {
create_channel_symlinks: false,
versionsdb_update_interval: default_versionsdb_update_interval(),
should_check_channel_uptodate: true,
}
}
}
Expand Down Expand Up @@ -178,6 +189,7 @@ pub fn load_config_db(paths: &GlobalPaths) -> Result<JuliaupReadonlyConfigFile>
settings: JuliaupConfigSettings {
create_channel_symlinks: false,
versionsdb_update_interval: default_versionsdb_update_interval(),
should_check_channel_uptodate: true,
},
last_version_db_update: None,
},
Expand Down Expand Up @@ -274,6 +286,7 @@ pub fn load_mut_config_db(paths: &GlobalPaths) -> Result<JuliaupConfigFile> {
settings: JuliaupConfigSettings {
create_channel_symlinks: false,
versionsdb_update_interval: default_versionsdb_update_interval(),
should_check_channel_uptodate: true,
},
last_version_db_update: None,
};
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use anyhow::Context;
pub mod command_add;
pub mod command_api;
pub mod command_config_backgroundselfupdate;
pub mod command_config_checkchanneluptodate;
pub mod command_config_modifypath;
pub mod command_config_startupselfupdate;
pub mod command_config_symlinks;
Expand Down