diff --git a/src/deb/local.rs b/src/deb/local.rs index 6270a10..23d684d 100644 --- a/src/deb/local.rs +++ b/src/deb/local.rs @@ -188,17 +188,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 @@ -266,6 +256,59 @@ 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 + if !deb_files.is_empty() || !package_names.is_empty() { + log::info!("Installing .deb files: {:?}", deb_files); + let mut cmd = ctx.command("apt-get"); + cmd.envs(env.clone()) + .arg("-y") + .arg("--allow-downgrades") + .arg("install"); + // Add the .deb file paths with ./ prefix for apt to recognize them as local files + for deb_path in &deb_files { + cmd.arg(format!("./{}", deb_path.trim_start_matches('/'))); + } + if !package_names.is_empty() { + cmd.args(&package_names); + } + let status = cmd.status()?; + if !status.success() { + return Err(format!("Could not install injected packages: {:?}", deb_files).into()); + } + } + + Ok(()) +} + fn dose3_explain_dependencies( package: &str, version: &str,