[pacman-dev] [PATCH] makepkg: Add a late check if package exists when using package functions

Nezmer git at nezmer.info
Tue May 25 12:00:47 EDT 2010


pkgver and pkgrel can be overridden in package functions. makepkg can't
use the overridden values when doing the early check if a package file
already exists. That means makepkg will silently delete the existing
package file and generate a new one.

pkgbase=N
pkgname=(N1 N2)
pkgver=1
pkgrel=1
arch=(any)

package_N1() {
  pkgver=v1
}

package_N2() {
  pkgver=v2
}

Signed-off-by: Nezmer <git at nezmer.info>
---

This is just a quick fix I needed. There is probably better ways to do
this.

 scripts/makepkg.sh.in |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 8c0da8b..c2953b4 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -979,6 +979,17 @@ check_package() {
 	if grep -R "${srcdir}" "${pkgdir}" &>/dev/null; then
 		warning "$(gettext "Package contains reference to %s")" "\$srcdir"
 	fi
+
+	# Check again if package already exists in case pkgver or pkgrel was overridden
+	if (( PKGFUNC || SPLITPKG )); then
+		for pkg in ${pkgname[@]}; do
+			if [[ -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT} \
+				|| -f $PKGDEST/${pkg}-${pkgver}-${pkgrel}-any${PKGEXT} ]]; then
+				error "$(gettext "A package already exists.")"
+				exit 1
+			fi
+		done
+	fi
 }
 
 create_package() {
-- 
1.7.1



More information about the pacman-dev mailing list