1998-10-09 22:27:31 +04:00
|
|
|
/* $NetBSD: pl.c,v 1.7 1998/10/09 18:27:33 agc Exp $ */
|
1997-06-05 16:59:18 +04:00
|
|
|
|
1997-10-17 18:53:18 +04:00
|
|
|
#include <sys/cdefs.h>
|
1997-06-05 12:54:23 +04:00
|
|
|
#ifndef lint
|
1997-06-05 16:59:18 +04:00
|
|
|
#if 0
|
1997-10-16 04:31:32 +04:00
|
|
|
static const char *rcsid = "from FreeBSD Id: pl.c,v 1.11 1997/10/08 07:46:35 charnier Exp";
|
1997-06-05 16:59:18 +04:00
|
|
|
#else
|
1998-10-09 22:27:31 +04:00
|
|
|
__RCSID("$NetBSD: pl.c,v 1.7 1998/10/09 18:27:33 agc Exp $");
|
1997-06-05 16:59:18 +04:00
|
|
|
#endif
|
1997-06-05 12:54:23 +04: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
|
|
|
|
*
|
|
|
|
* Routines for dealing with the packing list.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lib.h"
|
|
|
|
#include "create.h"
|
|
|
|
#include <errno.h>
|
1997-10-16 04:31:32 +04:00
|
|
|
#include <err.h>
|
1997-06-05 12:54:23 +04:00
|
|
|
#include <md5.h>
|
|
|
|
|
|
|
|
/* Check a list for files that require preconversion */
|
|
|
|
void
|
1998-10-09 22:27:31 +04:00
|
|
|
check_list(char *home, package_t *pkg)
|
1997-06-05 12:54:23 +04:00
|
|
|
{
|
1998-10-09 22:27:31 +04:00
|
|
|
plist_t *tmp;
|
|
|
|
plist_t *p;
|
|
|
|
char *cwd = home;
|
|
|
|
char *there = NULL;
|
|
|
|
char *cp;
|
|
|
|
char name[FILENAME_MAX];
|
|
|
|
char buf[LegibleChecksumLen];
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1998-10-09 22:27:31 +04:00
|
|
|
for (p = pkg->head ; p ; p = p->next) {
|
|
|
|
switch (p->type) {
|
|
|
|
case PLIST_CWD:
|
|
|
|
cwd = p->name;
|
|
|
|
break;
|
|
|
|
case PLIST_IGNORE:
|
|
|
|
p = p->next;
|
|
|
|
break;
|
|
|
|
case PLIST_SRC:
|
|
|
|
there = p->name;
|
|
|
|
break;
|
|
|
|
case PLIST_FILE:
|
|
|
|
(void) snprintf(name, sizeof(name), "%s/%s", there ? there : cwd, p->name);
|
|
|
|
if ((cp = MD5File(name, buf)) != NULL) {
|
|
|
|
tmp = new_plist_entry();
|
|
|
|
tmp->name = copy_string(strconcat("MD5:", cp));
|
|
|
|
tmp->type = PLIST_COMMENT;
|
|
|
|
tmp->next = p->next;
|
|
|
|
tmp->prev = p;
|
|
|
|
p->next = tmp;
|
|
|
|
p = tmp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
trylink(const char *from, const char *to)
|
|
|
|
{
|
1998-10-09 22:27:31 +04:00
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if (link(from, to) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
/* try making the container directory */
|
|
|
|
if ((cp = strrchr(to, '/')) != (char *) NULL) {
|
|
|
|
vsystem("mkdir -p %.*s", (size_t)(cp - to), to);
|
|
|
|
}
|
|
|
|
return link(from, to);
|
|
|
|
}
|
|
|
|
return -1;
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define STARTSTRING "tar cf -"
|
|
|
|
#define TOOBIG(str) strlen(str) + 6 + strlen(home) + where_count > maxargs
|
1998-10-09 22:27:31 +04:00
|
|
|
#define PUSHOUT() /* push out string */ \
|
|
|
|
if (where_count > sizeof(STARTSTRING)-1) { \
|
|
|
|
strcat(where_args, "|tar xpf -"); \
|
|
|
|
if (system(where_args)) { \
|
|
|
|
cleanup(0); \
|
|
|
|
errx(2, "can't invoke tar pipeline"); \
|
|
|
|
} \
|
|
|
|
memset(where_args, 0, maxargs); \
|
|
|
|
last_chdir = NULL; \
|
|
|
|
strcpy(where_args, STARTSTRING); \
|
|
|
|
where_count = sizeof(STARTSTRING)-1; \
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy unmarked files in packing list to playpen - marked files
|
|
|
|
* have already been copied in an earlier pass through the list.
|
|
|
|
*/
|
|
|
|
void
|
1998-10-09 22:27:31 +04:00
|
|
|
copy_plist(char *home, package_t *plist)
|
1997-06-05 12:54:23 +04:00
|
|
|
{
|
1998-10-09 22:27:31 +04:00
|
|
|
plist_t *p = plist->head;
|
1997-06-05 12:54:23 +04:00
|
|
|
char *where = home;
|
|
|
|
char *there = NULL, *mythere;
|
|
|
|
char *where_args, *last_chdir, *root = "/";
|
|
|
|
int maxargs, where_count = 0, add_count;
|
|
|
|
struct stat stb;
|
|
|
|
dev_t curdir;
|
|
|
|
|
|
|
|
maxargs = sysconf(_SC_ARG_MAX);
|
|
|
|
maxargs -= 64; /* some slop for the tar cmd text,
|
|
|
|
and sh -c */
|
|
|
|
where_args = malloc(maxargs);
|
1998-10-09 15:16:57 +04:00
|
|
|
if (!where_args) {
|
|
|
|
cleanup(0);
|
|
|
|
errx(2, "can't get argument list space");
|
|
|
|
}
|
1997-06-05 12:54:23 +04:00
|
|
|
|
|
|
|
memset(where_args, 0, maxargs);
|
|
|
|
strcpy(where_args, STARTSTRING);
|
|
|
|
where_count = sizeof(STARTSTRING)-1;
|
|
|
|
last_chdir = 0;
|
|
|
|
|
|
|
|
if (stat(".", &stb) == 0)
|
|
|
|
curdir = stb.st_dev;
|
|
|
|
else
|
|
|
|
curdir = (dev_t) -1; /* It's ok if this is a valid dev_t;
|
|
|
|
this is just a hint for an
|
|
|
|
optimization. */
|
|
|
|
|
|
|
|
while (p) {
|
|
|
|
if (p->type == PLIST_CWD)
|
|
|
|
where = p->name;
|
|
|
|
else if (p->type == PLIST_SRC)
|
|
|
|
there = p->name;
|
|
|
|
else if (p->type == PLIST_IGNORE)
|
|
|
|
p = p->next;
|
|
|
|
else if (p->type == PLIST_FILE && !p->marked) {
|
|
|
|
char fn[FILENAME_MAX];
|
|
|
|
|
|
|
|
|
|
|
|
/* First, look for it in the "home" dir */
|
1998-10-08 16:57:58 +04:00
|
|
|
(void) snprintf(fn, sizeof(fn), "%s/%s", home, p->name);
|
1997-06-05 12:54:23 +04:00
|
|
|
if (fexists(fn)) {
|
|
|
|
if (lstat(fn, &stb) == 0 && stb.st_dev == curdir &&
|
|
|
|
S_ISREG(stb.st_mode)) {
|
|
|
|
/* if we can link it to the playpen, that avoids a copy
|
|
|
|
and saves time. */
|
|
|
|
if (p->name[0] != '/') {
|
|
|
|
/* don't link abspn stuff--it doesn't come from
|
|
|
|
local dir! */
|
|
|
|
if (trylink(fn, p->name) == 0) {
|
|
|
|
p = p->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (TOOBIG(fn)) {
|
|
|
|
PUSHOUT();
|
|
|
|
}
|
|
|
|
if (p->name[0] == '/') {
|
|
|
|
add_count = snprintf(&where_args[where_count],
|
|
|
|
maxargs - where_count,
|
|
|
|
" %s %s",
|
|
|
|
last_chdir == root ? "" : "-C /",
|
|
|
|
p->name);
|
|
|
|
last_chdir = root;
|
|
|
|
} else {
|
|
|
|
add_count = snprintf(&where_args[where_count],
|
|
|
|
maxargs - where_count,
|
|
|
|
" %s%s %s",
|
|
|
|
last_chdir == home ? "" : "-C ",
|
|
|
|
last_chdir == home ? "" : home,
|
|
|
|
p->name);
|
|
|
|
last_chdir = home;
|
|
|
|
}
|
1998-10-09 15:16:57 +04:00
|
|
|
if (add_count > maxargs - where_count) {
|
|
|
|
cleanup(0);
|
|
|
|
errx(2, "oops, miscounted strings!");
|
|
|
|
}
|
1997-06-05 12:54:23 +04:00
|
|
|
where_count += add_count;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Otherwise, try along the actual extraction path..
|
|
|
|
*/
|
|
|
|
else {
|
|
|
|
if (p->name[0] == '/')
|
|
|
|
mythere = root;
|
|
|
|
else mythere = there;
|
1998-10-08 16:57:58 +04:00
|
|
|
(void) snprintf(fn, sizeof(fn), "%s/%s", mythere ? mythere : where, p->name);
|
1997-06-05 12:54:23 +04:00
|
|
|
if (lstat(fn, &stb) == 0 && stb.st_dev == curdir &&
|
|
|
|
S_ISREG(stb.st_mode)) {
|
|
|
|
/* if we can link it to the playpen, that avoids a copy
|
|
|
|
and saves time. */
|
|
|
|
if (trylink(fn, p->name) == 0) {
|
|
|
|
p = p->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (TOOBIG(p->name)) {
|
|
|
|
PUSHOUT();
|
|
|
|
}
|
|
|
|
if (last_chdir == (mythere ? mythere : where))
|
|
|
|
add_count = snprintf(&where_args[where_count],
|
|
|
|
maxargs - where_count,
|
|
|
|
" %s", p->name);
|
|
|
|
else
|
|
|
|
add_count = snprintf(&where_args[where_count],
|
|
|
|
maxargs - where_count,
|
|
|
|
" -C %s %s",
|
|
|
|
mythere ? mythere : where,
|
|
|
|
p->name);
|
1998-10-09 15:16:57 +04:00
|
|
|
if (add_count > maxargs - where_count) {
|
|
|
|
cleanup(0);
|
|
|
|
errx(2, "oops, miscounted strings!");
|
|
|
|
}
|
1997-06-05 12:54:23 +04:00
|
|
|
where_count += add_count;
|
|
|
|
last_chdir = (mythere ? mythere : where);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
PUSHOUT();
|
|
|
|
free(where_args);
|
|
|
|
}
|