diff options
author | krion <krion@FreeBSD.org> | 2006-01-07 22:10:58 +0000 |
---|---|---|
committer | krion <krion@FreeBSD.org> | 2006-01-07 22:10:58 +0000 |
commit | 62a303f1e1f438d456ebe73b252a83c17de02ed5 (patch) | |
tree | e5c518889fdd186fddcfbdcde20ffa538eeab4cd /usr.sbin/pkg_install | |
parent | e1a07793db64c060a0d1491248a1e7fc5e39bb7c (diff) | |
download | FreeBSD-src-62a303f1e1f438d456ebe73b252a83c17de02ed5.zip FreeBSD-src-62a303f1e1f438d456ebe73b252a83c17de02ed5.tar.gz |
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.
PR: bin/77212
Submitted by: flz
Diffstat (limited to 'usr.sbin/pkg_install')
-rw-r--r-- | usr.sbin/pkg_install/add/extract.c | 13 | ||||
-rw-r--r-- | usr.sbin/pkg_install/create/perform.c | 7 | ||||
-rw-r--r-- | usr.sbin/pkg_install/create/pkg_create.1 | 6 | ||||
-rw-r--r-- | usr.sbin/pkg_install/create/pl.c | 13 | ||||
-rw-r--r-- | usr.sbin/pkg_install/info/show.c | 5 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/plist.c | 7 |
6 files changed, 42 insertions, 9 deletions
diff --git a/usr.sbin/pkg_install/add/extract.c b/usr.sbin/pkg_install/add/extract.c index 2085f3d..4b0ef51 100644 --- a/usr.sbin/pkg_install/add/extract.c +++ b/usr.sbin/pkg_install/add/extract.c @@ -56,6 +56,7 @@ rollback(const char *name, const char *home, PackingList start, PackingList stop 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 @@ rollback(const char *name, const char *home, PackingList start, PackingList stop } } 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 @@ void 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 @@ extract_plist(const char *home, Package *pkg) 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 --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c index 51a3cfa..77ec1f2 100644 --- a/usr.sbin/pkg_install/create/perform.c +++ b/usr.sbin/pkg_install/create/perform.c @@ -345,6 +345,8 @@ make_dist(const char *homedir, const char *pkg, const char *suff, Package *plist FILE *totar; pid_t pid; const char *cname; + char *prefix = NULL; + args[nargs++] = "tar"; /* argv[0] */ @@ -428,12 +430,17 @@ make_dist(const char *homedir, const char *pkg, const char *suff, Package *plist 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 --git a/usr.sbin/pkg_install/create/pkg_create.1 b/usr.sbin/pkg_install/create/pkg_create.1 index e7666cd..6fb6d58 100644 --- a/usr.sbin/pkg_install/create/pkg_create.1 +++ b/usr.sbin/pkg_install/create/pkg_create.1 @@ -368,10 +368,14 @@ This is done by embedding specialized command sequences 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 --git a/usr.sbin/pkg_install/create/pl.c b/usr.sbin/pkg_install/create/pl.c index 52a0082..18bbaf2 100644 --- a/usr.sbin/pkg_install/create/pl.c +++ b/usr.sbin/pkg_install/create/pl.c @@ -64,12 +64,15 @@ check_list(const char *home, Package *pkg) 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 @@ copy_plist(const char *home, Package *plist) 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 @@ copy_plist(const char *home, Package *plist) 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 --git a/usr.sbin/pkg_install/info/show.c b/usr.sbin/pkg_install/info/show.c index cb2c3df..a1f9e8d 100644 --- a/usr.sbin/pkg_install/info/show.c +++ b/usr.sbin/pkg_install/info/show.c @@ -86,6 +86,7 @@ show_plist(const char *title, Package *plist, plist_t type, Boolean showall) { PackingList p; Boolean ign = FALSE; + char *prefix = NULL; if (!Quiet) printf("%s%s", InfoPrefix, title); @@ -106,7 +107,9 @@ show_plist(const char *title, Package *plist, plist_t type, Boolean showall) 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 --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c index e5aa6dc..11e9d13 100644 --- a/usr.sbin/pkg_install/lib/plist.c +++ b/usr.sbin/pkg_install/lib/plist.c @@ -320,7 +320,7 @@ write_plist(Package *pkg, FILE *fp) 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: @@ -420,6 +420,7 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg) 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) { @@ -433,7 +434,9 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg) 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; |