Date: Mon, 7 Feb 2005 16:34:31 +0100 (CET) From: Florent Thoumie <flz@xbsd.org> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/77212: src/usr.sbin/pkg_install - make directory argument for @cwd optional Message-ID: <20050207153431.8D9DA119E0@gate.xbsd.org> Resent-Message-ID: <200502071540.j17FeBrT096022@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 77212 >Category: bin >Synopsis: src/usr.sbin/pkg_install - make directory argument for @cwd optional >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Feb 07 15:40:11 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Florent Thoumie >Release: FreeBSD 5.3-RELEASE i386 >Organization: Xbsd.org >Environment: System: FreeBSD gate.xbsd.org 5.3-RELEASE FreeBSD 5.3-RELEASE #2: Wed Nov 24 16:35:34 CET 2004 root@gate.xbsd.org:/usr/src/sys/i386/compile/GATE i386 >Description: When using @cwd %%FOO%%, we must ensure to return in the original prefix later, but doing so with @cwd %%OLDPREFIX%% (having PLIST_SUB+="OLDPREFIX=${PREFIX}") hardcodes the value in the packing list. That's not really a problem when dealing with ports but that's a problem with packages since pkg_add -p option only overrides the first @cwd occurrence. This patch allow us to use @cwd without any argument. If no directory argument is given, it will set current working directory to the first prefix given by the @cwd command. >How-To-Repeat: >Fix: --- pkginstall-cwd.diff begins here --- 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); Binary files pkg_install.orig/create/.pkg_create.1.swp and pkg_install/create/.pkg_create.1.swp differ 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 Mon Feb 7 16:12:59 2005 @@ -310,6 +310,8 @@ FILE *totar; pid_t pid; const char *cname; + char *prefix = NULL; + args[nargs++] = "tar"; /* argv[0] */ @@ -395,10 +397,15 @@ fprintf(totar, "%s\n", p->name); 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 && BaseDir && p->name == NULL) + fprintf(totar, "-C\n%s%s\n", BaseDir, prefix); 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; --- pkginstall-cwd.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050207153431.8D9DA119E0>