fn write_machine_toml(toml: &MachineToml) -> std::io::Result<()> {
let path = machine_config_path();
let parent = crate::utils::fs_perms::parent_or_err(&path, "machine config")?;
crate::utils::fs_perms::create_private_dir_all(parent)?;
let text = toml::to_string_pretty(toml).map_err(std::io::Error::other)?;
atomic_write(&path, text.as_bytes())
}
pub fn set_machine(name: &str) -> std::io::Result<()> {
let name = name.trim();
if name.is_empty() {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"machine name must not be empty",
));
}
let _guard = machine_toml_lock().lock_recover();
let mut toml = read_machine_toml();
toml.name = Some(name.to_string());
write_machine_toml(&toml)
}
pub fn max_concurrent_runs_override() -> Option<usize> {
read_machine_toml().max_concurrent_runs
}
pub fn set_max_concurrent_runs_override(value: Option<usize>) -> std::io::Result<()> {
let _guard = machine_toml_lock().lock_recover();
let mut toml = read_machine_toml();
toml.max_concurrent_runs = value;
write_machine_toml(&toml)
}
pub fn referenced_machines() -> std::collections::BTreeSet<String> {
let mut names = std::collections::BTreeSet::new();
let routines = crate::routine_storage::load_store();
for routine in routines.lock_recover().values() {
names.extend(routine.machines.iter().cloned());
}
names
}
pub fn targets(machines: &[String], me: &str) -> bool {
machines.iter().any(|pattern| {
if pattern.contains('*') {
glob_match(pattern, me)
} else {
pattern == me
}
})
}
#[cfg(test)]
#[path = "mod_tests.rs"]
mod machine_tests;
#[cfg(test)]
#[path = "mod_concurrency_tests.rs"]
mod machine_concurrency_tests;