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