diff --git a/buildrepo.in b/buildrepo.in
index d719c347df002aebb82709b54b98de6b6cc3333c..c211789714b4d6f7e0ee6bdff814f55a70778a87 100755
--- a/buildrepo.in
+++ b/buildrepo.in
@@ -22,9 +22,9 @@ usage() {
 
 
 listpackages() {
+	cd "$aportsdir/$1"
 	for i in */APKBUILD; do
-		cd "$aportsdir"/$1/${i%/*} 
-		abuild listpkg
+		APKBUILD=$i abuild listpkg
 	done
 }