From d4a8ed85079fe5822fa9e8d26fdc47786204ffc8 Mon Sep 17 00:00:00 2001 From: Joerg Herbel Date: Mon, 5 Aug 2024 17:08:00 +0200 Subject: [PATCH] RCC setup: Fix crash if no plans for current session are configured Long path support is always enabled in the current session. If no plans for the current session were configured, attempting to enable long path support crashed because the directory for the stdio files was missing. CMK-18570 --- src/bin/scheduler/setup/general.rs | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/bin/scheduler/setup/general.rs b/src/bin/scheduler/setup/general.rs index 084ebf54..4d1f6ec9 100644 --- a/src/bin/scheduler/setup/general.rs +++ b/src/bin/scheduler/setup/general.rs @@ -93,10 +93,32 @@ fn setup_rcc_working_directories( &environment_building_working_directory(working_directory), rcc_plans, ); + + #[cfg(unix)] let (mut surviving_plans, rcc_setup_failures) = setup_with_one_directory_per_user( &rcc_setup_working_directory(working_directory), surviving_plans, ); + #[cfg(windows)] + let (mut surviving_plans, rcc_setup_failures) = { + let (surviving_plans, rcc_setup_failures) = setup_with_one_directory_per_user( + &rcc_setup_working_directory(working_directory), + surviving_plans, + ); + let (surviving_plans, rcc_setup_failures_long_path_support) = + setup_with_one_directory_for_current_session( + &rcc_setup_working_directory(working_directory), + surviving_plans, + ); + ( + surviving_plans, + rcc_setup_failures + .into_iter() + .chain(rcc_setup_failures_long_path_support) + .collect::>(), + ) + }; + surviving_plans.extend(system_plans); ( surviving_plans, @@ -156,6 +178,27 @@ fn setup_with_one_directory_per_user( (surviving_plans, failures) } +#[cfg(windows)] +fn setup_with_one_directory_for_current_session( + target: &Utf8Path, + plans: Vec, +) -> (Vec, HashMap) { + use robotmk::session::CurrentSession; + + match create_dir_all(target.join(CurrentSession {}.id())) { + Ok(()) => (plans, HashMap::new()), + Err(error) => { + let error = anyhow!(error).context(format!("Failed to create directory {target}",)); + info!("{error:#}"); + let mut failures = HashMap::new(); + for plan in plans { + failures.insert(plan.id.clone(), format!("{error:#}")); + } + (vec![], failures) + } + } +} + fn setup_results_directories(global_config: &GlobalConfig, plans: &[Plan]) -> AnyhowResult<()> { create_dir_all(&global_config.results_directory) .context("Failed to create results directory")?;