1993-08-26 01:19:55 +00:00
|
|
|
#ifndef lint
|
1997-10-08 07:48:21 +00:00
|
|
|
static const char rcsid[] =
|
1999-08-28 01:35:59 +00:00
|
|
|
"$FreeBSD$";
|
1993-08-26 01:19:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FreeBSD install - a package for the installation and maintainance
|
|
|
|
* of non-core utilities.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* Jordan K. Hubbard
|
|
|
|
* 18 July 1993
|
|
|
|
*
|
|
|
|
* This is the package extraction code for the add module.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1997-10-08 07:48:21 +00:00
|
|
|
#include <err.h>
|
1993-08-26 01:19:55 +00:00
|
|
|
#include "lib.h"
|
|
|
|
#include "add.h"
|
|
|
|
|
1994-12-06 00:51:50 +00:00
|
|
|
|
1997-02-25 07:22:23 +00:00
|
|
|
#define STARTSTRING "tar cf - "
|
1999-06-09 09:29:53 +00:00
|
|
|
#define TOOBIG(str) ((strlen(str) + FILENAME_MAX + where_count > maxargs) \
|
|
|
|
|| (strlen(str) + FILENAME_MAX + perm_count > maxargs))
|
1994-12-06 00:51:50 +00:00
|
|
|
|
|
|
|
#define PUSHOUT(todir) /* push out string */ \
|
1997-02-25 07:22:23 +00:00
|
|
|
if (where_count > sizeof(STARTSTRING)-1) { \
|
1998-10-28 22:44:24 +00:00
|
|
|
strcat(where_args, "|tar --unlink -xf - -C "); \
|
1994-12-06 00:51:50 +00:00
|
|
|
strcat(where_args, todir); \
|
1998-09-11 07:26:58 +00:00
|
|
|
if (system(where_args)) { \
|
|
|
|
cleanup(0); \
|
2000-10-22 09:53:27 +00:00
|
|
|
errx(2, __FUNCTION__ ": can not invoke %d byte tar pipeline: %s", \
|
1998-09-11 07:26:58 +00:00
|
|
|
strlen(where_args), where_args); \
|
|
|
|
} \
|
1994-12-06 00:51:50 +00:00
|
|
|
strcpy(where_args, STARTSTRING); \
|
|
|
|
where_count = sizeof(STARTSTRING)-1; \
|
|
|
|
} \
|
|
|
|
if (perm_count) { \
|
1997-02-14 01:52:38 +00:00
|
|
|
apply_perms(todir, perm_args); \
|
1994-12-06 00:51:50 +00:00
|
|
|
perm_args[0] = 0;\
|
|
|
|
perm_count = 0; \
|
|
|
|
}
|
|
|
|
|
1997-06-29 10:41:49 +00:00
|
|
|
static void
|
|
|
|
rollback(char *name, char *home, PackingList start, PackingList stop)
|
|
|
|
{
|
|
|
|
PackingList q;
|
|
|
|
char try[FILENAME_MAX], bup[FILENAME_MAX], *dir;
|
|
|
|
|
|
|
|
dir = home;
|
|
|
|
for (q = start; q != stop; q = q->next) {
|
|
|
|
if (q->type == PLIST_FILE) {
|
|
|
|
snprintf(try, FILENAME_MAX, "%s/%s", dir, q->name);
|
1997-07-01 06:13:51 +00:00
|
|
|
if (make_preserve_name(bup, FILENAME_MAX, name, try) && fexists(bup)) {
|
1997-06-29 10:41:49 +00:00
|
|
|
(void)chflags(try, 0);
|
|
|
|
(void)unlink(try);
|
|
|
|
if (rename(bup, try))
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("rollback: unable to rename %s back to %s", bup, try);
|
1997-06-29 10:41:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (q->type == PLIST_CWD) {
|
|
|
|
if (strcmp(q->name, "."))
|
|
|
|
dir = q->name;
|
|
|
|
else
|
|
|
|
dir = home;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
void
|
|
|
|
extract_plist(char *home, Package *pkg)
|
|
|
|
{
|
|
|
|
PackingList p = pkg->head;
|
|
|
|
char *last_file;
|
1994-12-06 00:51:50 +00:00
|
|
|
char *where_args, *perm_args, *last_chdir;
|
|
|
|
int maxargs, where_count = 0, perm_count = 0, add_count;
|
1997-06-29 10:41:49 +00:00
|
|
|
Boolean preserve;
|
1994-12-06 00:51:50 +00:00
|
|
|
|
1997-02-25 07:22:23 +00:00
|
|
|
maxargs = sysconf(_SC_ARG_MAX) / 2; /* Just use half the argument space */
|
1997-02-15 16:34:47 +00:00
|
|
|
where_args = alloca(maxargs);
|
1998-09-11 07:26:58 +00:00
|
|
|
if (!where_args) {
|
|
|
|
cleanup(0);
|
2000-10-22 09:53:27 +00:00
|
|
|
errx(2, __FUNCTION__ ": can't get argument list space");
|
1998-09-11 07:26:58 +00:00
|
|
|
}
|
1997-02-15 16:34:47 +00:00
|
|
|
perm_args = alloca(maxargs);
|
1998-09-11 07:26:58 +00:00
|
|
|
if (!perm_args) {
|
|
|
|
cleanup(0);
|
2000-10-22 09:53:27 +00:00
|
|
|
errx(2, __FUNCTION__ ": can't get argument list space");
|
1998-09-11 07:26:58 +00:00
|
|
|
}
|
1994-12-06 00:51:50 +00:00
|
|
|
|
|
|
|
strcpy(where_args, STARTSTRING);
|
|
|
|
where_count = sizeof(STARTSTRING)-1;
|
|
|
|
perm_args[0] = 0;
|
|
|
|
|
|
|
|
last_chdir = 0;
|
1997-06-29 10:41:49 +00:00
|
|
|
preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
/* Reset the world */
|
|
|
|
Owner = NULL;
|
|
|
|
Group = NULL;
|
|
|
|
Mode = NULL;
|
|
|
|
last_file = NULL;
|
|
|
|
Directory = home;
|
|
|
|
|
|
|
|
/* Do it */
|
|
|
|
while (p) {
|
1993-09-18 03:38:48 +00:00
|
|
|
char cmd[FILENAME_MAX];
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
switch(p->type) {
|
|
|
|
case PLIST_NAME:
|
|
|
|
PkgName = p->name;
|
|
|
|
if (Verbose)
|
|
|
|
printf("extract: Package name is %s\n", p->name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_FILE:
|
|
|
|
last_file = p->name;
|
|
|
|
if (Verbose)
|
|
|
|
printf("extract: %s/%s\n", Directory, p->name);
|
|
|
|
if (!Fake) {
|
1993-09-05 04:53:51 +00:00
|
|
|
char try[FILENAME_MAX];
|
|
|
|
|
1998-09-11 07:26:58 +00:00
|
|
|
if (strrchr(p->name,'\'')) {
|
|
|
|
cleanup(0);
|
2000-10-22 09:53:27 +00:00
|
|
|
errx(2, __FUNCTION__ ": Bogus filename \"%s\"", p->name);
|
1998-09-11 07:26:58 +00:00
|
|
|
}
|
1998-01-21 00:12:56 +00:00
|
|
|
|
1993-09-05 04:53:51 +00:00
|
|
|
/* first try to rename it into place */
|
1997-07-01 06:13:51 +00:00
|
|
|
snprintf(try, FILENAME_MAX, "%s/%s", Directory, p->name);
|
|
|
|
if (fexists(try)) {
|
1997-06-29 10:41:49 +00:00
|
|
|
(void)chflags(try, 0); /* XXX hack - if truly immutable, rename fails */
|
1997-07-01 06:13:51 +00:00
|
|
|
if (preserve && PkgName) {
|
|
|
|
char pf[FILENAME_MAX];
|
|
|
|
|
|
|
|
if (make_preserve_name(pf, FILENAME_MAX, PkgName, try)) {
|
|
|
|
if (rename(try, pf)) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx(
|
|
|
|
"unable to back up %s to %s, aborting pkg_add",
|
|
|
|
try, pf);
|
1997-07-01 06:13:51 +00:00
|
|
|
rollback(PkgName, home, pkg->head, p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1997-06-29 10:41:49 +00:00
|
|
|
}
|
|
|
|
}
|
1994-12-06 00:51:50 +00:00
|
|
|
if (rename(p->name, try) == 0) {
|
1997-02-25 07:22:23 +00:00
|
|
|
/* try to add to list of perms to be changed and run in bulk. */
|
|
|
|
if (p->name[0] == '/' || TOOBIG(p->name)) {
|
1997-02-15 16:34:47 +00:00
|
|
|
PUSHOUT(Directory);
|
1997-02-25 07:22:23 +00:00
|
|
|
}
|
1998-01-21 00:12:56 +00:00
|
|
|
add_count = snprintf(&perm_args[perm_count], maxargs - perm_count, "'%s' ", p->name);
|
1998-09-11 07:26:58 +00:00
|
|
|
if (add_count > maxargs - perm_count) {
|
|
|
|
cleanup(0);
|
2000-10-22 09:53:27 +00:00
|
|
|
errx(2, __FUNCTION__ ": oops, miscounted strings!");
|
1998-09-11 07:26:58 +00:00
|
|
|
}
|
1994-12-06 00:51:50 +00:00
|
|
|
perm_count += add_count;
|
1997-02-15 16:34:47 +00:00
|
|
|
}
|
|
|
|
else {
|
1994-12-06 00:51:50 +00:00
|
|
|
/* rename failed, try copying with a big tar command */
|
1997-02-25 07:22:23 +00:00
|
|
|
if (last_chdir != Directory) {
|
1998-07-04 14:13:01 +00:00
|
|
|
if (last_chdir == NULL) {
|
|
|
|
PUSHOUT(Directory);
|
|
|
|
} else {
|
|
|
|
PUSHOUT(last_chdir);
|
|
|
|
}
|
1994-12-06 00:51:50 +00:00
|
|
|
last_chdir = Directory;
|
|
|
|
}
|
1997-02-25 07:22:23 +00:00
|
|
|
else if (p->name[0] == '/' || TOOBIG(p->name)) {
|
|
|
|
PUSHOUT(Directory);
|
|
|
|
}
|
1998-01-21 00:12:56 +00:00
|
|
|
add_count = snprintf(&where_args[where_count], maxargs - where_count, " '%s'", p->name);
|
1998-09-11 07:26:58 +00:00
|
|
|
if (add_count > maxargs - where_count) {
|
|
|
|
cleanup(0);
|
2000-10-22 09:53:27 +00:00
|
|
|
errx(2, __FUNCTION__ ": oops, miscounted strings!");
|
1998-09-11 07:26:58 +00:00
|
|
|
}
|
1994-12-06 00:51:50 +00:00
|
|
|
where_count += add_count;
|
|
|
|
add_count = snprintf(&perm_args[perm_count],
|
|
|
|
maxargs - perm_count,
|
1998-01-21 00:12:56 +00:00
|
|
|
"'%s' ", p->name);
|
1998-09-11 07:26:58 +00:00
|
|
|
if (add_count > maxargs - perm_count) {
|
|
|
|
cleanup(0);
|
2000-10-22 09:53:27 +00:00
|
|
|
errx(2, __FUNCTION__ ": oops, miscounted strings!");
|
1998-09-11 07:26:58 +00:00
|
|
|
}
|
1994-12-06 00:51:50 +00:00
|
|
|
perm_count += add_count;
|
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_CWD:
|
|
|
|
if (Verbose)
|
|
|
|
printf("extract: CWD to %s\n", p->name);
|
1994-12-06 00:51:50 +00:00
|
|
|
PUSHOUT(Directory);
|
1993-08-26 01:19:55 +00:00
|
|
|
if (strcmp(p->name, ".")) {
|
1998-09-11 07:26:58 +00:00
|
|
|
if (!Fake && make_hierarchy(p->name) == FAIL) {
|
|
|
|
cleanup(0);
|
2000-10-22 09:53:27 +00:00
|
|
|
errx(2, __FUNCTION__ ": unable to cwd to '%s'", p->name);
|
1998-09-11 07:26:58 +00:00
|
|
|
}
|
1993-08-26 01:19:55 +00:00
|
|
|
Directory = p->name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Directory = home;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_CMD:
|
1997-10-24 08:32:06 +00:00
|
|
|
if ((strstr(p->name, "%B") || strstr(p->name, "%F") ||
|
1998-09-11 07:26:58 +00:00
|
|
|
strstr(p->name, "%f")) && last_file == NULL) {
|
|
|
|
cleanup(0);
|
2000-10-22 09:53:27 +00:00
|
|
|
errx(2, __FUNCTION__ ": no last file specified for '%s' command", p->name);
|
1998-09-11 07:26:58 +00:00
|
|
|
}
|
|
|
|
if (strstr(p->name, "%D") && Directory == NULL) {
|
|
|
|
cleanup(0);
|
2000-10-22 09:53:27 +00:00
|
|
|
errx(2, __FUNCTION__ ": no directory specified for '%s' command", p->name);
|
1998-09-11 07:26:58 +00:00
|
|
|
}
|
1993-09-18 03:38:48 +00:00
|
|
|
format_cmd(cmd, p->name, Directory, last_file);
|
1994-12-06 00:51:50 +00:00
|
|
|
PUSHOUT(Directory);
|
1993-08-26 01:19:55 +00:00
|
|
|
if (Verbose)
|
1993-09-18 03:38:48 +00:00
|
|
|
printf("extract: execute '%s'\n", cmd);
|
|
|
|
if (!Fake && system(cmd))
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("command '%s' failed", cmd);
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_CHMOD:
|
1994-12-06 00:51:50 +00:00
|
|
|
PUSHOUT(Directory);
|
1993-08-26 01:19:55 +00:00
|
|
|
Mode = p->name;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_CHOWN:
|
1994-12-06 00:51:50 +00:00
|
|
|
PUSHOUT(Directory);
|
1993-08-26 01:19:55 +00:00
|
|
|
Owner = p->name;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_CHGRP:
|
1994-12-06 00:51:50 +00:00
|
|
|
PUSHOUT(Directory);
|
1993-08-26 01:19:55 +00:00
|
|
|
Group = p->name;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_COMMENT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_IGNORE:
|
|
|
|
p = p->next;
|
|
|
|
break;
|
2001-01-22 12:01:55 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
1994-12-06 00:51:50 +00:00
|
|
|
PUSHOUT(Directory);
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|