From ohauer@FreeBSD.org  Fri Dec 31 02:08:23 2010
Return-Path: <ohauer@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 50243106566C;
	Fri, 31 Dec 2010 02:08:23 +0000 (UTC)
	(envelope-from ohauer@FreeBSD.org)
Received: from u18-124.dslaccess.de (unknown [194.231.39.124])
	by mx1.freebsd.org (Postfix) with ESMTP id 91DE88FC14;
	Fri, 31 Dec 2010 02:08:22 +0000 (UTC)
Received: by u18-124.dslaccess.de (Postfix, from userid 1100)
	id 478DF205CC; Fri, 31 Dec 2010 03:08:20 +0100 (CET)
Message-Id: <20101231020820.478DF205CC@u18-124.dslaccess.de>
Date: Fri, 31 Dec 2010 03:08:20 +0100 (CET)
From: Olli Hauer <ohauer@FreeBSD.org>
To: <FreeBSD-gnats-submit@freebsd.org>
Subject: [patch] ports/Mk bsd.license.mk honor pkg_add -p/-P
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         153573
>Category:       ports
>Synopsis:       [patch] ports/Mk bsd.license.mk honor pkg_add -p/-P
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    tabthorpe
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Dec 31 02:10:10 UTC 2010
>Closed-Date:    Mon Jan 09 15:34:29 UTC 2012
>Last-Modified:  Mon Jan  9 15:40:10 UTC 2012
>Originator:     Olli Hauer
>Release:        
>Organization:
>Environment:


>Description:

If a package is installed with pkg_add -p or -P there is an issue
during deinstall of the package.

You will notice a simmilar message during deinstall:

# pkg_delete lic-test-1.0
pkg_delete: file '/usr/local/share/licenses/lic-test-1.0' doesn't exist
pkg_delete: unable to completely remove directory '/usr/local/share/licenses/lic-test-1.0'
pkg_delete: couldn't entirely delete package (perhaps the packing list is incorrectly specified?)

This issue comes from a hard coded PREFIX injected to TMPPLIST during package generation.
( @\${ECHO_CMD} "@cwd \${PREFIX}" >> \${TMPPLIST} )


>How-To-Repeat:

I've made some tests and found an interesting behavior of pkg_add which solves this issue.
If "@cwd " without target is given it will be replaced during pkg_add with "@cwd $PKG_PREFIX".
Important, there must be an whitespace behind "@cwd "!

Testcase:
1)      create package with test port

2)      pkg_info -f lic-test-1.0 | grep CWD
            CWD to /usr/local
            CWD to /tmp
            CWD to /var/tmp
            CWD to /usr/local

3)      pkg_delete lic-test-1.0

4)      mtree -U -f /usr/ports/Templates/BSD.local.dist -d -e -p /tmp/lic-test >/dev/null

5)      pkg_add -p /tmp/lic-test lic-test-1.0.tbz

6)      pkg_info -f lic-test-1.0 | grep CWD
            CWD to /tmp/lic-test
            CWD to /tmp
            CWD to /var/tmp
wrong -->   CWD to /usr/local

7)      pkg_delete lic-test-1.0
            pkg_delete: file '/usr/local/share/licenses/lic-test-1.0' doesn't exist
            pkg_delete: unable to completely remove directory '/usr/local/share/licenses/lic-test-1.0'
            pkg_delete: couldn't entirely delete package (perhaps the packing list is incorrectly specified?)

8)      Apply patch for bsd.license.mk and go back to 1)

Now we have the follwing output for 2) and 6)
2)          CWD to /usr/local
            CWD to /tmp
            CWD to /var/tmp
            CWD to /usr/local

6)          CWD to /tmp/lic-test
            CWD to /tmp
            CWD to /var/tmp
OK -->      CWD to /tmp/lic-test

Even in /var/db/pkg/lic-test-1.0/+CONTENTS we can find this lines
@comment the following entries are added by the ports framework
@cwd /tmp/lic-test
@dirrm share/licenses/lic-test-1.0

 

>Fix:

--- patch_ports-MK__bsd.license.mk.txt begins here ---
Index: Mk/bsd.licenses.mk
===================================================================
RCS file: /home/pcvs/ports/Mk/bsd.licenses.mk,v
retrieving revision 1.4
diff -u -r1.4 bsd.licenses.mk
--- Mk/bsd.licenses.mk
+++ Mk/bsd.licenses.mk
@@ -744,7 +744,8 @@
 .	endfor
 .endif
 # XXX @dirrmtry entry must be here (no way to do with PLIST_* vars)
-	@${ECHO_CMD} "@cwd ${PREFIX}" >> ${TMPPLIST}
+# XXX Important, keep the whitespace behind "@cwd "!
+	@${ECHO_CMD} "@cwd " >> ${TMPPLIST}
 	@${ECHO_CMD} "@dirrm ${_LICENSE_DIR_REL}" >> ${TMPPLIST}
 	@${ECHO_CMD} "@unexec rmdir %D/share/licenses 2>/dev/null || true" >> ${TMPPLIST}
 
