summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHermes Agent <hermes@localhost>2026-08-12 07:58:08 +0000
committerHermes Agent <hermes@localhost>2026-08-12 07:58:08 +0000
commitb9d43cb9d3dc4becec598ec83614c3561d7fc771 (patch)
tree5de35d6866d82dc59a3057fbb3466cdedb8caf75 /src
parentf967d698efd44473a9285e02d0109f3bb0641622 (diff)
Clean workspace when native packaging fails
Diffstat (limited to 'src')
-rw-r--r--src/build.rs42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/build.rs b/src/build.rs
index 7fd3989..8b6ebb0 100644
--- a/src/build.rs
+++ b/src/build.rs
@@ -109,25 +109,31 @@ impl<I: PackageInstaller, B: InitramfsBuilder> BuildExecutor<I, B> {
Ok(initrd) => initrd,
Err(error) => return Self::fail_and_remove_workspace(workspace, error),
};
- std::fs::create_dir_all(parent)
- .with_context(|| format!("create artifact directory {}", parent.display()))?;
- self.tar_writer.write(&rootfs, artifact)?;
- let manifest = ArtifactManifest::collect(
- &rootfs,
- Vec::new(),
- Some(InitrdRecord::new(
- initrd.initrd_path().display().to_string(),
- initrd.sha256(),
- )),
- artifact,
- )?;
- let manifest_path = manifest.write_beside(artifact)?;
+ let result = (|| {
+ std::fs::create_dir_all(parent)
+ .with_context(|| format!("create artifact directory {}", parent.display()))?;
+ self.tar_writer.write(&rootfs, artifact)?;
+ let manifest = ArtifactManifest::collect(
+ &rootfs,
+ Vec::new(),
+ Some(InitrdRecord::new(
+ initrd.initrd_path().display().to_string(),
+ initrd.sha256(),
+ )),
+ artifact,
+ )?;
+ let manifest_path = manifest.write_beside(artifact)?;
- Ok(BuildResult {
- artifact: artifact.to_path_buf(),
- manifest: manifest_path,
- initrd: Some(initrd),
- })
+ Ok(BuildResult {
+ artifact: artifact.to_path_buf(),
+ manifest: manifest_path,
+ initrd: Some(initrd),
+ })
+ })();
+ match result {
+ Ok(result) => Ok(result),
+ Err(error) => Self::fail_and_remove_workspace(workspace, error),
+ }
}
fn fail_and_remove_workspace<T>(workspace: &Path, error: anyhow::Error) -> Result<T> {