bin/77212: src/usr.sbin/pkg_install - make directory argument for @cwd optional

Florent Thoumie flz at xbsd.org
Tue Feb 8 06:00:38 PST 2005


The following reply was made to PR bin/77212; it has been noted by GNATS.

From: Florent Thoumie <flz at xbsd.org>
To: Boris Kovalenko <boris at ntmk.ru>, FreeBSD-gnats-submit at FreeBSD.org
Cc: eik at FreeBSD.org
Subject: Re: bin/77212: src/usr.sbin/pkg_install - make directory argument
 for @cwd optional
Date: Tue, 08 Feb 2005 14:59:02 +0100

 This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
 --------------enig2F04D11FFA6F2D60FEA92DED
 Content-Type: multipart/mixed;
  boundary="------------040905070306010406050105"
 
 This is a multi-part message in MIME format.
 --------------040905070306010406050105
 Content-Type: text/plain; charset=KOI8-R; format=flowed
 Content-Transfer-Encoding: 7bit
 
 Boris Kovalenko wrote:
 
 >     Yeah, now patch is working, but not as expected. pkg_add -p changes
 > only the first occurence of @cwd. So, in the last of the +INSTALL file I
 > see:
 > @cwd /etc/rc.d
 > ....
 > @cwd /usr/local <--- !!!
 >
 > When installing with pkg_add -p all files after this line (info files
 > for example) are going to wrong place. So @pushwd and @popwd, imho, will
 > be better choise.
 
 	Here is the new diff. I patched too much and there was no "@cwd"
 	(without dir argument) command anymore in the resulting package.
 
 	This one should work fine, unless I overlooked something (which
 	is more than possible).
 
 	I'm CC'ing eik, just in case he could help us reviewing this
 	patch.
 
 --
 Florent Thoumie
 flz at xbsd.org
 
 --------------040905070306010406050105
 Content-Type: text/plain;
  name="pkginstall-cwd-v3.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="pkginstall-cwd-v3.diff"
 
 diff -ruN pkg_install.orig/add/extract.c pkg_install/add/extract.c
 --- pkg_install.orig/add/extract.c	Wed Jul 28 09:19:15 2004
 +++ pkg_install/add/extract.c	Tue Feb  8 14:28:39 2005
 @@ -56,6 +56,7 @@
      PackingList q;
      char try[FILENAME_MAX], bup[FILENAME_MAX];
      const char *dir;
 +    char *prefix = NULL;
 
      dir = home;
      for (q = start; q != stop; q = q->next) {
 @@ -69,7 +70,11 @@
  	    }
  	}
  	else if (q->type == PLIST_CWD) {
 -	    if (strcmp(q->name, "."))
 +	    if (!prefix)
 +		prefix = q->name;
 +	    if (q->name == NULL)
 +		q->name = prefix;
 +	    else if (strcmp(q->name, "."))
  		dir = q->name;
  	    else
  		dir = home;
 @@ -103,7 +108,7 @@
  extract_plist(const char *home, Package *pkg)
  {
      PackingList p = pkg->head;
 -    char *last_file;
 +    char *last_file, *prefix = NULL;
      char *where_args, *perm_args, *last_chdir;
      int maxargs, where_count = 0, perm_count = 0, add_count;
      Boolean preserve;
 @@ -212,6 +217,10 @@
  	    break;
 
  	case PLIST_CWD:
 +	    if (!prefix)
 +		prefix = p->name;
 +	    if (p->name == NULL)
 +		p->name = strdup(prefix);
  	    if (Verbose)
  		printf("extract: CWD to %s\n", p->name);
  	    PUSHOUT(Directory);
 diff -ruN pkg_install.orig/create/perform.c pkg_install/create/perform.c
 --- pkg_install.orig/create/perform.c	Wed Jul 28 09:19:15 2004
 +++ pkg_install/create/perform.c	Tue Feb  8 07:43:01 2005
 @@ -310,6 +310,8 @@
      FILE *totar;
      pid_t pid;
      const char *cname;
 +    char *prefix = NULL;
 +
 
      args[nargs++] = "tar";	/* argv[0] */
 
 @@ -393,12 +395,17 @@
      for (p = plist->head; p; p = p->next) {
  	if (p->type == PLIST_FILE)
  	    fprintf(totar, "%s\n", p->name);
 +	else if (p->type == PLIST_CWD && p->name == NULL)
 +	    fprintf(totar, "-C\n%s\n", prefix);
  	else if (p->type == PLIST_CWD && BaseDir && p->name && p->name[0] == '/')
  	    fprintf(totar, "-C\n%s%s\n", BaseDir, p->name);
  	else if (p->type == PLIST_CWD || p->type == PLIST_SRC)
  	    fprintf(totar, "-C\n%s\n", p->name);
  	else if (p->type == PLIST_IGNORE)
  	     p = p->next;
 +	if (p->type == PLIST_CWD && !prefix)
 +	    prefix = p->name;
 +
      }
 
      fclose(totar);
 diff -ruN pkg_install.orig/create/pkg_create.1 pkg_install/create/pkg_create.1
 --- pkg_install.orig/create/pkg_create.1	Sat Jul  3 01:12:52 2004
 +++ pkg_install/create/pkg_create.1	Tue Feb  8 07:43:01 2005
 @@ -353,10 +353,14 @@
  in the packing list.
  Briefly described, these sequences are:
  .Bl -tag -width indent -compact
 -.It Cm @cwd Ar directory
 +.It Cm @cwd Op Ar directory
  Set the internal directory pointer to point to
  .Ar directory .
  All subsequent filenames will be assumed relative to this directory.
 +If no
 +.Ar directory
 +argument is given, it will set the internal directory pointer to the
 +first prefix value.
  Note:
  .Cm @cd
  is also an alias for this command.
 diff -ruN pkg_install.orig/create/pl.c pkg_install/create/pl.c
 --- pkg_install.orig/create/pl.c	Tue Jun 29 21:06:41 2004
 +++ pkg_install/create/pl.c	Tue Feb  8 14:42:49 2005
 @@ -64,12 +64,15 @@
      const char *where = home;
      const char *there = NULL;
      char name[FILENAME_MAX];
 +    char *prefix = NULL;
      PackingList p;
 
      for (p = pkg->head; p != NULL; p = p->next)
  	switch (p->type) {
  	case PLIST_CWD:
 -	    where = p->name;
 +	    if (!prefix)
 +		prefix = p->name;
 +	    where = (p->name == NULL) ? prefix : p->name;
  	    break;
 
  	case PLIST_IGNORE:
 @@ -135,7 +138,7 @@
      PackingList p = plist->head;
      const char *where = home;
      const char *there = NULL, *mythere;
 -    char *where_args;
 +    char *where_args, *prefix = NULL;
      const char *last_chdir, *root = "/";
      int maxargs, where_count = 0, add_count;
      struct stat stb;
 @@ -168,7 +171,11 @@
 
      while (p) {
  	if (p->type == PLIST_CWD)
 -	    where = p->name;
 +	{
 +	    if (!prefix)
 +		prefix = p->name;
 +	    where = p->name == NULL ? prefix : p->name;
 +	}
  	else if (p->type == PLIST_SRC)
  	    there = p->name;
  	else if (p->type == PLIST_IGNORE)
 diff -ruN pkg_install.orig/info/show.c pkg_install/info/show.c
 --- pkg_install.orig/info/show.c	Mon May 26 19:06:05 2003
 +++ pkg_install/info/show.c	Tue Feb  8 14:41:44 2005
 @@ -86,6 +86,7 @@
  {
      PackingList p;
      Boolean ign = FALSE;
 +    char *prefix = NULL;
 
      if (!Quiet)
  	printf("%s%s", InfoPrefix, title);
 @@ -106,7 +107,9 @@
  	    break;
 
  	case PLIST_CWD:
 -	    printf(Quiet ? "@cwd %s\n" : "\tCWD to %s\n", p->name);
 +	    if (!prefix)
 +		prefix = p->name;
 +	    printf(Quiet ? "@cwd %s\n" : "\tCWD to %s\n", (p->name == NULL) ? prefix : p->name);
  	    break;
 
  	case PLIST_SRC:
 diff -ruN pkg_install.orig/lib/plist.c pkg_install/lib/plist.c
 --- pkg_install.orig/lib/plist.c	Wed Jul 28 09:19:15 2004
 +++ pkg_install/lib/plist.c	Tue Feb  8 14:43:55 2005
 @@ -318,7 +318,7 @@
  	    break;
 
  	case PLIST_CWD:
 -	    fprintf(fp, "%ccwd %s\n", CMD_CHAR, plist->name);
 +	    fprintf(fp, "%ccwd %s\n", CMD_CHAR, (plist->name == NULL) ? "" : plist->name);
  	    break;
 
  	case PLIST_SRC:
 @@ -414,6 +414,7 @@
      Boolean fail = SUCCESS;
      Boolean preserve;
      char tmp[FILENAME_MAX], *name = NULL;
 +    char *prefix = NULL;
 
      preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;
      for (p = pkg->head; p; p = p->next) {
 @@ -427,7 +428,9 @@
  	    break;
 
  	case PLIST_CWD:
 -	    Where = p->name;
 +	    if (!prefix)
 +		prefix = p->name;
 +	    Where = (p->name == NULL) ? prefix : p->name;
  	    if (Verbose)
  		printf("Change working directory to %s\n", Where);
  	    break;
 
 --------------040905070306010406050105--
 
 --------------enig2F04D11FFA6F2D60FEA92DED
 Content-Type: application/pgp-signature; name="signature.asc"
 Content-Description: OpenPGP digital signature
 Content-Disposition: attachment; filename="signature.asc"
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.0 (FreeBSD)
 Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
 
 iD8DBQFCCMWtMxEkbVFH3PQRAkYAAJ9vtf4Ncarx2w61xFVTN6sAoHhssQCdE6l/
 vYfMdfhHLLH0pMrQ6EpBUZs=
 =E8T2
 -----END PGP SIGNATURE-----
 
 --------------enig2F04D11FFA6F2D60FEA92DED--


More information about the freebsd-bugs mailing list