From mandree@FreeBSD.org  Tue Oct  4 21:07:25 2011
Return-Path: <mandree@FreeBSD.org>
Received: from apollo.emma.line.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28])
	by hub.freebsd.org (Postfix) with ESMTP id D0631106564A;
	Tue,  4 Oct 2011 21:07:24 +0000 (UTC)
	(envelope-from mandree@FreeBSD.org)
Received: from mandree by apollo.emma.line.org with local (Exim 4.76 (FreeBSD))
	(envelope-from <mandree@FreeBSD.org>)
	id 1RBCCx-000EHv-Tu; Tue, 04 Oct 2011 23:07:23 +0200
Message-Id: <E1RBCCx-000EHv-Tu@apollo.emma.line.org>
Date: Tue, 04 Oct 2011 23:07:23 +0200
From: Matthias Andree <mandree@FreeBSD.org>
Reply-To: Matthias Andree <mandree@FreeBSD.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc: portmgr@freebsd.org
Subject: [PATCH] Mk/bsd.port.mk: fix check-already-installed target
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         161287
>Category:       ports
>Synopsis:       [PATCH] Mk/bsd.port.mk: fix check-already-installed target
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    portmgr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 04 21:10:07 UTC 2011
>Closed-Date:    Sun Jan 15 22:13:56 UTC 2012
>Last-Modified:  Sun Jan 15 22:20:10 UTC 2012
>Originator:     Matthias Andree
>Release:        FreeBSD 8.2-STABLE amd64
>Organization:
>Environment:
System: FreeBSD apollo.emma.line.org 8.2-STABLE FreeBSD 8.2-STABLE #18: Wed Sep 28 22:02:18 CEST 2011 toor@apollo.emma.line.org:/usr/obj/usr/src/sys/GENERIC amd64


	
>Description:
The bsd.port.mk "check-already-installed" target has two bugs that
jeopardize the effectiveness.  The current version fails to detect
security/openvpn-devel updates, as noted by Eric F. Crist.

The reason is that the freshly generated ${TMPPLIST} and the pkg-plist
of the previously installed same-origin same-prefix port are compared in
an inadequate way:

- the plists aren't sorted, which, however, is a requisite for comm to
  work properly.

- TMPPLIST doesn't get lines starting with @ removed

While plists are more-or-less sorted already along a porter's handbook
recommendation in chapter 3, with the automatic addition
of various other lines to the TMPPLIST, the assumption "plist is sorted"
no longer holds - especially in context with the LICENSE framework which
adds files up front into PORTVERSIONed directories.

Fix this by:

- factoring out the normalization code

- identically normalizing package lists

- only then feeding them to the comm(1) command.

The patch below has been lightly tested and corrects the problem for
security/openvpn-devel and does not regress on news/leafnode.

	
>How-To-Repeat:
	
>Fix:

Index: Mk/bsd.port.mk
===================================================================
RCS file: /home/pcvs/ports/Mk/bsd.port.mk,v
retrieving revision 1.696
diff -u -r1.696 bsd.port.mk
--- Mk/bsd.port.mk	23 Sep 2011 22:20:46 -0000	1.696
+++ Mk/bsd.port.mk	4 Oct 2011 20:57:42 -0000
@@ -3940,6 +3940,7 @@
 # Utility targets follow
 
 .if !target(check-already-installed)
+_normalize_c_a_i_plists:= ${GREP} -v "^@" | ${SORT}
 check-already-installed:
 .if !defined(NO_PKG_REGISTER) && !defined(FORCE_PKG_REGISTER)
 		@${ECHO_MSG} "===>  Checking if ${PKGORIGIN} already installed"; \
@@ -3949,7 +3950,9 @@
 				for p in $${already_installed}; do \
 						prfx=`${PKG_INFO} -q -p $${p} 2> /dev/null | ${SED} -ne '1s|^@cwd ||p'`; \
 						if [ "x${PREFIX}" = "x$${prfx}" ]; then \
-								df=`${PKG_INFO} -q -f $${p} 2> /dev/null | ${GREP} -v "^@" | ${COMM} -12 - ${TMPPLIST}`; \
+								${CAT} ${TMPPLIST} | ${_normalize_c_a_i_plists} >${TMPPLIST}.sorted; \
+								df=`${PKG_INFO} -q -f $${p} 2> /dev/null | ${_normalize_c_a_i_plists} | ${COMM} -12 - ${TMPPLIST}.sorted`; \
+								${RM} -f ${TMPPLIST}.sorted; \
 								if [ -n "$${df}" ]; then \
 										found_package=$${p}; \
 										break; \
	


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->portmgr 
Responsible-Changed-By: pav 
Responsible-Changed-When: Tue Oct 4 21:16:28 UTC 2011 
Responsible-Changed-Why:  
Infrastructure patch - assign to portmgr 

