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

Add the "no-self-update" feature #602

Merged
merged 1 commit into from
Jul 21, 2016
Merged
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
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 @@ -400,7 +400,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 @@ -503,6 +508,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/multirust{}", EXE_SUFFIX)).exists() {
Expand Down Expand Up @@ -1051,7 +1061,11 @@ fn do_remove_from_path(methods: &[PathUpdateMethod]) -> Result<()> {
/// multirust-setup is stored in CARGO_HOME/bin, and then deleted next
/// time multirust 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