use crate::bubblewrap::{launch, HasNeither};
use crate::global::ChrootVerified;
use crate::GlobalsFinal;
use anyhow::Result as AResult;
use std::path::Path;
pub(super) struct BWParams<'a> {
pub(super) chroot: ChrootVerified,
pub(super) archive: &'a Path,
}
impl<'a> BWParams<'a> {
pub(super) fn dispatch(&self, globals: &GlobalsFinal) -> AResult<()> {
let archive = self.archive.canonicalize()?;
let command = format!("tar {} --file={}", TARARGS.join(" "), archive.display());
let args = HasNeither::new()
.namespace(&NSCONF)
.capabilities(&CAPABS)
.usercfg(&USRCONF)
.chroot(Path::new("/"))
.chdir(&self.chroot)
.command(&command)
.build();
launch(args, globals)?;
Ok(())
}
}
const TARARGS: &[&str] = &[
"--exclude=dev/*",
"--exclude=proc/*",
"--extract",
"--verbose",
"--preserve-permissions",
"--xattrs-include='*.*'",
"--numeric-owner",
];
const NSCONF: [&str; 2] = ["--unshare-all", "--unshare-user"];
const USRCONF: [&str; 4] = ["--uid", "0", "--gid", "0"];
const CAPABS: [&str; 3] = ["CAP_CHOWN", "CAP_FOWNER", "CAP_SETFCAP"];