bin/145000: [patch] pkg_create(1) needs realpath(3) on -p argument
Garrett Cooper
gcooper at FreeBSD.org
Wed Mar 24 09:10:01 UTC 2010
>Number: 145000
>Category: bin
>Synopsis: [patch] pkg_create(1) needs realpath(3) on -p argument
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Wed Mar 24 09:10:00 UTC 2010
>Closed-Date:
>Last-Modified:
>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 at 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:
>Unformatted:
More information about the freebsd-bugs
mailing list