From d65115241f28916fdf0ab244e1ec087062f68088 Mon Sep 17 00:00:00 2001 From: SFG545 Date: Mon, 13 Jul 2026 01:06:03 -0500 Subject: [PATCH] add psudofs mounting to transation hooks because im stupid and it wasn't a feature before --- src/install/hooks.rs | 22 +++++++++++++++++++++- src/install/scripts.rs | 6 +++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/install/hooks.rs b/src/install/hooks.rs index 4caf4ee..c519510 100644 --- a/src/install/hooks.rs +++ b/src/install/hooks.rs @@ -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(); diff --git a/src/install/scripts.rs b/src/install/scripts.rs index ab998f0..1c28350 100644 --- a/src/install/scripts.rs +++ b/src/install/scripts.rs @@ -320,7 +320,7 @@ enum HookRunOutcome { } #[derive(Default)] -struct ChrootMountGuard { +pub(super) struct ChrootMountGuard { mounted: Vec, } @@ -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 {