From nobody@FreeBSD.org  Wed Mar 24 09:07:01 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 08607106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 24 Mar 2010 09:07:01 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id EADEC8FC1D
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 24 Mar 2010 09:07:00 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o2O970cv051147
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 24 Mar 2010 09:07:00 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o2O97030051146;
	Wed, 24 Mar 2010 09:07:00 GMT
	(envelope-from nobody)
Message-Id: <201003240907.o2O97030051146@www.freebsd.org>
Date: Wed, 24 Mar 2010 09:07:00 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] pkg_create(1) needs realpath(3) on -p argument
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         145000
>Category:       bin
>Synopsis:       [patch] pkg_create(1) needs realpath(3) on -p argument
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    eadler
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 24 09:10:00 UTC 2010
>Closed-Date:    Fri Mar 30 03:11:01 UTC 2012
>Last-Modified:  Sun Feb 03 22:28:25 UTC 2013
>Originator:     Garrett Cooper
>Release:        9-CURRENT
>Organization:
Cisco Systems, Inc.
>Environment:
FreeBSD bayonetta.local 9.0-CURRENT FreeBSD 9.0-CURRENT #5 r205310: Sat Mar 20 01:32:51 PDT 2010     gcooper@bayonetta.local:/usr/obj/usr/src/sys/BAYONETTA  amd64
>Description:
When using -p with pkg_create(1) one must specify the full path to the prefix one is installing in. Example:

$ > desc; > comment; echo "bar" | pkg_create -f - -c comment -d desc -p $PWD ../foo.tbz
$

This doesn't work when using relative paths because it's looking for the files in the `playpen':

$ > desc; > comment; echo "bar" | pkg_create -f - -c comment -d desc -p . ../foo.tbz
tar: bar: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors.
pkg_create: make_dist: tar command failed with code 256
$

So my proposal is to change the argument so that it does a realpath on the path segment, s.t. the prefix is explicitly the path set (which makes sense, as a relative path would be nothing more than installing into the playpen, which makes absolutely no sense at all). I verified that this is the behavior that ports are currently using.

Positive test:
> desc; > comment; echo "bar" | /scratch/freebsd/perforce/pkg_install-enhancements/usr.sbin/pkg_install/create/pkg_create -f - -c comment -d desc -p . ../foo.tbz
$ bzcat ../foo.tbz 
+CONTENTS000644 001750 000000 00000000472 11352352166 013107 0ustar00gcooperwheel000000 000000 @comment PKG_FORMAT_REVISION:1.1
@name foo
@cwd /scratch/freebsd/perforce/pkg_install-enhancements/tools/regression/usr.sbin/pkg_install/foo
bar
@comment MD5:d41d8cd98f00b204e9800998ecf8427e
@ignore
+COMMENT
@comment MD5:d41d8cd98f00b204e9800998ecf8427e
@ignore
+DESC
@comment MD5:d41d8cd98f00b204e9800998ecf8427e
+COMMENT000644 001750 000000 00000000000 11352352166 012737 0ustar00gcooperwheel000000 000000 +DESC000644 001750 000000 00000000000 11352352166 012353 0ustar00gcooperwheel000000 000000 bar000644 001750 000000 00000000000 11352345452 012326 0ustar00gcooperwheel000000 000000

Negative test:
$ > desc; > comment; echo "bar" | /scratch/freebsd/perforce/pkg_install-enhancements/usr.sbin/pkg_install/create/pkg_create -f - -c comment -d desc -p /somewhere/that/does/not/exist ../foo.tbz
pkg_create: couldn't resolve path for prefix: /somewhere/that/does/not/exist: No such file or directory

The proposed patch also removes an unnecessary `@cwd .' from created plists added whenever -p is specified, as I noticed that @cwd was being added twice when I specified -p (even though I expected it to only be once).
>How-To-Repeat:
Provide a relative path to -p, i.e.:

. , ./ , usr/local, etc
>Fix:
See patch.

Patch attached with submission follows:

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/perform.c#1 - /scratch/freebsd/perforce/pkg_install-enhancements/usr.sbin/pkg_install/create/perform.c ====
@@ -208,8 +208,12 @@
     read_plist(&plist, pkg_in);
 
     /* Prefix should add an @cwd to the packing list */
