[dbscripts,3/3] Globally set $PKGEXT to a bash extended glob representing valid choices.

Message ID 20180216034504.27610-4-eschwartz@archlinux.org
State Superseded
Headers show
Series Fix ambiguous uses of | expand

Commit Message

Emil Velikov via arch-projects Feb. 16, 2018, 3:45 a.m. UTC
This can be anything makepkg.conf accepts, therefore it needs to be able
to match all that. Document the fact that this has *always* been some
sort of glob, and update the two cases where this was (not!) being
evaluated by bash [[ ... ]], to use a proxy function is_globfile()

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
---
 config       |  3 ++-
 db-functions | 11 ++++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

Patch

diff --git a/config b/config
index d2c1942..7a90fc6 100644
--- a/config
+++ b/config
@@ -25,7 +25,8 @@  TMPDIR="/var/tmp"
 ARCHES=(x86_64)
 DBEXT=".db.tar.gz"
 FILESEXT=".files.tar.gz"
-PKGEXT=".pkg.tar.?z"
+# bash glob listing allowed extensions. Note that db-functions turns on extglob.
+PKGEXT=".pkg.tar.@(gz|bz2|xz|lzo|lrz|Z)"
 SRCEXT=".src.tar.gz"
 
 # Allowed licenses: get sourceballs only for licenses in this array
diff --git a/db-functions b/db-functions
index f0f8980..7cf8444 100644
--- a/db-functions
+++ b/db-functions
@@ -3,7 +3,7 @@ 
 . /usr/share/makepkg/util.sh
 
 # global shell options for enhanced bash scripting
-shopt -s globstar nullglob
+shopt -s extglob globstar nullglob
 
 
 # Some PKGBUILDs need CARCH to be set
@@ -20,6 +20,11 @@  restore_umask () {
 	umask $UMASK >/dev/null
 }
 
+# Check if a file exists, even if the file uses wildcards
+is_globfile() {
+	[[ -f $1 ]]
+}
+
 # just like mv -f, but we touch the file and then copy the content so
 # default ACLs in the target dir will be applied
 mv_acl() {
@@ -378,8 +383,8 @@  check_pkgrepos() {
 	local pkgver="$(getpkgver ${pkgfile})" || return 1
 	local pkgarch="$(getpkgarch ${pkgfile})" || return 1
 
-	[[ -f ${FTP_BASE}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}${PKGEXT} ]] && return 1
-	[[ -f ${FTP_BASE}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}${PKGEXT}.sig ]] && return 1
+	is_globfile "${FTP_BASE}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}"${PKGEXT} && return 1
+	is_globfile "${FTP_BASE}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}"${PKGEXT}.sig && return 1
 	[[ -f ${FTP_BASE}/${PKGPOOL}/${pkgfile##*/} ]] && return 1
 	[[ -f ${FTP_BASE}/${PKGPOOL}/${pkgfile##*/}.sig ]] && return 1