Don't remove nyx tools if setting up the workdir failed
This commit is contained in:
parent
bad2725805
commit
737682ab16
20
src/nyx.rs
20
src/nyx.rs
@ -84,28 +84,22 @@ 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]
|
||||
fn shell(cwd: impl AsRef<Path>, command_string: &str) -> anyhow::Result<()> {
|
||||
println!("Running ({}) {command_string}", cwd.as_ref().display());
|
||||
|
Loading…
x
Reference in New Issue
Block a user