-    if (Prefix)
-	add_plist_top(&plist, PLIST_CWD, Prefix);
+    if (Prefix) {
+        char resolved_prefix[PATH_MAX];
+        if (realpath(Prefix, resolved_prefix) == NULL)
+	    err(EXIT_FAILURE, "couldn't resolve path for prefix: %s", Prefix);
+	add_plist_top(&plist, PLIST_CWD, resolved_prefix);
+    }
 
     /* Add the origin if asked, at the top */
     if (Origin)
@@ -254,7 +258,9 @@
     /* mark_plist(&plist); */
 
     /* Now put the release specific items in */
-    add_plist(&plist, PLIST_CWD, ".");
+    if (!Prefix) {
+	add_plist(&plist, PLIST_CWD, ".");
+    }
     write_file(COMMENT_FNAME, Comment);
     add_plist(&plist, PLIST_IGNORE, NULL);
     add_plist(&plist, PLIST_FILE, COMMENT_FNAME);


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->portmgr 
Responsible-Changed-By: flz 
Responsible-Changed-When: Thu Apr 1 17:19:22 UTC 2010 
Responsible-Changed-Why:  
pkg_install is maintained by portmgr. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=145000 
State-Changed-From-To: open->analyzed 
State-Changed-By: flz 
State-Changed-When: Sat Apr 24 11:31:50 UTC 2010 
State-Changed-Why:  
Patch looks good. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=145000 
Responsible-Changed-From-To: portmgr->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Mon Jan 2 15:26:41 UTC 2012 
Responsible-Changed-Why:  
patch approved by portmgr 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/145000: commit references a PR
Date: Thu,  9 Feb 2012 20:51:21 +0000 (UTC)

 Author: eadler
 Date: Thu Feb  9 20:51:03 2012
 New Revision: 231300
 URL: http://svn.freebsd.org/changeset/base/231300
 
 Log:
   Permit the use of relative paths for the prefix argument.
   Remove an unnecessary cwd from created plists when -p is specified
   
   PR:		bin/145000
   Submitted by:	gcooper
   Approved by:	portmgr (flo)
   MFC after:	1 month
 
 Modified:
   head/usr.sbin/pkg_install/create/perform.c
 
 Modified: head/usr.sbin/pkg_install/create/perform.c
 ==============================================================================
 --- head/usr.sbin/pkg_install/create/perform.c	Thu Feb  9 20:49:03 2012	(r231299)
 +++ head/usr.sbin/pkg_install/create/perform.c	Thu Feb  9 20:51:03 2012	(r231300)
 @@ -214,8 +214,12 @@ pkg_perform(char **pkgs)
      read_plist(&plist, pkg_in);
  
      /* Prefix should add an @cwd to the packing list */
 -    if (Prefix)
 -	add_plist_top(&plist, PLIST_CWD, Prefix);
 +    if (Prefix) {
 +        char resolved_prefix[PATH_MAX];
 +        if (realpath(Prefix, resolved_prefix) != 0)
 +	    err(EXIT_FAILURE, "couldn't resolve path for prefix: %s", Prefix);
 +	add_plist_top(&plist, PLIST_CWD, resolved_prefix);
 +    }
  
      /* Add the origin if asked, at the top */
      if (Origin)
 @@ -260,7 +264,9 @@ pkg_perform(char **pkgs)
      /* mark_plist(&plist); */
  
      /* Now put the release specific items in */
 -    add_plist(&plist, PLIST_CWD, ".");
 +    if (!Prefix) {
 +	add_plist(&plist, PLIST_CWD, ".");
 +    }
      write_file(COMMENT_FNAME, Comment);
      add_plist(&plist, PLIST_IGNORE, NULL);
      add_plist(&plist, PLIST_FILE, COMMENT_FNAME);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: analyzed->patched 
State-Changed-By: eadler 
State-Changed-When: Mon Feb 13 05:21:17 UTC 2012 
State-Changed-Why:  
committed already in 231300 

http://www.freebsd.org/cgi/query-pr.cgi?pr=145000 
State-Changed-From-To: patched->closed 
State-Changed-By: eadler 
State-Changed-When: Fri Mar 30 03:10:59 UTC 2012 
State-Changed-Why:  
Committed. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=145000 
>Unformatted:
