The following failure will make makepkg still exit with return code 0:

    % PKGEXT=.tar makepkg -srief
    ...
    ==> Installing package awesome-git with pacman -U...
    error: failed to init transaction (unable to lock database)
    error: could not lock database: File exists
      if you're sure a package manager is not already
      running, you can remove /var/lib/pacman/db.lck
    ==> WARNING: Failed to install built package(s).


The code:

        if ! run_pacman -U "${pkglist[@]}"; then
                warning "$(gettext "Failed to install built package(s).")"
                return 0
        fi

It seems to be done intentionally:

    tree 2b824312ec75e6bf3e3247ebd28d5335f61d9190
    parent 7370fd595bc0447e7c17135e3a27cc3ae64015d4
    author Allan McRae <[email protected]> Sun Mar 29 16:49:57 2009 +1000
    committer Allan McRae <[email protected]> Sun Mar 29 16:49:57 2009 +1000
    
    makepkg: do not bail on failure to install built package
    
    Fixes FS#13417.  Do no exit makepkg on a failure to install the
    built package(s).  This allows clean-up to still occur.
    
    Signed-off-by: Allan McRae <[email protected]>
    
    diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
    index ff2663b..716c5a9 100644
    --- a/scripts/makepkg.sh.in
    +++ b/scripts/makepkg.sh.in
    @@ -1071,10 +1071,16 @@ install_package() {
                pkglist="${pkglist} 
$PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
        done
     
    +   local ret=0
        if [ "$ASROOT" -eq 0 ]; then
    -           sudo pacman $PACMAN_OPTS -U ${pkglist} || exit $?
    +           sudo pacman $PACMAN_OPTS -U ${pkglist} || ret=$?
        else
    -           pacman $PACMAN_OPTS -U ${pkglist} || exit $?
    +           pacman $PACMAN_OPTS -U ${pkglist} || ret=$?
    +   fi
    +
    +   if [ $ret -ne 0 ]; then
    +           warning "$(gettext "Failed to install built package(s).")"
    +           return 0
        fi
     }

Since the whole purpose of this appears to be running the clean-up in
case of errors, the following would work:

    --- /usr/bin/makepkg        2016-03-31 15:59:32.028531972 +0200
    +++ /tmp/makepkg.new        2016-03-31 15:59:27.255110641 +0200
    @@ -1426,7 +1427,7 @@
     
            if ! run_pacman -U "${pkglist[@]}"; then
                    warning "$(gettext "Failed to install built package(s).")"
    -           return 0
    +           return 1
            fi
     }
     
    @@ -2393,7 +2394,7 @@
     
     msg "$(gettext "Finished making: %s")" "$pkgbase $basever ($(date))"
     
    -install_package
    +install_package || exit $?
     
     exit 0 #E_OK

(just a proof of concept, there are other calls to install_package)


My use case is a script to rebuild and install a package locally, and
this should abort also in case of install failures.
The workaround might be to not use `-i` with `makepkg`, but run `pacman`
on the generated package instead.


Thanks,
Daniel.

Reply via email to