From: Sébastien Luttringer <[email protected]>

In order to install/downgrade packages with dependencies (e.g gcc-multilib),
pass all packages to install in a row to pacman.

As a side improvement, when a package installation fails, build fails.
---
 makechrootpkg.in | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/makechrootpkg.in b/makechrootpkg.in
index 3c8a20f..447157d 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -126,23 +126,26 @@ clean_temporary() {
        stat_done
 }
 
+# install packages in one call to pacman to let it manage correctly
+# dependencies between packages
 install_packages() {
-       local pkgname
+       (( ${#install_pkgs[*]} == 0 )) && return 0
 
-       for install_pkg in "${install_pkgs[@]}"; do
-               pkgname="${install_pkg##*/}"
-               cp "$install_pkg" "$copydir/$pkgname"
+       local src dst
+       local -a dsts
 
-               arch-nspawn "$copydir" \
-                       "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
-                       pacman -U /$pkgname --noconfirm
-               (( ret += !! $? ))
-
-               rm "$copydir/$pkgname"
+       for src in "${install_pkgs[@]}"; do
+               dst=/"${src##*/}"
+               dsts+=("$dst")
+               cp "$src" "$copydir$dst"
        done
 
-       # If there is no PKGBUILD we are done
-       [[ -f PKGBUILD ]] || exit $ret
+       arch-nspawn "$copydir" "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
+               pacman -U "${dsts[@]}" --noconfirm || exit $?
+
+       for dst in "${dsts[@]}"; do
+               rm "$copydir$dst"
+       done
 }
 
 prepare_chroot() {
@@ -384,6 +387,9 @@ $update_first && arch-nspawn "$copydir" \
 
 [[ -n ${install_pkgs[*]} ]] && install_packages
 
+# If there is no PKGBUILD we are done
+[[ -f PKGBUILD ]] || exit 0
+
 download_sources
 
 prepare_chroot
-- 
Sébastien "Seblu" Luttringer

Reply via email to