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

Don't install when multirust metadata exists. Fixes #424 #456

Merged
merged 1 commit into from
May 13, 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
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");
});
}