use std::path::Path;
use anyhow::{Result, bail};
use openmoat_hosts::Host;
use crate::home::Home;
use crate::install::{HostConfig, Recorded, other_name};
pub(super) fn applies(lock_existed: bool, person: bool) -> bool {
lock_existed && !person
}
pub(super) fn refuse_other_binary(recorded: &Path, binary: &Path) -> Result<()> {
if recorded == binary || other_name(recorded).as_deref() == Some(binary) {
return Ok(());
}
bail!(
"refusing to point the hooks at {} without a person at a terminal: the policy lock \
records {}; run `openmoat init` in a terminal of your own to change it",
binary.display(),
recorded.display()
)
}
pub(super) fn config(home: &Home, host: Host, unattended: bool) -> Result<HostConfig> {
if unattended {
HostConfig::for_host(home, host)
} else {
HostConfig::for_init(home, host)
}
}
pub(super) fn record(recorded: &mut Recorded, config: &HostConfig, unattended: bool) {
if unattended && recorded.dir(config.host).is_some() {
return;
}
recorded.insert(config);
}