[arch-dev-public] [PATCH 1/4] Handle error case of parsepkgbuild correctly

Dan McGee dan at archlinux.org
Tue Jun 15 01:29:23 EDT 2010


We were never checking the return code of parsepkgbuild so would try to
parse the error message it printed out as a package definition rather than
erroring and returning None. Look at the return code, and as a bonus, use
the more correct communicate() rather than stdout.read().

Signed-off-by: Dan McGee <dan at archlinux.org>
---
 pacman.py     |    7 +++++--
 parsepkgbuild |    6 +++---
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/pacman.py b/pacman.py
index 1f78be2..f8edaab 100644
--- a/pacman.py
+++ b/pacman.py
@@ -105,8 +105,11 @@ def load(package, root=None):
 			workingdir = None
 		filename = os.path.basename(package)
 		process = subprocess.Popen(['parsepkgbuild',filename], stdout=subprocess.PIPE, cwd=workingdir)
-		data = process.stdout.read()
-		ret = loaddb(None, data)
+		data = process.communicate()
+		# this means parsepkgbuild returned an error, so we are not valid
+		if process.returncode > 0:
+			return None
+		ret = loaddb(None, data[0])
 
 		# Add a nice little .pkgbuild surprise
 		pkgbuild = open(package)
diff --git a/parsepkgbuild b/parsepkgbuild
index f9b5a91..d8bcc98 100755
--- a/parsepkgbuild
+++ b/parsepkgbuild
@@ -9,9 +9,9 @@ export PATH=/tmp/parsepkgbuild; exec /bin/bash --noprofile --norc -r << EOF
 
 source $1
 
-# ensure $pkgname and $pkgver variables were found
-if [ -z "\$pkgname" -o -z "\$pkgver" ]; then
-	echo "   error: invalid package file"
+# ensure $pkgname, $pkgver, and $pkgrel variables were found
+if [ -z "\$pkgname" -o -z "\$pkgver" -o -z "\$pkgrel" ]; then
+	echo "error: invalid package file"
 	exit 1
 fi 
 
-- 
1.7.1



More information about the arch-dev-public mailing list