--- patch_ports-MK__bsd.license.mk.txt ends here ---

--- test-port-and-patch-for-bsd.license.mk begins here ---
--- /dev/null
+++ Makefile
@@ -0,0 +1,19 @@
+# lic-test
+
+PORTNAME=	lic-test
+PORTVERSION=	1.0
+CATEGORIES=	misc
+MASTER_SITES=	# none
+DISTFILES=	# none
+
+MAINTAINER=	devnull@example.org
+COMMENT=	Lic test for pkg_add -p or -P
+
+LICENSE=	BSD
+NO_BUILD=	yes
+
+do-install:
+	@${MKDIR} ${DATADIR}
+	@${INSTALL_DATA} ${WRKDIR}/.PLIST.mktmp ${DATADIR}/PLIST
+
+.include <bsd.port.mk>
--- /dev/null
+++ pkg-plist
@@ -0,0 +1,7 @@
+%%DATADIR%%/PLIST
+@dirrm %%DATADIR%%
+@exec echo "PKG_PREFIX $PKG_PREFIX"
+@comment do at last 2x cwd
+@cwd /tmp
+@cwd /var/tmp
+@comment the following entries are added by the ports framework
--- /dev/null
+++ pkg-descr
@@ -0,0 +1,5 @@
+license test if installed from package
+with parameter -p or -P
+
+for example:
+pkg_add -p /foo/bar dummy.pkg
--- test-port-and-patch-for-bsd.license.mk ends here ---
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->alepulver 
Responsible-Changed-By: sunpoet 
Responsible-Changed-When: Tue Feb 8 09:04:59 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=153573 
Responsible-Changed-From-To: alepulver->portmgr 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Feb 24 23:53:44 UTC 2011 
Responsible-Changed-Why:  
portmgr will take a look at this now. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=153573 
Responsible-Changed-From-To: portmgr->tabthorpe 
Responsible-Changed-By: tabthorpe 
Responsible-Changed-When: Thu Mar 31 03:49:00 UTC 2011 
Responsible-Changed-Why:  
I'll take it. 

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

From: Chris Rees <chris@bayofrum.net>
To: bug-followup@FreeBSD.org, ohauer@FreeBSD.org
Cc:  
Subject: Re: ports/153573: [patch] ports/Mk bsd.license.mk honor pkg_add -p/-P
Date: Thu, 30 Jun 2011 08:16:34 +0100

 This is even documented in pkg_add (1).
 
   -p, --prefix prefix
               Set prefix as the directory in which to extract files from a
               package.  If a package has set its default directory, it 
 will be
               overridden by this flag.  Note that only the first @cwd 
 directive
               will be replaced, since pkg_add has no way of knowing which
               directory settings are relative and which are absolute.  It is
               rare in any case to see more than one directory transition 
 made,
               but when such does happen and you wish to have control 
 over *all*
               directory transitions, then you may then wish to look into the
               use of MASTER and SLAVE modes (see the -M and -S options).  If
               the -p flag appears after any -P flag on the command line, it
               overrides its effect, causing pkg_add not to use the given 
 prefix
               recursively.
 
 I don't think there's an easy solution to this.
 
 Also, considering the sheer number of ports that s#/usr/local#${PREFIX} 
 on build, any autohell ports, cmake etc will all hardcode the default 
 prefix I think that even offering the -p option on pkg_add is a bad idea.
 
 Chris
 
 -- 
 This message has been scanned for viruses and
 dangerous content by MailScanner, and is
 believed to be clean.
 

From: Chris Rees <crees@FreeBSD.org>
To: bug-followup@FreeBSD.org, ohauer@FreeBSD.org
Cc:  
Subject: Re: ports/153573: [patch] ports/Mk bsd.license.mk honor pkg_add -p/-P
Date: Thu, 30 Jun 2011 09:50:08 +0100

 OK, sorry after reading the PR more carefully I see how it should work.
 
 I'll fix that in my CONF_FILES patch too...
 
 I still think it's a bad idea to even have that option though.
 
 Chris
 
 -- 
 This message has been scanned for viruses and
 dangerous content by MailScanner, and is
 believed to be clean.
 

State-Changed-From-To: open->closed 
State-Changed-By: tabthorpe 
State-Changed-When: Mon Jan 9 15:34:28 UTC 2012 
State-Changed-Why:  
Committed. Thanks! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/153573: commit references a PR
Date: Mon,  9 Jan 2012 15:31:36 +0000 (UTC)

 tabthorpe    2012-01-09 15:31:27 UTC
 
   FreeBSD ports repository
 
   Modified files:
     Mk                   bsd.licenses.mk 
   Log:
   - Make pkg_add honour -p/-P
   
   PR:             ports/153573
   Submitted by:   ohauer
   Exp run by:     pav
   
   Revision  Changes    Path
   1.9       +3 -2      ports/Mk/bsd.licenses.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:
