Don't remove nyx tools if setting up the workdir failed

This commit is contained in:
David Venhoff 2025-09-12 12:16:30 +02:00
parent bad2725805
commit 737682ab16

View File

@ -84,26 +84,20 @@ impl Drop for NyxRunner {
///
/// Returns the path to the working directory
pub fn setup_nyx(out_dir: &Path, client: &Path) -> anyhow::Result<PathBuf> {
fn inner(out_dir: &Path, client: &Path) -> anyhow::Result<PathBuf> {
if !out_dir.exists() {
fs::create_dir(out_dir)?;
}
println!("Installing nyx...");
setup_nyx_tools(out_dir).with_context(|| "Setting up nyx tools")?;
let result = setup_nyx_tools(out_dir);
if let Err(e) = result {
// Remove the out directory as it may be tainted
fs::remove_dir_all(out_dir)
.with_context(|| format!("Error while handling error: {e}"))?;
return Err(e);
}
create_nyx_workdir(out_dir, client).with_context(|| "Creating the nyx working directory")
}
// Clean up the out directory if something went wrong
match inner(out_dir, client) {
Ok(path) => Ok(path),
Err(err) => {
fs::remove_dir_all(out_dir)
.with_context(|| format!("Error while handling error: {err}"))?;
Err(err)
}
}
}
#[track_caller]