From 737682ab163feb892b4440318e597d61d652d8da Mon Sep 17 00:00:00 2001 From: David Venhoff Date: Fri, 12 Sep 2025 12:16:30 +0200 Subject: [PATCH] Don't remove nyx tools if setting up the workdir failed --- src/nyx.rs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/nyx.rs b/src/nyx.rs index 95ab770..527bbc1 100644 --- a/src/nyx.rs +++ b/src/nyx.rs @@ -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 { - fn inner(out_dir: &Path, client: &Path) -> anyhow::Result { - if !out_dir.exists() { - 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") + if !out_dir.exists() { + fs::create_dir(out_dir)?; } - // 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) - } + println!("Installing nyx..."); + 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") } #[track_caller]