add psudofs mounting to transation hooks because im stupid and it wasn't a feature before
This commit is contained in:
+21
-1
@@ -550,7 +550,14 @@ fn run_hook_command(
|
||||
None
|
||||
};
|
||||
|
||||
let mut command = if fakeroot::is_root() && rootfs.join("bin/sh").exists() {
|
||||
let use_chroot = fakeroot::is_root() && rootfs.join("bin/sh").exists();
|
||||
let _mounts = if should_mount_chroot_filesystems(rootfs, use_chroot) {
|
||||
Some(super::scripts::mount_chroot_filesystems(rootfs, None)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let mut command = if use_chroot {
|
||||
let mut cmd = Command::new("chroot");
|
||||
cmd.arg(rootfs).arg("/bin/sh").arg("-lc").arg(&hook.command);
|
||||
cmd
|
||||
@@ -589,6 +596,10 @@ fn run_hook_command(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn should_mount_chroot_filesystems(rootfs: &Path, use_chroot: bool) -> bool {
|
||||
use_chroot && super::scripts::should_use_chroot(rootfs)
|
||||
}
|
||||
|
||||
fn run_command_with_optional_stdin(
|
||||
command: &mut Command,
|
||||
stdin_payload: Option<&str>,
|
||||
@@ -662,6 +673,15 @@ mod tests {
|
||||
assert!(!wildcard_match("usr/bin/*", "usr/lib/libc.so"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transaction_hooks_mount_filesystems_only_for_target_chroots() {
|
||||
let rootfs = tempfile::tempdir().unwrap();
|
||||
|
||||
assert!(should_mount_chroot_filesystems(rootfs.path(), true));
|
||||
assert!(!should_mount_chroot_filesystems(rootfs.path(), false));
|
||||
assert!(!should_mount_chroot_filesystems(Path::new("/"), true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_hook_accepts_starpack_style_sections() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
|
||||
@@ -320,7 +320,7 @@ enum HookRunOutcome {
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct ChrootMountGuard {
|
||||
pub(super) struct ChrootMountGuard {
|
||||
mounted: Vec<Mount>,
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ impl Drop for ChrootMountGuard {
|
||||
}
|
||||
}
|
||||
|
||||
fn should_use_chroot(rootfs: &Path) -> bool {
|
||||
pub(super) fn should_use_chroot(rootfs: &Path) -> bool {
|
||||
let canonical_root = fs::canonicalize("/").ok();
|
||||
let canonical_rootfs = fs::canonicalize(rootfs).ok();
|
||||
match (canonical_rootfs, canonical_root) {
|
||||
@@ -372,7 +372,7 @@ fn should_bootstrap_host_shell(should_chroot: bool, is_root: bool, shell_exists:
|
||||
should_chroot && is_root && !shell_exists
|
||||
}
|
||||
|
||||
fn mount_chroot_filesystems(
|
||||
pub(super) fn mount_chroot_filesystems(
|
||||
rootfs: &Path,
|
||||
bootstrap_script_path: Option<&Path>,
|
||||
) -> Result<ChrootMountGuard> {
|
||||
|
||||
Reference in New Issue
Block a user