Subject: pkg/32163: pkg_create: @src does not override @cwd as advertised
To: None <,,>
From: None <>
List: pkgsrc-bugs
Date: 11/25/2005 13:27:00
>Number:         32163
>Category:       pkg
>Synopsis:       pkg_create: @src does not override @cwd as advertised
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Nov 25 13:27:00 +0000 2005
>Originator:     Stefan Sperling
>Release:        NetBSD 2.0.2
Elego Software Solutions GmbH (
System: NetBSD 2.0.2 NetBSD 2.0.2 (GENERIC) #0: Wed Mar 23 08:53:42 UTC 2005 i386
I am building packages for lots of different UNIX-like systems out of a
single source tree. I install everything into an image directory using
and call the target system specific package creation tools to wrap it up
into a package.

Consider the following extract from the pkg_create man page:

     @cwd directory
             Set the internal directory pointer to point to directory.  All
             subsequent filenames will be assumed relative to this directory.
             Note: @cd is also an alias for this command.
     @src directory
             Set the internal directory pointer for _creation only_ to
             directory.  That is to say that it overrides @cwd for package
             creation but not extraction.

According to the above, I set @cwd to /usr/pkg, and @src to the image directory.
I put these right at the top of the packlist so that all subsequent files
get the right prefix.

But pkg_create's behaviour differs from what is described in the man page.
Whatever I set @src to in my packlist, as soon as there is a @cwd before or
after it, @cwd overrides @src. The result is that pkg_create cannot find any
of the files to pack, because it ends up looking in /usr/pkg instead of
my image directory.

If I understood the pkgsrc makefile jungle (grain of salt) correctly, this
problem does not show up in standard pkgsrc operation because there @src and
@cwd are always the same (/usr/pkg or whatever PKG_PREFIX is set to).
This works because packages are always directly created from files installed
in /usr/pkg.

Create a packlist with @src and @cwd set to different values.
@src should point to an image of the package you want to create.
run pkg_create and watch it fail (lots of "can't stat <file>").

        The following patch corrects the problem for me.
        It makes sure that @src always overrides @cwd at package creation time,
        just as advertised in the man page:

--- pkgtools/pkg_install/files/create/pl.c.orig 2005-11-25 15:58:05.000000000 +0100
+++ pkgtools/pkg_install/files/create/pl.c      2005-11-25 15:59:39.000000000 +0100
@@ -188,8 +188,8 @@
                                /* after @cwd */
                                /* prepend DESTDIR if set?  - HF */
                                (void) snprintf(name, sizeof(name), "%s%s%s",
-                                       cwd,
-                                       (strcmp(cwd, "/") == 0) ? "" : "/",
+                                       srcdir ? srcdir : cwd,
+                                       (strcmp(srcdir ? srcdir : cwd, "/") == 0) ? "" : "/",
                        if (lstat(name, &st) < 0) {