[dbscripts,v2,4/8] Correctly treat PKGEXT_glob as a glob

Message ID 20180218171736.4473-5-lukeshu@lukeshu.com
State Rejected
Headers show
Series PKGEXT fixup | expand

Commit Message

Luke Shumaker Feb. 18, 2018, 5:17 p.m. UTC
From: Luke Shumaker <lukeshu@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@archlinux.org>
---
 db-functions                   | 9 +++++++--
 test/cases/ftpdir-cleanup.bats | 4 ++--
 2 files changed, 9 insertions(+), 4 deletions(-)

Comments

Luke Shumaker Feb. 18, 2018, 6:19 p.m. UTC | #1
On Sun, 18 Feb 2018 12:17:32 -0500,
Luke Shumaker wrote:
> 
> 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

Shoot, that needs to be __isGlobfile; we don't load db-functions here;
is_globfile is undefined.  It's basically doing "! false".

No mater how many times you look over it before hitting send...

Patch

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
 }