Skip to content

Commit

Permalink
Merge pull request #181 from axodotdev/use_no_update_path
Browse files Browse the repository at this point in the history
feat: avoid modifying path if inappropriate
  • Loading branch information
mistydemeo authored Sep 19, 2024
2 parents 1a26a8c + e20be7e commit 1074a07
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
14 changes: 13 additions & 1 deletion axoupdater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ pub struct AxoUpdater {
/// When set to true, skips performing version checks and always assumes
/// the software is out of date.
always_update: bool,
/// Whether to modify the system path when installing
modify_path: bool,
}

impl Default for AxoUpdater {
Expand All @@ -123,6 +125,7 @@ impl AxoUpdater {
installer_path: None,
tokens: AuthorizationTokens::default(),
always_update: false,
modify_path: true,
}
}

Expand All @@ -141,6 +144,7 @@ impl AxoUpdater {
installer_path: None,
tokens: AuthorizationTokens::default(),
always_update: false,
modify_path: true,
}
}

Expand Down Expand Up @@ -170,6 +174,7 @@ impl AxoUpdater {
installer_path: None,
tokens: AuthorizationTokens::default(),
always_update: false,
modify_path: true,
})
}
Expand Down Expand Up @@ -517,9 +522,16 @@ impl AxoUpdater {
// Also set the app-specific name for this; in the future, the
// CARGO_DIST_ version may be removed.
let app_name = self.name.clone().unwrap_or_default();
let app_specific_env_var = app_name.to_ascii_uppercase().replace('-', "_") + "_INSTALL_DIR";
let app_name_env_var = app_name.to_ascii_uppercase().replace('-', "_");
let app_specific_env_var = format!("{app_name_env_var}_INSTALL_DIR");
command.env(app_specific_env_var, &install_prefix);

// If the previous installation didn't modify the path, we shouldn't either
if !self.modify_path {
let app_specific_modify_path = format!("{app_name_env_var}_NO_MODIFY_PATH");
command.env(app_specific_modify_path, "1");
}

let result = command.output();

let failed;
Expand Down
9 changes: 9 additions & 0 deletions axoupdater/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use axotag::Version;
use camino::Utf8PathBuf;
use serde::Deserialize;

fn default_as_true() -> bool {
true
}

/// Information parsed from a cargo-dist install receipt
#[derive(Clone, Debug, Deserialize)]
pub struct InstallReceipt {
Expand All @@ -26,6 +30,10 @@ pub struct InstallReceipt {
pub version: String,
/// Information about the tool used to produce this receipt
pub provider: ReceiptProvider,
/// Information about whether new installations should modify system paths
// Added in cargo-dist 0.23.0, missing in older receipts
#[serde(default = "default_as_true")]
pub modify_path: bool,
}

/// Tool used to produce this install receipt
Expand Down Expand Up @@ -60,6 +68,7 @@ impl AxoUpdater {

self.current_version_installed_by = Some(provider);
self.install_prefix = Some(receipt.install_prefix);
self.modify_path = receipt.modify_path;

Ok(self)
}
Expand Down

0 comments on commit 1074a07

Please sign in to comment.