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
This commit is contained in:
parent
1851bd711a
commit
ce036f4091
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=154102
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user