Skip to content

Commit

Permalink
RCC setup: Fix crash if no plans for current session are configured
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jherbel committed Aug 5, 2024
1 parent 21f255d commit d4a8ed8
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/bin/scheduler/setup/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<HashMap<String, String>>(),
)
};

surviving_plans.extend(system_plans);
(
surviving_plans,
Expand Down Expand Up @@ -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<Plan>,
) -> (Vec<Plan>, HashMap<String, String>) {
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")?;
Expand Down

0 comments on commit d4a8ed8

Please sign in to comment.