From 5697097e676967784de4666ffec3d03a03d0c205 Mon Sep 17 00:00:00 2001 From: Marcelo Hernandez Lopez Date: Wed, 14 Feb 2024 22:50:14 -0500 Subject: [PATCH] fix: only set cwd for editor command fixes relative tmp directories not being deleted --- src/lib.rs | 9 +++++---- src/templates.rs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9ccb35d..3d5df1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,12 +24,13 @@ pub fn try_template( .join(format!("{template}_{time}")); copy_dir_recursively(wanted_dir, &tmp_dir)?; - std::env::set_current_dir(&tmp_dir).expect("Could not change to temp directory!"); Command::new(editor) - .arg(&tmp_dir) - .spawn()? + .current_dir(&tmp_dir) + .arg(".") + .spawn() + .context("Failed to launch editor!")? .wait() - .expect("Could not launch editor!"); + .context("Failed waiting for editor!")?; if delete || ask_y_n("Would you like to keep this project?")? { println!("Saved as {tmp_dir:?}."); diff --git a/src/templates.rs b/src/templates.rs index 394f940..69e0c23 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -42,7 +42,7 @@ impl TryFrom<&Path> for Templates { let mut templates = Vec::new(); for entry in entries { - let path = entry?.path(); + let path = entry.context("Failed to unwrap templates entry!")?.path(); if path.is_dir() { templates.push(path);