diff --git a/src/deb/ephemeral.rs b/src/deb/ephemeral.rs index 65c3440..d611072 100644 --- a/src/deb/ephemeral.rs +++ b/src/deb/ephemeral.rs @@ -17,7 +17,7 @@ pub struct EphemeralContextGuard { impl EphemeralContextGuard { /// Create a new ephemeral unshare context for the specified series - pub fn new(series: &str) -> Result> { + pub async fn new(series: &str) -> Result> { let current_context_name = context::manager().current_name(); // Create a temporary directory for the chroot @@ -31,7 +31,7 @@ impl EphemeralContextGuard { ); // Download and extract the chroot tarball - Self::download_and_extract_chroot(series, &chroot_path)?; + Self::download_and_extract_chroot(series, &chroot_path).await?; // Switch to an ephemeral context to build the package in the chroot context::manager().set_current_ephemeral(Context::new(ContextConfig::Unshare { @@ -46,7 +46,7 @@ impl EphemeralContextGuard { }) } - fn download_and_extract_chroot( + async fn download_and_extract_chroot( series: &str, chroot_path: &PathBuf, ) -> Result<(), Box> { @@ -95,7 +95,7 @@ impl EphemeralContextGuard { // Download tarball if it doesn't exist if !tarball_path.exists() { log::debug!("Downloading chroot tarball for {}...", series); - Self::download_chroot_tarball(series, &tarball_path)?; + Self::download_chroot_tarball(series, &tarball_path).await?; } else { log::debug!("Using cached chroot tarball for {}", series); } @@ -111,7 +111,10 @@ impl EphemeralContextGuard { Ok(()) } - fn download_chroot_tarball(series: &str, tarball_path: &Path) -> Result<(), Box> { + async fn download_chroot_tarball( + series: &str, + tarball_path: &Path, + ) -> Result<(), Box> { let ctx = context::current(); // Create a lock file to make sure that noone tries to use the file while it's not fully downloaded @@ -121,9 +124,7 @@ impl EphemeralContextGuard { .status()?; // Make sure we have the right apt keyrings to mmdebstrap the chroot - tokio::runtime::Runtime::new().unwrap().block_on( - crate::apt::keyring::download_trust_keyring(Some(ctx.clone()), series), - )?; + crate::apt::keyring::download_trust_keyring(Some(ctx.clone()), series).await?; // Use mmdebstrap to download the tarball to the cache directory let status = ctx diff --git a/src/deb/mod.rs b/src/deb/mod.rs index a63919d..1f217e8 100644 --- a/src/deb/mod.rs +++ b/src/deb/mod.rs @@ -17,7 +17,7 @@ pub enum BuildMode { } /// Build package in 'cwd' to a .deb -pub fn build_binary_package( +pub async fn build_binary_package( arch: Option<&str>, series: Option<&str>, cwd: Option<&Path>, @@ -49,7 +49,7 @@ pub fn build_binary_package( // Create an ephemeral unshare context for all Local builds let mut guard = if mode == BuildMode::Local { - Some(ephemeral::EphemeralContextGuard::new(series)?) + Some(ephemeral::EphemeralContextGuard::new(series).await?) } else { None }; @@ -227,6 +227,7 @@ mod tests { log::info!("Starting binary package build..."); crate::deb::build_binary_package(arch, Some(series), Some(&cwd), cross, None) + .await .expect("Cannot build binary package (deb)"); log::info!("Successfully built binary package"); diff --git a/src/main.rs b/src/main.rs index 628d6fc..118bcd5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -157,9 +157,10 @@ fn main() { _ => None, }; - if let Err(e) = + if let Err(e) = rt.block_on(async { pkh::deb::build_binary_package(arch, series, Some(cwd.as_path()), *cross, mode) - { + .await + }) { error!("{}", e); std::process::exit(1); }