diff --git a/src/deb/local.rs b/src/deb/local.rs index b44dccb..b068c0f 100644 --- a/src/deb/local.rs +++ b/src/deb/local.rs @@ -178,17 +178,7 @@ pub async fn build( // Install injected packages if specified if let Some(packages) = inject_packages { - log::info!("Installing injected packages: {:?}", packages); - let mut cmd = ctx.command("apt-get"); - cmd.envs(env.clone()) - .arg("-y") - .arg("--allow-downgrades") - .arg("install") - .args(packages); - let status = cmd.status()?; - if !status.success() { - return Err(format!("Could not install injected packages: {:?}", packages).into()); - } + install_injected_packages(packages, &env, ctx.clone())?; } // Install arch-specific build dependencies @@ -256,6 +246,64 @@ pub async fn build( Ok(()) } +fn install_injected_packages( + packages: &[&str], + env: &HashMap, + ctx: Arc, +) -> Result<(), Box> { + log::info!("Installing injected packages: {:?}", packages); + + // Separate .deb files from package names + let mut deb_files: Vec = Vec::new(); + let mut package_names: Vec<&str> = Vec::new(); + + for pkg in packages { + // Check if it's a .deb file path (ends with .deb and exists as a file) + let pkg_path = Path::new(pkg); + if pkg.ends_with(".deb") && pkg_path.exists() { + // Copy the .deb file into the build context + let dest_root = ctx.create_temp_dir()?; + let chroot_path = ctx.ensure_available(pkg_path, &dest_root)?; + log::debug!( + "Copied .deb file '{}' to chroot path '{}'", + pkg, + chroot_path.display() + ); + deb_files.push(chroot_path.to_string_lossy().to_string()); + } else { + package_names.push(pkg); + } + } + + // Install .deb files using dpkg -i + if !deb_files.is_empty() { + log::info!("Installing .deb files: {:?}", deb_files); + let mut cmd = ctx.command("dpkg"); + cmd.envs(env.clone()).arg("-i").args(&deb_files); + let status = cmd.status()?; + if !status.success() { + return Err(format!("Could not install .deb files: {:?}", deb_files).into()); + } + } + + // Install package names using apt-get + if !package_names.is_empty() { + log::info!("Installing packages from archive: {:?}", package_names); + let mut cmd = ctx.command("apt-get"); + cmd.envs(env.clone()) + .arg("-y") + .arg("--allow-downgrades") + .arg("install") + .args(&package_names); + let status = cmd.status()?; + if !status.success() { + return Err(format!("Could not install injected packages: {:?}", package_names).into()); + } + } + + Ok(()) +} + fn dose3_explain_dependencies( package: &str, version: &str,