pub struct ChrootCmd<'a> {
chroot_path: Cow<'a, Utf8Path>,
bind_mounts: Vec<(&'a str, &'a str)>,
env_vars: Vec<(&'a str, &'a str)>,
}Expand description
Builder for running commands inside a target directory using a mount namespace + chroot.
Fields§
§chroot_path: Cow<'a, Utf8Path>The target directory to use as root for the chroot.
bind_mounts: Vec<(&'a str, &'a str)>Bind mounts in format (host source, chroot-relative target).
env_vars: Vec<(&'a str, &'a str)>Environment variables to set on the spawned command.
Implementations§
Source§impl<'a> ChrootCmd<'a>
impl<'a> ChrootCmd<'a>
Sourcepub fn bind(
self,
source: &'a impl AsRef<Utf8Path>,
target: &'a impl AsRef<Utf8Path>,
) -> Self
pub fn bind( self, source: &'a impl AsRef<Utf8Path>, target: &'a impl AsRef<Utf8Path>, ) -> Self
Add a bind mount from source (on the host) to target (a path
inside the chroot, e.g. /boot).
Sourcepub fn setenv(self, key: &'a str, value: &'a str) -> Self
pub fn setenv(self, key: &'a str, value: &'a str) -> Self
Set an environment variable for the child. The chrooted command runs with a cleared environment, isolating it from the buildroot — callers must set every variable they want the child to see.
Sourcepub fn set_default_path(self) -> Self
pub fn set_default_path(self) -> Self
Set $PATH to a reasonable default covering the standard
system binary directories.
Sourcefn build_command<S: AsRef<OsStr>>(
self,
args: impl IntoIterator<Item = S>,
) -> Result<Command>
fn build_command<S: AsRef<OsStr>>( self, args: impl IntoIterator<Item = S>, ) -> Result<Command>
Build the underlying Command with the mount-namespace
setup and chroot installed as a pre_exec hook.
Sourcepub fn run<S: AsRef<OsStr>>(
self,
args: impl IntoIterator<Item = S>,
) -> Result<()>
pub fn run<S: AsRef<OsStr>>( self, args: impl IntoIterator<Item = S>, ) -> Result<()>
Run the specified command inside the chroot, inheriting stdio.
args must include the program as its first element.
Sourcepub fn run_get_string<S: AsRef<OsStr>>(
self,
args: impl IntoIterator<Item = S>,
) -> Result<String>
pub fn run_get_string<S: AsRef<OsStr>>( self, args: impl IntoIterator<Item = S>, ) -> Result<String>
Run the specified command inside the chroot and capture stdout
as a string. args must include the program as its first
element.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for ChrootCmd<'a>
impl<'a> RefUnwindSafe for ChrootCmd<'a>
impl<'a> Send for ChrootCmd<'a>
impl<'a> Sync for ChrootCmd<'a>
impl<'a> Unpin for ChrootCmd<'a>
impl<'a> UnsafeUnpin for ChrootCmd<'a>
impl<'a> UnwindSafe for ChrootCmd<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg] or
a color-specific method, such as [OwoColorize::green], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg] or
a color-specific method, such as [OwoColorize::on_yellow], Read more