use std::{io, path::Path, sync::OnceLock};
pub(crate) fn paths_equal(left: &Path, right: &Path) -> bool {
let identity = |path: &Path| {
super::open_directory(path)
.or_else(|_| super::open_regular(path))
.and_then(|file| super::file_identity(&file))
};
match (identity(left), identity(right)) {
(Ok(left), Ok(right)) => left == right,
_ => left == right,
}
}
pub(crate) fn is_within(path: &Path, root: &Path) -> bool {
path.ancestors().any(|ancestor| paths_equal(ancestor, root))
}
pub(crate) fn label() -> &'static str {
static LABEL: OnceLock<String> = OnceLock::new();
LABEL.get_or_init(|| format!("{} {}", std::env::consts::OS, std::env::consts::ARCH))
}
pub(crate) fn private_anonymous_file() -> io::Result<std::fs::File> {
let file = tempfile::tempfile()?;
super::restrict_file(&file)?;
Ok(file)
}