Skip to content

Commit

Permalink
Introduce fuelup_bin_or_current_bin() function
Browse files Browse the repository at this point in the history
  • Loading branch information
crodas committed Feb 21, 2024
1 parent 34dea3d commit 5ac35f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ pub fn fuelup_bin_dir() -> PathBuf {
fuelup_dir().join("bin")
}

/// Similar to fuelup_bin() but it never fails. If the fuelup binary is not found in $PATH, it
/// returns the current executable binary path
pub fn fuelup_bin_or_current_bin() -> PathBuf {
let fuelup_bin = fuelup_bin();
if fuelup_bin.exists() {
fuelup_bin
} else {
env::current_exe().unwrap()
}
}

pub fn fuelup_bin() -> PathBuf {
fuelup_bin_dir().join("fuelup")
}
Expand Down
13 changes: 2 additions & 11 deletions src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use crate::channel::{self, Channel};
use crate::constants::DATE_FORMAT;
use crate::download::DownloadCfg;
use crate::file::{hard_or_symlink_file, is_executable};
use crate::ops::fuelup_self::self_update;
use crate::path::{
ensure_dir_exists, fuelup_bin, fuelup_bin_dir, fuelup_tmp_dir, settings_file,
ensure_dir_exists, fuelup_bin_dir, fuelup_bin_or_current_bin, fuelup_tmp_dir, settings_file,
toolchain_bin_dir, toolchain_dir,
};
use crate::settings::SettingsFile;
Expand Down Expand Up @@ -305,15 +304,7 @@ impl Toolchain {
let fuelup_bin_dir = fuelup_bin_dir();
ensure_dir_exists(&fuelup_bin_dir)?;

let fuelup_bin = fuelup_bin();
if !fuelup_bin.is_file() {
info!("fuelup not found - attempting to self update");
match self_update(true) {
Ok(()) => info!("fuelup installed."),
Err(e) => bail!("Could not install fuelup: {}", e),
};
}

let fuelup_bin = fuelup_bin_or_current_bin();
let store = Store::from_env()?;

if !store.has_component(&download_cfg.name, &download_cfg.version)
Expand Down

0 comments on commit 5ac35f5

Please sign in to comment.