From e3c4a409e19ffdafb9dd7997a96b0e771c168228 Mon Sep 17 00:00:00 2001 From: Teo Voinea <58236992+tevoinea@users.noreply.github.com> Date: Thu, 21 Sep 2023 14:17:02 -0400 Subject: [PATCH] Create directories if they don't exist in the template (#3522) * Create directories if they don't exist in the template * fmt --- src/agent/onefuzz-task/src/local/template.rs | 8 ++++---- .../onefuzz-task/tests/template_integration.rs | 16 ++++++---------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/agent/onefuzz-task/src/local/template.rs b/src/agent/onefuzz-task/src/local/template.rs index 73ae6e5e48..64b342744d 100644 --- a/src/agent/onefuzz-task/src/local/template.rs +++ b/src/agent/onefuzz-task/src/local/template.rs @@ -136,16 +136,16 @@ impl RunContext { name: impl AsRef, path: impl AsRef, ) -> Result { - if !path.as_ref().exists() { - std::fs::create_dir_all(&path)?; - } - self.to_sync_dir(name, path)? .monitor_count(&self.event_sender) } pub fn to_sync_dir(&self, name: impl AsRef, path: impl AsRef) -> Result { let path = path.as_ref(); + if !path.exists() { + std::fs::create_dir_all(path)?; + } + let name = name.as_ref(); let current_dir = std::env::current_dir()?; if self.create_job_dir { diff --git a/src/agent/onefuzz-task/tests/template_integration.rs b/src/agent/onefuzz-task/tests/template_integration.rs index d0e68e5d02..bcfefd3bda 100644 --- a/src/agent/onefuzz-task/tests/template_integration.rs +++ b/src/agent/onefuzz-task/tests/template_integration.rs @@ -4,6 +4,7 @@ use std::{ path::{Path, PathBuf}, }; +use path_absolutize::Absolutize; use tokio::fs; use anyhow::Result; @@ -131,25 +132,20 @@ async fn create_test_directory(config: &Path, target_exe: &Path) -> Result