diff --git a/src/agent/onefuzz-agent/src/local/generic_analysis.rs b/src/agent/onefuzz-agent/src/local/generic_analysis.rs index 0cefd32dc..0bc241584 100644 --- a/src/agent/onefuzz-agent/src/local/generic_analysis.rs +++ b/src/agent/onefuzz-agent/src/local/generic_analysis.rs @@ -29,7 +29,12 @@ pub fn build_analysis_config( let analyzer_env = get_hash_map(args, ANALYZER_ENV)?; let analysis = get_synced_dir(ANALYSIS_DIR, common.job_id, common.task_id, args)?; let tools = get_synced_dir(TOOLS_DIR, common.job_id, common.task_id, args)?; - let crashes = get_synced_dir(CRASHES_DIR, common.job_id, common.task_id, args).ok(); + let crashes = if input_queue.is_none() { + get_synced_dir(CRASHES_DIR, common.job_id, common.task_id, args).ok() + } else { + None + }; + let reports = get_synced_dir(REPORTS_DIR, common.job_id, common.task_id, args).ok(); let no_repro = get_synced_dir(NO_REPRO_DIR, common.job_id, common.task_id, args).ok(); let unique_reports = diff --git a/src/agent/onefuzz-agent/src/tasks/analysis/generic.rs b/src/agent/onefuzz-agent/src/tasks/analysis/generic.rs index 77047237b..6b6450c63 100644 --- a/src/agent/onefuzz-agent/src/tasks/analysis/generic.rs +++ b/src/agent/onefuzz-agent/src/tasks/analysis/generic.rs @@ -6,10 +6,10 @@ use crate::tasks::{ }; use anyhow::{Context, Result}; use futures::stream::StreamExt; -use onefuzz::{az_copy, blob::url::BlobUrl, fs::SyncPath}; +use onefuzz::{az_copy, blob::url::BlobUrl}; use onefuzz::{ expand::Expand, - fs::{copy, set_executable, OwnedDir}, + fs::{set_executable, OwnedDir}, jitter::delay_with_jitter, process::monitor_process, syncdir::SyncedDir, @@ -22,7 +22,7 @@ use std::{ str, }; use storage_queue::{QueueClient, EMPTY_QUEUE_DELAY}; -use tempfile::tempdir; +use tempfile::tempdir_in; use tokio::{fs, process::Command}; #[derive(Debug, Deserialize)] @@ -48,8 +48,16 @@ pub struct Config { } pub async fn run(config: Config) -> Result<()> { - let tmp_dir = PathBuf::from(format!("./{}/tmp", config.common.task_id)); - let tmp = OwnedDir::new(tmp_dir); + let task_dir = config + .analysis + .path + .parent() + .ok_or_else(|| anyhow!("Invalid input path"))?; + let temp_path = task_dir.join(".temp"); + tokio::fs::create_dir_all(&temp_path).await?; + let tmp_dir = tempdir_in(&temp_path)?; + let tmp = OwnedDir::new(tmp_dir.path()); + tmp.reset().await?; config.analysis.init().await?; @@ -60,7 +68,7 @@ pub async fn run(config: Config) -> Result<()> { // report SyncedDir. The idea is that the option for where to write reports // is only available for target option / env expansion if one of the reports // SyncedDir is provided. - let reports_dir = tempdir()?; + let reports_dir = tempdir_in(temp_path)?; let (reports_path, reports_monitor_future) = if config.unique_reports.is_some() || config.reports.is_some() || config.no_repro.is_some() { @@ -175,20 +183,14 @@ async fn _copy(input_url: BlobUrl, destination_folder: &OwnedDir) -> Result { - az_copy::copy(input_url.as_ref(), destination_path.clone(), false).await? + az_copy::copy(input_url.as_ref(), &destination_path, false).await? } BlobUrl::LocalFile(path) => { - copy( - SyncPath::file(path), - SyncPath::dir(destination_path.clone()), - false, - ) - .await? + tokio::fs::copy(path, &destination_path).await?; } } Ok(destination_path) } - pub async fn run_tool( input: impl AsRef, config: &Config, diff --git a/src/agent/onefuzz/src/blob/url.rs b/src/agent/onefuzz/src/blob/url.rs index 949048b7a..9aa9b851c 100644 --- a/src/agent/onefuzz/src/blob/url.rs +++ b/src/agent/onefuzz/src/blob/url.rs @@ -70,17 +70,24 @@ impl BlobUrl { } pub fn name(&self) -> String { - let name_segments: Vec<_> = self - .url() - .path_segments() - .unwrap() - .skip(match self { - Self::AzureBlob(_) => 1, - _ => 0, - }) - .map(|s| s.to_owned()) - .collect(); - name_segments.join("/") + match self { + Self::AzureBlob(url) => { + let name_segments: Vec<_> = url + .path_segments() + .unwrap() + .skip(1) + .map(|s| s.to_owned()) + .collect(); + name_segments.join("/") + } + Self::LocalFile(path) => path + .file_name() + .expect("Invalid file path") + .to_os_string() + .to_str() + .expect("Invalid file path") + .into(), + } } }