diff --git a/usr.sbin/pkg_install/add/extract.c b/usr.sbin/pkg_install/add/extract.c index 2085f3d13091..4b0ef510d38e 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 51a3cfa4d740..77ec1f216a31 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 e7666cde5240..6fb6d58640ea 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 52a00821c616..18bbaf24734b 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 cb2c3df7819c..a1f9e8dc3c8a 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 e5aa6dc55f34..11e9d13980e9 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;