Skip to content
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
21 changes: 10 additions & 11 deletions src/bin/juliainstaller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ pub fn main() -> Result<()> {
}
}

let juliaupselfbin = install_choices.install_location.join("bin");
let juliaupselfexecfolder = install_choices.install_location.join("bin");

trace!("Set juliaupselfbin to `{:?}`", juliaupselfbin);
trace!("Set juliaupselfexecfolder to `{:?}`", juliaupselfexecfolder);

println!("Now installing Juliaup");

Expand All @@ -447,10 +447,10 @@ pub fn main() -> Result<()> {
})?;
}

std::fs::create_dir_all(&juliaupselfbin).with_context(|| {
std::fs::create_dir_all(&juliaupselfexecfolder).with_context(|| {
format!(
"Failed to create install folder for Juliaup at `{}`.",
juliaupselfbin.display()
juliaupselfexecfolder.display()
)
})?;

Expand All @@ -473,7 +473,7 @@ pub fn main() -> Result<()> {
)
})?;

download_extract_sans_parent(new_juliaup_url.as_ref(), &juliaupselfbin, 0)?;
download_extract_sans_parent(new_juliaup_url.as_ref(), &juliaupselfexecfolder, 0)?;

{
let new_selfconfig_data = JuliaupSelfConfig {
Expand Down Expand Up @@ -526,7 +526,7 @@ pub fn main() -> Result<()> {
)
})?;

paths.juliaupselfbin = juliaupselfbin.clone();
paths.juliaupselfexecfolder = juliaupselfexecfolder.clone();
paths.juliaupselfconfig = self_config_path.clone();
}

