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

Florent Thoumie flz at xbsd.org
Mon Feb 7 22:50:35 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:  
Subject: Re: bin/77212: src/usr.sbin/pkg_install - make directory argument
 for @cwd optional
Date: Tue, 08 Feb 2005 07:46:05 +0100

 This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
 --------------enigB739B6CC2182B52359FE6A0A
 Content-Type: multipart/mixed;
  boundary="------------000308030009060202020702"
 
 This is a multi-part message in MIME format.
 --------------000308030009060202020702
 Content-Type: text/plain; charset=KOI8-R; format=flowed
 Content-Transfer-Encoding: 7bit
 
 Ok, looks like I broke it between my last test and the PR
 submission. Here is the good diff.
 
 --------------000308030009060202020702
 Content-Type: text/plain;
  name="pkginstall-cwd-v2.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="pkginstall-cwd-v2.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	Mon Feb  7 15:40:56 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:39:48 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	Mon Feb  7 16:21:40 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	Mon Feb  7 15:32:03 2005
 @@ -64,12 +64,17 @@
      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;
 +	    if (p->name == NULL)
 +		where = prefix;
 +	    else where = p->name;
  	    break;
 
  	case 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	Mon Feb  7 15:38:51 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	Mon Feb  7 15:38:22 2005
 @@ -310,6 +310,7 @@
  write_plist(Package *pkg, FILE *fp)
  {
      PackingList plist = pkg->head;
 +    char *prefix = NULL;
 
      while (plist) {
  	switch(plist->type) {
 @@ -318,7 +319,9 @@
  	    break;
 
  	case PLIST_CWD:
 -	    fprintf(fp, "%ccwd %s\n", CMD_CHAR, plist->name);
 +	    if (!prefix)
 +		prefix = plist->name;
 +	    fprintf(fp, "%ccwd %s\n", CMD_CHAR, (plist->name == NULL) ? prefix : plist->name);
  	    break;
 
  	case PLIST_SRC:
 @@ -414,6 +417,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 +431,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;
 
 --------------000308030009060202020702--
 
 --------------enigB739B6CC2182B52359FE6A0A
 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
 
 iD8DBQFCCGA0MxEkbVFH3PQRApT0AJ9byLWBdWVAIO+5UmO5KbhUdINKZQCggIJ7
 3XMONYbdffQK9KXrl5ivtjo=
 =esiR
 -----END PGP SIGNATURE-----
 
 --------------enigB739B6CC2182B52359FE6A0A--


More information about the freebsd-bugs mailing list