[pacman-dev] [PATCH] repo-remove: Fix infinite loop when given a pkgname ending in '*'

Rafael Ascensão rafa.almas at gmail.com
Fri Apr 26 20:03:22 UTC 2019


While this is most likely the result of user error, as repo-remove
doesn't accept globs, using 'package*' as the pkgname will result in an
endless loop of the following message being printed:

  -> Removing existing entry 'package**'...

This happens because find_pkgentry() fails to account the case where
globbing fails and the expression is taken literally. Fix that by
checking the existence of the file before doing anything else.

Signed-off-by: Rafael Ascensão <rafa.almas at gmail.com>
---
 scripts/repo-add.sh.in | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 57413df5..123bb796 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -120,10 +120,12 @@ find_pkgentry() {
 	local pkgentry
 
 	for pkgentry in "$tmpdir/db/$pkgname"*; do
-		name=${pkgentry##*/}
-		if [[ ${name%-*-*} = $pkgname ]]; then
-			echo $pkgentry
-			return 0
+		if [[ -e $pkgentry ]]; then
+			name=${pkgentry##*/}
+			if [[ ${name%-*-*} = $pkgname ]]; then
+				echo $pkgentry
+				return 0
+			fi
 		fi
 	done
 	return 1
-- 
2.21.0


More information about the pacman-dev mailing list