[arch-projects] [dbscripts] [PATCH v2 4/8] Correctly treat PKGEXT_glob as a glob

Luke Shumaker lukeshu at lukeshu.com
Sun Feb 18 17:17:32 UTC 2018


From: Luke Shumaker <lukeshu at parabola.nu>

Several places treated PKGEXT as a fixed string in [[ -f ]] existence
checks.  Fix that elegantly by introducing an is_globfile function.

This fixes the failing db-update.bats "update same any package to same
repository fails" test.

This is based on a patch by Eli Schwartz <eschwartz at archlinux.org>
---
 db-functions                   | 9 +++++++--
 test/cases/ftpdir-cleanup.bats | 4 ++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/db-functions b/db-functions
index 84be241..769d7ef 100644
--- a/db-functions
+++ b/db-functions
@@ -16,6 +16,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() {
@@ -374,8 +379,8 @@ check_pkgrepos() {
 	local pkgver="$(getpkgver ${pkgfile})" || return 1
 	local pkgarch="$(getpkgarch ${pkgfile})" || return 1
 
-	[[ -f ${FTP_BASE}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}${PKGEXT_glob} ]] && return 1
-	[[ -f ${FTP_BASE}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}${PKGEXT_glob}.sig ]] && return 1
+	is_globfile "${FTP_BASE}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}"${PKGEXT_glob} && return 1
+	is_globfile "${FTP_BASE}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}"${PKGEXT_glob}.sig && return 1
 	[[ -f ${FTP_BASE}/${PKGPOOL}/${pkgfile##*/} ]] && return 1
 	[[ -f ${FTP_BASE}/${PKGPOOL}/${pkgfile##*/}.sig ]] && return 1
 
diff --git a/test/cases/ftpdir-cleanup.bats b/test/cases/ftpdir-cleanup.bats
index 7dfad4a..efc18a8 100644
--- a/test/cases/ftpdir-cleanup.bats
+++ b/test/cases/ftpdir-cleanup.bats
@@ -13,8 +13,8 @@ __checkRepoRemovedPackage() {
 	local pkgname
 
 	for pkgname in $(__getPackageNamesFromPackageBase ${pkgbase}); do
-		[[ ! -f ${FTP_BASE}/${PKGPOOL}/${pkgname}-*${PKGEXT_glob} ]]
-		[[ ! -f ${FTP_BASE}/${repo}/os/${repoarch}/${pkgname}-*${PKGEXT_glob} ]]
+		! is_globfile "${FTP_BASE}/${PKGPOOL}/${pkgname}"-*${PKGEXT_glob}
+		! is_globfile "${FTP_BASE}/${repo}/os/${repoarch}/${pkgname}"-*${PKGEXT_glob}
 	done
 }
 
-- 
2.16.1


More information about the arch-projects mailing list