use std::env;
const HELPER_ENV: &str = "MERRY_SANDBOX_HELPER";
const POLICY_ENV: &str = "MERRY_SANDBOX_POLICY";
const SETUP_EXIT_CODE: i32 = 126;
#[must_use]
pub fn sandbox_helper_requested() -> bool {
env::var_os(HELPER_ENV).is_some() && env::var_os(POLICY_ENV).is_some()
}
pub fn sandbox_helper_main() -> ! {
eprintln!("merry-sandbox: {}", unavailable_reason());
std::process::exit(SETUP_EXIT_CODE);
}
pub fn probe_workspace_sandbox() -> Result<(), String> {
Err(unavailable_reason())
}
fn unavailable_reason() -> String {
if !cfg!(feature = "sandbox") && cfg!(any(target_os = "linux", target_os = "macos")) {
"workspace sandbox is disabled in this build (compiled without the `sandbox` feature)"
.to_owned()
} else {
format!(
"workspace sandbox is unavailable on {}",
std::env::consts::OS
)
}
}
pub(crate) fn setup_failure(stderr: &[u8]) -> Option<String> {
let text = String::from_utf8_lossy(stderr);
text.lines()
.find(|line| line.starts_with("merry-sandbox:"))
.map(|line| line.trim().to_owned())
}