Skip to content

Commit

Permalink
Merge pull request #456 from brson/more-defenses
Browse files Browse the repository at this point in the history
Don't install when multirust metadata exists. Fixes #424
  • Loading branch information
alexcrichton committed May 13, 2016
2 parents 449b50a + 2dbcf34 commit a2e90ae
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
41 changes: 36 additions & 5 deletions src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ fn do_pre_install_sanity_checks() -> Result<()> {
= PathBuf::from("/usr/local/lib/rustlib/manifest-rustc");
let uninstaller_path
= PathBuf::from("/usr/local/lib/rustlib/uninstall.sh");
let multirust_meta_path
= env::home_dir().map(|d| d.join(".multirust"));
let multirust_version_path
= multirust_meta_path.as_ref().map(|p| p.join("version"));
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"));
Expand All @@ -303,12 +307,39 @@ fn do_pre_install_sanity_checks() -> Result<()> {
rustc_manifest_path.exists() && uninstaller_path.exists();
let rustup_sh_exists =
rustup_sh_version_path.map(|p| p.exists()) == Some(true);
let old_multirust_meta_exists = if let Some(ref multirust_version_path) = multirust_version_path {
multirust_version_path.exists() && {
let version = utils::read_file("old-multirust", &multirust_version_path);
let version = version.unwrap_or(String::new());
let version = version.parse().unwrap_or(0);
let cutoff_version = 12; // First rustup version

version < cutoff_version
}
} else {
false
};

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());
match (multirust_exists, old_multirust_meta_exists) {
(true, false) => {
warn!("it looks like you have an existing installation of multirust");
warn!("rustup cannot be installed alongside multirust");
warn!("run `{}` as root to uninstall multirust before installing rustup", uninstaller_path.display());
return Err("cannot install while multirust is installed".into());
}
(false, true) => {
warn!("it looks like you have existing multirust metadata");
warn!("rustup cannot be installed alongside multirust");
warn!("delete `{}` before installing rustup", multirust_version_path.expect("").display());
return Err("cannot install while multirust is installed".into());
}
(true, true) => {
warn!("it looks like you have an existing installation of multirust");
warn!("rustup cannot be installed alongside multirust");
warn!("run `{}` as root and delete `{}` before installing rustup", uninstaller_path.display(), multirust_version_path.expect("").display());
return Err("cannot install while multirust is installed".into());
}
(false, false) => ()
}

if rustc_exists {
Expand Down
12 changes: 12 additions & 0 deletions tests/cli-self-update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,3 +1077,15 @@ fn install_but_rustup_sh_is_installed() {
"cannot install while rustup.sh is installed");
});
}

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

0 comments on commit a2e90ae

Please sign in to comment.