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

Refuse to install if it looks like other Rust installations are present #408

Merged
merged 1 commit into from
May 7, 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
45 changes: 45 additions & 0 deletions src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ fn canonical_cargo_home() -> Result<String> {
pub fn install(no_prompt: bool, verbose: bool,
opts: InstallOpts) -> Result<()> {

try!(do_pre_install_sanity_checks());

let selected_opts;

if !no_prompt {
Expand Down Expand Up @@ -290,6 +292,49 @@ pub fn install(no_prompt: bool, verbose: bool,
Ok(())
}

fn do_pre_install_sanity_checks() -> Result<()> {

let multirust_manifest_path
= PathBuf::from("/usr/local/lib/rustlib/manifest-multirust");
let rustc_manifest_path
= PathBuf::from("/usr/local/lib/rustlib/manifest-rustc");
let uninstaller_path
= PathBuf::from("/usr/local/lib/rustlib/uninstall.sh");
let rustup_sh_path
= env::home_dir().map(|d| d.join(".rustup"));
let rustup_sh_version_path = rustup_sh_path.as_ref().map(|p| p.join("rustup-version"));

let multirust_exists =
multirust_manifest_path.exists() && uninstaller_path.exists();
let rustc_exists =
rustc_manifest_path.exists() && uninstaller_path.exists();
let rustup_sh_exists =
rustup_sh_version_path.map(|p| p.exists()) == Some(true);

if multirust_exists {
warn!("it looks like you have an existing installation of multirust");
warn!("rustup cannot be installed alongside multirust. Please uninstall first");
warn!("run `{}` as root to uninstall multirust", uninstaller_path.display());
return Err("cannot install while multirust is installed".into());
}

if rustc_exists {
warn!("it looks like you have an existing installation of Rust");
warn!("rustup cannot be installed alongside Rust. Please uninstall first");
warn!("run `{}` as root to uninstall Rust", uninstaller_path.display());
return Err("cannot install while Rust is installed".into());
}

if rustup_sh_exists {
warn!("it looks like you have existing rustup.sh metadata");
warn!("rustup cannot be installed while rustup.sh metadata exists");
warn!("delete `{}` to remove rustup.sh", rustup_sh_path.expect("").display());
return Err("cannot install while rustup.sh is installed".into());
}

Ok(())
}

fn pre_install_msg(no_modify_path: bool) -> Result<String> {
let cargo_home = try!(utils::cargo_home());
let cargo_home_bin = cargo_home.join("bin");
Expand Down
22 changes: 22 additions & 0 deletions tests/cli-self-update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,3 +1046,25 @@ fn uninstall_doesnt_mess_with_a_non_unicode_path() {
assert!(path.bytes == reg_value.bytes);
});
}

#[test]
#[ignore] // untestable
fn install_but_multirust_is_installed() {
}

#[test]
#[ignore] // untestable
fn install_but_rustc_is_installed() {
}

#[test]
fn install_but_rustup_sh_is_installed() {
setup(&|config| {
let rustup_dir = config.homedir.join(".rustup");
fs::create_dir_all(&rustup_dir).unwrap();
let version_file = rustup_dir.join("rustup-version");
raw::write_file(&version_file, "").unwrap();
expect_err(config, &["rustup-init", "-y"],
"cannot install while rustup.sh is installed");
});
}