Skip to content

Commit

Permalink
Robustify SDK installation (#1053)
Browse files Browse the repository at this point in the history
* Retry installing sdk if previous attempt did not complete correctly

* Remove old SDK directory before installing

* Notify user that incomplete sdk is being removed

* Separate cleanup and installation steps
  • Loading branch information
knoellle authored Jun 13, 2024
1 parent a78c1c2 commit 695b09c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions crates/repository/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use serde_json::{from_slice, from_str, to_string_pretty, to_value, Value};
use tempfile::{tempdir, TempDir};
use tokio::{
fs::{
create_dir_all, read_dir, read_link, read_to_string, remove_file, rename, set_permissions,
symlink, try_exists, write, File,
create_dir_all, read_dir, read_link, read_to_string, remove_dir_all, remove_file, rename,
set_permissions, symlink, try_exists, write, File,
},
io::AsyncReadExt,
process::Command,
Expand Down Expand Up @@ -327,6 +327,15 @@ impl Repository {
directory
};
let sdk = installation_directory.join(version);

let incomplete_marker = installation_directory.join(format!("{version}.incomplete"));
if sdk.exists() && incomplete_marker.exists() {
println!("Removing incomplete SDK directory...");
remove_dir_all(&sdk)
.await
.wrap_err("failed to remove old SDK directory")?;
}

if !sdk.exists() {
let downloads_directory = installation_directory.join("downloads");
let installer_name = format!("HULKs-OS-toolchain-{version}.sh");
Expand All @@ -336,9 +345,16 @@ impl Repository {
.await
.wrap_err("failed to download SDK")?;
}

File::create(&incomplete_marker)
.await
.wrap_err("failed to create marker")?;
install_sdk(installer_path, &sdk)
.await
.wrap_err("failed to install SDK")?;
remove_file(&incomplete_marker)
.await
.wrap_err("failed to remove marker")?;
}
Ok(())
}
Expand Down

0 comments on commit 695b09c

Please sign in to comment.