Skip to content

Commit

Permalink
ostree_prepareroot: Add an internal enum
Browse files Browse the repository at this point in the history
This will allow us to more cleanly warn in the future
if composefs is not enabled in some situations.
  • Loading branch information
cgwalters committed Mar 13, 2024
1 parent ae87efc commit 0c8f873
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions rust/src/ostree_prepareroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,37 @@ pub(crate) fn load_config(rootfs: &Dir) -> Result<Option<glib::KeyFile>> {
Ok(None)
}

pub(crate) enum Rootfs {
Legacy,
Composefs,
Transient,
}

pub fn rootfs_setup(rootfs: &Dir) -> Result<Rootfs> {
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<bool> {
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))
}

0 comments on commit 0c8f873

Please sign in to comment.