Subject: pkg/15827: failed su during make update incorrectly continues
To: None <gnats-bugs@gnats.netbsd.org>
From: Aaron J. Grier <agrier@poofygoof.com>
List: netbsd-bugs
Date: 03/06/2002 21:47:17
>Number:         15827
>Category:       pkg
>Synopsis:       if su fails during a make update, another make update barfs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pkg-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 06 21:48:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        NetBSD 1.5.1
>Organization:
Poofy Goof Enterprises
>Environment:
System: NetBSD gorbag 1.5.2 NetBSD 1.5.2 (GENERIC) #0: Wed Aug 22 04:33:09 CST 2001 toor@proxima:/usr/src/sys/arch/sparc/compile/GENERIC sparc


>Description:
	since DDIR doesn't get removed if the su for package deletion
	fails, the next time make update runs, it will see DDIR, and
	assume that the package was removed.  this causes problems when
	it comes time to actually install the updated package: "package
	foo is already installed, perhaps an older version?"  it's not a
	showstopper, but is easily fixed with a few lines of shell in
	bsd.pkg.mk.
>How-To-Repeat:
	run make update as a non-root user, and control-C or otherwise
	cause the su to fail.  re-run make update, and watch as make
	update blissfully continues, unaware until install time that the
	pkg_delete completed unsuccessfully.
>Fix:
	the following patch, while (somewhat) inelegant, seems to work
	on my systems after a few days of banging, and has the extra
	side-benefit of not trying to uninstall non-existant packages
	due to the if clause.  it's very helpful when bringing up
	packages on a bare system not to have to type in passwords for
	every single package to be deinstalled and still have the update
	run as a no-priviliged user.

Index: bsd.pkg.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.mk,v
retrieving revision 1.942
diff -u -r1.942 bsd.pkg.mk
--- bsd.pkg.mk	2002/03/06 11:37:28	1.942
+++ bsd.pkg.mk	2002/03/07 05:10:09
@@ -2552,8 +2552,10 @@
 
 update:
 	${_PKG_SILENT}${_PKG_DEBUG}${MAKE} ${MAKEFLAGS} ${DDIR}
-	${_PKG_SILENT}${_PKG_DEBUG}					\
-		${MAKE} ${MAKEFLAGS} deinstall DEINSTALLDEPENDS=ALL
+	${_PKG_SILENT}${_PKG_DEBUG}if ${PKG_INFO} -qe ${PKGNAME}; then \
+		${MAKE} ${MAKEFLAGS} deinstall DEINSTALLDEPENDS=ALL \
+		|| (${RM} ${DDIR} && ${FALSE}); \
+	fi
 .endif
 	${_PKG_SILENT}${_PKG_DEBUG}					\
 		${MAKE} ${MAKEFLAGS} ${UPDATE_TARGET} KEEP_WRKDIR=YES	\
>Release-Note:
>Audit-Trail:
>Unformatted: