From b9d43cb9d3dc4becec598ec83614c3561d7fc771 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Wed, 12 Aug 2026 07:58:08 +0000 Subject: Clean workspace when native packaging fails --- src/build.rs | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'src/build.rs') 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 BuildExecutor { 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(workspace: &Path, error: anyhow::Error) -> Result { -- cgit v1.2.3