exp: cross #3

This commit is contained in:
2025-12-21 21:37:56 +01:00
parent 31bcd28c72
commit 0d4ae565dd
5 changed files with 197 additions and 59 deletions

View File

@@ -78,12 +78,20 @@ impl ContextDriver for UnshareDriver {
))
}
fn list_files(&self, _path: &Path) -> io::Result<Vec<PathBuf>> {
// TODO: Implement chroot file listing logic
Err(io::Error::new(
io::ErrorKind::Unsupported,
"list_files not yet implemented for chroot",
))
fn list_files(&self, path: &Path) -> io::Result<Vec<PathBuf>> {
let host_path = Path::new(&self.path).join(path.to_string_lossy().trim_start_matches('/'));
let host_entries = self.parent().list_files(&host_path)?;
let mut entries = Vec::new();
let prefix = Path::new(&self.path);
for entry in host_entries {
if let Ok(rel_path) = entry.strip_prefix(prefix) {
entries.push(Path::new("/").join(rel_path));
} else {
entries.push(entry);
}
}
Ok(entries)
}
fn run(
@@ -164,7 +172,10 @@ impl UnshareDriver {
let mut cmd = self.parent().command("sudo");
cmd.args(env.iter().map(|(k, v)| format!("{k}={v}")));
cmd.arg("unshare").arg("-R").arg(&self.path);
cmd.arg("unshare")
.arg("--mount-proc")
.arg("-R")
.arg(&self.path);
if let Some(dir) = cwd {
cmd.arg("-w").arg(dir);