diff --git a/src/download.rs b/src/download.rs index bd804efac..c9a4dd5f7 100644 --- a/src/download.rs +++ b/src/download.rs @@ -207,7 +207,8 @@ pub fn download_file(url: &str, path: &PathBuf) -> Result<()> { response.into_reader().read_to_end(&mut data)?; if let Err(e) = file.write_all(&data) { - error!( + fs::remove_file(path)?; + bail!( "Something went wrong writing data to {}: {}", path.display(), e @@ -225,12 +226,14 @@ pub fn download_file(url: &str, path: &PathBuf) -> Result<()> { thread::sleep(Duration::from_secs(retry)); } Err(e) => { + fs::remove_file(path)?; // handle other status code and non-status code errors bail!("Unexpected error: {}", e.to_string()); } } } + fs::remove_file(path)?; bail!("Could not download file"); } diff --git a/src/toolchain.rs b/src/toolchain.rs index 5eed7eba2..b247bb307 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -268,7 +268,9 @@ impl Toolchain { &download_cfg.name, &download_cfg.version, self.name ); - if !store.has_component(&download_cfg.name, &download_cfg.version) { + if !store.has_component(&download_cfg.name, &download_cfg.version) + || !self.has_component(&download_cfg.name) + { match store.install_component(&download_cfg) { Ok(downloaded) => { for bin in downloaded {