diffpkg: prefer to search inside the pool dir if available

On certain packaging machines where the pacman cache gets updated very
infrequently, the behavior of diffpkg may not function correctly as old
packages were to be downloaded as diff target. In such cases we look for
a pool directory first and search via a glob for an available pool
package sorted by version.

The pool search glob has three glob segments each disallowing the dash
delimiter to split across pkgrel, pkgver and arch. This will return the
correct package from the pool without considering overly eager wildcards
that potentially match different pkgnames.

The default pool search directory is /srv/ftp/pool
This commit is contained in:
Levente Polyak 2022-08-31 02:00:28 +02:00
parent 70a3041ff8
commit f4e8047d65
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8
3 changed files with 32 additions and 3 deletions

View File

@ -52,6 +52,7 @@ _diffpkg_args=(
'(-y --side-by-side)'{-y,--side-by-side}'[Output in two columns]' '(-y --side-by-side)'{-y,--side-by-side}'[Output in two columns]'
'--color=[Color output]:when:($_colors[*])' '--color=[Color output]:when:($_colors[*])'
'(-W --width=)'{-W,--width=}'[Output at most NUM print columns]:num:(auto columns)' '(-W --width=)'{-W,--width=}'[Output at most NUM print columns]:num:(auto columns)'
'(-P --pool=)'{-P,--pool=}'[pool directory]:dir:_files -/'
'(-v --verbose)'{-v,--verbose}'[Provide more detailed/unfiltered output]' '(-v --verbose)'{-v,--verbose}'[Provide more detailed/unfiltered output]'
'(-h --help)'{-h,--help}'[Display usage]' '(-h --help)'{-h,--help}'[Display usage]'
'*:packages:_devtools_completions_all_packages' '*:packages:_devtools_completions_all_packages'

View File

@ -21,7 +21,7 @@ When given one package, use it to diff against the locally built one.
When given two packages, diff both packages against each other. When given two packages, diff both packages against each other.
In either case, a package name will be converted to a filename from the In either case, a package name will be converted to a filename from the
cache, and diffpkg will proceed as though this filename was initially cache or pool, and diffpkg will proceed as though this filename was initially
specified. specified.
Options Options
@ -30,6 +30,10 @@ Options
*-M, --makepkg-config*:: *-M, --makepkg-config*::
Set an alternate makepkg configuration file Set an alternate makepkg configuration file
*-P, --pool*='DIR'::
Search diff target in pool dir (default `'/srv/ftp/pool'`)
*-v, --verbose*:: *-v, --verbose*::
Provide more detailed/unfiltered output Provide more detailed/unfiltered output

View File

@ -24,6 +24,7 @@ usage() {
OPTIONS OPTIONS
-M, --makepkg-config Set an alternate makepkg configuration file -M, --makepkg-config Set an alternate makepkg configuration file
-P, --pool=DIR Search diff target in pool dir (default '/srv/ftp/pool')
-v, --verbose Provide more detailed/unfiltered output -v, --verbose Provide more detailed/unfiltered output
-h, --help Show this help text -h, --help Show this help text
@ -44,6 +45,8 @@ _EOF_
} }
MAKEPKG_CONF=/etc/makepkg.conf MAKEPKG_CONF=/etc/makepkg.conf
POOLDIR=/srv/ftp/pool
VERBOSE=0 VERBOSE=0
TARLIST=0 TARLIST=0
DIFFOSCOPE=0 DIFFOSCOPE=0
@ -63,6 +66,7 @@ while (( $# )); do
exit 0 exit 0
;; ;;
-M|--makepkg-config) -M|--makepkg-config)
(( $# <= 1 )) && die "missing argument for %s" "$1"
MAKEPKG_CONF="$2" MAKEPKG_CONF="$2"
shift 2 shift 2
;; ;;
@ -112,6 +116,15 @@ while (( $# )); do
DIFFWIDTH="$1" DIFFWIDTH="$1"
shift shift
;; ;;
-P|--pool)
(( $# <= 1 )) && die "missing argument for %s" "$1"
POOLDIR="$2"
shift 2
;;
--pool=*)
POOLDIR="${1#*=}"
shift
;;
--) --)
shift shift
break break
@ -248,8 +261,19 @@ fetch_pkg() {
pkg=$1 ;; pkg=$1 ;;
esac esac
[[ -n $pkgurl ]] || pkgurl=$(pacman -Spdd --print-format '%l' --noconfirm "$pkg") || if [[ -z ${pkgurl} ]]; then
die "Couldn't download previous package for %s." "$pkg" # Try to find latest package in pool dir
if [[ -d ${POOLDIR} ]]; then
shopt -s extglob nullglob
pkgurl=$(printf "%s\n" "${POOLDIR}"/*/"${_pkgname}"-!(*-*)-!(*-*)-!(*-*).pkg.tar!(*.sig)|sort -Vr|head -1)
shopt -u extglob nullglob
fi
# Search via pacman database if no pool file exists
if [[ ! -f ${pkgurl} ]]; then
pkgurl=$(pacman -Spdd --print-format '%l' --noconfirm "$pkg") ||
die "Couldn't download previous package for %s." "$pkg"
fi
fi
pkg=${pkgurl##*/} pkg=${pkgurl##*/}
pkgdest=$(mktemp -t -d "${pkg}-XXXXXX")/${pkg} pkgdest=$(mktemp -t -d "${pkg}-XXXXXX")/${pkg}