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

canonicalize the current_exe result when self updating, so that it works with symlinking. #886

Open
wants to merge 3 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 1 addition & 14 deletions src/bin/julialauncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use itertools::Itertools;
use juliaup::config_file::{load_config_db, JuliaupConfig, JuliaupConfigChannel};
use juliaup::global_paths::get_paths;
use juliaup::jsonstructs_versionsdb::JuliaupVersionDB;
use juliaup::utils::get_juliaup_path;
use juliaup::versions_file::load_versions_db;
#[cfg(not(windows))]
use nix::{
Expand All @@ -22,20 +23,6 @@ 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<()> {
if !juliaupconfig_path.exists() {
let juliaup_path = get_juliaup_path().with_context(|| "Failed to obtain juliaup path.")?;
Expand Down
11 changes: 2 additions & 9 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(paths).with_context(|| "Failed to update versions db.")?;

Expand Down Expand Up @@ -71,19 +71,12 @@ 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.to_string(), &my_own_folder, 0)?;
download_extract_sans_parent(&new_juliaup_url.to_string(), &paths.juliaupselfbin, 0)?;
eprintln!("Updated Juliaup to version {}.", version);
}

Expand Down
5 changes: 2 additions & 3 deletions src/global_paths.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::get_juliaup_target;
#[cfg(feature = "selfupdate")]
use anyhow::Context;
use crate::utils::get_juliaup_path;
use anyhow::{anyhow, bail, Result};
use std::path::PathBuf;
pub struct GlobalPaths {
Expand Down Expand Up @@ -57,8 +57,7 @@ pub fn get_paths() -> Result<GlobalPaths> {
let juliauphome = get_juliaup_home_path()?;

#[cfg(feature = "selfupdate")]
let my_own_path = std::env::current_exe()
.with_context(|| "Could not determine the path of the running exe.")?;
let my_own_path = get_juliaup_path()?;

#[cfg(feature = "selfupdate")]
let juliaupselfbin = my_own_path
Expand Down
6 changes: 3 additions & 3 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::get_juliaup_path;
use anyhow::{anyhow, bail, Context, Result};
use bstr::ByteSlice;
use bstr::ByteVec;
Expand Down Expand Up @@ -292,7 +293,7 @@ pub fn install_version(
// TODO At some point we could put this behind a conditional compile, we know
// that we don't ship a bundled version for some platforms.
let full_version_string_of_bundled_version = get_bundled_julia_version();
let my_own_path = std::env::current_exe()?;
let my_own_path = get_juliaup_path()?;
let path_of_bundled_version = my_own_path
.parent()
.unwrap() // unwrap OK because we can't get a path that does not have a parent
Expand Down Expand Up @@ -711,8 +712,7 @@ pub fn install_background_selfupdate(interval: i64) -> Result<()> {
use itertools::Itertools;
use std::process::Stdio;

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

let my_own_path = own_exe_path.to_str().unwrap();

Expand Down
17 changes: 15 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ use semver::{BuildMetadata, Version};
use std::path::PathBuf;
use url::Url;

pub 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)
}

pub fn get_juliaserver_base_url() -> Result<Url> {
let base_url = if let Ok(val) = std::env::var("JULIAUP_SERVER") {
if val.ends_with('/') {
Expand Down Expand Up @@ -63,8 +77,7 @@ pub fn get_bin_dir() -> Result<PathBuf> {
path
}
Err(_) => {
let mut path = std::env::current_exe()
.with_context(|| "Could not determine the path of the running exe.")?
let mut path = get_juliaup_path()?
.parent()
.ok_or_else(|| anyhow!("Could not determine parent."))?
.to_path_buf();
Expand Down