1use anyhow::{Result, anyhow};
2use std::path::{Path, PathBuf};
3
4pub fn to_container_path(host_path: &Path, mappings: &[(&Path, &Path)]) -> Result<PathBuf> {
5 for (host_base, container_base) in mappings {
6 if let Ok(rel) = host_path.strip_prefix(host_base) {
7 return Ok(container_base.join(rel));
8 }
9 }
10 let mut bases = String::new();
11 for (host_base, _) in mappings {
12 bases.push_str(&format!("{}\n", host_base.display()));
13 }
14 Err(anyhow!(
15 "path {:?} is outside allowed roots:\n{}",
16 host_path,
17 bases.trim_end()
18 ))
19}