Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions crates/lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,13 @@ pub(crate) struct InstallComposefsOpts {
impl InstallComposefsOpts {
/// Check that the options fit together, once `composefs_backend` says
/// whether the composefs backend is used (passed, or selected by the image).
/// `config_stateroot` comes from the install configuration and only counts
/// when `--stateroot` isn't passed.
pub(crate) fn validate(
&self,
bootloader: Option<&Bootloader>,
stateroot: Option<&str>,
config_stateroot: Option<&str>,
) -> Result<()> {
if self.composefs_backend {
anyhow::ensure!(
Expand All @@ -436,6 +439,12 @@ impl InstallComposefsOpts {
"--stateroot {stateroot} is not supported with the composefs backend, which only uses {default}"
);
}
if let (None, Some(stateroot)) = (stateroot, config_stateroot.filter(|&s| s != default))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to

Suggested change
if let (None, Some(stateroot)) = (stateroot, config_stateroot.filter(|&s| s != default))
if let Some(stateroot) = config_stateroot.filter(|&s| s != default)

since we're already checking stateroot in the above if?

{
anyhow::bail!(
"stateroot {stateroot} in the install configuration is not supported with the composefs backend, which only uses {default}"
);
}
} else {
anyhow::ensure!(
!self.allow_missing_verity,
Expand Down Expand Up @@ -1817,9 +1826,16 @@ async fn prepare_install(
)?;
tracing::debug!("Composefs default: {composefs_default}");
composefs_options.composefs_backend |= composefs_required || composefs_default;
// An image may set a stateroot in its install configuration for its ostree
// installs, so only check it when the image can't be installed with ostree.
let config_stateroot = install_config
.as_ref()
.and_then(|c| c.stateroot.as_deref())
.filter(|_| composefs_required || composefs_default);
composefs_options.validate(
config_opts.bootloader.as_ref(),
config_opts.stateroot.as_deref(),
config_stateroot,
)?;

composefs_options.validate_bound_images(config_opts.bound_images, &rootfs)?;
Expand Down Expand Up @@ -3202,7 +3218,7 @@ mod tests {
uki_addon,
};
assert_eq!(
opts.validate(bootloader.as_ref(), stateroot).is_ok(),
opts.validate(bootloader.as_ref(), stateroot, None).is_ok(),
valid,
"{opts:?} {bootloader:?} {stateroot:?}"
);
Expand All @@ -3213,9 +3229,25 @@ mod tests {
..Default::default()
};
assert_eq!(
opts.validate(None, Some("myroot")).unwrap_err().to_string(),
opts.validate(None, Some("myroot"), None)
.unwrap_err()
.to_string(),
"--stateroot myroot is not supported with the composefs backend, which only uses default"
);

assert!(opts.validate(None, None, Some("default")).is_ok());
assert!(opts.validate(None, Some("default"), Some("myroot")).is_ok());
assert!(
InstallComposefsOpts::default()
.validate(None, None, Some("myroot"))
.is_ok()
);
assert_eq!(
opts.validate(None, None, Some("myroot"))
.unwrap_err()
.to_string(),
"stateroot myroot in the install configuration is not supported with the composefs backend, which only uses default"
);
}

#[test]
Expand Down
Loading