Expand Down Expand Up @@ -555,16 +555,15 @@ pub fn main() -> Result<()> {
run_command_default(&args.default_channel, &paths)
.with_context(|| "Failed to run `run_command_default`.")?;

let symlink_path = juliaupselfbin.join("julia");
let symlink_path = juliaupselfexecfolder.join("julia");

std::os::unix::fs::symlink(juliaupselfbin.join("julialauncher"), &symlink_path).with_context(
|| {
std::os::unix::fs::symlink(juliaupselfexecfolder.join("julialauncher"), &symlink_path)
.with_context(|| {
format!(
"failed to create symlink `{}`.",
symlink_path.to_string_lossy()
)
},
)?;
})?;

println!("Julia was successfully installed on your system.");

Expand Down
61 changes: 23 additions & 38 deletions src/bin/julialauncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use juliaup::config_file::{
load_config_db_lockfree, load_mut_config_db, save_config_db, JuliaupConfig,
JuliaupConfigChannel, JuliaupConfigVersion,
};
use juliaup::global_paths::get_paths;
use juliaup::global_paths::{get_paths, GlobalPaths};
use juliaup::jsonstructs_versionsdb::JuliaupVersionDB;
use juliaup::operations::{is_pr_channel, is_valid_channel};
use juliaup::utils::{print_juliaup_style, resolve_julia_binary_path, JuliaupMessageType};
Expand Down Expand Up @@ -37,25 +37,9 @@ pub struct UserError {
msg: String,
}

fn get_juliaup_path() -> Result<PathBuf> {
let my_own_path = std::env::current_exe()
.with_context(|| "std::env::current_exe() did not find its own path.")?
.canonicalize()
.with_context(|| "Failed to canonicalize the path to the Julia launcher.")?;

let juliaup_path = my_own_path
.parent()
.unwrap() // unwrap OK here because this can't happen
.join(format!("juliaup{}", std::env::consts::EXE_SUFFIX));

Ok(juliaup_path)
}

fn do_initial_setup(juliaupconfig_path: &Path) -> Result<()> {
fn do_initial_setup(juliaupconfig_path: &Path, path: &GlobalPaths) -> Result<()> {
if !juliaupconfig_path.exists() {
let juliaup_path = get_juliaup_path().with_context(|| "Failed to obtain juliaup path.")?;

std::process::Command::new(juliaup_path)
std::process::Command::new(&path.juliaupselfexec)
.arg("46029ef5-0b73-4a71-bff3-d0d05de42aac") // This is our internal command to do the initial setup
.status()
.with_context(|| "Failed to start juliaup for the initial setup.")?;
Expand All @@ -65,6 +49,7 @@ fn do_initial_setup(juliaupconfig_path: &Path) -> Result<()> {

fn run_versiondb_update(
config_file: &juliaup::config_file::JuliaupReadonlyConfigFile,
paths: &GlobalPaths,
) -> Result<()> {
use chrono::Utc;
use std::process::Stdio;
Expand All @@ -82,10 +67,7 @@ fn run_versiondb_update(
};

if should_run {
let juliaup_path =
get_juliaup_path().with_context(|| "Failed to obtain juliaup path.")?;

std::process::Command::new(juliaup_path)
std::process::Command::new(&paths.juliaupselfexec)
.args(["0cf1528f-0b15-46b1-9ac9-e5bf5ccccbcf"])
.stdout(Stdio::null())
.stderr(Stdio::null())
Expand All @@ -99,7 +81,10 @@ fn run_versiondb_update(
}

#[cfg(feature = "selfupdate")]
fn run_selfupdate(config_file: &juliaup::config_file::JuliaupReadonlyConfigFile) -> Result<()> {
fn run_selfupdate(
config_file: &juliaup::config_file::JuliaupReadonlyConfigFile,
paths: &GlobalPaths,
) -> Result<()> {
use chrono::Utc;
use std::process::Stdio;

Expand All @@ -113,10 +98,7 @@ fn run_selfupdate(config_file: &juliaup::config_file::JuliaupReadonlyConfigFile)
};

if should_run {
let juliaup_path =
get_juliaup_path().with_context(|| "Failed to obtain juliaup path.")?;

std::process::Command::new(juliaup_path)
std::process::Command::new(&paths.juliaupselfexec)
.args(["self", "update"])
.stdout(Stdio::null())
.stderr(Stdio::null())
Expand All @@ -130,7 +112,10 @@ fn run_selfupdate(config_file: &juliaup::config_file::JuliaupReadonlyConfigFile)
}

#[cfg(not(feature = "selfupdate"))]
fn run_selfupdate(_config_file: &juliaup::config_file::JuliaupReadonlyConfigFile) -> Result<()> {
fn run_selfupdate(
_config_file: &juliaup::config_file::JuliaupReadonlyConfigFile,
_paths: &GlobalPaths,
) -> Result<()> {
Ok(())
}

Expand Down Expand Up @@ -251,7 +236,7 @@ fn set_auto_install_preference(

fn spawn_juliaup_add(
channel: &str,
_paths: &juliaup::global_paths::GlobalPaths,
paths: &juliaup::global_paths::GlobalPaths,
is_automatic: bool,
) -> Result<()> {
if is_automatic {
Expand All @@ -268,9 +253,7 @@ fn spawn_juliaup_add(
);
}

let juliaup_path = get_juliaup_path().with_context(|| "Failed to obtain juliaup path.")?;

let status = std::process::Command::new(juliaup_path)
let status = std::process::Command::new(&paths.juliaupselfexec)
.args(["add", channel])
.status()
.with_context(|| format!("Failed to spawn juliaup to install channel '{}'", channel))?;
Expand Down Expand Up @@ -621,7 +604,7 @@ fn run_app() -> Result<i32> {

let paths = get_paths().with_context(|| "Trying to load all global paths.")?;

do_initial_setup(&paths.juliaupconfig)
do_initial_setup(&paths.juliaupconfig, &paths)
.with_context(|| "The Julia launcher failed to run the initial setup steps.")?;

// Read the configuration without taking the configuration lock, so that
Expand Down Expand Up @@ -745,10 +728,11 @@ fn run_app() -> Result<i32> {
ctrlc::set_handler(|| ())
.with_context(|| "Failed to set the Ctrl-C handler.")?;

run_versiondb_update(&config_file)
run_versiondb_update(&config_file, &paths)
.with_context(|| "Failed to run version db update")?;

run_selfupdate(&config_file).with_context(|| "Failed to run selfupdate.")?;
run_selfupdate(&config_file, &paths)
.with_context(|| "Failed to run selfupdate.")?;
}
Err(_) => panic!("Could not double-fork"),
}
Expand Down Expand Up @@ -809,9 +793,10 @@ fn run_app() -> Result<i32> {
)
};

run_versiondb_update(&config_file).with_context(|| "Failed to run version db update")?;
run_versiondb_update(&config_file, &paths)
.with_context(|| "Failed to run version db update")?;

run_selfupdate(&config_file).with_context(|| "Failed to run selfupdate.")?;
run_selfupdate(&config_file, &paths).with_context(|| "Failed to run selfupdate.")?;

let status = child_process
.wait()
Expand Down
2 changes: 1 addition & 1 deletion src/command_config_backgroundselfupdate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn run_command_config_backgroundselfupdate(

match value {
Some(value) => {
install_background_selfupdate(value).unwrap();
install_background_selfupdate(value, paths).unwrap();
}
None => {
uninstall_background_selfupdate().unwrap();
Expand Down
5 changes: 4 additions & 1 deletion src/command_config_modifypath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ pub fn run_command_config_modifypath(
}

if value {
add_binfolder_to_path_in_shell_scripts(&paths.juliaupselfbin, &paths.juliauphome)?;
add_binfolder_to_path_in_shell_scripts(
&paths.juliaupselfexecfolder,
&paths.juliauphome,
)?;
} else {
remove_binfolder_from_path_in_shell_scripts()?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/command_config_symlinks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn run_command_config_symlinks(
if value {
create_symlink(channel, &format!("julia-{}", channel_name), paths)?;
} else {
remove_symlink(&format!("julia-{}", channel_name))?;
remove_symlink(&format!("julia-{}", channel_name), paths)?;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/command_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn run_command_remove(channel: &str, paths: &GlobalPaths) -> Result<()> {
config_file.data.installed_channels.remove(channel);

#[cfg(not(windows))]
remove_symlink(&format!("julia-{channel}"))?;
remove_symlink(&format!("julia-{channel}"), paths)?;

garbage_collect_versions(false, &mut config_file.data, paths)?;

Expand Down
25 changes: 13 additions & 12 deletions src/command_selfuninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@ pub fn run_command_selfuninstall(paths: &crate::global_paths::GlobalPaths) -> Re
Err(e) => eprintln!(" Failed: {e}."),
};

if paths.juliauphome != paths.juliaupselfhome {
let juliaup_binfolder_path = paths.juliaupselfhome.join("bin");
let juliaupselfhome = paths
.juliaupselfexecfolder
.parent()
.ok_or_else(|| anyhow::anyhow!("Could not determine parent of own executable folder."))?;

if paths.juliauphome != juliaupselfhome {
let juliaup_binfolder_path = paths.juliaupselfexecfolder.clone();
let julia_symlink_path = juliaup_binfolder_path.join("julia");
let julialauncher_path = juliaup_binfolder_path.join("julialauncher");
let juliaup_path = juliaup_binfolder_path.join("juliaup");
let juliaup_config_path = paths.juliaupselfhome.join("juliaupself.json");
let juliaup_config_path = paths.juliaupselfconfig.clone();

eprint!("Deleting julia symlink {}.", julia_symlink_path.display());
match std::fs::remove_file(&julia_symlink_path) {
Expand Down Expand Up @@ -111,23 +116,19 @@ pub fn run_command_selfuninstall(paths: &crate::global_paths::GlobalPaths) -> Re
Err(e) => eprintln!(" Failed: {e}."),
};

if paths
.juliaupselfhome
if juliaupselfhome
.read_dir()
.with_context(|| {
format!(
"Failed to read Juliaup folder `{}`.",
paths.juliaupselfhome.display()
juliaupselfhome.display()
)
})?
.next()
.is_none()
{
eprint!(
"Deleting the Juliaup folder {}.",
paths.juliaupselfhome.display()
);
match std::fs::remove_dir(&paths.juliaupselfhome) {
eprint!("Deleting the Juliaup folder {}.", juliaupselfhome.display());
match std::fs::remove_dir(juliaupselfhome) {
Ok(_) => eprintln!(" Success."),
Err(e) => {
eprintln!(
Expand All @@ -138,7 +139,7 @@ pub fn run_command_selfuninstall(paths: &crate::global_paths::GlobalPaths) -> Re
} else {
eprintln!(
"The Juliaup folder {} is not empty, skipping removal of the entire Juliaup folder.",
paths.juliaupselfhome.display()
juliaupselfhome.display()
);
}
}
Expand Down
18 changes: 4 additions & 14 deletions src/command_selfupdate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
use crate::operations::{download_extract_sans_parent, download_juliaup_version};
use crate::utils::get_juliaserver_base_url;
use crate::{get_juliaup_target, get_own_version};
use anyhow::{anyhow, bail};
use anyhow::bail;

update_version_db(&None, paths).with_context(|| "Failed to update versions db.")?;

Expand Down Expand Up @@ -100,27 +100,17 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
)
})?;

let my_own_path = std::env::current_exe()
.with_context(|| "Could not determine the path of the running exe.")?;

let my_own_folder = my_own_path
.parent()
.ok_or_else(|| anyhow!("Could not determine parent."))?;

eprintln!(
"Found new version {} on channel {}.",
version, juliaup_channel
);

download_extract_sans_parent(new_juliaup_url.as_ref(), my_own_folder, 0)?;
download_extract_sans_parent(new_juliaup_url.as_ref(), &paths.juliaupselfexecfolder, 0)?;

let new_juliaup = my_own_folder.join(format!("juliaup{}", std::env::consts::EXE_SUFFIX));
if let Err(e) = std::process::Command::new(&new_juliaup)
std::process::Command::new(&paths.juliaupselfexec)
.arg("_post-update")
.status()
{
eprintln!("Warning: post-update hook failed: {e}");
}
.with_context(|| "Failed to run post-update hook.")?;

eprintln!("Updated Juliaup to version {}.", version);
}
Expand Down
4 changes: 4 additions & 0 deletions src/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,10 @@ mod tests {
GlobalPaths {
juliauphome: dir.to_path_buf(),
juliaupconfig: dir.join("juliaup.json"),
juliaupselfexecfolder: dir.join("bin"),
juliaupselfexec: dir
.join("bin")
.join(format!("juliaup{}", std::env::consts::EXE_SUFFIX)),
lockfile: dir.join(".juliaup-lock"),
versiondb: dir.join("versiondb-test.json"),
}
Expand Down
Loading
Loading