diff --git a/v2/robotmk/src/bin/scheduler/setup/rcc.rs b/v2/robotmk/src/bin/scheduler/setup/rcc.rs index 7a3d6f1e..dcb0cb76 100644 --- a/v2/robotmk/src/bin/scheduler/setup/rcc.rs +++ b/v2/robotmk/src/bin/scheduler/setup/rcc.rs @@ -10,15 +10,14 @@ use camino::{Utf8Path, Utf8PathBuf}; use log::{debug, error}; use robotmk::section::WriteSection; use std::collections::HashMap; -use std::fs::create_dir_all; +use std::fs::{create_dir_all, remove_dir_all}; pub fn setup(global_config: &GlobalConfig, suites: Vec) -> Result> { adjust_rcc_binary_permissions(&global_config.rcc_binary_path) .context("Failed to adjust permissions of RCC binary")?; - create_dir_all(rcc_setup_working_directory( + clear_rcc_setup_working_directory(&rcc_setup_working_directory( &global_config.working_directory, - )) - .context("Failed to create working directory for RCC setup")?; + ))?; let (rcc_suites, mut surviving_suites): (Vec, Vec) = suites .into_iter() @@ -35,6 +34,15 @@ fn adjust_rcc_binary_permissions(executable_path: &Utf8Path) -> Result<()> { )) } +fn clear_rcc_setup_working_directory(working_directory: &Utf8Path) -> Result<()> { + remove_dir_all(working_directory).context(format!( + "Failed to remove working directory for RCC setup: {working_directory}" + ))?; + create_dir_all(working_directory).context(format!( + "Failed to create working directory for RCC setup: {working_directory}" + )) +} + fn rcc_setup_working_directory(working_directory: &Utf8Path) -> Utf8PathBuf { working_directory.join("rcc_setup") }