From 9cc6517e4a0034c7f1b3ed94c092870ece4f81a2 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 12 Jul 2016 01:13:47 +0000 Subject: [PATCH] Remove toolchain directory if initial toolchain install fails If initial toolchain installation fails it leaves behind a directory, which confuses rustup into thinking it's installed. --- src/rustup-dist/src/dist.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/rustup-dist/src/dist.rs b/src/rustup-dist/src/dist.rs index e60be4d3dc..b512154698 100644 --- a/src/rustup-dist/src/dist.rs +++ b/src/rustup-dist/src/dist.rs @@ -497,6 +497,33 @@ pub fn update_from_dist<'a>(download: DownloadCfg<'a>, remove: &[Component]) -> Result> { + let fresh_install = !prefix.path().exists(); + + let res = update_from_dist_(download, + update_hash, + toolchain, + prefix, + add, + remove); + + // Don't leave behind an empty / broken installation directory + if res.is_err() && fresh_install { + // FIXME Ignoring cascading errors + let _ = utils::remove_dir("toolchain", prefix.path(), + &|n| (download.notify_handler)(n.into())); + } + + res +} + +pub fn update_from_dist_<'a>(download: DownloadCfg<'a>, + update_hash: Option<&Path>, + toolchain: &ToolchainDesc, + prefix: &InstallPrefix, + add: &[Component], + remove: &[Component]) + -> Result> { + let toolchain_str = toolchain.to_string(); let manifestation = try!(Manifestation::open(prefix.clone(), toolchain.target.clone()));