http://www.freebsd.org/cgi/query-pr.cgi?pr=161287 

From: Juergen Lock <nox@jelal.kn-bremen.de>
To: bug-followup@freebsd.org
Cc: pav@freebsd.org
Subject: Re: ports/161287: [PATCH] Mk/bsd.port.mk: fix
 check-already-installed target
Date: Tue, 10 Jan 2012 21:04:58 +0100

 Hi!
 
  I stumbled across the same bug today without knowing about this PR
 (actually hselasky did with his webcamd update, but I looked for
 the cause), discussed the problem on irc and was asked to post my
 version of the fix as Pav preferred it, so here it is:
 
 Index: Mk/bsd.port.mk
 ===================================================================
 RCS file: /home/pcvs/ports/Mk/bsd.port.mk,v
 retrieving revision 1.699
 diff -u -p -r1.699 bsd.port.mk
 --- Mk/bsd.port.mk	9 Nov 2011 08:53:12 -0000	1.699
 +++ Mk/bsd.port.mk	10 Jan 2012 19:17:10 -0000
 @@ -2407,6 +2407,7 @@ PKGREQ?=		${PKGDIR}/pkg-req
  PKGMESSAGE?=	${PKGDIR}/pkg-message
  
  TMPPLIST?=	${WRKDIR}/.PLIST.mktmp
 +TMPPLIST_SORT?=	${WRKDIR}/.PLIST.mktmp.sorted
  TMPGUCMD?=	${WRKDIR}/.PLIST.gucmd
  
  .for _CATEGORY in ${CATEGORIES}
 @@ -3962,7 +3963,7 @@ delete-package-list: delete-package-link
  # Utility targets follow
  
  .if !target(check-already-installed)
 -check-already-installed:
 +check-already-installed: ${TMPPLIST_SORT}
  .if !defined(NO_PKG_REGISTER) && !defined(FORCE_PKG_REGISTER)
  		@${ECHO_MSG} "===>  Checking if ${PKGORIGIN} already installed"; \
  		${MKDIR} ${PKG_DBDIR}; \
 @@ -3971,7 +3972,7 @@ check-already-installed:
  				for p in $${already_installed}; do \
  						prfx=`${PKG_INFO} -q -p $${p} 2> /dev/null | ${SED} -ne '1s|^@cwd ||p'`; \
  						if [ "x${PREFIX}" = "x$${prfx}" ]; then \
 -								df=`${PKG_INFO} -q -f $${p} 2> /dev/null | ${GREP} -v "^@" | ${COMM} -12 - ${TMPPLIST}`; \
 +								df=`${PKG_INFO} -q -f $${p} 2> /dev/null | ${GREP} -v "^@" | ${SORT} -u | ${COMM} -12 - ${TMPPLIST_SORT}`; \
  								if [ -n "$${df}" ]; then \
  										found_package=$${p}; \
  										break; \
 @@ -5694,6 +5695,9 @@ generate-plist:
  ${TMPPLIST}:
  	@cd ${.CURDIR} && ${MAKE} generate-plist
  
 +${TMPPLIST_SORT}: ${TMPPLIST}
 +	@${SORT} -u ${TMPPLIST} >${TMPPLIST_SORT}
 +
  .if !target(add-plist-docs)
  add-plist-docs:
  .if defined(PORTDOCS) && !defined(NOPORTDOCS)
State-Changed-From-To: open->closed 
State-Changed-By: pav 
State-Changed-When: Sun Jan 15 22:11:23 UTC 2012 
State-Changed-Why:  
Committed, thanks! (nox's patch) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=161287 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/161287: commit references a PR
Date: Sun, 15 Jan 2012 22:13:50 +0000 (UTC)

 pav         2012-01-15 22:13:42 UTC
 
   FreeBSD ports repository
 
   Modified files:
     Mk                   bsd.port.mk 
   Log:
   - Fix check-already-installed target: comm expects the input to be sorted
   
   PR:             ports/161287
   Submitted by:   mandree, nox (used nox's version)
   
   Revision  Changes    Path
   1.702     +7 -3      ports/Mk/bsd.port.mk
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
