From: Luca BRUNO Date: Wed, 27 Oct 2021 09:45:34 +0000 (+0000) Subject: sysroot: add a builder object X-Git-Tag: archive/raspbian/2022.4-1+rpi1^2~9^2^2~20^2~35 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=ec572d786ea862724e6d53d58fd1ea61e4db4c3f;p=ostree.git sysroot: add a builder object This adds a `SysrootBuilder` in order to allow consumers to load a configured `Sysroot` in an ergonomic way. It tries to prevent logic bugs coming from handling half-initialized entities. --- diff --git a/rust-bindings/rust/src/lib.rs b/rust-bindings/rust/src/lib.rs index 41cdd58b..5bce2adb 100644 --- a/rust-bindings/rust/src/lib.rs +++ b/rust-bindings/rust/src/lib.rs @@ -33,6 +33,8 @@ mod checksum; pub use crate::checksum::*; mod core; pub use crate::core::*; +mod sysroot; +pub use crate::sysroot::*; #[cfg(any(feature = "v2018_6", feature = "dox"))] mod collection_ref; diff --git a/rust-bindings/rust/src/sysroot.rs b/rust-bindings/rust/src/sysroot.rs new file mode 100644 index 00000000..7e207f38 --- /dev/null +++ b/rust-bindings/rust/src/sysroot.rs @@ -0,0 +1,48 @@ +use crate::gio; +use crate::Sysroot; +use std::path::PathBuf; + +#[derive(Clone, Debug, Default)] +/// Builder object for `Sysroot`. +pub struct SysrootBuilder { + path: Option, + mount_namespace_in_use: bool, +} + +impl SysrootBuilder { + /// Create a new builder for `Sysroot`. + pub fn new() -> Self { + Self::default() + } + + /// Set the path to the sysroot location. + pub fn path(mut self, path: Option) -> Self { + self.path = path; + self + } + + #[cfg(any(feature = "v2020_1", feature = "dox"))] + #[cfg_attr(feature = "dox", doc(cfg(feature = "v2020_1")))] + /// Set whether the logic is running in its own mount namespace. + pub fn mount_namespace_in_use(mut self, mount_namespace_in_use: bool) -> Self { + self.mount_namespace_in_use = mount_namespace_in_use; + self + } + + /// Finalize this builder into a `Sysroot`. + pub fn build(self, cancellable: Option<&gio::Cancellable>) -> Result { + let sysroot = { + let opt_file = self.path.map(|p| gio::File::for_path(p)); + Sysroot::new(opt_file.as_ref()) + }; + + #[cfg(feature = "v2020_1")] + if self.mount_namespace_in_use { + sysroot.set_mount_namespace_in_use(); + } + + sysroot.load(cancellable)?; + + Ok(sysroot) + } +}