From 0c8f87396a7978bf18cc7597524a0b5b74f6709f Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 1 Mar 2024 10:57:57 -0500 Subject: [PATCH] ostree_prepareroot: Add an internal enum This will allow us to more cleanly warn in the future if composefs is not enabled in some situations. --- rust/src/ostree_prepareroot.rs | 37 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/rust/src/ostree_prepareroot.rs b/rust/src/ostree_prepareroot.rs index a6ecef18cd..10ce3f5335 100644 --- a/rust/src/ostree_prepareroot.rs +++ b/rust/src/ostree_prepareroot.rs @@ -37,14 +37,37 @@ pub(crate) fn load_config(rootfs: &Dir) -> Result> { Ok(None) } +pub(crate) enum Rootfs { + Legacy, + Composefs, + Transient, +} + +pub fn rootfs_setup(rootfs: &Dir) -> Result { + let config = if let Some(config) = load_config(rootfs)? { + config + } else { + return Ok(Rootfs::Legacy); + }; + let r = if config + .optional_bool("root", "transient")? + .unwrap_or_default() + { + Rootfs::Transient + } else if config + .optional_string("composefs", "enabled")? + .map(|s| s.as_str() == "yes") + .unwrap_or_default() + { + Rootfs::Composefs + } else { + Rootfs::Legacy + }; + Ok(r) +} + /// Query whether the target root has the `root.transient` key /// which sets up a transient overlayfs. pub(crate) fn transient_root_enabled(rootfs: &Dir) -> Result { - if let Some(config) = load_config(rootfs)? { - Ok(config - .optional_bool("root", "transient")? - .unwrap_or_default()) - } else { - Ok(false) - } + Ok(matches!(rootfs_setup(rootfs)?, Rootfs::Transient)) }