Subject: pkg_install and mk/ patch for user-destdir support
To: None <tech-pkg@netbsd.org>
From: Joerg Sonnenberger <joerg@britannica.bec.de>
List: tech-pkg
Date: 11/01/2006 16:44:05
--Boundary_(ID_OOMjblcpTdmjDVh+OHGlug)
Content-type: text/plain; charset="us-ascii"
Content-transfer-encoding: 7BIT
Content-disposition: inline

Hi all,

during the work of getting the packages I use fully user-destdir save,
I've stumpled over a bug in pkg_install. The first patch tries to fix
that, but I'd like to have another opinion as the code is quite messy
and full of side effects. The problem is that without the patch pushout
will be called with NULL when a rename failed and when any
@chmod/@chown/@chgrp is active, path names relative to PREFIX end up as
arguments for programs called with cwd /.

The second patch adds package-install, which behaves like package for
normal packages and like bin-install with forced rebuild for those
supporting DESTDIR. It is intended esp. as dependency target in
combination with bin-install.

Joerg

--Boundary_(ID_OOMjblcpTdmjDVh+OHGlug)
Content-type: text/plain; charset=us-ascii; NAME="pkg_install.diff"
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename="pkg_install.diff"

Index: add/extract.c
===================================================================
RCS file: /repo/netbsd/src/usr.sbin/pkg_install/add/extract.c,v
retrieving revision 1.38
diff -u -r1.38 extract.c
--- add/extract.c	11 May 2006 23:50:15 -0000	1.38
+++ add/extract.c	1 Nov 2006 00:16:11 -0000
@@ -243,7 +243,8 @@
 				} else {
 					/* rename failed, try copying with a big tar command */
 					if (last_chdir != Directory) {
-						pushout(last_chdir);
+						if (last_chdir != NULL)
+							pushout(last_chdir);
 						last_chdir = Directory;
 					} else if (p->name[0] == '/') {
 						pushout(Directory);

--Boundary_(ID_OOMjblcpTdmjDVh+OHGlug)
Content-type: text/plain; charset=us-ascii; NAME="package-install.diff"
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename="package-install.diff"

Index: bsd.pkg.barrier.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.barrier.mk,v
retrieving revision 1.12
diff -u -r1.12 bsd.pkg.barrier.mk
--- bsd.pkg.barrier.mk	6 Oct 2006 19:04:37 -0000	1.12
+++ bsd.pkg.barrier.mk	1 Nov 2006 15:43:22 -0000
@@ -27,6 +27,7 @@
 _BARRIER_POST_TARGETS+=	replace
 _BARRIER_POST_TARGETS+=	package
 _BARRIER_POST_TARGETS+=	repackage
+_BARRIER_POST_TARGETS+=	package-install
 
 .for _target_ in ${_BARRIER_POST_TARGETS}
 .  if make(${_target_})
Index: flavor/pkg/package.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/flavor/pkg/package.mk,v
retrieving revision 1.5
diff -u -r1.5 package.mk
--- flavor/pkg/package.mk	9 Oct 2006 12:25:44 -0000	1.5
+++ flavor/pkg/package.mk	1 Nov 2006 15:43:22 -0000
@@ -111,3 +111,29 @@
 	${SETENV} PKG_DBDIR=${_PKG_DBDIR} PKG_SUFX=${PKG_SUFX}		\
 		PKGREPOSITORY=${PKGREPOSITORY}				\
 		${_PKG_TARUP_CMD} ${PKGNAME}
+
+######################################################################
+### package-install (PUBLIC)
+######################################################################
+### When DESTDIR support is active, package-install uses package to
+### create a binary package and installs it.
+### Otherwise it is identical to calling package.
+###
+
+.PHONY: package-install real-package-install su-real-package-install
+.if defined(_PKGSRC_BARRIER)
+package-install: package real-package-install
+.else
+package-install: barrier
+.endif
+
+.if ${_USE_DESTDIR} != "no"
+real-package-install: su-target
+.else
+real-package-install:
+	@${DO_NADA}
+.endif
+
+su-real-package-install:
+	@${PHASE_MSG} "Install binary package of "${PKGNAME:Q}
+	cd ${PREFIX} && ${PKG_ADD} ${PKGFILE}
Index: install/deinstall.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/install/deinstall.mk,v
retrieving revision 1.6
diff -u -r1.6 deinstall.mk
--- install/deinstall.mk	9 Aug 2006 15:31:01 -0000	1.6
+++ install/deinstall.mk	1 Nov 2006 15:43:23 -0000
@@ -24,7 +24,9 @@
 _SU_DEINSTALL_TARGETS=	acquire-deinstall-lock
 _SU_DEINSTALL_TARGETS+=	deinstall-pkg
 _SU_DEINSTALL_TARGETS+=	release-deinstall-lock
+.if ${_USE_DESTDIR} == "no"
 _SU_DEINSTALL_TARGETS+=	install-clean
+.endif
 su-deinstall: ${_SU_DEINSTALL_TARGETS}
 
 .PHONY: acquire-deinstall-lock release-deinstall-lock

--Boundary_(ID_OOMjblcpTdmjDVh+OHGlug)--