summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHermes Agent <hermes@localhost>2026-08-12 07:29:47 +0000
committerHermes Agent <hermes@localhost>2026-08-12 07:29:47 +0000
commit1c88ac5cba34058fc172001325dd2703d6fb3b92 (patch)
treee958658763070f5bed739cc98d02c31b150e9cf9
parent9afc0370eb2805c50b2bff7e519ee454e1b9cf8d (diff)
Clean workspace when installer produces no rootfs
-rw-r--r--src/build.rs5
-rw-r--r--tests/build.rs27
2 files changed, 31 insertions, 1 deletions
diff --git a/src/build.rs b/src/build.rs
index e6ddf14..994b793 100644
--- a/src/build.rs
+++ b/src/build.rs
@@ -65,7 +65,10 @@ impl<I: PackageInstaller, B: InitramfsBuilder> BuildExecutor<I, B> {
let rootfs = workspace.join("chroot");
if !rootfs.is_dir() {
- bail!("package installer did not create rootfs: {}", rootfs.display());
+ return Self::fail_and_remove_workspace(
+ workspace,
+ anyhow::anyhow!("package installer did not create rootfs: {}", rootfs.display()),
+ );
}
RootfsFinalization::new(
Vec::new(),
diff --git a/tests/build.rs b/tests/build.rs
index 987811a..cae79b0 100644
--- a/tests/build.rs
+++ b/tests/build.rs
@@ -31,6 +31,14 @@ impl PackageInstaller for FailingInstaller {
}
}
+struct RootfslessInstaller;
+
+impl PackageInstaller for RootfslessInstaller {
+ fn install(&self, _request: &PackageRequest) -> anyhow::Result<()> {
+ Ok(())
+ }
+}
+
struct FailingInitramfsBuilder;
impl InitramfsBuilder for FailingInitramfsBuilder {
@@ -191,6 +199,25 @@ fn removes_the_new_workspace_when_package_installation_fails() {
}
#[test]
+fn removes_the_new_workspace_when_the_installer_does_not_create_a_rootfs() {
+ let fixture = tempdir().expect("fixture directory");
+ let spec = ImageSpec::load(std::path::Path::new("profiles/alt-controller.toml"))
+ .expect("load controller spec");
+ let plan = BuildPlan::compile(spec).expect("compile build plan");
+ let mut executor = BuildExecutor::new(RootfslessInstaller, FixtureInitramfsBuilder);
+ let workspace = fixture.path().join("work");
+ let artifact = fixture.path().join("image.tar");
+
+ let error = executor
+ .execute(&plan, &workspace, "profiles/apt.conf", &artifact)
+ .expect_err("missing rootfs must fail the build");
+
+ assert!(error.to_string().contains("package installer did not create rootfs"));
+ assert!(!workspace.exists(), "failed build must not leave a workspace");
+ assert!(!artifact.exists());
+}
+
+#[test]
fn removes_the_new_workspace_when_initramfs_build_fails() {
let fixture = tempdir().expect("fixture directory");
let spec = ImageSpec::load(std::path::Path::new("profiles/alt-controller.toml"))