Skip to content

Commit

Permalink
fix: fix component install when fail to be installed at the first time (
Browse files Browse the repository at this point in the history
#520)

* fix: fix component re-installation when fail to install the first time

* remove the file and bail when write file error

* make cargo fmt happy

---------

Co-authored-by: Sophie Dankel <[email protected]>
  • Loading branch information
Halimao and sdankel authored Dec 11, 2023
1 parent 152774c commit 423e5bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
}

Expand Down
4 changes: 3 additions & 1 deletion src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 423e5bb

Please sign in to comment.