Skip to content

Commit

Permalink
Merge pull request #602 from inejge/no-self-update
Browse files Browse the repository at this point in the history
Add the "no-self-update" feature
  • Loading branch information
brson authored Jul 21, 2016
2 parents 2eba92f + 5c3bd25 commit fd3e9f1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ curl-backend = ["download/curl-backend"]
hyper-backend = ["download/hyper-backend"]
rustls-backend = ["download/rustls-backend"]

# Include in the default set to disable self-update and uninstall.
no-self-update = []

[dependencies]
rustup-dist = { path = "src/rustup-dist", version = "0.3.0" }
rustup-utils = { path = "src/rustup-utils", version = "0.3.0" }
Expand Down
2 changes: 1 addition & 1 deletion src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ fn update(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
try!(common::show_channel_update(cfg, toolchain.name(), Ok(status)));
}
} else {
try!(common::update_all_channels(cfg, !m.is_present("no-self-update")));
try!(common::update_all_channels(cfg, !m.is_present("no-self-update") && !self_update::NEVER_SELF_UPDATE));
}

Ok(())
Expand Down
16 changes: 15 additions & 1 deletion src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ pub struct InstallOpts {
pub no_modify_path: bool,
}

#[cfg(feature = "no-self-update")]
pub const NEVER_SELF_UPDATE: bool = true;
#[cfg(not(feature = "no-self-update"))]
pub const NEVER_SELF_UPDATE: bool = false;

// The big installation messages. These are macros because the first
// argument of format! needs to be a literal.

Expand Down Expand Up @@ -504,6 +509,11 @@ fn maybe_install_rust(toolchain_str: &str, default_host_triple: &str, verbose: b
}

pub fn uninstall(no_prompt: bool) -> Result<()> {
if NEVER_SELF_UPDATE {
err!("self-uninstall is disabled for this build of rustup");
err!("you should probably use your system package manager to uninstall rustup");
process::exit(1);
}
let ref cargo_home = try!(utils::cargo_home());

if !cargo_home.join(&format!("bin/rustup{}", EXE_SUFFIX)).exists() {
Expand Down Expand Up @@ -1052,7 +1062,11 @@ fn do_remove_from_path(methods: &[PathUpdateMethod]) -> Result<()> {
/// rustup-init is stored in CARGO_HOME/bin, and then deleted next
/// time rustup runs.
pub fn update() -> Result<()> {

if NEVER_SELF_UPDATE {
err!("self-update is disabled for this build of rustup");
err!("you should probably use your system package manager to update rustup");
process::exit(1);
}
let setup_path = try!(prepare_update());
if let Some(ref p) = setup_path {
info!("rustup updated successfully");
Expand Down

0 comments on commit fd3e9f1

Please sign in to comment.