From 72b600107c2cef981c4bcfbac5811124363c6030 Mon Sep 17 00:00:00 2001 From: Halimao <1065621723@qq.com> Date: Tue, 21 Nov 2023 14:37:44 +0800 Subject: [PATCH 1/3] fix: fix component re-installation when fail to install the first time --- src/download.rs | 2 ++ src/toolchain.rs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/download.rs b/src/download.rs index bd804efac..63cd95633 100644 --- a/src/download.rs +++ b/src/download.rs @@ -225,12 +225,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..42307cb7a 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -268,7 +268,7 @@ 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 { From 873596c6fa3adbd526c27084babdaefadc9227ca Mon Sep 17 00:00:00 2001 From: Halimao <1065621723@qq.com> Date: Sun, 3 Dec 2023 18:27:39 +0800 Subject: [PATCH 2/3] remove the file and bail when write file error --- src/download.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/download.rs b/src/download.rs index 63cd95633..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 From 4080bd1772d28e456158892f94f4873885aec6a2 Mon Sep 17 00:00:00 2001 From: Halimao <1065621723@qq.com> Date: Mon, 4 Dec 2023 09:11:58 +0800 Subject: [PATCH 3/3] make cargo fmt happy --- src/toolchain.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/toolchain.rs b/src/toolchain.rs index 42307cb7a..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) || !self.has_component(&download_cfg.name) { + 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 {