Compare commits
1 Commits
v1.0.0
...
d65115241f
| Author | SHA1 | Date | |
|---|---|---|---|
| d65115241f |
+21
-1
@@ -550,7 +550,14 @@ fn run_hook_command(
|
|||||||
None
|
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");
|
let mut cmd = Command::new("chroot");
|
||||||
cmd.arg(rootfs).arg("/bin/sh").arg("-lc").arg(&hook.command);
|
cmd.arg(rootfs).arg("/bin/sh").arg("-lc").arg(&hook.command);
|
||||||
cmd
|
cmd
|
||||||
@@ -589,6 +596,10 @@ fn run_hook_command(
|
|||||||
Ok(())
|
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(
|
fn run_command_with_optional_stdin(
|
||||||
command: &mut Command,
|
command: &mut Command,
|
||||||
stdin_payload: Option<&str>,
|
stdin_payload: Option<&str>,
|
||||||
@@ -662,6 +673,15 @@ mod tests {
|
|||||||
assert!(!wildcard_match("usr/bin/*", "usr/lib/libc.so"));
|
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]
|
#[test]
|
||||||
fn parse_hook_accepts_starpack_style_sections() {
|
fn parse_hook_accepts_starpack_style_sections() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
|||||||
@@ -320,7 +320,7 @@ enum HookRunOutcome {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct ChrootMountGuard {
|
pub(super) struct ChrootMountGuard {
|
||||||
mounted: Vec<Mount>,
|
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_root = fs::canonicalize("/").ok();
|
||||||
let canonical_rootfs = fs::canonicalize(rootfs).ok();
|
let canonical_rootfs = fs::canonicalize(rootfs).ok();
|
||||||
match (canonical_rootfs, canonical_root) {
|
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
|
should_chroot && is_root && !shell_exists
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mount_chroot_filesystems(
|
pub(super) fn mount_chroot_filesystems(
|
||||||
rootfs: &Path,
|
rootfs: &Path,
|
||||||
bootstrap_script_path: Option<&Path>,
|
bootstrap_script_path: Option<&Path>,
|
||||||
) -> Result<ChrootMountGuard> {
|
) -> Result<ChrootMountGuard> {
|
||||||
|
|||||||
Reference in New Issue
Block a user