Bring closer to /usr/share/misc/style with the aid of indent(1).

This commit is contained in:
hubertf 1999-08-24 00:48:37 +00:00
parent fd8ab6e67c
commit 8ee940971e
26 changed files with 3884 additions and 3779 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: add.h,v 1.3 1998/10/09 18:27:31 agc Exp $ */
/* $NetBSD: add.h,v 1.4 1999/08/24 00:48:37 hubertf Exp $ */
/* from FreeBSD Id: add.h,v 1.8 1997/02/22 16:09:15 peter Exp */
@ -25,22 +25,24 @@
#ifndef _INST_ADD_H_INCLUDE
#define _INST_ADD_H_INCLUDE
typedef enum { NORMAL, MASTER, SLAVE } add_mode_t;
typedef enum {
NORMAL, MASTER, SLAVE
} add_mode_t;
extern char *Prefix;
extern Boolean NoInstall;
extern Boolean NoRecord;
extern Boolean Force;
extern char *Mode;
extern char *Owner;
extern char *Group;
extern char *Directory;
extern char *PkgName;
extern char FirstPen[];
extern char *Prefix;
extern Boolean NoInstall;
extern Boolean NoRecord;
extern Boolean Force;
extern char *Mode;
extern char *Owner;
extern char *Group;
extern char *Directory;
extern char *PkgName;
extern char FirstPen[];
extern add_mode_t AddMode;
int make_hierarchy(char *);
void extract_plist(char *, package_t *);
void apply_perms(char *, char *);
int make_hierarchy(char *);
void extract_plist(char *, package_t *);
void apply_perms(char *, char *);
#endif /* _INST_ADD_H_INCLUDE */
#endif /* _INST_ADD_H_INCLUDE */

View File

@ -1,11 +1,11 @@
/* $NetBSD: extract.c,v 1.19 1999/08/19 13:29:59 agc Exp $ */
/* $NetBSD: extract.c,v 1.20 1999/08/24 00:48:38 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "FreeBSD - Id: extract.c,v 1.17 1997/10/08 07:45:35 charnier Exp";
#else
__RCSID("$NetBSD: extract.c,v 1.19 1999/08/19 13:29:59 agc Exp $");
__RCSID("$NetBSD: extract.c,v 1.20 1999/08/24 00:48:38 hubertf Exp $");
#endif
#endif
@ -60,257 +60,255 @@ __RCSID("$NetBSD: extract.c,v 1.19 1999/08/19 13:29:59 agc Exp $");
perm_count = 0; \
}
static void
rollback(char *name, char *home, plist_t *start, plist_t *stop)
{
plist_t *q;
char try[FILENAME_MAX], bup[FILENAME_MAX], *dir;
plist_t *q;
char try[FILENAME_MAX], bup[FILENAME_MAX], *dir;
dir = home;
for (q = start; q != stop; q = q->next) {
if (q->type == PLIST_FILE) {
(void) snprintf(try, sizeof(try), "%s/%s", dir, q->name);
if (make_preserve_name(bup, sizeof(bup), name, try) && fexists(bup)) {
(void)chflags(try, 0);
(void)unlink(try);
if (rename(bup, try))
warnx("rollback: unable to rename %s back to %s", bup, try);
}
dir = home;
for (q = start; q != stop; q = q->next) {
if (q->type == PLIST_FILE) {
(void) snprintf(try, sizeof(try), "%s/%s", dir, q->name);
if (make_preserve_name(bup, sizeof(bup), name, try) && fexists(bup)) {
(void) chflags(try, 0);
(void) unlink(try);
if (rename(bup, try))
warnx("rollback: unable to rename %s back to %s", bup, try);
}
} else if (q->type == PLIST_CWD) {
if (strcmp(q->name, "."))
dir = q->name;
else
dir = home;
}
}
else if (q->type == PLIST_CWD) {
if (strcmp(q->name, "."))
dir = q->name;
else
dir = home;
}
}
}
void
extract_plist(char *home, package_t *pkg)
{
plist_t *p = pkg->head;
char *last_file;
char *where_args, *perm_args, *last_chdir;
int maxargs, where_count = 0, perm_count = 0, add_count;
Boolean preserve;
plist_t *p = pkg->head;
char *last_file;
char *where_args, *perm_args, *last_chdir;
int maxargs, where_count = 0, perm_count = 0, add_count;
Boolean preserve;
maxargs = sysconf(_SC_ARG_MAX) / 2; /* Just use half the argument space */
where_args = alloca(maxargs);
if (!where_args) {
cleanup(0);
errx(2, "can't get argument list space");
}
perm_args = alloca(maxargs);
if (!perm_args) {
cleanup(0);
errx(2, "can't get argument list space");
}
strcpy(where_args, TAR_CMD);
strcat(where_args, TAR_ARGS);
where_count = sizeof(TAR_CMD) + sizeof(TAR_ARGS) - 2;
perm_args[0] = 0;
last_chdir = 0;
preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;
/* Reset the world */
Owner = NULL;
Group = NULL;
Mode = NULL;
last_file = NULL;
Directory = home;
/* Open Package Database for writing */
if (pkgdb_open(0) == -1) {
cleanup(0);
err(1, "can't open pkgdb");
}
/* Do it */
while (p) {
char cmd[FILENAME_MAX];
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) {
char try[FILENAME_MAX];
if (strrchr(p->name,'\'')) {
cleanup(0);
errx(2, "Bogus filename \"%s\"", p->name);
}
/* first try to rename it into place */
(void) snprintf(try, sizeof(try), "%s/%s", Directory, p->name);
if (fexists(try)) {
(void)chflags(try, 0); /* XXX hack - if truly immutable, rename fails */
if (preserve && PkgName) {
char pf[FILENAME_MAX];
if (make_preserve_name(pf, sizeof(pf), PkgName, try)) {
if (rename(try, pf)) {
warnx(
"unable to back up %s to %s, aborting pkg_add",
try, pf);
rollback(PkgName, home, pkg->head, p);
return;
}
}
}
}
if (rename(p->name, try) == 0) {
/* note in pkgdb */
{
char *s, t[FILENAME_MAX];
int rc;
(void) snprintf(t, sizeof(t), "%s/%s", Directory, p->name);
s=pkgdb_retrieve(t);
#ifdef PKGDB_DEBUG
printf("pkgdb_retrieve(\"%s\")=\"%s\"\n", t, s); /* pkgdb-debug - HF */
#endif
if (s)
warnx("Overwriting %s - pkg %s bogus/conflicting?", t, s);
else {
rc=pkgdb_store(t, PkgName);
#ifdef PKGDB_DEBUG
printf("pkgdb_store(\"%s\", \"%s\") = %d\n", t, PkgName, rc); /* pkgdb-debug - HF */
#endif
}
}
/* try to add to list of perms to be changed and run in bulk. */
if (p->name[0] == '/' || TOOBIG(p->name)) {
PUSHOUT(Directory);
}
add_count = snprintf(&perm_args[perm_count], maxargs - perm_count, "'%s' ", p->name);
if (add_count > maxargs - perm_count) {
cleanup(0);
errx(2, "oops, miscounted strings!");
}
perm_count += add_count;
} else {
/* rename failed, try copying with a big tar command */
if (last_chdir != Directory) {
PUSHOUT(last_chdir);
last_chdir = Directory;
}
else if (p->name[0] == '/' || TOOBIG(p->name)) {
PUSHOUT(Directory);
}
add_count = snprintf(&where_args[where_count], maxargs - where_count, " '%s'", p->name);
if (add_count > maxargs - where_count) {
cleanup(0);
errx(2, "oops, miscounted strings!");
}
where_count += add_count;
add_count = snprintf(&perm_args[perm_count],
maxargs - perm_count,
"'%s' ", p->name);
if (add_count > maxargs - perm_count) {
cleanup(0);
errx(2, "oops, miscounted strings!");
}
perm_count += add_count;
/* note in pkgdb */
/* XXX would be better to store in PUSHOUT, but
that would probably affect too much code I prefer
not to touch - HF */
{
char *s, t[FILENAME_MAX], *u;
int rc;
if (p->name[0] == '/')
u=p->name;
else {
(void) snprintf(t, sizeof(t), "%s/%s", Directory, p->name);
u=t;
}
s=pkgdb_retrieve(t);
#ifdef PKGDB_DEBUG
printf("pkgdb_retrieve(\"%s\")=\"%s\"\n", t, s); /* pkgdb-debug - HF */
#endif
if (s)
warnx("Overwriting %s - pkg %s bogus/conflicting?", t, s);
else {
rc = pkgdb_store(t, PkgName);
#ifdef PKGDB_DEBUG
printf("pkgdb_store(\"%s\", \"%s\") = %d\n", t, PkgName, rc); /* pkgdb-debug - HF */
#endif
}
}
}
}
break;
case PLIST_CWD:
if (Verbose)
printf("extract: CWD to %s\n", p->name);
PUSHOUT(Directory);
if (strcmp(p->name, ".")) {
if (!Fake && make_hierarchy(p->name) == FAIL) {
cleanup(0);
errx(2, "unable to make directory '%s'", p->name);
}
Directory = p->name;
} else
Directory = home;
break;
case PLIST_CMD:
if (last_file == NULL && strchr(p->name, '%') != NULL) {
maxargs = sysconf(_SC_ARG_MAX) / 2; /* Just use half the argument space */
where_args = alloca(maxargs);
if (!where_args) {
cleanup(0);
errx(2, "no last file specified for '%s' command", p->name);
}
format_cmd(cmd, sizeof(cmd), p->name, Directory, last_file);
PUSHOUT(Directory);
if (Verbose)
printf("extract: execute '%s'\n", cmd);
if (!Fake && system(cmd))
warnx("command '%s' failed", cmd);
break;
case PLIST_CHMOD:
PUSHOUT(Directory);
Mode = p->name;
break;
case PLIST_CHOWN:
PUSHOUT(Directory);
Owner = p->name;
break;
case PLIST_CHGRP:
PUSHOUT(Directory);
Group = p->name;
break;
case PLIST_COMMENT:
break;
case PLIST_IGNORE:
p = p->next;
break;
default:
break;
errx(2, "can't get argument list space");
}
p = p->next;
}
PUSHOUT(Directory);
pkgdb_close();
perm_args = alloca(maxargs);
if (!perm_args) {
cleanup(0);
errx(2, "can't get argument list space");
}
strcpy(where_args, TAR_CMD);
strcat(where_args, TAR_ARGS);
where_count = sizeof(TAR_CMD) + sizeof(TAR_ARGS) - 2;
perm_args[0] = 0;
last_chdir = 0;
preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;
/* Reset the world */
Owner = NULL;
Group = NULL;
Mode = NULL;
last_file = NULL;
Directory = home;
/* Open Package Database for writing */
if (pkgdb_open(0) == -1) {
cleanup(0);
err(1, "can't open pkgdb");
}
/* Do it */
while (p) {
char cmd[FILENAME_MAX];
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) {
char try[FILENAME_MAX];
if (strrchr(p->name, '\'')) {
cleanup(0);
errx(2, "Bogus filename \"%s\"", p->name);
}
/* first try to rename it into place */
(void) snprintf(try, sizeof(try), "%s/%s", Directory, p->name);
if (fexists(try)) {
(void) chflags(try, 0); /* XXX hack - if truly immutable, rename fails */
if (preserve && PkgName) {
char pf[FILENAME_MAX];
if (make_preserve_name(pf, sizeof(pf), PkgName, try)) {
if (rename(try, pf)) {
warnx(
"unable to back up %s to %s, aborting pkg_add",
try, pf);
rollback(PkgName, home, pkg->head, p);
return;
}
}
}
}
if (rename(p->name, try) == 0) {
/* note in pkgdb */
{
char *s, t[FILENAME_MAX];
int rc;
(void) snprintf(t, sizeof(t), "%s/%s", Directory, p->name);
s = pkgdb_retrieve(t);
#ifdef PKGDB_DEBUG
printf("pkgdb_retrieve(\"%s\")=\"%s\"\n", t, s); /* pkgdb-debug - HF */
#endif
if (s)
warnx("Overwriting %s - pkg %s bogus/conflicting?", t, s);
else {
rc = pkgdb_store(t, PkgName);
#ifdef PKGDB_DEBUG
printf("pkgdb_store(\"%s\", \"%s\") = %d\n", t, PkgName, rc); /* pkgdb-debug - HF */
#endif
}
}
/* try to add to list of perms to be changed and run in bulk. */
if (p->name[0] == '/' || TOOBIG(p->name)) {
PUSHOUT(Directory);
}
add_count = snprintf(&perm_args[perm_count], maxargs - perm_count, "'%s' ", p->name);
if (add_count > maxargs - perm_count) {
cleanup(0);
errx(2, "oops, miscounted strings!");
}
perm_count += add_count;
} else {
/* rename failed, try copying with a big tar command */
if (last_chdir != Directory) {
PUSHOUT(last_chdir);
last_chdir = Directory;
} else if (p->name[0] == '/' || TOOBIG(p->name)) {
PUSHOUT(Directory);
}
add_count = snprintf(&where_args[where_count], maxargs - where_count, " '%s'", p->name);
if (add_count > maxargs - where_count) {
cleanup(0);
errx(2, "oops, miscounted strings!");
}
where_count += add_count;
add_count = snprintf(&perm_args[perm_count],
maxargs - perm_count,
"'%s' ", p->name);
if (add_count > maxargs - perm_count) {
cleanup(0);
errx(2, "oops, miscounted strings!");
}
perm_count += add_count;
/* note in pkgdb */
/* XXX would be better to store in PUSHOUT, but
* that would probably affect too much code I prefer
* not to touch - HF */
{
char *s, t[FILENAME_MAX], *u;
int rc;
if (p->name[0] == '/')
u = p->name;
else {
(void) snprintf(t, sizeof(t), "%s/%s", Directory, p->name);
u = t;
}
s = pkgdb_retrieve(t);
#ifdef PKGDB_DEBUG
printf("pkgdb_retrieve(\"%s\")=\"%s\"\n", t, s); /* pkgdb-debug - HF */
#endif
if (s)
warnx("Overwriting %s - pkg %s bogus/conflicting?", t, s);
else {
rc = pkgdb_store(t, PkgName);
#ifdef PKGDB_DEBUG
printf("pkgdb_store(\"%s\", \"%s\") = %d\n", t, PkgName, rc); /* pkgdb-debug - HF */
#endif
}
}
}
}
break;
case PLIST_CWD:
if (Verbose)
printf("extract: CWD to %s\n", p->name);
PUSHOUT(Directory);
if (strcmp(p->name, ".")) {
if (!Fake && make_hierarchy(p->name) == FAIL) {
cleanup(0);
errx(2, "unable to make directory '%s'", p->name);
}
Directory = p->name;
} else
Directory = home;
break;
case PLIST_CMD:
if (last_file == NULL && strchr(p->name, '%') != NULL) {
cleanup(0);
errx(2, "no last file specified for '%s' command", p->name);
}
format_cmd(cmd, sizeof(cmd), p->name, Directory, last_file);
PUSHOUT(Directory);
if (Verbose)
printf("extract: execute '%s'\n", cmd);
if (!Fake && system(cmd))
warnx("command '%s' failed", cmd);
break;
case PLIST_CHMOD:
PUSHOUT(Directory);
Mode = p->name;
break;
case PLIST_CHOWN:
PUSHOUT(Directory);
Owner = p->name;
break;
case PLIST_CHGRP:
PUSHOUT(Directory);
Group = p->name;
break;
case PLIST_COMMENT:
break;
case PLIST_IGNORE:
p = p->next;
break;
default:
break;
}
p = p->next;
}
PUSHOUT(Directory);
pkgdb_close();
}

View File

@ -1,11 +1,11 @@
/* $NetBSD: futil.c,v 1.7 1999/08/23 10:34:53 agc Exp $ */
/* $NetBSD: futil.c,v 1.8 1999/08/24 00:48:38 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: futil.c,v 1.7 1997/10/08 07:45:39 charnier Exp";
#else
__RCSID("$NetBSD: futil.c,v 1.7 1999/08/23 10:34:53 agc Exp $");
__RCSID("$NetBSD: futil.c,v 1.8 1999/08/24 00:48:38 hubertf Exp $");
#endif
#endif
@ -37,63 +37,62 @@ __RCSID("$NetBSD: futil.c,v 1.7 1999/08/23 10:34:53 agc Exp $");
* Assuming dir is a desired directory name, make it and all intervening
* directories necessary.
*/
int
make_hierarchy(char *dir)
{
char *cp1, *cp2;
char *cp1, *cp2;
if (dir[0] == '/')
cp1 = cp2 = dir + 1;
else
cp1 = cp2 = dir;
while (cp2) {
if ((cp2 = strchr(cp1, '/')) !=NULL )
*cp2 = '\0';
if (fexists(dir)) {
if (!(isdir(dir) || islinktodir(dir)))
return FAIL;
if (dir[0] == '/')
cp1 = cp2 = dir + 1;
else
cp1 = cp2 = dir;
while (cp2) {
if ((cp2 = strchr(cp1, '/')) != NULL)
*cp2 = '\0';
if (fexists(dir)) {
if (!(isdir(dir) || islinktodir(dir)))
return FAIL;
} else {
if (vsystem("mkdir %s", dir))
return FAIL;
apply_perms(NULL, dir);
}
/* Put it back */
if (cp2) {
*cp2 = '/';
cp1 = cp2 + 1;
}
}
else {
if (vsystem("mkdir %s", dir))
return FAIL;
apply_perms(NULL, dir);
}
/* Put it back */
if (cp2) {
*cp2 = '/';
cp1 = cp2 + 1;
}
}
return SUCCESS;
return SUCCESS;
}
/* Using permission defaults, apply them as necessary */
/*
* Using permission defaults, apply them as necessary
*/
void
apply_perms(char *dir, char *arg)
{
char *cd_to;
char *cd_to;
if (!dir || *arg == '/') /* absolute path? */
cd_to = "/";
else
cd_to = dir;
if (!dir || *arg == '/')/* absolute path? */
cd_to = "/";
else
cd_to = dir;
if (Mode)
if (vsystem("cd %s && %s -R %s %s", cd_to, CHMOD, Mode, arg))
warnx("couldn't change modes of '%s' to '%s'", arg, Mode);
if (Owner && Group) {
if (vsystem("cd %s && %s -R %s.%s %s", cd_to, CHOWN, Owner, Group, arg))
warnx("couldn't change owner/group of '%s' to '%s.%s'",
arg, Owner, Group);
return;
}
if (Owner) {
if (vsystem("cd %s && %s -R %s %s", cd_to, CHOWN, Owner, arg))
warnx("couldn't change owner of '%s' to '%s'", arg, Owner);
return;
} else if (Group)
if (vsystem("cd %s && %s -R %s %s", cd_to, CHGRP, Group, arg))
warnx("couldn't change group of '%s' to '%s'", arg, Group);
if (Mode)
if (vsystem("cd %s && %s -R %s %s", cd_to, CHMOD, Mode, arg))
warnx("couldn't change modes of '%s' to '%s'", arg, Mode);
if (Owner && Group) {
if (vsystem("cd %s && %s -R %s.%s %s", cd_to, CHOWN, Owner, Group, arg))
warnx("couldn't change owner/group of '%s' to '%s.%s'",
arg, Owner, Group);
return;
}
if (Owner) {
if (vsystem("cd %s && %s -R %s %s", cd_to, CHOWN, Owner, arg))
warnx("couldn't change owner of '%s' to '%s'", arg, Owner);
return;
} else if (Group)
if (vsystem("cd %s && %s -R %s %s", cd_to, CHGRP, Group, arg))
warnx("couldn't change group of '%s' to '%s'", arg, Group);
}

View File

@ -1,11 +1,11 @@
/* $NetBSD: main.c,v 1.11 1999/08/23 15:17:03 hubertf Exp $ */
/* $NetBSD: main.c,v 1.12 1999/08/24 00:48:38 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char *rcsid = "from FreeBSD Id: main.c,v 1.16 1997/10/08 07:45:43 charnier Exp";
#else
__RCSID("$NetBSD: main.c,v 1.11 1999/08/23 15:17:03 hubertf Exp $");
__RCSID("$NetBSD: main.c,v 1.12 1999/08/24 00:48:38 hubertf Exp $");
#endif
#endif
@ -37,130 +37,129 @@ __RCSID("$NetBSD: main.c,v 1.11 1999/08/23 15:17:03 hubertf Exp $");
static char Options[] = "hvIRfnp:SMt:";
char *Prefix = NULL;
Boolean NoInstall = FALSE;
Boolean NoRecord = FALSE;
char *Prefix = NULL;
Boolean NoInstall = FALSE;
Boolean NoRecord = FALSE;
char *Mode = NULL;
char *Owner = NULL;
char *Group = NULL;
char *PkgName = NULL;
char *Directory = NULL;
char FirstPen[FILENAME_MAX];
add_mode_t AddMode = NORMAL;
char *Mode = NULL;
char *Owner = NULL;
char *Group = NULL;
char *PkgName = NULL;
char *Directory = NULL;
char FirstPen[FILENAME_MAX];
add_mode_t AddMode = NORMAL;
static void
usage(void)
{
fprintf(stderr, "%s\n%s\n",
"usage: pkg_add [-vInfRMS] [-t template] [-p prefix]",
" pkg-name [pkg-name ...]");
exit(1);
fprintf(stderr, "%s\n%s\n",
"usage: pkg_add [-vInfRMS] [-t template] [-p prefix]",
" pkg-name [pkg-name ...]");
exit(1);
}
int
main(int argc, char **argv)
{
int ch, error;
lpkg_head_t pkgs;
lpkg_t *lpp;
char *cp;
char pkgname[MAXPATHLEN];
int ch, error;
lpkg_head_t pkgs;
lpkg_t *lpp;
char *cp;
char pkgname[MAXPATHLEN];
while ((ch = getopt(argc, argv, Options)) != -1) {
switch(ch) {
case 'v':
Verbose = TRUE;
break;
while ((ch = getopt(argc, argv, Options)) != -1) {
switch (ch) {
case 'v':
Verbose = TRUE;
break;
case 'p':
Prefix = optarg;
break;
case 'p':
Prefix = optarg;
break;
case 'I':
NoInstall = TRUE;
break;
case 'I':
NoInstall = TRUE;
break;
case 'R':
NoRecord = TRUE;
break;
case 'R':
NoRecord = TRUE;
break;
case 'f':
Force = TRUE;
break;
case 'f':
Force = TRUE;
break;
case 'n':
Fake = TRUE;
Verbose = TRUE;
break;
case 'n':
Fake = TRUE;
Verbose = TRUE;
break;
case 't':
strcpy(FirstPen, optarg);
break;
case 't':
strcpy(FirstPen, optarg);
break;
case 'S':
AddMode = SLAVE;
break;
case 'S':
AddMode = SLAVE;
break;
case 'M':
AddMode = MASTER;
break;
case 'M':
AddMode = MASTER;
break;
case 'h':
case '?':
default:
usage();
break;
}
}
argc -= optind;
argv += optind;
TAILQ_INIT(&pkgs);
if (AddMode != SLAVE) {
/* Get all the remaining package names, if any */
for (ch = 0; *argv; ch++, argv++) {
if (!strcmp(*argv, "-")) /* stdin? */
lpp = alloc_lpkg("-");
else if (IS_URL(*argv)) /* preserve URLs */
lpp = alloc_lpkg(*argv);
else { /* expand all pathnames to fullnames */
char *s;
if (fexists(*argv)) { /* refers to a file directly */
lpp = alloc_lpkg(realpath(*argv, pkgname));
} else if (ispkgpattern(*argv)
&& (s=findbestmatchingname(dirname_of(*argv),
basename_of(*argv))) != NULL) {
if (Verbose)
printf("Using %s for %s\n",s, *argv);
lpp = alloc_lpkg(realpath(s, pkgname));
} else {
/* look for the file(pattern) in the expected places */
if (!(cp = fileFindByPath(NULL, *argv))) {
lpp = NULL;
warnx("can't find package '%s'", *argv);
} else
lpp = alloc_lpkg(cp);
case 'h':
case '?':
default:
usage();
break;
}
}
if (lpp)
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
}
}
/* If no packages, yelp */
else if (!ch)
warnx("missing package name(s)"), usage();
else if (ch > 1 && AddMode == MASTER)
warnx("only one package name may be specified with master mode"),
usage();
if ((error = pkg_perform(&pkgs)) != 0) {
if (Verbose)
warnx("%d package addition(s) failed", error);
return error;
}
else
return 0;
argc -= optind;
argv += optind;
TAILQ_INIT(&pkgs);
if (AddMode != SLAVE) {
/* Get all the remaining package names, if any */
for (ch = 0; *argv; ch++, argv++) {
if (!strcmp(*argv, "-")) /* stdin? */
lpp = alloc_lpkg("-");
else if (IS_URL(*argv)) /* preserve URLs */
lpp = alloc_lpkg(*argv);
else { /* expand all pathnames to fullnames */
char *s;
if (fexists(*argv)) { /* refers to a file directly */
lpp = alloc_lpkg(realpath(*argv, pkgname));
} else if (ispkgpattern(*argv)
&& (s = findbestmatchingname(dirname_of(*argv),
basename_of(*argv))) != NULL) {
if (Verbose)
printf("Using %s for %s\n", s, *argv);
lpp = alloc_lpkg(realpath(s, pkgname));
} else {
/* look for the file(pattern) in the expected places */
if (!(cp = fileFindByPath(NULL, *argv))) {
lpp = NULL;
warnx("can't find package '%s'", *argv);
} else
lpp = alloc_lpkg(cp);
}
}
if (lpp)
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
}
}
/* If no packages, yelp */
else if (!ch)
warnx("missing package name(s)"), usage();
else if (ch > 1 && AddMode == MASTER)
warnx("only one package name may be specified with master mode"),
usage();
if ((error = pkg_perform(&pkgs)) != 0) {
if (Verbose)
warnx("%d package addition(s) failed", error);
return error;
} else
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
/* $NetBSD: main.c,v 1.6 1999/08/19 13:30:01 agc Exp $ */
/* $NetBSD: main.c,v 1.7 1999/08/24 00:48:38 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: main.c,v 1.6 1999/08/19 13:30:01 agc Exp $");
__RCSID("$NetBSD: main.c,v 1.7 1999/08/24 00:48:38 hubertf Exp $");
#endif
/*
@ -47,427 +47,431 @@ __RCSID("$NetBSD: main.c,v 1.6 1999/08/19 13:30:01 agc Exp $");
#include "lib.h"
void usage(void);
void usage(void);
extern const char *__progname; /* from crt0.o */
extern const char *__progname; /* from crt0.o */
int filecnt;
int filecnt;
/*
* assumes CWD is in /var/db/pkg/<pkg>!
* Assumes CWD is in /var/db/pkg/<pkg>!
*/
static void check1pkg(const char *pkgdir)
static void
check1pkg(const char *pkgdir)
{
FILE *f;
plist_t *p;
package_t Plist;
char *PkgName, *dirp=NULL, *md5file;
char file[FILENAME_MAX];
char dir[FILENAME_MAX];
f=fopen(CONTENTS_FNAME, "r");
if (f == NULL)
err(1, "can't open %s/%s/%s", _pkgdb_getPKGDB_DIR(), pkgdir, CONTENTS_FNAME);
Plist.head=Plist.tail=NULL;
read_plist(&Plist, f);
p = find_plist(&Plist, PLIST_NAME);
if (p == NULL)
errx(1, "Package %s has no @name, aborting.\n",
pkgdir);
PkgName=p->name;
for (p = Plist.head; p ; p = p->next) {
switch(p->type) {
case PLIST_FILE:
if (dirp == NULL) {
warnx("dirp not initialized, please send-pr!");
abort();
}
(void) snprintf(file, sizeof(file), "%s/%s", dirp, p->name);
if (!isfile(file))
warnx("%s: File %s is in %s but not on filesystem!", PkgName, file, CONTENTS_FNAME);
else {
if (p->next &&
p->next->type == PLIST_COMMENT &&
strncmp(p->next->name, CHECKSUM_HEADER, ChecksumHeaderLen) == 0) { /* || PLIST_MD5 - HF */
if ((md5file = MD5File(file, NULL)) != NULL) {
/* Mismatch? */
#ifdef PKGDB_DEBUG
printf("%s: md5 should=<%s>, is=<%s>\n",
file, p->next->name + ChecksumHeaderLen, md5file);
#endif
if (strcmp(md5file, p->next->name + ChecksumHeaderLen) != 0)
printf("%s fails MD5 checksum\n", file);
free(md5file);
}
}
filecnt++;
}
break;
case PLIST_CWD:
if (strcmp(p->name, ".") != 0)
dirp = p->name;
else {
(void) snprintf(dir, sizeof(dir), "%s/%s", _pkgdb_getPKGDB_DIR(), pkgdir);
dirp = dir;
}
break;
case PLIST_SRC:
warnx("@src is deprecated - please send-pr for %s!\n", PkgName);
break;
case PLIST_IGNORE:
p = p->next;
break;
case PLIST_SHOW_ALL:
case PLIST_CMD:
case PLIST_CHMOD:
case PLIST_CHOWN:
case PLIST_CHGRP:
case PLIST_COMMENT:
case PLIST_NAME:
case PLIST_UNEXEC:
case PLIST_DISPLAY:
case PLIST_PKGDEP:
case PLIST_MTREE:
case PLIST_DIR_RM:
case PLIST_IGNORE_INST:
case PLIST_OPTION:
case PLIST_PKGCFL:
break;
}
}
free_plist(&Plist);
fclose(f);
}
static void rebuild(void)
{
DIR *dp;
struct dirent *de;
FILE *f;
plist_t *p;
char *PkgName, dir[FILENAME_MAX], *dirp=NULL;
char *PkgDBDir=NULL, file[FILENAME_MAX];
int pkgcnt=0;
filecnt=0;
if (unlink(_pkgdb_getPKGDB_FILE()) != 0 && errno!=ENOENT)
err(1, "unlink %s", _pkgdb_getPKGDB_FILE());
if (pkgdb_open(0)==-1)
err(1, "cannot open pkgdb");
setbuf(stdout, NULL);
PkgDBDir=_pkgdb_getPKGDB_DIR();
chdir(PkgDBDir);
#ifdef PKGDB_DEBUG
printf("PkgDBDir='%s'\n", PkgDBDir);
#endif
dp=opendir(".");
if (dp == NULL)
err(1,"opendir failed");
while ((de = readdir(dp))) {
FILE *f;
plist_t *p;
package_t Plist;
if (!isdir(de->d_name))
continue;
char *PkgName, *dirp = NULL, *md5file;
char file[FILENAME_MAX];
char dir[FILENAME_MAX];
if (strcmp(de->d_name, ".")==0 ||
strcmp(de->d_name, "..")==0)
continue;
#ifdef PKGDB_DEBUG
printf("%s\n", de->d_name);
#else
printf(".");
#endif
chdir(de->d_name);
f=fopen(CONTENTS_FNAME, "r");
f = fopen(CONTENTS_FNAME, "r");
if (f == NULL)
err(1, "can't open %s/%s", de->d_name, CONTENTS_FNAME);
err(1, "can't open %s/%s/%s", _pkgdb_getPKGDB_DIR(), pkgdir, CONTENTS_FNAME);
Plist.head=Plist.tail=NULL;
Plist.head = Plist.tail = NULL;
read_plist(&Plist, f);
p = find_plist(&Plist, PLIST_NAME);
if (p == NULL)
errx(1, "Package %s has no @name, aborting.\n",
de->d_name);
PkgName=p->name;
for (p = Plist.head; p ; p = p->next) {
switch(p->type) {
case PLIST_FILE:
if (dirp == NULL) {
warnx("dirp not initialized, please send-pr!");
abort();
}
(void) snprintf(file, sizeof(file), "%s/%s", dirp, p->name);
errx(1, "Package %s has no @name, aborting.\n",
pkgdir);
PkgName = p->name;
for (p = Plist.head; p; p = p->next) {
switch (p->type) {
case PLIST_FILE:
if (dirp == NULL) {
warnx("dirp not initialized, please send-pr!");
abort();
}
(void) snprintf(file, sizeof(file), "%s/%s", dirp, p->name);
if (!isfile(file))
warnx("%s: File %s is in %s but not on filesystem!",
PkgName, file, CONTENTS_FNAME);
else {
pkgdb_store(file, PkgName);
filecnt++;
if (!isfile(file))
warnx("%s: File %s is in %s but not on filesystem!", PkgName, file, CONTENTS_FNAME);
else {
if (p->next &&
p->next->type == PLIST_COMMENT &&
strncmp(p->next->name, CHECKSUM_HEADER, ChecksumHeaderLen) == 0) { /* || PLIST_MD5 - HF */
if ((md5file = MD5File(file, NULL)) != NULL) {
/* Mismatch? */
#ifdef PKGDB_DEBUG
printf("%s: md5 should=<%s>, is=<%s>\n",
file, p->next->name + ChecksumHeaderLen, md5file);
#endif
if (strcmp(md5file, p->next->name + ChecksumHeaderLen) != 0)
printf("%s fails MD5 checksum\n", file);
free(md5file);
}
}
filecnt++;
}
break;
case PLIST_CWD:
if (strcmp(p->name, ".") != 0)
dirp = p->name;
else {
(void) snprintf(dir, sizeof(dir), "%s/%s", _pkgdb_getPKGDB_DIR(), pkgdir);
dirp = dir;
}
break;
case PLIST_SRC:
warnx("@src is deprecated - please send-pr for %s!\n", PkgName);
break;
case PLIST_IGNORE:
p = p->next;
break;
case PLIST_SHOW_ALL:
case PLIST_CMD:
case PLIST_CHMOD:
case PLIST_CHOWN:
case PLIST_CHGRP:
case PLIST_COMMENT:
case PLIST_NAME:
case PLIST_UNEXEC:
case PLIST_DISPLAY:
case PLIST_PKGDEP:
case PLIST_MTREE:
case PLIST_DIR_RM:
case PLIST_IGNORE_INST:
case PLIST_OPTION:
case PLIST_PKGCFL:
break;
}
break;
case PLIST_CWD:
if (strcmp(p->name, ".") != 0)
dirp = p->name;
else {
(void) snprintf(dir, sizeof(dir), "%s/%s", PkgDBDir, de->d_name);
dirp = dir;
}
break;
case PLIST_SRC:
warnx("@src is deprecated - please send-pr for %s!\n", PkgName);
break;
case PLIST_IGNORE:
p = p->next;
break;
case PLIST_SHOW_ALL:
case PLIST_CMD:
case PLIST_CHMOD:
case PLIST_CHOWN:
case PLIST_CHGRP:
case PLIST_COMMENT:
case PLIST_NAME:
case PLIST_UNEXEC:
case PLIST_DISPLAY:
case PLIST_PKGDEP:
case PLIST_MTREE:
case PLIST_DIR_RM:
case PLIST_IGNORE_INST:
case PLIST_OPTION:
case PLIST_PKGCFL:
break;
}
}
free_plist(&Plist);
fclose(f);
chdir("..");
pkgcnt++;
}
closedir(dp);
pkgdb_close();
printf("\n");
printf("Stored %d file%s from %d package%s in %s.\n",
filecnt, filecnt==1?"":"s",
pkgcnt, pkgcnt==1?"":"s",
_pkgdb_getPKGDB_FILE());
}
static void checkall(void)
static void
rebuild(void)
{
DIR *dp;
struct dirent *de;
int pkgcnt=0;
DIR *dp;
struct dirent *de;
FILE *f;
plist_t *p;
char *PkgName, dir[FILENAME_MAX], *dirp = NULL;
char *PkgDBDir = NULL, file[FILENAME_MAX];
int pkgcnt = 0;
filecnt = 0;
setbuf(stdout, NULL);
chdir(_pkgdb_getPKGDB_DIR());
dp=opendir(".");
if (dp == NULL)
err(1,"opendir failed");
while ((de = readdir(dp))) {
if (!isdir(de->d_name))
continue;
filecnt = 0;
if (strcmp(de->d_name, ".")==0 ||
strcmp(de->d_name, "..")==0)
continue;
if (unlink(_pkgdb_getPKGDB_FILE()) != 0 && errno != ENOENT)
err(1, "unlink %s", _pkgdb_getPKGDB_FILE());
chdir(de->d_name);
if (pkgdb_open(0) == -1)
err(1, "cannot open pkgdb");
check1pkg(de->d_name);
printf(".");
chdir("..");
setbuf(stdout, NULL);
PkgDBDir = _pkgdb_getPKGDB_DIR();
chdir(PkgDBDir);
#ifdef PKGDB_DEBUG
printf("PkgDBDir='%s'\n", PkgDBDir);
#endif
dp = opendir(".");
if (dp == NULL)
err(1, "opendir failed");
while ((de = readdir(dp))) {
package_t Plist;
pkgcnt++;
}
closedir(dp);
pkgdb_close();
if (!isdir(de->d_name))
continue;
printf("\n");
printf("Checked %d file%s from %d package%s.\n",
filecnt, (filecnt==1)?"":"s",
pkgcnt, (pkgcnt==1)?"":"s");
if (strcmp(de->d_name, ".") == 0 ||
strcmp(de->d_name, "..") == 0)
continue;
#ifdef PKGDB_DEBUG
printf("%s\n", de->d_name);
#else
printf(".");
#endif
chdir(de->d_name);
f = fopen(CONTENTS_FNAME, "r");
if (f == NULL)
err(1, "can't open %s/%s", de->d_name, CONTENTS_FNAME);
Plist.head = Plist.tail = NULL;
read_plist(&Plist, f);
p = find_plist(&Plist, PLIST_NAME);
if (p == NULL)
errx(1, "Package %s has no @name, aborting.\n",
de->d_name);
PkgName = p->name;
for (p = Plist.head; p; p = p->next) {
switch (p->type) {
case PLIST_FILE:
if (dirp == NULL) {
warnx("dirp not initialized, please send-pr!");
abort();
}
(void) snprintf(file, sizeof(file), "%s/%s", dirp, p->name);
if (!isfile(file))
warnx("%s: File %s is in %s but not on filesystem!",
PkgName, file, CONTENTS_FNAME);
else {
pkgdb_store(file, PkgName);
filecnt++;
}
break;
case PLIST_CWD:
if (strcmp(p->name, ".") != 0)
dirp = p->name;
else {
(void) snprintf(dir, sizeof(dir), "%s/%s", PkgDBDir, de->d_name);
dirp = dir;
}
break;
case PLIST_SRC:
warnx("@src is deprecated - please send-pr for %s!\n", PkgName);
break;
case PLIST_IGNORE:
p = p->next;
break;
case PLIST_SHOW_ALL:
case PLIST_CMD:
case PLIST_CHMOD:
case PLIST_CHOWN:
case PLIST_CHGRP:
case PLIST_COMMENT:
case PLIST_NAME:
case PLIST_UNEXEC:
case PLIST_DISPLAY:
case PLIST_PKGDEP:
case PLIST_MTREE:
case PLIST_DIR_RM:
case PLIST_IGNORE_INST:
case PLIST_OPTION:
case PLIST_PKGCFL:
break;
}
}
free_plist(&Plist);
fclose(f);
chdir("..");
pkgcnt++;
}
closedir(dp);
pkgdb_close();
printf("\n");
printf("Stored %d file%s from %d package%s in %s.\n",
filecnt, filecnt == 1 ? "" : "s",
pkgcnt, pkgcnt == 1 ? "" : "s",
_pkgdb_getPKGDB_FILE());
}
static void
checkall(void)
{
DIR *dp;
struct dirent *de;
int pkgcnt = 0;
filecnt = 0;
setbuf(stdout, NULL);
chdir(_pkgdb_getPKGDB_DIR());
dp = opendir(".");
if (dp == NULL)
err(1, "opendir failed");
while ((de = readdir(dp))) {
if (!isdir(de->d_name))
continue;
if (strcmp(de->d_name, ".") == 0 ||
strcmp(de->d_name, "..") == 0)
continue;
chdir(de->d_name);
check1pkg(de->d_name);
printf(".");
chdir("..");
pkgcnt++;
}
closedir(dp);
pkgdb_close();
printf("\n");
printf("Checked %d file%s from %d package%s.\n",
filecnt, (filecnt == 1) ? "" : "s",
pkgcnt, (pkgcnt == 1) ? "" : "s");
}
static int
checkpattern_fn(const char *pkg, char *data)
{
int rc;
int rc;
rc = chdir(pkg);
if (rc == -1)
err(1, "Cannot chdir to %s/%s", _pkgdb_getPKGDB_DIR(), pkg);
check1pkg(pkg);
printf(".");
chdir("..");
rc = chdir(pkg);
if (rc == -1)
err(1, "Cannot chdir to %s/%s", _pkgdb_getPKGDB_DIR(), pkg);
return 0;
check1pkg(pkg);
printf(".");
chdir("..");
return 0;
}
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
if (argc < 2)
usage();
if (strcasecmp(argv[1], "rebuild")==0) {
if (argc < 2)
usage();
rebuild();
} else if (strcasecmp(argv[1], "check")==0) {
if (strcasecmp(argv[1], "rebuild") == 0) {
argv++; /* argv[0] */
argv++; /* "check" */
if (*argv != NULL) {
/* args specified */
int pkgcnt=0;
int rc;
rebuild();
filecnt = 0;
setbuf(stdout, NULL);
rc = chdir(_pkgdb_getPKGDB_DIR());
if (rc == -1)
err(1, "Cannot chdir to %s", _pkgdb_getPKGDB_DIR());
while (*argv != NULL) {
if (ispkgpattern(*argv)){
if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, checkpattern_fn, NULL) == 0)
errx(1, "No matching pkg for %s.", *argv);
}else {
rc = chdir(*argv);
if (rc == -1)
err(1, "Cannot chdir to %s/%s", _pkgdb_getPKGDB_DIR(), *argv);
} else if (strcasecmp(argv[1], "check") == 0) {
check1pkg(*argv);
printf(".");
argv++; /* argv[0] */
argv++; /* "check" */
chdir("..");
if (*argv != NULL) {
/* args specified */
int pkgcnt = 0;
int rc;
filecnt = 0;
setbuf(stdout, NULL);
rc = chdir(_pkgdb_getPKGDB_DIR());
if (rc == -1)
err(1, "Cannot chdir to %s", _pkgdb_getPKGDB_DIR());
while (*argv != NULL) {
if (ispkgpattern(*argv)) {
if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, checkpattern_fn, NULL) == 0)
errx(1, "No matching pkg for %s.", *argv);
} else {
rc = chdir(*argv);
if (rc == -1)
err(1, "Cannot chdir to %s/%s", _pkgdb_getPKGDB_DIR(), *argv);
check1pkg(*argv);
printf(".");
chdir("..");
}
pkgcnt++;
argv++;
}
printf("\n");
printf("Checked %d file%s from %d package%s.\n",
filecnt, (filecnt == 1) ? "" : "s",
pkgcnt, (pkgcnt == 1) ? "" : "s");
} else {
checkall();
}
pkgcnt++;
argv++;
}
printf("\n");
printf("Checked %d file%s from %d package%s.\n",
filecnt, (filecnt==1)?"":"s",
pkgcnt, (pkgcnt==1)?"":"s");
} else {
checkall();
} else if (strcasecmp(argv[1], "list") == 0 ||
strcasecmp(argv[1], "dump") == 0) {
char *key, *val;
printf("Dumping pkgdb %s:\n", _pkgdb_getPKGDB_FILE());
if (pkgdb_open(1) == -1) {
err(1, "cannot open %s", _pkgdb_getPKGDB_FILE());
}
while ((key = pkgdb_iter())) {
val = pkgdb_retrieve(key);
printf("file: %-50s pkg: %s\n", key, val);
}
pkgdb_close();
}
} else if (strcasecmp(argv[1], "list")==0 ||
strcasecmp(argv[1], "dump")==0) {
char *key, *val;
printf("Dumping pkgdb %s:\n", _pkgdb_getPKGDB_FILE());
if (pkgdb_open(1)==-1) {
err(1, "cannot open %s", _pkgdb_getPKGDB_FILE());
}
while ((key=pkgdb_iter())) {
val=pkgdb_retrieve(key);
printf("file: %-50s pkg: %s\n", key, val);
}
pkgdb_close();
}
#ifdef PKGDB_DEBUG
else if (strcasecmp(argv[1], "del")==0 ||
strcasecmp(argv[1], "delete")==0) {
int rc;
if (pkgdb_open(0)==-1)
err(1, "cannot open pkgdb");
rc=pkgdb_remove(argv[2]);
if (rc) {
if (errno)
perror ("pkgdb_remove");
else
printf("Key not present in pkgdb.\n");
else if (strcasecmp(argv[1], "del") == 0 ||
strcasecmp(argv[1], "delete") == 0) {
int rc;
if (pkgdb_open(0) == -1)
err(1, "cannot open pkgdb");
rc = pkgdb_remove(argv[2]);
if (rc) {
if (errno)
perror("pkgdb_remove");
else
printf("Key not present in pkgdb.\n");
}
pkgdb_close();
} else if (strcasecmp(argv[1], "add") == 0) {
int rc;
if (pkgdb_open(0) == -1) {
err(1, "cannot open pkgdb");
}
rc = pkgdb_store(argv[2], argv[3]);
switch (rc) {
case -1:
perror("pkgdb_store");
break;
case 1:
printf("Key already present.\n");
break;
default:
/* 0: everything ok */
break;
}
pkgdb_close();
}
pkgdb_close();
} else if (strcasecmp(argv[1], "add")==0) {
int rc;
if (pkgdb_open(0)==-1) {
err(1, "cannot open pkgdb");
#endif
else {
usage();
}
rc=pkgdb_store(argv[2], argv[3]);
switch (rc) {
case -1:
perror ("pkgdb_store");
break;
case 1:
printf("Key already present.\n");
break;
default:
/* 0: everything ok */
break;
}
pkgdb_close();
}
#endif
else {
usage();
}
printf("Done.\n");
return 0;
printf("Done.\n");
return 0;
}
void usage(void)
void
usage(void)
{
printf("Usage: %s command args ...\n"
"Where 'commands' and 'args' are:\n"
" rebuild - rebuild pkgdb from +CONTENTS files\n"
" check [pkg ...] - check md5 checksum of installed files\n"
printf("Usage: %s command args ...\n"
"Where 'commands' and 'args' are:\n"
" rebuild - rebuild pkgdb from +CONTENTS files\n"
" check [pkg ...] - check md5 checksum of installed files\n"
#ifdef PKGDB_DEBUG
" add key value - add key & value\n"
" delete key - delete reference to key\n"
" add key value - add key & value\n"
" delete key - delete reference to key\n"
#endif
" dump - dump database\n"
, __progname );
exit(1);
" dump - dump database\n"
,__progname);
exit(1);
}
void
cleanup(int signo)
{
;
;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: create.h,v 1.11 1999/03/22 05:02:40 hubertf Exp $ */
/* $NetBSD: create.h,v 1.12 1999/08/24 00:48:38 hubertf Exp $ */
/* from FreeBSD Id: create.h,v 1.13 1997/10/08 07:46:19 charnier Exp */
@ -25,29 +25,29 @@
#ifndef _INST_CREATE_H_INCLUDE
#define _INST_CREATE_H_INCLUDE
extern char *Prefix;
extern char *Comment;
extern char *Desc;
extern char *Display;
extern char *Install;
extern char *DeInstall;
extern char *Contents;
extern char *Require;
extern char *SrcDir;
extern char *ExcludeFrom;
extern char *Mtree;
extern char *Pkgdeps;
extern char *Pkgcfl;
extern char *BuildVersion;
extern char *BuildInfo;
extern char PlayPen[];
extern size_t PlayPenSize;
extern int Dereference;
extern int PlistOnly;
extern int RelativeLinks;
extern int ReorderDirs;
extern char *Prefix;
extern char *Comment;
extern char *Desc;
extern char *Display;
extern char *Install;
extern char *DeInstall;
extern char *Contents;
extern char *Require;
extern char *SrcDir;
extern char *ExcludeFrom;
extern char *Mtree;
extern char *Pkgdeps;
extern char *Pkgcfl;
extern char *BuildVersion;
extern char *BuildInfo;
extern char PlayPen[];
extern size_t PlayPenSize;
extern int Dereference;
extern int PlistOnly;
extern int RelativeLinks;
extern int ReorderDirs;
void check_list(char *, package_t *, const char *);
void copy_plist(char *, package_t *);
void check_list(char *, package_t *, const char *);
void copy_plist(char *, package_t *);
#endif /* _INST_CREATE_H_INCLUDE */
#endif /* _INST_CREATE_H_INCLUDE */

View File

@ -1,11 +1,11 @@
/* $NetBSD: main.c,v 1.13 1999/03/22 05:02:40 hubertf Exp $ */
/* $NetBSD: main.c,v 1.14 1999/08/24 00:48:38 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: main.c,v 1.17 1997/10/08 07:46:23 charnier Exp";
#else
__RCSID("$NetBSD: main.c,v 1.13 1999/03/22 05:02:40 hubertf Exp $");
__RCSID("$NetBSD: main.c,v 1.14 1999/08/24 00:48:38 hubertf Exp $");
#endif
#endif
@ -26,166 +26,165 @@ __RCSID("$NetBSD: main.c,v 1.13 1999/03/22 05:02:40 hubertf Exp $");
static char Options[] = "ORhlvFf:p:P:C:c:d:i:k:r:t:X:D:m:s:b:B:";
char *Prefix = NULL;
char *Comment = NULL;
char *Desc = NULL;
char *SrcDir = NULL;
char *Display = NULL;
char *Install = NULL;
char *DeInstall = NULL;
char *Contents = NULL;
char *Require = NULL;
char *ExcludeFrom = NULL;
char *Mtree = NULL;
char *Pkgdeps = NULL;
char *Pkgcfl = NULL;
char *BuildVersion = NULL;
char *BuildInfo = NULL;
char PlayPen[FILENAME_MAX];
size_t PlayPenSize = sizeof(PlayPen);
int Dereference = 0;
int PlistOnly = 0;
int RelativeLinks = 0;
int ReorderDirs = 0;
Boolean File2Pkg = FALSE;
char *Prefix = NULL;
char *Comment = NULL;
char *Desc = NULL;
char *SrcDir = NULL;
char *Display = NULL;
char *Install = NULL;
char *DeInstall = NULL;
char *Contents = NULL;
char *Require = NULL;
char *ExcludeFrom = NULL;
char *Mtree = NULL;
char *Pkgdeps = NULL;
char *Pkgcfl = NULL;
char *BuildVersion = NULL;
char *BuildInfo = NULL;
char PlayPen[FILENAME_MAX];
size_t PlayPenSize = sizeof(PlayPen);
int Dereference = 0;
int PlistOnly = 0;
int RelativeLinks = 0;
int ReorderDirs = 0;
Boolean File2Pkg = FALSE;
static void
usage(void)
{
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
"usage: pkg_create [-ORhlv] [-P dpkgs] [-C cpkgs] [-p prefix] [-f contents]",
" [-i iscript] [-k dscript] [-r rscript] [-t template]",
" [-X excludefile] [-D displayfile] [-m mtreefile]",
" [-b build-version-file] [-B build-info-file]",
" -c comment -d description -f packlist pkg-name");
exit(1);
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
"usage: pkg_create [-ORhlv] [-P dpkgs] [-C cpkgs] [-p prefix] [-f contents]",
" [-i iscript] [-k dscript] [-r rscript] [-t template]",
" [-X excludefile] [-D displayfile] [-m mtreefile]",
" [-b build-version-file] [-B build-info-file]",
" -c comment -d description -f packlist pkg-name");
exit(1);
}
int
main(int argc, char **argv)
{
int ch;
lpkg_head_t pkgs;
lpkg_t *lpp;
int ch;
lpkg_head_t pkgs;
lpkg_t *lpp;
while ((ch = getopt(argc, argv, Options)) != -1)
switch(ch) {
case 'v':
Verbose = TRUE;
break;
while ((ch = getopt(argc, argv, Options)) != -1)
switch (ch) {
case 'v':
Verbose = TRUE;
break;
case 'O':
PlistOnly = 1;
break;
case 'O':
PlistOnly = 1;
break;
case 'R':
ReorderDirs = 1;
break;
case 'R':
ReorderDirs = 1;
break;
case 'p':
Prefix = optarg;
break;
case 'p':
Prefix = optarg;
break;
case 's':
SrcDir = optarg;
break;
case 's':
SrcDir = optarg;
break;
case 'f':
Contents = optarg;
break;
case 'f':
Contents = optarg;
break;
case 'c':
Comment = optarg;
break;
case 'c':
Comment = optarg;
break;
case 'd':
Desc = optarg;
break;
case 'd':
Desc = optarg;
break;
case 'i':
Install = optarg;
break;
case 'i':
Install = optarg;
break;
case 'k':
DeInstall = optarg;
break;
case 'k':
DeInstall = optarg;
break;
case 'l':
RelativeLinks = 1;
break;
case 'l':
RelativeLinks = 1;
break;
case 'r':
Require = optarg;
break;
case 'r':
Require = optarg;
break;
case 't':
strcpy(PlayPen, optarg);
break;
case 't':
strcpy(PlayPen, optarg);
break;
case 'X':
ExcludeFrom = optarg;
break;
case 'X':
ExcludeFrom = optarg;
break;
case 'h':
Dereference = 1;
break;
case 'h':
Dereference = 1;
break;
case 'D':
Display = optarg;
break;
case 'D':
Display = optarg;
break;
case 'm':
Mtree = optarg;
break;
case 'm':
Mtree = optarg;
break;
case 'P':
Pkgdeps = optarg;
break;
case 'P':
Pkgdeps = optarg;
break;
case 'C':
Pkgcfl = optarg;
break;
case 'C':
Pkgcfl = optarg;
break;
case 'b':
BuildVersion = optarg;
break;
case 'b':
BuildVersion = optarg;
break;
case 'B':
BuildInfo = optarg;
break;
case 'B':
BuildInfo = optarg;
break;
case '?':
default:
usage();
break;
case '?':
default:
usage();
break;
}
argc -= optind;
argv += optind;
TAILQ_INIT(&pkgs);
/* Get all the remaining package names, if any */
while (*argv) {
lpp = alloc_lpkg(*argv);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
argv++;
}
argc -= optind;
argv += optind;
TAILQ_INIT(&pkgs);
/* Get all the remaining package names, if any */
while (*argv) {
lpp = alloc_lpkg(*argv);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
argv++;
}
/* If no packages, yelp */
lpp = TAILQ_FIRST(&pkgs);
if (lpp == NULL)
warnx("missing package name"), usage();
lpp = TAILQ_NEXT(lpp, lp_link);
if (lpp != NULL)
warnx("only one package name allowed ('%s' extraneous)",
lpp->lp_name),
usage();
if (!pkg_perform(&pkgs)) {
if (Verbose)
warnx("package creation failed");
return 1;
}
else
return 0;
/* If no packages, yelp */
lpp = TAILQ_FIRST(&pkgs);
if (lpp == NULL)
warnx("missing package name"), usage();
lpp = TAILQ_NEXT(lpp, lp_link);
if (lpp != NULL)
warnx("only one package name allowed ('%s' extraneous)",
lpp->lp_name),
usage();
if (!pkg_perform(&pkgs)) {
if (Verbose)
warnx("package creation failed");
return 1;
} else
return 0;
}

View File

@ -1,11 +1,11 @@
/* $NetBSD: perform.c,v 1.18 1999/08/19 13:30:01 agc Exp $ */
/* $NetBSD: perform.c,v 1.19 1999/08/24 00:48:38 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.38 1997/10/13 15:03:51 jkh Exp";
#else
__RCSID("$NetBSD: perform.c,v 1.18 1999/08/19 13:30:01 agc Exp $");
__RCSID("$NetBSD: perform.c,v 1.19 1999/08/24 00:48:38 hubertf Exp $");
#endif
#endif
@ -43,84 +43,84 @@ static char *home;
static void
make_dist(char *home, char *pkg, char *suffix, package_t *plist)
{
char tball[FILENAME_MAX];
plist_t *p;
int ret;
char *args[50]; /* Much more than enough. */
int nargs = 0;
int pipefds[2];
FILE *totar;
pid_t pid;
char tball[FILENAME_MAX];
plist_t *p;
int ret;
char *args[50]; /* Much more than enough. */
int nargs = 0;
int pipefds[2];
FILE *totar;
pid_t pid;
args[nargs++] = TAR_CMD; /* argv[0] */
args[nargs++] = TAR_CMD;/* argv[0] */
if (*pkg == '/')
(void) snprintf(tball, sizeof(tball), "%s.%s", pkg, suffix);
else
(void) snprintf(tball, sizeof(tball), "%s/%s.%s", home, pkg, suffix);
if (*pkg == '/')
(void) snprintf(tball, sizeof(tball), "%s.%s", pkg, suffix);
else
(void) snprintf(tball, sizeof(tball), "%s/%s.%s", home, pkg, suffix);
args[nargs++] = "-c";
args[nargs++] = "-f";
args[nargs++] = tball;
if (strchr(suffix, 'z')) /* Compress/gzip? */
args[nargs++] = "-z";
if (Dereference)
args[nargs++] = "-h";
if (ExcludeFrom) {
args[nargs++] = "-X";
args[nargs++] = ExcludeFrom;
}
args[nargs++] = "-T"; /* Take filenames from file instead of args. */
args[nargs++] = "-"; /* Use stdin for the file. */
args[nargs] = NULL;
args[nargs++] = "-c";
args[nargs++] = "-f";
args[nargs++] = tball;
if (strchr(suffix, 'z'))/* Compress/gzip? */
args[nargs++] = "-z";
if (Dereference)
args[nargs++] = "-h";
if (ExcludeFrom) {
args[nargs++] = "-X";
args[nargs++] = ExcludeFrom;
}
args[nargs++] = "-T"; /* Take filenames from file instead of args. */
args[nargs++] = "-"; /* Use stdin for the file. */
args[nargs] = NULL;
if (Verbose)
printf("Creating gzip'd %s ball in '%s'\n", TAR_CMD, tball);
if (Verbose)
printf("Creating gzip'd %s ball in '%s'\n", TAR_CMD, tball);
/* Set up a pipe for passing the filenames, and fork off a tar process. */
if (pipe(pipefds) == -1) {
cleanup(0);
errx(2, "cannot create pipe");
}
if ((pid = fork()) == -1) {
cleanup(0);
errx(2, "cannot fork process for %s", TAR_CMD);
}
if (pid == 0) { /* The child */
dup2(pipefds[0], 0);
/* Set up a pipe for passing the filenames, and fork off a tar process. */
if (pipe(pipefds) == -1) {
cleanup(0);
errx(2, "cannot create pipe");
}
if ((pid = fork()) == -1) {
cleanup(0);
errx(2, "cannot fork process for %s", TAR_CMD);
}
if (pid == 0) { /* The child */
dup2(pipefds[0], 0);
close(pipefds[0]);
close(pipefds[1]);
execv(TAR_FULLPATHNAME, args);
cleanup(0);
errx(2, "failed to execute %s command", TAR_CMD);
}
/* Meanwhile, back in the parent process ... */
close(pipefds[0]);
close(pipefds[1]);
execv(TAR_FULLPATHNAME, args);
cleanup(0);
errx(2, "failed to execute %s command", TAR_CMD);
}
if ((totar = fdopen(pipefds[1], "w")) == NULL) {
cleanup(0);
errx(2, "fdopen failed");
}
/* Meanwhile, back in the parent process ... */
close(pipefds[0]);
if ((totar = fdopen(pipefds[1], "w")) == NULL) {
cleanup(0);
errx(2, "fdopen failed");
}
fprintf(totar, "%s\n", CONTENTS_FNAME);
fprintf(totar, "%s\n", COMMENT_FNAME);
fprintf(totar, "%s\n", DESC_FNAME);
fprintf(totar, "%s\n", CONTENTS_FNAME);
fprintf(totar, "%s\n", COMMENT_FNAME);
fprintf(totar, "%s\n", DESC_FNAME);
if (Install) {
fprintf(totar, "%s\n", INSTALL_FNAME);
}
if (DeInstall) {
fprintf(totar, "%s\n", DEINSTALL_FNAME);
}
if (Require) {
fprintf(totar, "%s\n", REQUIRE_FNAME);
}
if (Display) {
fprintf(totar, "%s\n", DISPLAY_FNAME);
}
if (Mtree) {
fprintf(totar, "%s\n", MTREE_FNAME);
}
if (Install) {
fprintf(totar, "%s\n", INSTALL_FNAME);
}
if (DeInstall) {
fprintf(totar, "%s\n", DEINSTALL_FNAME);
}
if (Require) {
fprintf(totar, "%s\n", REQUIRE_FNAME);
}
if (Display) {
fprintf(totar, "%s\n", DISPLAY_FNAME);
}
if (Mtree) {
fprintf(totar, "%s\n", MTREE_FNAME);
}
if (BuildVersion) {
(void) fprintf(totar, "%s\n", BUILD_VERSION_FNAME);
}
@ -128,243 +128,245 @@ make_dist(char *home, char *pkg, char *suffix, package_t *plist)
(void) fprintf(totar, "%s\n", BUILD_INFO_FNAME);
}
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->type == PLIST_SRC)
fprintf(totar, "-C\n%s\n", p->name);
else if (p->type == PLIST_IGNORE)
p = p->next;
}
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->type == PLIST_SRC)
fprintf(totar, "-C\n%s\n", p->name);
else if (p->type == PLIST_IGNORE)
p = p->next;
}
fclose(totar);
wait(&ret);
/* assume either signal or bad exit is enough for us */
if (ret) {
cleanup(0);
errx(2, "%s command failed with code %d", TAR_CMD, ret);
}
fclose(totar);
wait(&ret);
/* assume either signal or bad exit is enough for us */
if (ret) {
cleanup(0);
errx(2, "%s command failed with code %d", TAR_CMD, ret);
}
}
static void
sanity_check(void)
{
if (!Comment) {
cleanup(0);
errx(2, "required package comment string is missing (-c comment)");
}
if (!Desc) {
cleanup(0);
errx(2, "required package description string is missing (-d desc)");
}
if (!Contents) {
cleanup(0);
errx(2, "required package contents list is missing (-f [-]file)");
}
if (!Comment) {
cleanup(0);
errx(2, "required package comment string is missing (-c comment)");
}
if (!Desc) {
cleanup(0);
errx(2, "required package description string is missing (-d desc)");
}
if (!Contents) {
cleanup(0);
errx(2, "required package contents list is missing (-f [-]file)");
}
}
/* Clean up those things that would otherwise hang around */
/*
* Clean up those things that would otherwise hang around
*/
void
cleanup(int sig)
{
static int alreadyCleaning;
void (*oldint)(int);
void (*oldhup)(int);
oldint = signal(SIGINT, SIG_IGN);
oldhup = signal(SIGHUP, SIG_IGN);
static int alreadyCleaning;
void (*oldint) (int);
void (*oldhup) (int);
oldint = signal(SIGINT, SIG_IGN);
oldhup = signal(SIGHUP, SIG_IGN);
if (!alreadyCleaning) {
alreadyCleaning = 1;
if (sig)
printf("Signal %d received, cleaning up.\n", sig);
leave_playpen(home);
if (sig)
exit(1);
}
signal(SIGINT, oldint);
signal(SIGHUP, oldhup);
if (!alreadyCleaning) {
alreadyCleaning = 1;
if (sig)
printf("Signal %d received, cleaning up.\n", sig);
leave_playpen(home);
if (sig)
exit(1);
}
signal(SIGINT, oldint);
signal(SIGHUP, oldhup);
}
int
pkg_perform(lpkg_head_t *pkgs)
{
char *pkg;
char *cp;
FILE *pkg_in, *fp;
package_t plist;
char *suffix; /* What we tack on to the end of the finished package */
lpkg_t *lpp;
char *pkg;
char *cp;
FILE *pkg_in, *fp;
package_t plist;
char *suffix; /* What we tack on to the end of the finished package */
lpkg_t *lpp;
lpp = TAILQ_FIRST(pkgs);
pkg = lpp->lp_name; /* Only one arg to create */
lpp = TAILQ_FIRST(pkgs);
pkg = lpp->lp_name; /* Only one arg to create */
/* Preliminary setup */
sanity_check();
if (Verbose && !PlistOnly)
printf("Creating package %s\n", pkg);
get_dash_string(&Comment);
get_dash_string(&Desc);
if (!strcmp(Contents, "-"))
pkg_in = stdin;
else {
pkg_in = fopen(Contents, "r");
if (!pkg_in) {
cleanup(0);
errx(2, "unable to open contents file '%s' for input", Contents);
}
}
plist.head = plist.tail = NULL;
/* Break the package name into base and desired suffix (if any) */
if ((cp = strrchr(pkg, '.')) != NULL) {
suffix = cp + 1;
*cp = '\0';
}
else
suffix = "tgz";
/* Stick the dependencies, if any, at the top */
if (Pkgdeps) {
/* Preliminary setup */
sanity_check();
if (Verbose && !PlistOnly)
printf("Registering depends:");
while (Pkgdeps) {
cp = strsep(&Pkgdeps, " \t\n");
if (*cp) {
add_plist(&plist, PLIST_PKGDEP, cp);
printf("Creating package %s\n", pkg);
get_dash_string(&Comment);
get_dash_string(&Desc);
if (!strcmp(Contents, "-"))
pkg_in = stdin;
else {
pkg_in = fopen(Contents, "r");
if (!pkg_in) {
cleanup(0);
errx(2, "unable to open contents file '%s' for input", Contents);
}
}
plist.head = plist.tail = NULL;
/* Break the package name into base and desired suffix (if any) */
if ((cp = strrchr(pkg, '.')) != NULL) {
suffix = cp + 1;
*cp = '\0';
} else
suffix = "tgz";
/* Stick the dependencies, if any, at the top */
if (Pkgdeps) {
if (Verbose && !PlistOnly)
printf(" %s", cp);
}
}
if (Verbose && !PlistOnly)
printf(".\n");
}
/* Put the conflicts directly after the dependencies, if any */
if (Pkgcfl) {
if (Verbose && !PlistOnly)
printf("Registering conflicts:");
while (Pkgcfl) {
cp = strsep(&Pkgcfl, " \t\n");
if (*cp) {
add_plist(&plist, PLIST_PKGCFL, cp);
printf("Registering depends:");
while (Pkgdeps) {
cp = strsep(&Pkgdeps, " \t\n");
if (*cp) {
add_plist(&plist, PLIST_PKGDEP, cp);
if (Verbose && !PlistOnly)
printf(" %s", cp);
}
}
if (Verbose && !PlistOnly)
printf(" %s", cp);
}
printf(".\n");
}
if (Verbose && !PlistOnly)
printf(".\n");
}
/* If a SrcDir override is set, add it now */
if (SrcDir) {
if (Verbose && !PlistOnly)
printf("Using SrcDir value of %s\n", SrcDir);
add_plist(&plist, PLIST_SRC, SrcDir);
}
/* Put the conflicts directly after the dependencies, if any */
if (Pkgcfl) {
if (Verbose && !PlistOnly)
printf("Registering conflicts:");
while (Pkgcfl) {
cp = strsep(&Pkgcfl, " \t\n");
if (*cp) {
add_plist(&plist, PLIST_PKGCFL, cp);
if (Verbose && !PlistOnly)
printf(" %s", cp);
}
}
if (Verbose && !PlistOnly)
printf(".\n");
}
/* Slurp in the packing list */
read_plist(&plist, pkg_in);
/* If a SrcDir override is set, add it now */
if (SrcDir) {
if (Verbose && !PlistOnly)
printf("Using SrcDir value of %s\n", SrcDir);
add_plist(&plist, PLIST_SRC, SrcDir);
}
/* Prefix should override the packing list */
if (Prefix) {
delete_plist(&plist, FALSE, PLIST_CWD, NULL);
add_plist_top(&plist, PLIST_CWD, Prefix);
}
/*
* Run down the list and see if we've named it, if not stick in a name
* at the top.
*/
if (find_plist(&plist, PLIST_NAME) == NULL) {
add_plist_top(&plist, PLIST_NAME, basename_of(pkg));
}
/* Slurp in the packing list */
read_plist(&plist, pkg_in);
/*
* We're just here for to dump out a revised plist for the FreeBSD ports
* hack. It's not a real create in progress.
*/
if (PlistOnly) {
/* Prefix should override the packing list */
if (Prefix) {
delete_plist(&plist, FALSE, PLIST_CWD, NULL);
add_plist_top(&plist, PLIST_CWD, Prefix);
}
/*
* Run down the list and see if we've named it, if not stick in a name
* at the top.
*/
if (find_plist(&plist, PLIST_NAME) == NULL) {
add_plist_top(&plist, PLIST_NAME, basename_of(pkg));
}
/*
* We're just here for to dump out a revised plist for the FreeBSD ports
* hack. It's not a real create in progress.
*/
if (PlistOnly) {
check_list(home, &plist, basename_of(pkg));
write_plist(&plist, stdout);
exit(0);
}
/* Make a directory to stomp around in */
home = make_playpen(PlayPen, PlayPenSize, 0);
signal(SIGINT, cleanup);
signal(SIGHUP, cleanup);
/* Make first "real contents" pass over it */
check_list(home, &plist, basename_of(pkg));
write_plist(&plist, stdout);
exit(0);
}
(void) umask(022); /* make sure gen'ed directories, files
* don't have group or other write bits. */
/* Make a directory to stomp around in */
home = make_playpen(PlayPen, PlayPenSize, 0);
signal(SIGINT, cleanup);
signal(SIGHUP, cleanup);
/* Now put the release specific items in */
add_plist(&plist, PLIST_CWD, ".");
write_file(COMMENT_FNAME, Comment);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, COMMENT_FNAME);
write_file(DESC_FNAME, Desc);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, DESC_FNAME);
/* Make first "real contents" pass over it */
check_list(home, &plist, basename_of(pkg));
(void) umask(022); /* make sure gen'ed directories, files don't have
group or other write bits. */
if (Install) {
copy_file(home, Install, INSTALL_FNAME);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, INSTALL_FNAME);
}
if (DeInstall) {
copy_file(home, DeInstall, DEINSTALL_FNAME);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, DEINSTALL_FNAME);
}
if (Require) {
copy_file(home, Require, REQUIRE_FNAME);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, REQUIRE_FNAME);
}
if (Display) {
copy_file(home, Display, DISPLAY_FNAME);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, DISPLAY_FNAME);
add_plist(&plist, PLIST_DISPLAY, DISPLAY_FNAME);
}
if (Mtree) {
copy_file(home, Mtree, MTREE_FNAME);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, MTREE_FNAME);
add_plist(&plist, PLIST_MTREE, MTREE_FNAME);
}
if (BuildVersion) {
copy_file(home, BuildVersion, BUILD_VERSION_FNAME);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, BUILD_VERSION_FNAME);
}
if (BuildInfo) {
copy_file(home, BuildInfo, BUILD_INFO_FNAME);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, BUILD_INFO_FNAME);
}
/* Now put the release specific items in */
add_plist(&plist, PLIST_CWD, ".");
write_file(COMMENT_FNAME, Comment);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, COMMENT_FNAME);
write_file(DESC_FNAME, Desc);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, DESC_FNAME);
/* Finally, write out the packing list */
fp = fopen(CONTENTS_FNAME, "w");
if (!fp) {
cleanup(0);
errx(2, "can't open file %s for writing", CONTENTS_FNAME);
}
write_plist(&plist, fp);
if (fclose(fp)) {
cleanup(0);
errx(2, "error while closing %s", CONTENTS_FNAME);
}
if (Install) {
copy_file(home, Install, INSTALL_FNAME);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, INSTALL_FNAME);
}
if (DeInstall) {
copy_file(home, DeInstall, DEINSTALL_FNAME);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, DEINSTALL_FNAME);
}
if (Require) {
copy_file(home, Require, REQUIRE_FNAME);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, REQUIRE_FNAME);
}
if (Display) {
copy_file(home, Display, DISPLAY_FNAME);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, DISPLAY_FNAME);
add_plist(&plist, PLIST_DISPLAY, DISPLAY_FNAME);
}
if (Mtree) {
copy_file(home, Mtree, MTREE_FNAME);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, MTREE_FNAME);
add_plist(&plist, PLIST_MTREE, MTREE_FNAME);
}
if (BuildVersion) {
copy_file(home, BuildVersion, BUILD_VERSION_FNAME);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, BUILD_VERSION_FNAME);
}
if (BuildInfo) {
copy_file(home, BuildInfo, BUILD_INFO_FNAME);
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, BUILD_INFO_FNAME);
}
/* And stick it into a tar ball */
make_dist(home, pkg, suffix, &plist);
/* Finally, write out the packing list */
fp = fopen(CONTENTS_FNAME, "w");
if (!fp) {
cleanup(0);
errx(2, "can't open file %s for writing", CONTENTS_FNAME);
}
write_plist(&plist, fp);
if (fclose(fp)) {
cleanup(0);
errx(2, "error while closing %s", CONTENTS_FNAME);
}
/* And stick it into a tar ball */
make_dist(home, pkg, suffix, &plist);
/* Cleanup */
free(Comment);
free(Desc);
free_plist(&plist);
leave_playpen(home);
return TRUE; /* Success */
/* Cleanup */
free(Comment);
free(Desc);
free_plist(&plist);
leave_playpen(home);
return TRUE; /* Success */
}

View File

@ -1,11 +1,11 @@
/* $NetBSD: pl.c,v 1.15 1999/08/19 13:30:01 agc Exp $ */
/* $NetBSD: pl.c,v 1.16 1999/08/24 00:48:38 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: pl.c,v 1.11 1997/10/08 07:46:35 charnier Exp";
#else
__RCSID("$NetBSD: pl.c,v 1.15 1999/08/19 13:30:01 agc Exp $");
__RCSID("$NetBSD: pl.c,v 1.16 1999/08/24 00:48:38 hubertf Exp $");
#endif
#endif
@ -34,23 +34,25 @@ __RCSID("$NetBSD: pl.c,v 1.15 1999/08/19 13:30:01 agc Exp $");
#include <err.h>
#include <md5.h>
/* check that any symbolic link is relative to the prefix */
/*
* Check that any symbolic link is relative to the prefix
*/
static void
CheckSymlink(char *name, char *prefix, size_t prefixcc)
{
char newtgt[MAXPATHLEN];
char oldtgt[MAXPATHLEN];
char *slash;
int slashc;
int cc;
int i;
char newtgt[MAXPATHLEN];
char oldtgt[MAXPATHLEN];
char *slash;
int slashc;
int cc;
int i;
if ((cc = readlink(name, oldtgt, sizeof(oldtgt))) > 0) {
oldtgt[cc] = 0;
if (strncmp(oldtgt, prefix, prefixcc) == 0 && oldtgt[prefixcc] == '/') {
for (slashc = 0, slash = &name[prefixcc + 1] ; (slash = strchr(slash, '/')) != (char *) NULL ; slash++, slashc++) {
for (slashc = 0, slash = &name[prefixcc + 1]; (slash = strchr(slash, '/')) != (char *) NULL; slash++, slashc++) {
}
for (cc = i = 0 ; i < slashc ; i++) {
for (cc = i = 0; i < slashc; i++) {
strnncpy(&newtgt[cc], sizeof(newtgt) - cc, "../", 3);
cc += 3;
}
@ -65,31 +67,35 @@ CheckSymlink(char *name, char *prefix, size_t prefixcc)
}
}
/* (reversed) comparison routine for directory name sorting */
/*
* (Reversed) comparison routine for directory name sorting
*/
static int
dircmp(const void *vp1, const void *vp2)
{
return strcmp((const char *)vp2, (const char *)vp1);
return strcmp((const char *) vp2, (const char *) vp1);
}
/* re-order the PLIST_DIR_RM entries into reverse alphabetic order */
/*
* Re-order the PLIST_DIR_RM entries into reverse alphabetic order
*/
static void
reorder(package_t *pkg, int dirc)
{
plist_t *p;
char **dirv;
int i;
plist_t *p;
char **dirv;
int i;
if ((dirv = (char **) calloc(dirc, sizeof(char *))) == (char **) NULL) {
warn("No directory re-ordering will be done");
} else {
for (p = pkg->head, i = 0 ; p ; p = p->next) {
for (p = pkg->head, i = 0; p; p = p->next) {
if (p->type == PLIST_DIR_RM) {
dirv[i++] = p->name;
}
}
qsort(dirv, dirc, sizeof(char *), dircmp);
for (p = pkg->head, i = 0 ; p ; p = p->next) {
for (p = pkg->head, i = 0; p; p = p->next) {
if (p->type == PLIST_DIR_RM) {
p->name = dirv[i++];
}
@ -98,26 +104,28 @@ reorder(package_t *pkg, int dirc)
}
}
/* Check a list for files that require preconversion */
/*
* Check a list for files that require preconversion
*/
void
check_list(char *home, package_t *pkg, const char *PkgName)
{
struct stat st;
plist_t *tmp;
plist_t *p;
char name[FILENAME_MAX];
char buf[ChecksumHeaderLen + LegibleChecksumLen];
char *cwd = home;
char *srcdir = NULL;
int dirc;
struct stat st;
plist_t *tmp;
plist_t *p;
char name[FILENAME_MAX];
char buf[ChecksumHeaderLen + LegibleChecksumLen];
char *cwd = home;
char *srcdir = NULL;
int dirc;
/* Open Package Database for writing */
if (pkgdb_open(0) == -1) {
cleanup(0);
err(1, "can't open pkgdb");
cleanup(0);
err(1, "can't open pkgdb");
}
for (dirc = 0, p = pkg->head ; p ; p = p->next) {
for (dirc = 0, p = pkg->head; p; p = p->next) {
switch (p->type) {
case PLIST_CWD:
cwd = p->name;
@ -136,26 +144,26 @@ check_list(char *home, package_t *pkg, const char *PkgName)
* pkgdb handling - usually, we enter files
* into the pkgdb as soon as they hit the disk,
* but as they are present before pkg_create
* starts, it's ok to do this somewhere here
* starts, it's ok to do this somewhere here
*/
{
char *s, t[FILENAME_MAX];
(void) snprintf(t, sizeof(t), "%s/%s", cwd, p->name);
s=pkgdb_retrieve(t);
char *s, t[FILENAME_MAX];
(void) snprintf(t, sizeof(t), "%s/%s", cwd, p->name);
s = pkgdb_retrieve(t);
#ifdef PKGDB_DEBUG
fprintf(stderr, "pkgdb_retrieve(\"%s\")=\"%s\"\n", t, s); /* pkgdb-debug - HF */
fprintf(stderr, "pkgdb_retrieve(\"%s\")=\"%s\"\n", t, s); /* pkgdb-debug - HF */
#endif
if (s && PlistOnly)
warnx("Overwriting %s - "
"pkg %s bogus/conflicting?", t, s);
else {
pkgdb_store(t, PkgName);
if (s && PlistOnly)
warnx("Overwriting %s - "
"pkg %s bogus/conflicting?", t, s);
else {
pkgdb_store(t, PkgName);
#ifdef PKGDB_DEBUG
fprintf(stderr, "pkgdb_store(\"%s\", \"%s\")\n", t, PkgName); /* pkgdb-debug - HF */
fprintf(stderr, "pkgdb_store(\"%s\", \"%s\")\n", t, PkgName); /* pkgdb-debug - HF */
#endif
}
}
}
(void) snprintf(name, sizeof(name), "%s/%s", srcdir ? srcdir : cwd, p->name);
@ -163,7 +171,7 @@ check_list(char *home, package_t *pkg, const char *PkgName)
warnx("can't stat `%s'", name);
continue;
}
switch(st.st_mode & S_IFMT) {
switch (st.st_mode & S_IFMT) {
case S_IFDIR:
p->type = PLIST_DIR_RM;
dirc++;
@ -186,7 +194,7 @@ check_list(char *home, package_t *pkg, const char *PkgName)
if (MD5File(name, &buf[ChecksumHeaderLen]) != (char *) NULL) {
tmp = new_plist_entry();
tmp->name = strdup(buf);
tmp->type = PLIST_COMMENT; /* PLIST_MD5 - HF */
tmp->type = PLIST_COMMENT; /* PLIST_MD5 - HF */
tmp->next = p->next;
tmp->prev = p;
p->next = tmp;
@ -199,7 +207,7 @@ check_list(char *home, package_t *pkg, const char *PkgName)
}
pkgdb_close();
if (ReorderDirs && dirc > 0) {
reorder(pkg, dirc);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: delete.h,v 1.5 1999/08/19 19:37:20 hubertf Exp $ */
/* $NetBSD: delete.h,v 1.6 1999/08/24 00:48:39 hubertf Exp $ */
/* from FreeBSD Id: delete.h,v 1.4 1997/02/22 16:09:35 peter Exp */
@ -25,14 +25,14 @@
#ifndef _INST_DELETE_H_INCLUDE
#define _INST_DELETE_H_INCLUDE
extern char *Prefix;
extern char *ProgramPath;
extern Boolean NoDeInstall;
extern Boolean CleanDirs;
extern Boolean Force;
extern Boolean Recurse_up;
extern Boolean Recurse_down;
extern char *Prefix;
extern char *ProgramPath;
extern Boolean NoDeInstall;
extern Boolean CleanDirs;
extern Boolean Force;
extern Boolean Recurse_up;
extern Boolean Recurse_down;
extern int find_fn(const char *pkg, char *data);
extern int find_fn(const char *pkg, char *data);
#endif /* _INST_DELETE_H_INCLUDE */
#endif /* _INST_DELETE_H_INCLUDE */

View File

@ -1,11 +1,11 @@
/* $NetBSD: main.c,v 1.12 1999/08/19 19:37:21 hubertf Exp $ */
/* $NetBSD: main.c,v 1.13 1999/08/24 00:48:39 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char *rcsid = "from FreeBSD Id: main.c,v 1.11 1997/10/08 07:46:48 charnier Exp";
#else
__RCSID("$NetBSD: main.c,v 1.12 1999/08/19 19:37:21 hubertf Exp $");
__RCSID("$NetBSD: main.c,v 1.13 1999/08/24 00:48:39 hubertf Exp $");
#endif
#endif
@ -37,182 +37,180 @@ __RCSID("$NetBSD: main.c,v 1.12 1999/08/19 19:37:21 hubertf Exp $");
static char Options[] = "hvDdnfFp:OrR";
char *Prefix = NULL;
char *ProgramPath = NULL;
Boolean NoDeInstall = FALSE;
Boolean CleanDirs = FALSE;
Boolean File2Pkg = FALSE;
Boolean Recurse_up = FALSE;
Boolean Recurse_down = FALSE;
char *Prefix = NULL;
char *ProgramPath = NULL;
Boolean NoDeInstall = FALSE;
Boolean CleanDirs = FALSE;
Boolean File2Pkg = FALSE;
Boolean Recurse_up = FALSE;
Boolean Recurse_down = FALSE;
Boolean OnlyDeleteFromPkgDB = FALSE;
lpkg_head_t pkgs;
static void
usage(void)
{
fprintf(stderr, "usage: pkg_delete [-vDdnFfOrR] [-p prefix] pkg-name ...\n");
exit(1);
fprintf(stderr, "usage: pkg_delete [-vDdnFfOrR] [-p prefix] pkg-name ...\n");
exit(1);
}
int
find_fn(const char *pkg, char *data)
{
lpkg_t *lpp;
lpkg_t *lpp;
lpp=alloc_lpkg(pkg);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
lpp = alloc_lpkg(pkg);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
return 0;
return 0;
}
int
main(int argc, char **argv)
{
int ch, error;
lpkg_t *lpp;
int ch, error;
lpkg_t *lpp;
ProgramPath = argv[0];
ProgramPath = argv[0];
while ((ch = getopt(argc, argv, Options)) != -1)
switch(ch) {
case 'v':
Verbose = TRUE;
break;
while ((ch = getopt(argc, argv, Options)) != -1)
switch (ch) {
case 'v':
Verbose = TRUE;
break;
case 'f':
Force = TRUE;
break;
case 'f':
Force = TRUE;
break;
case 'F':
File2Pkg = TRUE;
break;
case 'F':
File2Pkg = TRUE;
break;
case 'p':
Prefix = optarg;
break;
case 'p':
Prefix = optarg;
break;
case 'D':
NoDeInstall = TRUE;
break;
case 'D':
NoDeInstall = TRUE;
break;
case 'd':
CleanDirs = TRUE;
break;
case 'd':
CleanDirs = TRUE;
break;
case 'n':
Fake = TRUE;
Verbose = TRUE;
break;
case 'n':
Fake = TRUE;
Verbose = TRUE;
break;
case 'r':
Recurse_up = TRUE;
break;
case 'r':
Recurse_up = TRUE;
break;
case 'R':
Recurse_down = TRUE;
break;
case 'R':
Recurse_down = TRUE;
break;
case 'O':
OnlyDeleteFromPkgDB = TRUE;
break;
case 'h':
case '?':
default:
usage();
break;
}
case 'O':
OnlyDeleteFromPkgDB = TRUE;
break;
argc -= optind;
argv += optind;
case 'h':
case '?':
default:
usage();
break;
}
TAILQ_INIT(&pkgs);
argc -= optind;
argv += optind;
/* Get all the remaining package names, if any */
if (File2Pkg)
if (pkgdb_open(1)==-1) {
err(1, "cannot open pkgdb");
}
/* Get all the remaining package names, if any */
while (*argv) {
/* pkgdb: if -F flag given, don't add pkgnames to pkgs but
* rather resolve the given filenames to pkgnames using
* pkgdb_retrieve, then add them.
*/
if (File2Pkg) {
char *s;
TAILQ_INIT(&pkgs);
s = pkgdb_retrieve(*argv);
/* Get all the remaining package names, if any */
if (File2Pkg)
if (pkgdb_open(1) == -1) {
err(1, "cannot open pkgdb");
}
/* Get all the remaining package names, if any */
while (*argv) {
/* pkgdb: if -F flag given, don't add pkgnames to pkgs but
* rather resolve the given filenames to pkgnames using
* pkgdb_retrieve, then add these. */
if (File2Pkg) {
char *s;
if (s) {
lpp = alloc_lpkg(s);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
} else
errx(1, "No matching pkg for %s in pkgdb.", *argv);
} else {
if (ispkgpattern(*argv)) {
if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, find_fn, NULL) == 0)
errx(1, "No matching pkg for %s.", *argv);
}else {
lpp = alloc_lpkg(*argv);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
}
}
argv++;
}
s = pkgdb_retrieve(*argv);
if (File2Pkg)
pkgdb_close();
/* If no packages, yelp */
if (TAILQ_FIRST(&pkgs) == NULL)
warnx("missing package name(s)"), usage();
if (!Fake && getuid() != 0)
errx(1, "you must be root to delete packages");
if (OnlyDeleteFromPkgDB) {
/* Only delete the given packages' files from pkgdb, do not touch
* the pkg itself. Used by "make reinstall" in bsd.pkg.mk
*/
char *key, *val;
if (pkgdb_open(0)==-1) {
err(1, "cannot open %s", _pkgdb_getPKGDB_FILE());
}
error = 0;
while ((key=pkgdb_iter())) {
val=pkgdb_retrieve(key);
lpp = TAILQ_FIRST(&pkgs);
if (lpp != NULL) {
do {
if (strcmp(val, lpp->lp_name) == 0) {
if (Verbose)
printf("Removing file %s from pkgdb\n", key);
errno=0;
if (pkgdb_remove(key)) {
if (errno)
printf("Error removing %s from pkgdb: %s\n", key, strerror(errno));
else
printf("Key %s not present in pkgdb?!\n", key);
error = 1;
if (s) {
lpp = alloc_lpkg(s);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
} else
errx(1, "No matching pkg for %s in pkgdb.", *argv);
} else {
if (ispkgpattern(*argv)) {
if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, find_fn, NULL) == 0)
errx(1, "No matching pkg for %s.", *argv);
} else {
lpp = alloc_lpkg(*argv);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
}
}
lpp = TAILQ_NEXT(lpp, lp_link);
} while(lpp != NULL);
}
}
argv++;
}
pkgdb_close();
return error;
} else if ((error = pkg_perform(&pkgs)) != 0) {
if (Verbose)
warnx("%d package deletion(s) failed", error);
return error;
}
else
return 0;
if (File2Pkg)
pkgdb_close();
/* If no packages, yelp */
if (TAILQ_FIRST(&pkgs) == NULL)
warnx("missing package name(s)"), usage();
if (!Fake && getuid() != 0)
errx(1, "you must be root to delete packages");
if (OnlyDeleteFromPkgDB) {
/* Only delete the given packages' files from pkgdb, do not
* touch the pkg itself. Used by "make reinstall" in
* bsd.pkg.mk */
char *key, *val;
if (pkgdb_open(0) == -1) {
err(1, "cannot open %s", _pkgdb_getPKGDB_FILE());
}
error = 0;
while ((key = pkgdb_iter())) {
val = pkgdb_retrieve(key);
lpp = TAILQ_FIRST(&pkgs);
if (lpp != NULL) {
do {
if (strcmp(val, lpp->lp_name) == 0) {
if (Verbose)
printf("Removing file %s from pkgdb\n", key);
errno = 0;
if (pkgdb_remove(key)) {
if (errno)
printf("Error removing %s from pkgdb: %s\n", key, strerror(errno));
else
printf("Key %s not present in pkgdb?!\n", key);
error = 1;
}
}
lpp = TAILQ_NEXT(lpp, lp_link);
} while (lpp != NULL);
}
}
pkgdb_close();
return error;
} else if ((error = pkg_perform(&pkgs)) != 0) {
if (Verbose)
warnx("%d package deletion(s) failed", error);
return error;
} else
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: info.h,v 1.10 1999/08/19 19:37:22 hubertf Exp $ */
/* $NetBSD: info.h,v 1.11 1999/08/24 00:48:39 hubertf Exp $ */
/* from FreeBSD Id: info.h,v 1.10 1997/02/22 16:09:40 peter Exp */
@ -60,11 +60,11 @@ extern char *CheckPkg;
extern size_t termwidth;
extern lpkg_head_t pkgs;
extern void show_file(char *, char *);
extern void show_plist(char *, package_t *, pl_ent_t);
extern void show_files(char *, package_t *);
extern void show_depends(char *, package_t *);
extern void show_index(char *, char *);
extern int find_fn(const char *pkg, char *data);
extern void show_file(char *, char *);
extern void show_plist(char *, package_t *, pl_ent_t);
extern void show_files(char *, package_t *);
extern void show_depends(char *, package_t *);
extern void show_index(char *, char *);
extern int find_fn(const char *pkg, char *data);
#endif /* _INST_INFO_H_INCLUDE */
#endif /* _INST_INFO_H_INCLUDE */

View File

@ -1,11 +1,11 @@
/* $NetBSD: main.c,v 1.17 1999/08/19 19:37:22 hubertf Exp $ */
/* $NetBSD: main.c,v 1.18 1999/08/24 00:48:39 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char *rcsid = "from FreeBSD Id: main.c,v 1.14 1997/10/08 07:47:26 charnier Exp";
#else
__RCSID("$NetBSD: main.c,v 1.17 1999/08/19 19:37:22 hubertf Exp $");
__RCSID("$NetBSD: main.c,v 1.18 1999/08/24 00:48:39 hubertf Exp $");
#endif
#endif
@ -40,222 +40,220 @@ __RCSID("$NetBSD: main.c,v 1.17 1999/08/19 19:37:22 hubertf Exp $");
static char Options[] = "aBbcDde:fFIikLl:mpqRrvh";
int Flags = 0;
Boolean AllInstalled = FALSE;
Boolean File2Pkg = FALSE;
Boolean Quiet = FALSE;
char *InfoPrefix = "";
char PlayPen[FILENAME_MAX];
size_t PlayPenSize = sizeof(PlayPen);
char *CheckPkg = NULL;
size_t termwidth = 0;
int Flags = 0;
Boolean AllInstalled = FALSE;
Boolean File2Pkg = FALSE;
Boolean Quiet = FALSE;
char *InfoPrefix = "";
char PlayPen[FILENAME_MAX];
size_t PlayPenSize = sizeof(PlayPen);
char *CheckPkg = NULL;
size_t termwidth = 0;
lpkg_head_t pkgs;
static void
usage(void)
{
fprintf(stderr, "%s\n%s\n%s\n",
"usage: pkg_info [-BbcDdFfIikLmpqRrvh] [-e package] [-l prefix]",
" pkg-name [pkg-name ...]",
" pkg_info -a [flags]");
exit(1);
fprintf(stderr, "%s\n%s\n%s\n",
"usage: pkg_info [-BbcDdFfIikLmpqRrvh] [-e package] [-l prefix]",
" pkg-name [pkg-name ...]",
" pkg_info -a [flags]");
exit(1);
}
int
find_fn(const char *pkg, char *data)
{
lpkg_t *lpp;
lpkg_t *lpp;
lpp=alloc_lpkg(pkg);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
lpp = alloc_lpkg(pkg);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
return 0;
return 0;
}
int
main(int argc, char **argv)
{
int ch, rc;
lpkg_t *lpp;
int ch, rc;
lpkg_t *lpp;
while ((ch = getopt(argc, argv, Options)) != -1)
switch(ch) {
case 'a':
AllInstalled = TRUE;
break;
while ((ch = getopt(argc, argv, Options)) != -1)
switch (ch) {
case 'a':
AllInstalled = TRUE;
break;
case 'B':
Flags |= SHOW_BUILD_INFO;
break;
case 'b':
Flags |= SHOW_BUILD_VERSION;
break;
case 'B':
Flags |= SHOW_BUILD_INFO;
break;
case 'c':
Flags |= SHOW_COMMENT;
break;
case 'b':
Flags |= SHOW_BUILD_VERSION;
break;
case 'D':
Flags |= SHOW_DISPLAY;
break;
case 'c':
Flags |= SHOW_COMMENT;
break;
case 'd':
Flags |= SHOW_DESC;
break;
case 'D':
Flags |= SHOW_DISPLAY;
break;
case 'e':
CheckPkg = optarg;
break;
case 'd':
Flags |= SHOW_DESC;
break;
case 'f':
Flags |= SHOW_PLIST;
break;
case 'e':
CheckPkg = optarg;
break;
case 'F':
File2Pkg = 1;
break;
case 'f':
Flags |= SHOW_PLIST;
break;
case 'I':
Flags |= SHOW_INDEX;
break;
case 'F':
File2Pkg = 1;
break;
case 'i':
Flags |= SHOW_INSTALL;
break;
case 'I':
Flags |= SHOW_INDEX;
break;
case 'k':
Flags |= SHOW_DEINSTALL;
break;
case 'i':
Flags |= SHOW_INSTALL;
break;
case 'L':
Flags |= SHOW_FILES;
break;
case 'k':
Flags |= SHOW_DEINSTALL;
break;
case 'l':
InfoPrefix = optarg;
break;
case 'L':
Flags |= SHOW_FILES;
break;
case 'm':
Flags |= SHOW_MTREE;
break;
case 'l':
InfoPrefix = optarg;
break;
case 'p':
Flags |= SHOW_PREFIX;
break;
case 'm':
Flags |= SHOW_MTREE;
break;
case 'q':
Quiet = TRUE;
break;
case 'p':
Flags |= SHOW_PREFIX;
break;
case 'R':
Flags |= SHOW_REQBY;
break;
case 'q':
Quiet = TRUE;
break;
case 'r':
Flags |= SHOW_REQUIRE;
break;
case 'R':
Flags |= SHOW_REQBY;
break;
case 'v':
Verbose = TRUE;
/* Reasonable definition of 'everything' */
Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL |
SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE |
SHOW_REQBY | SHOW_DEPENDS;
break;
case 'r':
Flags |= SHOW_REQUIRE;
break;
case 'h':
case '?':
default:
usage();
/* NOTREACHED */
case 'v':
Verbose = TRUE;
/* Reasonable definition of 'everything' */
Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL |
SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE |
SHOW_REQBY | SHOW_DEPENDS;
break;
case 'h':
case '?':
default:
usage();
/* NOTREACHED */
}
argc -= optind;
argv += optind;
if (argc == 0 && !Flags) {
/* No argument or flags specified - assume -Ia */
Flags = SHOW_INDEX;
AllInstalled = TRUE;
}
argc -= optind;
argv += optind;
/* Set some reasonable defaults */
if (!Flags)
Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY | SHOW_DEPENDS;
if (argc == 0 && !Flags) {
/* No argument or flags specified - assume -Ia */
Flags = SHOW_INDEX;
AllInstalled = TRUE;
}
/* -Fe /filename -> change CheckPkg to real packagename */
if (CheckPkg && File2Pkg) {
char *s;
/* Set some reasonable defaults */
if (!Flags)
Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY | SHOW_DEPENDS;
if (pkgdb_open(1) == -1)
err(1, "cannot open pkgdb");
/* -Fe /filename -> change CheckPkg to real packagename */
if (CheckPkg && File2Pkg) {
char *s;
if (pkgdb_open(1)==-1) {
err(1, "cannot open pkgdb");
s = pkgdb_retrieve(CheckPkg);
if (s) {
CheckPkg = s;
} else {
errx(1, "No matching pkg for %s.", CheckPkg);
}
pkgdb_close();
}
s=pkgdb_retrieve(CheckPkg);
TAILQ_INIT(&pkgs);
if (s)
CheckPkg = s;
else {
errx(1, "No matching pkg for %s.", CheckPkg);
/* Get all the remaining package names, if any */
if (File2Pkg && !AllInstalled)
if (pkgdb_open(1) == -1) {
err(1, "cannot open pkgdb");
}
while (*argv) {
/* pkgdb: if -F flag given, don't add pkgnames to the "pkgs"
* queue but rather resolve the given filenames to pkgnames
* using pkgdb_retrieve, then add them. */
if (File2Pkg) {
char *s;
s = pkgdb_retrieve(*argv);
if (s) {
lpp = alloc_lpkg(s);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
} else
errx(1, "No matching pkg for %s.", *argv);
} else {
if (ispkgpattern(*argv)) {
if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, find_fn, NULL) == 0)
errx(1, "No matching pkg for %s.", *argv);
} else {
lpp = alloc_lpkg(*argv);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
}
}
argv++;
}
pkgdb_close();
}
TAILQ_INIT(&pkgs);
/* Get all the remaining package names, if any */
if (File2Pkg && !AllInstalled)
if (pkgdb_open(1)==-1) {
err(1, "cannot open pkgdb");
if (File2Pkg)
pkgdb_close();
/* If no packages, yelp */
if (TAILQ_FIRST(&pkgs) == NULL && !AllInstalled && !CheckPkg)
warnx("missing package name(s)"), usage();
if (isatty(STDOUT_FILENO)) {
const char *p;
struct winsize win;
if ((p = getenv("COLUMNS")) != NULL)
termwidth = atoi(p);
else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 &&
win.ws_col > 0)
termwidth = win.ws_col;
}
while (*argv) {
/* pkgdb: if -F flag given, don't add pkgnames to the "pkgs"
* queue but rather resolve the given filenames to pkgnames
* using pkgdb_retrieve, then add them.
*/
if (File2Pkg) {
char *s;
s = pkgdb_retrieve(*argv);
if (s) {
lpp=alloc_lpkg(s);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
} else
errx(1, "No matching pkg for %s.", *argv);
} else {
if (ispkgpattern(*argv)){
if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, find_fn, NULL) == 0)
errx(1, "No matching pkg for %s.", *argv);
} else {
lpp=alloc_lpkg(*argv);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
}
}
argv++;
}
if (File2Pkg)
pkgdb_close();
/* If no packages, yelp */
if (TAILQ_FIRST(&pkgs)==NULL && !AllInstalled && !CheckPkg)
warnx("missing package name(s)"), usage();
if (isatty(STDOUT_FILENO)) {
const char *p;
struct winsize win;
if ((p = getenv("COLUMNS")) != NULL)
termwidth = atoi(p);
else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 &&
win.ws_col > 0)
termwidth = win.ws_col;
}
rc = pkg_perform(&pkgs);
exit(rc);
/* NOTREACHED */
rc = pkg_perform(&pkgs);
exit(rc);
/* NOTREACHED */
}

View File

@ -1,11 +1,11 @@
/* $NetBSD: perform.c,v 1.27 1999/08/23 15:17:03 hubertf Exp $ */
/* $NetBSD: perform.c,v 1.28 1999/08/24 00:48:39 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.23 1997/10/13 15:03:53 jkh Exp";
#else
__RCSID("$NetBSD: perform.c,v 1.27 1999/08/23 15:17:03 hubertf Exp $");
__RCSID("$NetBSD: perform.c,v 1.28 1999/08/24 00:48:39 hubertf Exp $");
#endif
#endif
@ -40,19 +40,19 @@ __RCSID("$NetBSD: perform.c,v 1.27 1999/08/23 15:17:03 hubertf Exp $");
#include <dirent.h>
#include <ctype.h>
static char *Home;
static char *Home;
static int
pkg_do(char *pkg)
{
Boolean installed = FALSE, isTMP = FALSE;
char log_dir[FILENAME_MAX];
char fname[FILENAME_MAX];
package_t plist;
FILE *fp;
struct stat sb;
char *cp = NULL;
int code = 0;
Boolean installed = FALSE, isTMP = FALSE;
char log_dir[FILENAME_MAX];
char fname[FILENAME_MAX];
package_t plist;
FILE *fp;
struct stat sb;
char *cp = NULL;
int code = 0;
if (IS_URL(pkg)) {
if ((cp = fileGetURL(NULL, pkg)) != NULL) {
@ -60,12 +60,12 @@ pkg_do(char *pkg)
isTMP = TRUE;
}
} else if (fexists(pkg) && isfile(pkg)) {
int len;
int len;
if (*pkg != '/') {
if (!getcwd(fname, FILENAME_MAX)) {
cleanup(0);
err(1, "fatal error during execution: getcwd");
cleanup(0);
err(1, "fatal error during execution: getcwd");
}
len = strlen(fname);
(void) snprintf(&fname[len], sizeof(fname) - len, "/%s", pkg);
@ -76,7 +76,7 @@ pkg_do(char *pkg)
if ((cp = fileFindByPath(NULL, pkg)) != NULL)
strncpy(fname, cp, FILENAME_MAX);
}
if (cp) {
if (IS_URL(pkg)) {
/* file is already unpacked by fileGetURL() */
@ -101,28 +101,26 @@ pkg_do(char *pkg)
}
}
} else {
/*
* It's not an uninstalled package, try and find it among the
* installed
*/
char *tmp;
/*
* It's not an uninstalled package, try and find it among the
* installed
*/
char *tmp;
(void) snprintf(log_dir, sizeof(log_dir), "%s/%s",
(tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR,
pkg);
(tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR,
pkg);
if (!fexists(log_dir) || !isdir(log_dir)) {
{
/* Check if the given package name matches something
* with 'pkg-[0-9]*'
*/
char try[FILENAME_MAX];
snprintf(try, FILENAME_MAX, "%s-[0-9]*", pkg);
if (findmatchingname(_pkgdb_getPKGDB_DIR(), try,
find_fn, NULL) != 0) {
return 0; /* we've just appended some names to the pkgs list,
* they will be processed after this package.
*/
}
/* Check if the given package name matches
* something with 'pkg-[0-9]*' */
char try[FILENAME_MAX];
snprintf(try, FILENAME_MAX, "%s-[0-9]*", pkg);
if (findmatchingname(_pkgdb_getPKGDB_DIR(), try,
find_fn, NULL) != 0) {
return 0; /* we've just appended some names to the pkgs list,
* they will be processed after this package. */
}
}
/* No match */
@ -153,7 +151,7 @@ pkg_do(char *pkg)
* any sense.
*/
if (Flags & SHOW_INDEX) {
char tmp[FILENAME_MAX];
char tmp[FILENAME_MAX];
(void) snprintf(tmp, sizeof(tmp), "%-19s ", pkg);
show_index(tmp, COMMENT_FNAME);
@ -213,7 +211,9 @@ bail:
return code;
}
/* fn to be called for pkgs found */
/*
* Function to be called for pkgs found
*/
static int
foundpkg(const char *found, char *data)
{
@ -223,18 +223,20 @@ foundpkg(const char *found, char *data)
return 0;
}
/* check if a package "pkgspec" (which can be a pattern) is installed */
/* return 0 if found, 1 otherwise (indicating an error). */
/*
* Check if a package "pkgspec" (which can be a pattern) is installed.
* Return 0 if found, 1 otherwise (indicating an error).
*/
static int
CheckForPkg(char *pkgspec, char *dbdir)
{
struct stat st;
char buf[FILENAME_MAX];
int error;
struct stat st;
char buf[FILENAME_MAX];
int error;
if (strpbrk(pkgspec, "<>[]?*{")) {
/* expensive (pattern) match */
return !findmatchingname(dbdir, pkgspec, foundpkg, NULL);
/* expensive (pattern) match */
return !findmatchingname(dbdir, pkgspec, foundpkg, NULL);
}
/* simple match */
(void) snprintf(buf, sizeof(buf), "%s/%s", dbdir, pkgspec);
@ -243,15 +245,14 @@ CheckForPkg(char *pkgspec, char *dbdir)
printf("%s\n", pkgspec);
}
if (error) {
/* found nothing - try 'pkg-[0-9]*'
*/
char try[FILENAME_MAX];
snprintf(try, FILENAME_MAX, "%s-[0-9]*", pkgspec);
if (findmatchingname(_pkgdb_getPKGDB_DIR(), try,
foundpkg, NULL) != 0) {
error = 0;
}
/* found nothing - try 'pkg-[0-9]*' */
char try[FILENAME_MAX];
snprintf(try, FILENAME_MAX, "%s-[0-9]*", pkgspec);
if (findmatchingname(_pkgdb_getPKGDB_DIR(), try,
foundpkg, NULL) != 0) {
error = 0;
}
}
return error;
}
@ -266,10 +267,10 @@ cleanup(int sig)
int
pkg_perform(lpkg_head_t *pkgs)
{
struct dirent *dp;
char *tmp;
DIR *dirp;
int err_cnt = 0;
struct dirent *dp;
char *tmp;
DIR *dirp;
int err_cnt = 0;
signal(SIGINT, cleanup);
@ -280,51 +281,51 @@ pkg_perform(lpkg_head_t *pkgs)
if (CheckPkg) {
err_cnt += CheckForPkg(CheckPkg, tmp);
} else if (AllInstalled) {
if (!(isdir(tmp) || islinktodir(tmp)))
return 1;
if (File2Pkg) {
/* Show all files with the package they belong to */
char *file, *pkg;
/* pkg_info -Fa => Dump pkgdb */
if (pkgdb_open(1)==-1) {
err(1, "cannot open pkgdb");
}
while ((file = pkgdb_iter())) {
pkg = pkgdb_retrieve(file);
printf("%-50s %s\n", file, pkg);
}
pkgdb_close();
} else {
/* Show all packges with description */
if ((dirp = opendir(tmp)) != (DIR *) NULL) {
while ((dp = readdir(dirp)) != (struct dirent *) NULL) {
char tmp2[FILENAME_MAX];
if (strcmp(dp->d_name, ".")==0 ||
strcmp(dp->d_name, "..")==0)
continue;
if (!(isdir(tmp) || islinktodir(tmp)))
return 1;
(void) snprintf(tmp2, sizeof(tmp2), "%s/%s",
tmp, dp->d_name);
if (isfile(tmp2))
continue;
err_cnt += pkg_do(dp->d_name);
if (File2Pkg) {
/* Show all files with the package they belong to */
char *file, *pkg;
/* pkg_info -Fa => Dump pkgdb */
if (pkgdb_open(1) == -1) {
err(1, "cannot open pkgdb");
}
(void) closedir(dirp);
}
}
} else {
/* Show info on individual pkg(s) */
lpkg_t *lpp;
while ((file = pkgdb_iter())) {
pkg = pkgdb_retrieve(file);
printf("%-50s %s\n", file, pkg);
}
pkgdb_close();
} else {
/* Show all packges with description */
if ((dirp = opendir(tmp)) != (DIR *) NULL) {
while ((dp = readdir(dirp)) != (struct dirent *) NULL) {
char tmp2[FILENAME_MAX];
while ((lpp = TAILQ_FIRST(pkgs))) {
TAILQ_REMOVE(pkgs, lpp, lp_link);
err_cnt += pkg_do(lpp->lp_name);
free_lpkg(lpp);
}
if (strcmp(dp->d_name, ".") == 0 ||
strcmp(dp->d_name, "..") == 0)
continue;
(void) snprintf(tmp2, sizeof(tmp2), "%s/%s",
tmp, dp->d_name);
if (isfile(tmp2))
continue;
err_cnt += pkg_do(dp->d_name);
}
(void) closedir(dirp);
}
}
} else {
/* Show info on individual pkg(s) */
lpkg_t *lpp;
while ((lpp = TAILQ_FIRST(pkgs))) {
TAILQ_REMOVE(pkgs, lpp, lp_link);
err_cnt += pkg_do(lpp->lp_name);
free_lpkg(lpp);
}
}
return err_cnt;
}

View File

@ -1,11 +1,11 @@
/* $NetBSD: show.c,v 1.15 1999/05/30 16:08:25 tron Exp $ */
/* $NetBSD: show.c,v 1.16 1999/08/24 00:48:39 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: show.c,v 1.11 1997/10/08 07:47:38 charnier Exp";
#else
__RCSID("$NetBSD: show.c,v 1.15 1999/05/30 16:08:25 tron Exp $");
__RCSID("$NetBSD: show.c,v 1.16 1999/08/24 00:48:39 hubertf Exp $");
#endif
#endif
@ -62,43 +62,46 @@ __RCSID("$NetBSD: show.c,v 1.15 1999/05/30 16:08:25 tron Exp $");
#include "lib.h"
#include "info.h"
/* structure to define entries for the "show table" */
/* Structure to define entries for the "show table" */
typedef struct show_t {
pl_ent_t sh_type; /* type of entry */
char *sh_quiet; /* message when quiet */
char *sh_verbose; /* message when verbose */
} show_t;
pl_ent_t sh_type; /* type of entry */
char *sh_quiet; /* message when quiet */
char *sh_verbose; /* message when verbose */
} show_t;
/* the entries in this table must be ordered the same as pl_ent_t constants */
static show_t showv[] = {
{ PLIST_FILE, "%s", "File: %s" },
{ PLIST_CWD, "@cwd %s", "\tCWD to: %s" },
{ PLIST_CMD, "@exec %s", "\tEXEC '%s'" },
{ PLIST_CHMOD, "@chmod %s", "\tCHMOD to %s" },
{ PLIST_CHOWN, "@chown %s", "\tCHOWN to %s" },
{ PLIST_CHGRP, "@chgrp %s", "\tCHGRP to %s" },
{ PLIST_COMMENT, "@comment %s", "\tComment: %s" },
{ PLIST_IGNORE, NULL, NULL },
{ PLIST_NAME, "@name %s", "\tPackage name: %s" },
{ PLIST_UNEXEC, "@unexec %s", "\tUNEXEC '%s'" },
{ PLIST_SRC, "@src: %s", "\tSRC to: %s" },
{ PLIST_DISPLAY, "@display %s", "\tInstall message file: %s" },
{ PLIST_PKGDEP, "@pkgdep %s", "\tPackage depends on: %s" },
{ PLIST_MTREE, "@mtree %s", "\tPackage mtree file: %s" },
{ PLIST_DIR_RM, "@dirrm %s", "\tDeinstall directory remove: %s" },
{ PLIST_IGNORE_INST, "@ignore_inst ??? doesn't belong here",
"\tIgnore next file installation directive (doesn't belong)" },
{ PLIST_OPTION, "@option %s", "\tPackage has option: %s" },
{ PLIST_PKGCFL, "@pkgcfl %s", "\tPackage conflicts with: %s" },
{ -1, NULL, NULL }
/*
* The entries in this table must be ordered the same as
* pl_ent_t constants
*/
static show_t showv[] = {
{PLIST_FILE, "%s", "File: %s"},
{PLIST_CWD, "@cwd %s", "\tCWD to: %s"},
{PLIST_CMD, "@exec %s", "\tEXEC '%s'"},
{PLIST_CHMOD, "@chmod %s", "\tCHMOD to %s"},
{PLIST_CHOWN, "@chown %s", "\tCHOWN to %s"},
{PLIST_CHGRP, "@chgrp %s", "\tCHGRP to %s"},
{PLIST_COMMENT, "@comment %s", "\tComment: %s"},
{PLIST_IGNORE, NULL, NULL},
{PLIST_NAME, "@name %s", "\tPackage name: %s"},
{PLIST_UNEXEC, "@unexec %s", "\tUNEXEC '%s'"},
{PLIST_SRC, "@src: %s", "\tSRC to: %s"},
{PLIST_DISPLAY, "@display %s", "\tInstall message file: %s"},
{PLIST_PKGDEP, "@pkgdep %s", "\tPackage depends on: %s"},
{PLIST_MTREE, "@mtree %s", "\tPackage mtree file: %s"},
{PLIST_DIR_RM, "@dirrm %s", "\tDeinstall directory remove: %s"},
{PLIST_IGNORE_INST, "@ignore_inst ??? doesn't belong here",
"\tIgnore next file installation directive (doesn't belong)"},
{PLIST_OPTION, "@option %s", "\tPackage has option: %s"},
{PLIST_PKGCFL, "@pkgcfl %s", "\tPackage conflicts with: %s"},
{-1, NULL, NULL}
};
void
show_file(char *title, char *fname)
{
FILE *fp;
char line[1024];
int n;
FILE *fp;
char line[1024];
int n;
if (!Quiet) {
printf("%s%s", InfoPrefix, title);
@ -111,16 +114,16 @@ show_file(char *title, char *fname)
}
(void) fclose(fp);
}
printf("\n"); /* just in case */
printf("\n"); /* just in case */
}
void
show_index(char *title, char *fname)
{
FILE *fp;
char *line;
size_t linelen;
size_t maxline = termwidth;
FILE *fp;
char *line;
size_t linelen;
size_t maxline = termwidth;
if (!Quiet) {
printf("%s%s", InfoPrefix, title);
@ -131,7 +134,7 @@ show_index(char *title, char *fname)
return;
}
if ((line = fgetln(fp, &linelen))) {
line[linelen - 1] = '\0'; /* tromp newline & terminate string */
line[linelen - 1] = '\0'; /* tromp newline & terminate string */
if (termwidth && (linelen > maxline)) {
/* XXX -1 if term does NOT have xn (or xenl) quirk */
line[maxline] = '\0';
@ -141,76 +144,80 @@ show_index(char *title, char *fname)
(void) fclose(fp);
}
/* Show a packing list item type. If type is PLIST_SHOW_ALL, show all */
/*
* Show a packing list item type. If type is PLIST_SHOW_ALL, show all
*/
void
show_plist(char *title, package_t *plist, pl_ent_t type)
{
plist_t *p;
Boolean ign;
if (!Quiet) {
printf("%s%s", InfoPrefix, title);
}
for (ign = FALSE, p = plist->head; p ; p = p->next) {
if (p->type == type || type == PLIST_SHOW_ALL) {
switch(p->type) {
case PLIST_FILE:
printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose, p->name);
if (ign) {
if (!Quiet) {
printf(" (ignored)");
}
ign = FALSE;
}
break;
case PLIST_CHMOD:
case PLIST_CHOWN:
case PLIST_CHGRP:
printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose,
p->name ? p->name : "(clear default)");
break;
case PLIST_IGNORE:
ign = TRUE;
break;
case PLIST_IGNORE_INST:
printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose, p->name);
ign = TRUE;
break;
case PLIST_CWD:
case PLIST_CMD:
case PLIST_SRC:
case PLIST_UNEXEC:
case PLIST_COMMENT:
case PLIST_NAME:
case PLIST_DISPLAY:
case PLIST_PKGDEP:
case PLIST_MTREE:
case PLIST_DIR_RM:
case PLIST_OPTION:
case PLIST_PKGCFL:
printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose, p->name);
break;
default:
warnx("unknown command type %d (%s)", p->type, p->name);
}
(void) fputc('\n', stdout);
}
}
}
/* Show all files in the packing list (except ignored ones) */
void
show_files(char *title, package_t *plist)
{
plist_t *p;
Boolean ign;
char *dir = ".";
plist_t *p;
Boolean ign;
if (!Quiet) {
printf("%s%s", InfoPrefix, title);
}
for (ign = FALSE, p = plist->head; p ; p = p->next) {
switch(p->type) {
for (ign = FALSE, p = plist->head; p; p = p->next) {
if (p->type == type || type == PLIST_SHOW_ALL) {
switch (p->type) {
case PLIST_FILE:
printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose, p->name);
if (ign) {
if (!Quiet) {
printf(" (ignored)");
}
ign = FALSE;
}
break;
case PLIST_CHMOD:
case PLIST_CHOWN:
case PLIST_CHGRP:
printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose,
p->name ? p->name : "(clear default)");
break;
case PLIST_IGNORE:
ign = TRUE;
break;
case PLIST_IGNORE_INST:
printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose, p->name);
ign = TRUE;
break;
case PLIST_CWD:
case PLIST_CMD:
case PLIST_SRC:
case PLIST_UNEXEC:
case PLIST_COMMENT:
case PLIST_NAME:
case PLIST_DISPLAY:
case PLIST_PKGDEP:
case PLIST_MTREE:
case PLIST_DIR_RM:
case PLIST_OPTION:
case PLIST_PKGCFL:
printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose, p->name);
break;
default:
warnx("unknown command type %d (%s)", p->type, p->name);
}
(void) fputc('\n', stdout);
}
}
}
/*
* Show all files in the packing list (except ignored ones)
*/
void
show_files(char *title, package_t *plist)
{
plist_t *p;
Boolean ign;
char *dir = ".";
if (!Quiet) {
printf("%s%s", InfoPrefix, title);
}
for (ign = FALSE, p = plist->head; p; p = p->next) {
switch (p->type) {
case PLIST_FILE:
if (!ign) {
printf("%s/%s\n", dir, p->name);
@ -229,16 +236,18 @@ show_files(char *title, package_t *plist)
}
}
/* Show dependencies (packages this pkg requires) */
/*
* Show dependencies (packages this pkg requires)
*/
void
show_depends(char *title, package_t *plist)
{
plist_t *p;
int nodepends;
plist_t *p;
int nodepends;
nodepends = 1;
for (p = plist->head; p && nodepends; p = p->next) {
switch(p->type) {
switch (p->type) {
case PLIST_PKGDEP:
nodepends = 0;
break;
@ -247,21 +256,20 @@ show_depends(char *title, package_t *plist)
}
}
if (nodepends)
return;
return;
if (!Quiet) {
printf("%s%s", InfoPrefix, title);
}
for (p = plist->head; p ; p = p->next) {
switch(p->type) {
for (p = plist->head; p; p = p->next) {
switch (p->type) {
case PLIST_PKGDEP:
printf("%s\n", p->name);
printf("%s\n", p->name);
break;
default:
break;
}
}
printf("\n");
}

View File

@ -1,11 +1,11 @@
/* $NetBSD: exec.c,v 1.5 1998/10/08 12:15:24 agc Exp $ */
/* $NetBSD: exec.c,v 1.6 1999/08/24 00:48:39 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: exec.c,v 1.6 1997/10/08 07:47:50 charnier Exp";
#else
__RCSID("$NetBSD: exec.c,v 1.5 1998/10/08 12:15:24 agc Exp $");
__RCSID("$NetBSD: exec.c,v 1.6 1999/08/24 00:48:39 hubertf Exp $");
#endif
#endif
@ -36,17 +36,16 @@ __RCSID("$NetBSD: exec.c,v 1.5 1998/10/08 12:15:24 agc Exp $");
* Unusual system() substitute. Accepts format string and args,
* builds and executes command. Returns exit code.
*/
int
vsystem(const char *fmt, ...)
vsystem(const char *fmt,...)
{
va_list args;
char *cmd;
size_t maxargs;
int ret;
va_list args;
char *cmd;
size_t maxargs;
int ret;
maxargs = (size_t) sysconf(_SC_ARG_MAX);
maxargs -= 32; /* some slop for the sh -c */
maxargs -= 32; /* some slop for the sh -c */
if ((cmd = (char *) malloc(maxargs)) == (char *) NULL) {
warnx("vsystem can't alloc arg space");
return 1;
@ -65,4 +64,3 @@ vsystem(const char *fmt, ...)
free(cmd);
return ret;
}

View File

@ -1,11 +1,11 @@
/* $NetBSD: file.c,v 1.31 1999/08/23 15:17:04 hubertf Exp $ */
/* $NetBSD: file.c,v 1.32 1999/08/24 00:48:39 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp";
#else
__RCSID("$NetBSD: file.c,v 1.31 1999/08/23 15:17:04 hubertf Exp $");
__RCSID("$NetBSD: file.c,v 1.32 1999/08/24 00:48:39 hubertf Exp $");
#endif
#endif
@ -40,18 +40,19 @@ __RCSID("$NetBSD: file.c,v 1.31 1999/08/23 15:17:04 hubertf Exp $");
#include <time.h>
#include <fcntl.h>
/* This is as ftpGetURL from FreeBSD's ftpio.c, except that it uses
/*
* This is as ftpGetURL from FreeBSD's ftpio.c, except that it uses
* NetBSD's ftp command to do all FTP, which will DTRT for proxies,
* etc.
*/
static FILE *
ftpGetURL(char *url, int *retcode)
{
FILE *ftp;
pid_t pid_ftp;
int p[2];
FILE *ftp;
pid_t pid_ftp;
int p[2];
*retcode=0;
*retcode = 0;
if (pipe(p) < 0) {
*retcode = 1;
@ -65,15 +66,15 @@ ftpGetURL(char *url, int *retcode)
}
if (pid_ftp == 0) {
/* child */
dup2(p[1],1);
dup2(p[1], 1);
close(p[1]);
fprintf(stderr, ">>> ftp -o - %s\n",url);
execl("/usr/bin/ftp","ftp","-V","-o","-",url,NULL);
fprintf(stderr, ">>> ftp -o - %s\n", url);
execl("/usr/bin/ftp", "ftp", "-V", "-o", "-", url, NULL);
exit(1);
} else {
/* parent */
ftp = fdopen(p[0],"r");
ftp = fdopen(p[0], "r");
close(p[1]);
@ -85,113 +86,128 @@ ftpGetURL(char *url, int *retcode)
return ftp;
}
/* Quick check to see if a file exists */
/*
* Quick check to see if a file exists
*/
Boolean
fexists(char *fname)
{
struct stat dummy;
if (!lstat(fname, &dummy))
return TRUE;
return FALSE;
}
/* Quick check to see if something is a directory */
Boolean
isdir(char *fname)
{
struct stat sb;
if (lstat(fname, &sb) != FAIL && S_ISDIR(sb.st_mode))
return TRUE;
else
struct stat dummy;
if (!lstat(fname, &dummy))
return TRUE;
return FALSE;
}
/* Check if something is a link to a directory */
/*
* Quick check to see if something is a directory
*/
Boolean
isdir(char *fname)
{
struct stat sb;
if (lstat(fname, &sb) != FAIL && S_ISDIR(sb.st_mode))
return TRUE;
else
return FALSE;
}
/*
* Check if something is a link to a directory
*/
Boolean
islinktodir(char *fname)
{
struct stat sb;
struct stat sb;
if (lstat(fname, &sb) != FAIL && S_ISLNK(sb.st_mode)) {
if (stat(fname, &sb) != FAIL && S_ISDIR(sb.st_mode))
return TRUE; /* link to dir! */
else
return FALSE; /* link to non-dir */
} else
return FALSE; /* non-link */
if (lstat(fname, &sb) != FAIL && S_ISLNK(sb.st_mode)) {
if (stat(fname, &sb) != FAIL && S_ISDIR(sb.st_mode))
return TRUE; /* link to dir! */
else
return FALSE; /* link to non-dir */
} else
return FALSE; /* non-link */
}
/* Check to see if file is a dir, and is empty */
/*
* Check to see if file is a dir, and is empty
*/
Boolean
isemptydir(char *fname)
{
if (isdir(fname) || islinktodir(fname)) {
DIR *dirp;
struct dirent *dp;
if (isdir(fname) || islinktodir(fname)) {
DIR *dirp;
struct dirent *dp;
dirp = opendir(fname);
if (!dirp)
return FALSE; /* no perms, leave it alone */
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
if (strcmp(dp->d_name, ".") && strcmp(dp->d_name, "..")) {
closedir(dirp);
return FALSE;
}
dirp = opendir(fname);
if (!dirp)
return FALSE; /* no perms, leave it alone */
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
if (strcmp(dp->d_name, ".") && strcmp(dp->d_name, "..")) {
closedir(dirp);
return FALSE;
}
}
(void) closedir(dirp);
return TRUE;
}
(void)closedir(dirp);
return TRUE;
}
return FALSE;
return FALSE;
}
/*
* Check if something is a regular file
*/
Boolean
isfile(char *fname)
{
struct stat sb;
if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode))
return TRUE;
return FALSE;
struct stat sb;
if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode))
return TRUE;
return FALSE;
}
/* Check to see if file is a file and is empty. If nonexistent or not
a file, say "it's empty", otherwise return TRUE if zero sized. */
/*
* Check to see if file is a file and is empty. If nonexistent or not
* a file, say "it's empty", otherwise return TRUE if zero sized.
*/
Boolean
isemptyfile(char *fname)
{
struct stat sb;
if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode)) {
if (sb.st_size != 0)
return FALSE;
}
return TRUE;
struct stat sb;
if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode)) {
if (sb.st_size != 0)
return FALSE;
}
return TRUE;
}
/* this struct defines the leading part of a valid URL name */
/* This struct defines the leading part of a valid URL name */
typedef struct url_t {
char *u_s; /* the leading part of the URL */
int u_len; /* its length */
} url_t;
char *u_s; /* the leading part of the URL */
int u_len; /* its length */
} url_t;
/* a table of valid leading strings for URLs */
static url_t urls[] = {
{ "ftp://", 6 },
{ "http://", 7 },
{ NULL }
/* A table of valid leading strings for URLs */
static url_t urls[] = {
{"ftp://", 6},
{"http://", 7},
{NULL}
};
/* Returns length of leading part of any URL from urls table, or -1 */
/*
* Returns length of leading part of any URL from urls table, or -1
*/
int
URLlength(char *fname)
{
url_t *up;
int i;
url_t *up;
int i;
if (fname != (char *) NULL) {
for (i = 0 ; isspace((unsigned char)*fname) ; i++) {
for (i = 0; isspace((unsigned char) *fname); i++) {
fname++;
}
for (up = urls ; up->u_s ; up++) {
for (up = urls; up->u_s; up++) {
if (strncmp(fname, up->u_s, up->u_len) == 0) {
return i + up->u_len;
}
@ -200,12 +216,14 @@ URLlength(char *fname)
return -1;
}
/* Returns the host part of a URL */
char *
/*
* Returns the host part of a URL
*/
char *
fileURLHost(char *fname, char *where, int max)
{
char *ret;
int i;
char *ret;
int i;
if ((i = URLlength(fname)) < 0) { /* invalid URL? */
errx(1, "fileURLhost called with a bad URL: `%s'", fname);
@ -226,12 +244,14 @@ fileURLHost(char *fname, char *where, int max)
return ret;
}
/* Returns the filename part of a URL */
char *
/*
* Returns the filename part of a URL
*/
char *
fileURLFilename(char *fname, char *where, int max)
{
char *ret;
int i;
char *ret;
int i;
if ((i = URLlength(fname)) < 0) { /* invalid URL? */
errx(1, "fileURLhost called with a bad URL: `%s'", fname);
@ -258,97 +278,92 @@ fileURLFilename(char *fname, char *where, int max)
* Try and fetch a file by URL, returning the directory name for where
* it's unpacked, if successful.
*/
char *
char *
fileGetURL(char *base, char *spec)
{
char host[MAXHOSTNAMELEN], file[FILENAME_MAX];
char *cp, *rp;
char fname[FILENAME_MAX];
char pen[FILENAME_MAX];
FILE *ftp;
pid_t tpid;
int i, status;
char *hint;
char host[MAXHOSTNAMELEN], file[FILENAME_MAX];
char *cp, *rp;
char fname[FILENAME_MAX];
char pen[FILENAME_MAX];
FILE *ftp;
pid_t tpid;
int i, status;
char *hint;
rp = NULL;
/* Special tip that sysinstall left for us */
hint = getenv("PKG_ADD_BASE");
if (!IS_URL(spec)) {
if (!base && !hint)
return NULL;
/* We've been given an existing URL (that's known-good) and now we need
to construct a composite one out of that and the basename we were
handed as a dependency. */
if (base) {
strcpy(fname, base);
/* Advance back two slashes to get to the root of the package hierarchy */
cp = strrchr(fname, '/');
if (cp) {
*cp = '\0'; /* chop name */
cp = strrchr(fname, '/');
}
if (cp) {
*(cp + 1) = '\0';
strcat(cp, "All/");
strcat(cp, spec);
strcat(cp, ".tgz");
}
else
rp = NULL;
/* Special tip that sysinstall left for us */
hint = getenv("PKG_ADD_BASE");
if (!IS_URL(spec)) {
if (!base && !hint)
return NULL;
/* We've been given an existing URL (that's known-good) and
* now we need to construct a composite one out of that and
* the basename we were handed as a dependency. */
if (base) {
strcpy(fname, base);
/* Advance back two slashes to get to the root of the package hierarchy */
cp = strrchr(fname, '/');
if (cp) {
*cp = '\0'; /* chop name */
cp = strrchr(fname, '/');
}
if (cp) {
*(cp + 1) = '\0';
strcat(cp, "All/");
strcat(cp, spec);
strcat(cp, ".tgz");
} else
return NULL;
} else {
/* Otherwise, we've been given an environment variable hinting at the right location from sysinstall */
strcpy(fname, hint);
strcat(fname, spec);
}
} else
strcpy(fname, spec);
cp = fileURLHost(fname, host, MAXHOSTNAMELEN);
if (!*cp) {
warnx("URL `%s' has bad host part!", fname);
return NULL;
} else {
/* Otherwise, we've been given an environment variable hinting at the right location from sysinstall */
strcpy(fname, hint);
strcat(fname, spec);
}
}
else
strcpy(fname, spec);
cp = fileURLHost(fname, host, MAXHOSTNAMELEN);
if (!*cp) {
warnx("URL `%s' has bad host part!", fname);
return NULL;
}
cp = fileURLFilename(fname, file, FILENAME_MAX);
if (!*cp) {
warnx("URL `%s' has bad filename part!", fname);
return NULL;
}
cp = fileURLFilename(fname, file, FILENAME_MAX);
if (!*cp) {
warnx("URL `%s' has bad filename part!", fname);
return NULL;
}
if (Verbose)
printf("Trying to fetch %s.\n", fname);
ftp = ftpGetURL(fname, &status);
if (ftp) {
pen[0] = '\0';
if ((rp = make_playpen(pen, sizeof(pen), 0)) != NULL) {
rp=strdup(pen); /* be safe for nested calls */
if (Verbose)
printf("Extracting from FTP connection into %s\n", pen);
tpid = fork();
if (!tpid) {
dup2(fileno(ftp), 0);
i = execl(TAR_FULLPATHNAME, TAR_CMD, Verbose ? "-xzvf" : "-xzf", "-", 0);
err(i, TAR_FULLPATHNAME " failed");
}
else {
int pstat;
if (Verbose)
printf("Trying to fetch %s.\n", fname);
ftp = ftpGetURL(fname, &status);
if (ftp) {
pen[0] = '\0';
if ((rp = make_playpen(pen, sizeof(pen), 0)) != NULL) {
rp = strdup(pen); /* be safe for nested calls */
if (Verbose)
printf("Extracting from FTP connection into %s\n", pen);
tpid = fork();
if (!tpid) {
dup2(fileno(ftp), 0);
i = execl(TAR_FULLPATHNAME, TAR_CMD, Verbose ? "-xzvf" : "-xzf", "-", 0);
err(i, TAR_FULLPATHNAME " failed");
} else {
int pstat;
fclose(ftp);
tpid = waitpid(tpid, &pstat, 0);
if (Verbose)
printf("%s command returns %d status\n", TAR_CMD, WEXITSTATUS(pstat));
}
} else
printf("Error: Unable to construct a new playpen for FTP!\n");
fclose(ftp);
tpid = waitpid(tpid, &pstat, 0);
if (Verbose)
printf("%s command returns %d status\n", TAR_CMD, WEXITSTATUS(pstat));
}
}
else
printf("Error: Unable to construct a new playpen for FTP!\n");
fclose(ftp);
}
else
printf("Error: FTP Unable to get %s: %s\n",
fname,
status ? "Error while performing FTP" :
hstrerror(h_errno));
return rp;
} else
printf("Error: FTP Unable to get %s: %s\n",
fname,
status ? "Error while performing FTP" :
hstrerror(h_errno));
return rp;
}
/*
@ -357,150 +372,153 @@ fileGetURL(char *base, char *spec)
* - $base/../All
* - all dirs in $PKG_PATH
*/
char *
char *
fileFindByPath(char *base, char *fname)
{
static char tmp[FILENAME_MAX];
char *cp;
static char tmp[FILENAME_MAX];
char *cp;
if (ispkgpattern(fname)) {
if ((cp=findbestmatchingname(".",fname)) != NULL) {
strcpy (tmp, cp);
return tmp;
if (ispkgpattern(fname)) {
if ((cp = findbestmatchingname(".", fname)) != NULL) {
strcpy(tmp, cp);
return tmp;
}
} else {
if (fexists(fname) && isfile(fname)) {
strcpy(tmp, fname);
return tmp;
}
}
}else{
if (fexists(fname) && isfile(fname)) {
strcpy(tmp, fname);
return tmp;
}
}
if (base) {
strcpy(tmp, base);
cp = strrchr(tmp, '/');
if (cp) {
*cp = '\0'; /* chop name */
cp = strrchr(tmp, '/');
}
if (cp) {
*(cp + 1) = '\0';
strcat(cp, "All/");
strcat(cp, fname);
strcat(cp, ".tgz");
if (ispkgpattern(tmp)) {
cp=findbestmatchingname(dirname_of(tmp), basename_of(tmp));
if (base) {
strcpy(tmp, base);
cp = strrchr(tmp, '/');
if (cp) {
char *s;
s=strrchr(tmp,'/');
assert(s != NULL);
strcpy(s+1, cp);
return tmp;
*cp = '\0'; /* chop name */
cp = strrchr(tmp, '/');
}
} else {
if (fexists(tmp)) {
return tmp;
if (cp) {
*(cp + 1) = '\0';
strcat(cp, "All/");
strcat(cp, fname);
strcat(cp, ".tgz");
if (ispkgpattern(tmp)) {
cp = findbestmatchingname(dirname_of(tmp), basename_of(tmp));
if (cp) {
char *s;
s = strrchr(tmp, '/');
assert(s != NULL);
strcpy(s + 1, cp);
return tmp;
}
} else {
if (fexists(tmp)) {
return tmp;
}
}
}
}
}
}
cp = getenv("PKG_PATH");
while (cp) {
char *cp2 = strsep(&cp, ":");
cp = getenv("PKG_PATH");
while (cp) {
char *cp2 = strsep(&cp, ":");
(void) snprintf(tmp, sizeof(tmp), "%s/%s.tgz", cp2 ? cp2 : cp, fname);
if (ispkgpattern(tmp)) {
char *s;
s = findbestmatchingname(dirname_of(tmp), basename_of(tmp));
if (s){
char *t;
t=strrchr(tmp, '/');
strcpy(t+1, s);
return tmp;
}
}else{
if (fexists(tmp) && isfile(tmp)) {
return tmp;
}
(void) snprintf(tmp, sizeof(tmp), "%s/%s.tgz", cp2 ? cp2 : cp, fname);
if (ispkgpattern(tmp)) {
char *s;
s = findbestmatchingname(dirname_of(tmp), basename_of(tmp));
if (s) {
char *t;
t = strrchr(tmp, '/');
strcpy(t + 1, s);
return tmp;
}
} else {
if (fexists(tmp) && isfile(tmp)) {
return tmp;
}
}
}
}
return NULL;
return NULL;
}
/*
* expect "fname" to point at a +CONTENTS file, and read it into
* the buffer returned.
* Expect "fname" to point at a +CONTENTS file, and read it into
* the buffer returned.
*/
char *
char *
fileGetContents(char *fname)
{
char *contents;
struct stat sb;
int fd;
char *contents;
struct stat sb;
int fd;
if (stat(fname, &sb) == FAIL) {
cleanup(0);
errx(2, "can't stat '%s'", fname);
}
if (stat(fname, &sb) == FAIL) {
cleanup(0);
errx(2, "can't stat '%s'", fname);
}
contents = (char *)malloc((size_t)(sb.st_size) + 1);
fd = open(fname, O_RDONLY, 0);
if (fd == FAIL) {
cleanup(0);
errx(2, "unable to open '%s' for reading", fname);
}
if (read(fd, contents, (size_t) sb.st_size) != (size_t) sb.st_size) {
cleanup(0);
errx(2, "short read on '%s' - did not get %qd bytes",
fname, (long long)sb.st_size);
}
close(fd);
contents[(size_t)sb.st_size] = '\0';
return contents;
contents = (char *) malloc((size_t) (sb.st_size) + 1);
fd = open(fname, O_RDONLY, 0);
if (fd == FAIL) {
cleanup(0);
errx(2, "unable to open '%s' for reading", fname);
}
if (read(fd, contents, (size_t) sb.st_size) != (size_t) sb.st_size) {
cleanup(0);
errx(2, "short read on '%s' - did not get %qd bytes",
fname, (long long) sb.st_size);
}
close(fd);
contents[(size_t) sb.st_size] = '\0';
return contents;
}
/* Takes a filename and package name, returning (in "try") the canonical
/*
* Takes a filename and package name, returning (in "try") the canonical
* "preserve" name for it.
*/
Boolean
make_preserve_name(char *try, size_t max, char *name, char *file)
{
int len, i;
int len, i;
if ((len = strlen(file)) == 0)
return FALSE;
else
i = len - 1;
strncpy(try, file, max);
if (try[i] == '/') /* Catch trailing slash early and save checking in the loop */
--i;
for (; i; i--) {
if (try[i] == '/') {
try[i + 1]= '.';
strncpy(&try[i + 2], &file[i + 1], max - i - 2);
break;
if ((len = strlen(file)) == 0)
return FALSE;
else
i = len - 1;
strncpy(try, file, max);
if (try[i] == '/') /* Catch trailing slash early and save checking in the loop */
--i;
for (; i; i--) {
if (try[i] == '/') {
try[i + 1] = '.';
strncpy(&try[i + 2], &file[i + 1], max - i - 2);
break;
}
}
}
if (!i) {
try[0] = '.';
strncpy(try + 1, file, max - 1);
}
/* I should probably be called rude names for these inline assignments */
strncat(try, ".", max -= strlen(try));
strncat(try, name, max -= strlen(name));
strncat(try, ".", max--);
strncat(try, "backup", max -= 6);
return TRUE;
if (!i) {
try[0] = '.';
strncpy(try + 1, file, max - 1);
}
/* I should probably be called rude names for these inline assignments */
strncat(try, ".", max -= strlen(try));
strncat(try, name, max -= strlen(name));
strncat(try, ".", max--);
strncat(try, "backup", max -= 6);
return TRUE;
}
/* Write the contents of "str" to a file */
/*
* Write the contents of "str" to a file
*/
void
write_file(char *name, char *str)
{
size_t len;
FILE *fp;
size_t len;
FILE *fp;
if ((fp = fopen(name, "w")) == (FILE *) NULL) {
cleanup(0);
@ -510,7 +528,7 @@ write_file(char *name, char *str)
if (fwrite(str, 1, len, fp) != len) {
cleanup(0);
errx(2, "short fwrite on '%s', tried to write %ld bytes",
name, (long) len);
name, (long) len);
}
if (fclose(fp)) {
cleanup(0);
@ -521,89 +539,90 @@ write_file(char *name, char *str)
void
copy_file(char *dir, char *fname, char *to)
{
char cmd[FILENAME_MAX];
char cmd[FILENAME_MAX];
if (fname[0] == '/')
(void) snprintf(cmd, sizeof(cmd), "cp -p -r %s %s", fname, to);
else
(void) snprintf(cmd, sizeof(cmd), "cp -p -r %s/%s %s", dir, fname, to);
if (vsystem(cmd)) {
cleanup(0);
errx(2, "could not perform '%s'", cmd);
}
if (fname[0] == '/')
(void) snprintf(cmd, sizeof(cmd), "cp -p -r %s %s", fname, to);
else
(void) snprintf(cmd, sizeof(cmd), "cp -p -r %s/%s %s", dir, fname, to);
if (vsystem(cmd)) {
cleanup(0);
errx(2, "could not perform '%s'", cmd);
}
}
void
move_file(char *dir, char *fname, char *to)
{
char cmd[FILENAME_MAX];
char cmd[FILENAME_MAX];
if (fname[0] == '/')
(void) snprintf(cmd, sizeof(cmd), "mv %s %s", fname, to);
else
(void) snprintf(cmd, sizeof(cmd), "mv %s/%s %s", dir, fname, to);
if (vsystem(cmd)) {
cleanup(0);
errx(2, "could not perform '%s'", cmd);
}
if (fname[0] == '/')
(void) snprintf(cmd, sizeof(cmd), "mv %s %s", fname, to);
else
(void) snprintf(cmd, sizeof(cmd), "mv %s/%s %s", dir, fname, to);
if (vsystem(cmd)) {
cleanup(0);
errx(2, "could not perform '%s'", cmd);
}
}
/* Unpack a tar file */
/*
* Unpack a tar file
*/
int
unpack(char *pkg, char *flist)
{
char args[10], suff[80], *cp;
char args[10], suff[80], *cp;
args[0] = '\0';
/*
* Figure out by a crude heuristic whether this or not this is probably
* compressed.
*/
if (strcmp(pkg, "-")) {
cp = strrchr(pkg, '.');
if (cp) {
strcpy(suff, cp + 1);
if (strchr(suff, 'z') || strchr(suff, 'Z'))
strcpy(args, "-z");
args[0] = '\0';
/*
* Figure out by a crude heuristic whether this or not this is probably
* compressed.
*/
if (strcmp(pkg, "-")) {
cp = strrchr(pkg, '.');
if (cp) {
strcpy(suff, cp + 1);
if (strchr(suff, 'z') || strchr(suff, 'Z'))
strcpy(args, "-z");
}
} else
strcpy(args, "z");
strcat(args, "xpf");
if (vsystem("%s %s %s %s", TAR_CMD, args, pkg, flist ? flist : "")) {
warnx("%s extract of %s failed!", TAR_CMD, pkg);
return 1;
}
}
else
strcpy(args, "z");
strcat(args, "xpf");
if (vsystem("%s %s %s %s", TAR_CMD, args, pkg, flist ? flist : "")) {
warnx("%s extract of %s failed!", TAR_CMD, pkg);
return 1;
}
return 0;
return 0;
}
/*
* Using fmt, replace all instances of:
*
*
* %F With the parameter "name"
* %D With the parameter "dir"
* %B Return the directory part ("base") of %D/%F
* %f Return the filename part of %D/%F
*
*
* Check that no overflows can occur.
*/
void
format_cmd(char *buf, size_t size, char *fmt, char *dir, char *name)
{
char scratch[FILENAME_MAX * 2];
char scratch[FILENAME_MAX * 2];
char *bufp;
char *cp;
for (bufp = buf ; (int)(bufp - buf) < size && *fmt ; ) {
for (bufp = buf; (int) (bufp - buf) < size && *fmt;) {
if (*fmt == '%') {
switch (*++fmt) {
case 'F':
strnncpy(bufp, size - (int)(bufp - buf), name, strlen(name));
strnncpy(bufp, size - (int) (bufp - buf), name, strlen(name));
bufp += strlen(bufp);
break;
case 'D':
strnncpy(bufp, size - (int)(bufp - buf), dir, strlen(dir));
strnncpy(bufp, size - (int) (bufp - buf), dir, strlen(dir));
bufp += strlen(bufp);
break;
@ -612,7 +631,7 @@ format_cmd(char *buf, size_t size, char *fmt, char *dir, char *name)
if ((cp = strrchr(scratch, '/')) == (char *) NULL) {
cp = scratch;
}
strnncpy(bufp, size - (int)(bufp - buf), scratch, (size_t)(cp - scratch));
strnncpy(bufp, size - (int) (bufp - buf), scratch, (size_t) (cp - scratch));
bufp += strlen(bufp);
break;
@ -623,7 +642,7 @@ format_cmd(char *buf, size_t size, char *fmt, char *dir, char *name)
} else {
cp++;
}
strnncpy(bufp, size - (int)(bufp - buf), cp, strlen(cp));
strnncpy(bufp, size - (int) (bufp - buf), cp, strlen(cp));
bufp += strlen(bufp);
break;

View File

@ -1,11 +1,11 @@
/* $NetBSD: global.c,v 1.5 1998/10/09 09:22:17 agc Exp $ */
/* $NetBSD: global.c,v 1.6 1999/08/24 00:48:39 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: global.c,v 1.6 1997/10/08 07:47:58 charnier Exp";
#else
__RCSID("$NetBSD: global.c,v 1.5 1998/10/09 09:22:17 agc Exp $");
__RCSID("$NetBSD: global.c,v 1.6 1999/08/24 00:48:39 hubertf Exp $");
#endif
#endif
@ -33,8 +33,6 @@ __RCSID("$NetBSD: global.c,v 1.5 1998/10/09 09:22:17 agc Exp $");
#include "lib.h"
/* These are global for all utils */
Boolean Verbose = FALSE;
Boolean Fake = FALSE;
Boolean Force = FALSE;
Boolean Verbose = FALSE;
Boolean Fake = FALSE;
Boolean Force = FALSE;

View File

@ -1,4 +1,4 @@
/* $NetBSD: lib.h,v 1.24 1999/08/23 15:17:04 hubertf Exp $ */
/* $NetBSD: lib.h,v 1.25 1999/08/24 00:48:39 hubertf Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@ -56,12 +56,12 @@
/* Usually "rm", but often "echo" during debugging! */
#define RMDIR_CMD "rmdir"
/* define tar as a string, in case it's called gtar or something */
/* Define tar as a string, in case it's called gtar or something */
#ifndef TAR_CMD
#define TAR_CMD "tar"
#endif
/* full path name of TAR_CMD */
/* Full path name of TAR_CMD */
#ifndef TAR_FULLPATHNAME
#define TAR_FULLPATHNAME "/usr/bin/tar"
#endif
@ -90,13 +90,13 @@
#define PKG_PREFIX_VNAME "PKG_PREFIX"
/* This should only happen on 1.3 and 1.3.1, not 1.3.2 and up */
#ifndef TAILQ_FIRST
#ifndef TAILQ_FIRST
#define TAILQ_FIRST(head) ((head)->tqh_first)
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
#endif
/* enumerated constants for plist entry types */
/* Enumerated constants for plist entry types */
typedef enum pl_ent_t {
PLIST_SHOW_ALL = -1,
PLIST_FILE,
@ -117,132 +117,132 @@ typedef enum pl_ent_t {
PLIST_IGNORE_INST,
PLIST_OPTION,
PLIST_PKGCFL
} pl_ent_t;
} pl_ent_t;
/* Types */
typedef unsigned int Boolean;
/* this structure describes a packing list entry */
/* This structure describes a packing list entry */
typedef struct plist_t {
struct plist_t *prev; /* previous entry */
struct plist_t *next; /* next entry */
char *name; /* name of entry */
Boolean marked; /* whether entry has been marked */
pl_ent_t type; /* type of entry */
} plist_t;
struct plist_t *prev; /* previous entry */
struct plist_t *next; /* next entry */
char *name; /* name of entry */
Boolean marked; /* whether entry has been marked */
pl_ent_t type; /* type of entry */
} plist_t;
/* this structure describes a package's complete packing list */
/* This structure describes a package's complete packing list */
typedef struct package_t {
plist_t *head; /* head of list */
plist_t *tail; /* tail of list */
} package_t;
plist_t *head; /* head of list */
plist_t *tail; /* tail of list */
} package_t;
#define CHECKSUM_HEADER "MD5:"
enum {
ChecksumHeaderLen = 4, /* strlen(CHECKSUM_HEADER) */
ChecksumHeaderLen = 4, /* strlen(CHECKSUM_HEADER) */
ChecksumLen = 16,
LegibleChecksumLen = 33
};
/* List of packages */
typedef struct _lpkg_t {
TAILQ_ENTRY(_lpkg_t) lp_link;
char *lp_name;
} lpkg_t;
TAILQ_ENTRY(_lpkg_t) lp_link;
char *lp_name;
} lpkg_t;
TAILQ_HEAD(_lpkg_head_t, _lpkg_t);
typedef struct _lpkg_head_t lpkg_head_t;
/* type of function to be handed to findmatchingname; return value of this
/* Type of function to be handed to findmatchingname; return value of this
* is currently ignored */
typedef int (*matchfn)(const char *found, char *data);
typedef int (*matchfn) (const char *found, char *data);
/* if URLlength()>0, then there is a ftp:// or http:// in the string,
/* If URLlength()>0, then there is a ftp:// or http:// in the string,
* and this must be an URL. Hide this behind a more obvious name. */
#define IS_URL(str) (URLlength(str) > 0)
/* Prototypes */
/* Misc */
int vsystem(const char *, ...);
void cleanup(int);
char *make_playpen(char *, size_t, size_t);
char *where_playpen(void);
void leave_playpen(char *);
off_t min_free(char *);
void save_dirs(char **c, char **p);
void restore_dirs(char *c, char *p);
int vsystem(const char *,...);
void cleanup(int);
char *make_playpen(char *, size_t, size_t);
char *where_playpen(void);
void leave_playpen(char *);
off_t min_free(char *);
void save_dirs(char **c, char **p);
void restore_dirs(char *c, char *p);
/* String */
char *get_dash_string(char **);
void str_lowercase(char *);
char *basename_of(char *);
char *dirname_of(const char *);
int pmatch(const char *, const char *);
int findmatchingname(const char *, const char *, matchfn, char *); /* doesn't really belong here */
char *findbestmatchingname(const char *, const char *); /* neither */
int ispkgpattern(const char *);
char *strnncpy(char *to, size_t tosize, char *from, size_t cc);
char *get_dash_string(char **);
void str_lowercase(char *);
char *basename_of(char *);
char *dirname_of(const char *);
int pmatch(const char *, const char *);
int findmatchingname(const char *, const char *, matchfn, char *); /* doesn't really belong here */
char *findbestmatchingname(const char *, const char *); /* neither */
int ispkgpattern(const char *);
char *strnncpy(char *to, size_t tosize, char *from, size_t cc);
/* File */
Boolean fexists(char *);
Boolean isdir(char *);
Boolean islinktodir(char *);
Boolean isemptydir(char *fname);
Boolean isemptyfile(char *fname);
Boolean isfile(char *);
Boolean isempty(char *);
int URLlength(char *);
char *fileGetURL(char *, char *);
char *fileURLFilename(char *, char *, int);
char *fileURLHost(char *, char *, int);
char *fileFindByPath(char *, char *);
char *fileGetContents(char *);
Boolean make_preserve_name(char *, size_t, char *, char *);
void write_file(char *, char *);
void copy_file(char *, char *, char *);
void move_file(char *, char *, char *);
int delete_hierarchy(char *, Boolean, Boolean);
int unpack(char *, char *);
void format_cmd(char *, size_t , char *, char *, char *);
Boolean fexists(char *);
Boolean isdir(char *);
Boolean islinktodir(char *);
Boolean isemptydir(char *fname);
Boolean isemptyfile(char *fname);
Boolean isfile(char *);
Boolean isempty(char *);
int URLlength(char *);
char *fileGetURL(char *, char *);
char *fileURLFilename(char *, char *, int);
char *fileURLHost(char *, char *, int);
char *fileFindByPath(char *, char *);
char *fileGetContents(char *);
Boolean make_preserve_name(char *, size_t, char *, char *);
void write_file(char *, char *);
void copy_file(char *, char *, char *);
void move_file(char *, char *, char *);
int delete_hierarchy(char *, Boolean, Boolean);
int unpack(char *, char *);
void format_cmd(char *, size_t, char *, char *, char *);
/* Packing list */
plist_t *new_plist_entry(void);
plist_t *last_plist(package_t *);
plist_t *find_plist(package_t *, pl_ent_t);
char *find_plist_option(package_t *, char *name);
void plist_delete(package_t *, Boolean, pl_ent_t, char *);
void free_plist(package_t *);
void mark_plist(package_t *);
void csum_plist_entry(char *, plist_t *);
void add_plist(package_t *, pl_ent_t, char *);
void add_plist_top(package_t *, pl_ent_t, char *);
void delete_plist(package_t *pkg, Boolean all, pl_ent_t type, char *name);
void write_plist(package_t *, FILE *);
void read_plist(package_t *, FILE *);
int plist_cmd(char *, char **);
int delete_package(Boolean, Boolean, package_t *);
plist_t *new_plist_entry(void);
plist_t *last_plist(package_t *);
plist_t *find_plist(package_t *, pl_ent_t);
char *find_plist_option(package_t *, char *name);
void plist_delete(package_t *, Boolean, pl_ent_t, char *);
void free_plist(package_t *);
void mark_plist(package_t *);
void csum_plist_entry(char *, plist_t *);
void add_plist(package_t *, pl_ent_t, char *);
void add_plist_top(package_t *, pl_ent_t, char *);
void delete_plist(package_t *pkg, Boolean all, pl_ent_t type, char *name);
void write_plist(package_t *, FILE *);
void read_plist(package_t *, FILE *);
int plist_cmd(char *, char **);
int delete_package(Boolean, Boolean, package_t *);
/* Package Database */
int pkgdb_open(int);
void pkgdb_close(void);
int pkgdb_store(const char *, const char *);
char* pkgdb_retrieve(const char *);
int pkgdb_remove(const char *);
char* pkgdb_iter(void);
char* _pkgdb_getPKGDB_FILE(void);
char* _pkgdb_getPKGDB_DIR(void);
int pkgdb_open(int);
void pkgdb_close(void);
int pkgdb_store(const char *, const char *);
char *pkgdb_retrieve(const char *);
int pkgdb_remove(const char *);
char *pkgdb_iter(void);
char *_pkgdb_getPKGDB_FILE(void);
char *_pkgdb_getPKGDB_DIR(void);
/* List of packages functions */
lpkg_t *alloc_lpkg(const char *);
lpkg_t *find_on_queue(lpkg_head_t *, const char *);
void free_lpkg(lpkg_t *);
lpkg_t *alloc_lpkg(const char *);
lpkg_t *find_on_queue(lpkg_head_t *, const char *);
void free_lpkg(lpkg_t *);
/* For all */
int pkg_perform(lpkg_head_t *);
int pkg_perform(lpkg_head_t *);
/* Externs */
extern Boolean Verbose;
extern Boolean Fake;
extern Boolean Force;
extern Boolean Verbose;
extern Boolean Fake;
extern Boolean Force;
#endif /* _INST_LIB_LIB_H_ */
#endif /* _INST_LIB_LIB_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: lpkg.c,v 1.1 1999/03/22 05:02:41 hubertf Exp $ */
/* $NetBSD: lpkg.c,v 1.2 1999/08/24 00:48:39 hubertf Exp $ */
/*
* Copyright (c) 1999 Christian E. Hopps
@ -32,33 +32,35 @@
#include <err.h>
#include "lib.h"
/* add a package to the recursive delete list */
/*
* Add a package to the recursive delete list
*/
lpkg_t *
alloc_lpkg(const char *pkgname)
{
lpkg_t *lpp;
lpkg_t *lpp;
if ((lpp = malloc(sizeof(*lpp))) == 0)
err(1, "cannot allocate recursion data");
if ((lpp->lp_name = strdup(pkgname)) == 0)
err(1, "cannot allocate recursion data");
return (lpp);
if ((lpp = malloc(sizeof(*lpp))) == 0)
err(1, "cannot allocate recursion data");
if ((lpp->lp_name = strdup(pkgname)) == 0)
err(1, "cannot allocate recursion data");
return (lpp);
}
void
free_lpkg(lpkg_t *lpp)
{
free(lpp->lp_name);
free(lpp);
free(lpp->lp_name);
free(lpp);
}
lpkg_t *
find_on_queue(lpkg_head_t *qp, const char *name)
{
lpkg_t *lpp;
lpkg_t *lpp;
for (lpp = TAILQ_FIRST(qp); lpp; lpp = TAILQ_NEXT(lpp, lp_link))
if (!strcmp(name, lpp->lp_name))
return (lpp);
return (0);
for (lpp = TAILQ_FIRST(qp); lpp; lpp = TAILQ_NEXT(lpp, lp_link))
if (!strcmp(name, lpp->lp_name))
return (lpp);
return (0);
}

View File

@ -1,11 +1,11 @@
/* $NetBSD: pen.c,v 1.15 1999/03/02 03:04:06 hubertf Exp $ */
/* $NetBSD: pen.c,v 1.16 1999/08/24 00:48:39 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: pen.c,v 1.25 1997/10/08 07:48:12 charnier Exp";
#else
__RCSID("$NetBSD: pen.c,v 1.15 1999/03/02 03:04:06 hubertf Exp $");
__RCSID("$NetBSD: pen.c,v 1.16 1999/08/24 00:48:39 hubertf Exp $");
#endif
#endif
@ -38,153 +38,171 @@ __RCSID("$NetBSD: pen.c,v 1.15 1999/03/02 03:04:06 hubertf Exp $");
/* For keeping track of where we are */
static char Current[FILENAME_MAX];
static char Previous[FILENAME_MAX];
static int CurrentSet; /* rm -rf Current only if it's really set! */
static int CurrentSet; /* rm -rf Current only if it's really set! */
/* CurrentSet is set to 0 before strcpy()s
* to prevent rm'ing of a partial string
* when interrupted by ^C */
/* Backup Current and Previous into temp. strings that are later
/*
* Backup Current and Previous into temp. strings that are later
* restored & freed by restore_dirs
* This is to make nested calls to makeplaypen/leave_playpen work
*/
void
save_dirs(char **c, char **p)
{
*c=strdup(Current); /* XXX */
*p=strdup(Previous);
*c = strdup(Current); /* XXX */
*p = strdup(Previous);
}
/* Restore Current and Previous from temp strings that were created
/*
* Restore Current and Previous from temp strings that were created
* by safe_dirs.
* This is to make nested calls to makeplaypen/leave_playpen work
*/
void
restore_dirs(char *c, char *p)
{
CurrentSet=0; strcpy(Current, c); free(c); CurrentSet=1;
strcpy(Previous, p); free(p);
CurrentSet = 0; /* prevent from deleting */
strcpy(Current, c);
CurrentSet = 1; /* rm -fr Current is safe now */
free(c);
strcpy(Previous, p);
free(p);
}
char *
char *
where_playpen(void)
{
return Current;
return Current;
}
/* Find a good place to play. */
/*
* Find a good place to play.
*/
static char *
find_play_pen(char *pen, size_t pensize, size_t sz)
{
char *cp;
struct stat sb;
char *cp;
struct stat sb;
if (pen[0] && stat(pen, &sb) != FAIL && (min_free(pen) >= sz))
if (pen[0] && stat(pen, &sb) != FAIL && (min_free(pen) >= sz))
return pen;
else if ((cp = getenv("PKG_TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz))
(void) snprintf(pen, pensize, "%s/instmp.XXXXXX", cp);
else if ((cp = getenv("TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz))
(void) snprintf(pen, pensize, "%s/instmp.XXXXXX", cp);
else if (stat("/var/tmp", &sb) != FAIL && min_free("/var/tmp") >= sz)
strcpy(pen, "/var/tmp/instmp.XXXXXX");
else if (stat("/tmp", &sb) != FAIL && min_free("/tmp") >= sz)
strcpy(pen, "/tmp/instmp.XXXXXX");
else if ((stat("/usr/tmp", &sb) == SUCCESS || mkdir("/usr/tmp", 01777) == SUCCESS) && min_free("/usr/tmp") >= sz)
strcpy(pen, "/usr/tmp/instmp.XXXXXX");
else {
cleanup(0);
errx(2,
"can't find enough temporary space to extract the files, please set your\n"
"PKG_TMPDIR environment variable to a location with at least %lu bytes\n"
"free", (u_long) sz);
return NULL;
}
return pen;
else if ((cp = getenv("PKG_TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz))
(void) snprintf(pen, pensize, "%s/instmp.XXXXXX", cp);
else if ((cp = getenv("TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz))
(void) snprintf(pen, pensize, "%s/instmp.XXXXXX", cp);
else if (stat("/var/tmp", &sb) != FAIL && min_free("/var/tmp") >= sz)
strcpy(pen, "/var/tmp/instmp.XXXXXX");
else if (stat("/tmp", &sb) != FAIL && min_free("/tmp") >= sz)
strcpy(pen, "/tmp/instmp.XXXXXX");
else if ((stat("/usr/tmp", &sb) == SUCCESS || mkdir("/usr/tmp", 01777) == SUCCESS) && min_free("/usr/tmp") >= sz)
strcpy(pen, "/usr/tmp/instmp.XXXXXX");
else {
cleanup(0);
errx(2,
"can't find enough temporary space to extract the files, please set your\n"
"PKG_TMPDIR environment variable to a location with at least %lu bytes\n"
"free", (u_long)sz);
return NULL;
}
return pen;
}
/*
* Make a temporary directory to play in and chdir() to it, returning
* pathname of previous working directory.
*/
char *
char *
make_playpen(char *pen, size_t pensize, size_t sz)
{
if (!find_play_pen(pen, pensize, sz))
return NULL;
if (!find_play_pen(pen, pensize, sz))
return NULL;
#if (defined(NetBSD1_3) || (NetBSD <= 199713)) && (NetBSD1_3 <9)
/* values from 1.3.2/1.3I */
/* mkdtemp(3) is not present on 1.3.3 and below */
if (!mktemp(pen)) {
cleanup(0);
errx(2, "can't mktemp '%s'", pen);
}
if (mkdir(pen, 0755) == FAIL) {
cleanup(0);
errx(2, "can't mkdir '%s'", pen);
}
/* values from 1.3.2/1.3I */
/* mkdtemp(3) is not present on 1.3.3 and below */
if (!mktemp(pen)) {
cleanup(0);
errx(2, "can't mktemp '%s'", pen);
}
if (mkdir(pen, 0755) == FAIL) {
cleanup(0);
errx(2, "can't mkdir '%s'", pen);
}
#else
if (!mkdtemp(pen)) {
cleanup(0);
errx(2, "can't mkdtemp '%s'", pen);
}
if (!mkdtemp(pen)) {
cleanup(0);
errx(2, "can't mkdtemp '%s'", pen);
}
#endif
if (Verbose) {
if (sz)
fprintf(stderr, "Requested space: %lu bytes, free space: %qd bytes in %s\n", (u_long)sz, (long long)min_free(pen), pen);
}
if (min_free(pen) < sz) {
rmdir(pen);
cleanup(0);
errx(2, "not enough free space to create '%s'.\n"
"Please set your PKG_TMPDIR environment variable to a location\n"
"with more space and\ntry the command again", pen);
}
if (Current[0])
strcpy(Previous, Current);
else if (!getcwd(Previous, FILENAME_MAX)) {
cleanup(0);
err(1, "fatal error during execution: getcwd");
}
if (chdir(pen) == FAIL) {
cleanup(0);
errx(2, "can't chdir to '%s'", pen);
}
strcpy(Current, pen); CurrentSet=1;
return Previous;
if (Verbose) {
if (sz)
fprintf(stderr, "Requested space: %lu bytes, free space: %qd bytes in %s\n", (u_long) sz, (long long) min_free(pen), pen);
}
if (min_free(pen) < sz) {
rmdir(pen);
cleanup(0);
errx(2, "not enough free space to create '%s'.\n"
"Please set your PKG_TMPDIR environment variable to a location\n"
"with more space and\ntry the command again", pen);
}
if (Current[0])
strcpy(Previous, Current);
else if (!getcwd(Previous, FILENAME_MAX)) {
cleanup(0);
err(1, "fatal error during execution: getcwd");
}
if (chdir(pen) == FAIL) {
cleanup(0);
errx(2, "can't chdir to '%s'", pen);
}
strcpy(Current, pen); CurrentSet = 1;
return Previous;
}
/* Convenience routine for getting out of playpen */
/*
* Convenience routine for getting out of playpen
*/
void
leave_playpen(char *save)
{
void (*oldsig)(int);
void (*oldsig) (int);
/* Make us interruptable while we're cleaning up - just in case... */
oldsig = signal(SIGINT, SIG_DFL);
if (Previous[0] && chdir(Previous) == FAIL) {
cleanup(0);
errx(2, "can't chdir back to '%s'", Previous);
} else if (CurrentSet && Current[0] && strcmp(Current, Previous)) {
if (strcmp(Current,"/")==0) {
fprintf(stderr,"PANIC: About to rm -rf / (not doing so, aborting)\n");
abort();
}
if (vsystem("rm -rf %s", Current))
warnx("couldn't remove temporary dir '%s'", Current);
strcpy(Current, Previous);
}
if (save)
strcpy(Previous, save);
else
Previous[0] = '\0';
signal(SIGINT, oldsig);
/* Make us interruptable while we're cleaning up - just in case... */
oldsig = signal(SIGINT, SIG_DFL);
if (Previous[0] && chdir(Previous) == FAIL) {
cleanup(0);
errx(2, "can't chdir back to '%s'", Previous);
} else if (CurrentSet && Current[0] && strcmp(Current, Previous)) {
if (strcmp(Current, "/") == 0) {
fprintf(stderr, "PANIC: About to rm -rf / (not doing so, aborting)\n");
abort();
}
if (vsystem("rm -rf %s", Current))
warnx("couldn't remove temporary dir '%s'", Current);
strcpy(Current, Previous);
}
if (save)
strcpy(Previous, save);
else
Previous[0] = '\0';
signal(SIGINT, oldsig);
}
/*
* Return free disk space (in bytes) on given file system
*/
off_t
min_free(char *tmpdir)
{
struct statfs buf;
struct statfs buf;
if (statfs(tmpdir, &buf) != 0) {
warn("statfs");
return -1;
}
return (off_t)buf.f_bavail * (off_t)buf.f_bsize;
if (statfs(tmpdir, &buf) != 0) {
warn("statfs");
return -1;
}
return (off_t) buf.f_bavail * (off_t) buf.f_bsize;
}

View File

@ -1,8 +1,8 @@
/* $NetBSD: pkgdb.c,v 1.3 1999/03/01 12:06:57 agc Exp $ */
/* $NetBSD: pkgdb.c,v 1.4 1999/08/24 00:48:40 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: pkgdb.c,v 1.3 1999/03/01 12:06:57 agc Exp $");
__RCSID("$NetBSD: pkgdb.c,v 1.4 1999/08/24 00:48:40 hubertf Exp $");
#endif
/*
@ -57,24 +57,24 @@ static int pkgdb_iter_flag;
int
pkgdb_open(int ro)
{
BTREEINFO info;
pkgdb_iter_flag=0; /* used in pkgdb_iter() */
BTREEINFO info;
/* try our btree format first */
info.flags = 0;
info.cachesize = 0;
info.maxkeypage = 0;
info.minkeypage = 0;
info.psize = 0;
info.compare = NULL;
info.prefix = NULL;
info.lorder = 0;
pkgdbp = (DB *)dbopen(_pkgdb_getPKGDB_FILE(),
ro?O_RDONLY:O_RDWR|O_CREAT,
0644, DB_BTREE, (void *)&info);
return (pkgdbp==NULL)?-1:0;
}
pkgdb_iter_flag = 0; /* used in pkgdb_iter() */
/* try our btree format first */
info.flags = 0;
info.cachesize = 0;
info.maxkeypage = 0;
info.minkeypage = 0;
info.psize = 0;
info.compare = NULL;
info.prefix = NULL;
info.lorder = 0;
pkgdbp = (DB *) dbopen(_pkgdb_getPKGDB_FILE(),
ro ? O_RDONLY : O_RDWR | O_CREAT,
0644, DB_BTREE, (void *) &info);
return (pkgdbp == NULL) ? -1 : 0;
}
/*
* Close the pkg database
@ -82,8 +82,8 @@ pkgdb_open(int ro)
void
pkgdb_close(void)
{
if (pkgdbp != NULL)
(void)(pkgdbp->close)(pkgdbp);
if (pkgdbp != NULL)
(void) (pkgdbp->close) (pkgdbp);
}
/*
@ -96,20 +96,20 @@ pkgdb_close(void)
int
pkgdb_store(const char *key, const char *val)
{
DBT keyd, vald;
if (pkgdbp == NULL)
return -1;
keyd.data = (void *) key;
keyd.size = strlen(key) + 1;
vald.data = (void *) val;
vald.size = strlen(val) + 1;
DBT keyd, vald;
if (keyd.size > FILENAME_MAX || vald.size > FILENAME_MAX)
return -1;
if (pkgdbp == NULL)
return -1;
return (pkgdbp->put)(pkgdbp, &keyd, &vald, R_NOOVERWRITE);
keyd.data = (void *) key;
keyd.size = strlen(key) + 1;
vald.data = (void *) val;
vald.size = strlen(val) + 1;
if (keyd.size > FILENAME_MAX || vald.size > FILENAME_MAX)
return -1;
return (pkgdbp->put) (pkgdbp, &keyd, &vald, R_NOOVERWRITE);
}
/*
@ -118,30 +118,31 @@ pkgdb_store(const char *key, const char *val)
* NULL if some error occurred or value for key not found (check errno!)
* String for "value" else
*/
char *
char *
pkgdb_retrieve(const char *key)
{
DBT keyd, vald;
int status;
if (pkgdbp == NULL)
return NULL;
keyd.data=(void *)key; keyd.size=strlen(key)+1;
errno=0; /* to be sure it's 0 if the key doesn't match anything */
DBT keyd, vald;
int status;
status = (pkgdbp->get)(pkgdbp, &keyd, &vald, 0);
if (status) {
vald.data = NULL;
vald.size = 0;
}
return vald.data;
if (pkgdbp == NULL)
return NULL;
keyd.data = (void *) key;
keyd.size = strlen(key) + 1;
errno = 0; /* to be sure it's 0 if the key doesn't match anything */
status = (pkgdbp->get) (pkgdbp, &keyd, &vald, 0);
if (status) {
vald.data = NULL;
vald.size = 0;
}
return vald.data;
}
/*
* Remove data set from pkgdb
* Return value as ypdb_delete:
* Return value as ypdb_delete:
* 0: everything ok
* 1: key not present
* -1: some error occured (see errno)
@ -149,26 +150,26 @@ pkgdb_retrieve(const char *key)
int
pkgdb_remove(const char *key)
{
DBT keyd;
int status;
if (pkgdbp == NULL)
return -1;
DBT keyd;
int status;
keyd.data=(char *)key;
keyd.size=strlen(key)+1;
if (keyd.size > FILENAME_MAX)
return -1;
errno=0;
status = (pkgdbp->del)(pkgdbp, &keyd, 0);
if (status) {
if (errno)
return -1; /* error */
else
return 1; /* key not present */
} else
return 0; /* everything fine */
if (pkgdbp == NULL)
return -1;
keyd.data = (char *) key;
keyd.size = strlen(key) + 1;
if (keyd.size > FILENAME_MAX)
return -1;
errno = 0;
status = (pkgdbp->del) (pkgdbp, &keyd, 0);
if (status) {
if (errno)
return -1; /* error */
else
return 1; /* key not present */
} else
return 0; /* everything fine */
}
/*
@ -177,52 +178,52 @@ pkgdb_remove(const char *key)
* NULL if no more data is available
* !NULL else
*/
char *
char *
pkgdb_iter(void)
{
DBT key, val;
int status;
if (pkgdb_iter_flag == 0) {
pkgdb_iter_flag = 1;
DBT key, val;
int status;
status = (pkgdbp->seq)(pkgdbp, &key, &val, R_FIRST);
} else
status = (pkgdbp->seq)(pkgdbp, &key, &val, R_NEXT);
if (status)
key.data = NULL;
return (char *) key.data;
if (pkgdb_iter_flag == 0) {
pkgdb_iter_flag = 1;
status = (pkgdbp->seq) (pkgdbp, &key, &val, R_FIRST);
} else
status = (pkgdbp->seq) (pkgdbp, &key, &val, R_NEXT);
if (status)
key.data = NULL;
return (char *) key.data;
}
/*
* return filename as string that can be passed to free(3)
* Return filename as string that can be passed to free(3)
*/
char *
char *
_pkgdb_getPKGDB_FILE(void)
{
char *tmp;
char *tmp;
tmp=malloc(FILENAME_MAX);
if (tmp==NULL)
errx(1, "_pkgdb_getPKGDB_FILE: out of memory");
snprintf(tmp, FILENAME_MAX, "%s/%s", _pkgdb_getPKGDB_DIR(), PKGDB_FILE);
return tmp;
tmp = malloc(FILENAME_MAX);
if (tmp == NULL)
errx(1, "_pkgdb_getPKGDB_FILE: out of memory");
snprintf(tmp, FILENAME_MAX, "%s/%s", _pkgdb_getPKGDB_DIR(), PKGDB_FILE);
return tmp;
}
/*
* return directory where pkgdb is stored
* Return directory where pkgdb is stored
* as string that can be passed to free(3)
*/
char *
char *
_pkgdb_getPKGDB_DIR(void)
{
char *tmp;
static char *cache=NULL;
char *tmp;
static char *cache = NULL;
if (cache == NULL)
cache = (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR;
return cache;
if (cache == NULL)
cache = (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR;
return cache;
}

View File

@ -1,11 +1,11 @@
/* $NetBSD: plist.c,v 1.21 1999/06/18 09:50:35 mrg Exp $ */
/* $NetBSD: plist.c,v 1.22 1999/08/24 00:48:40 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: plist.c,v 1.24 1997/10/08 07:48:15 charnier Exp";
#else
__RCSID("$NetBSD: plist.c,v 1.21 1999/06/18 09:50:35 mrg Exp $");
__RCSID("$NetBSD: plist.c,v 1.22 1999/08/24 00:48:40 hubertf Exp $");
#endif
#endif
@ -34,37 +34,39 @@ __RCSID("$NetBSD: plist.c,v 1.21 1999/06/18 09:50:35 mrg Exp $");
#include <err.h>
#include <md5.h>
/* this struct defines a plist command type */
/* This struct defines a plist command type */
typedef struct cmd_t {
char *c_s; /* string to recognise */
pl_ent_t c_type; /* type of command */
int c_argc; /* # of arguments */
} cmd_t;
char *c_s; /* string to recognise */
pl_ent_t c_type; /* type of command */
int c_argc; /* # of arguments */
} cmd_t;
/* commands to recognise */
static cmd_t cmdv[] = {
{ "cwd", PLIST_CWD, 1 },
{ "src", PLIST_SRC, 1 },
{ "cd", PLIST_CWD, 1 },
{ "exec", PLIST_CMD, 1 },
{ "unexec", PLIST_UNEXEC, 1 },
{ "mode", PLIST_CHMOD, 1 },
{ "owner", PLIST_CHOWN, 1 },
{ "group", PLIST_CHGRP, 1 },
{ "comment", PLIST_COMMENT, 1 },
{ "ignore", PLIST_IGNORE, 0 },
{ "ignore_inst", PLIST_IGNORE_INST, 0 },
{ "name", PLIST_NAME, 1 },
{ "display", PLIST_DISPLAY, 1 },
{ "pkgdep", PLIST_PKGDEP, 1 },
{ "pkgcfl", PLIST_PKGCFL, 1 },
{ "mtree", PLIST_MTREE, 1 },
{ "dirrm", PLIST_DIR_RM, 1 },
{ "option", PLIST_OPTION, 1 },
{ NULL, FAIL, 0 }
/* Commands to recognise */
static cmd_t cmdv[] = {
{"cwd", PLIST_CWD, 1},
{"src", PLIST_SRC, 1},
{"cd", PLIST_CWD, 1},
{"exec", PLIST_CMD, 1},
{"unexec", PLIST_UNEXEC, 1},
{"mode", PLIST_CHMOD, 1},
{"owner", PLIST_CHOWN, 1},
{"group", PLIST_CHGRP, 1},
{"comment", PLIST_COMMENT, 1},
{"ignore", PLIST_IGNORE, 0},
{"ignore_inst", PLIST_IGNORE_INST, 0},
{"name", PLIST_NAME, 1},
{"display", PLIST_DISPLAY, 1},
{"pkgdep", PLIST_PKGDEP, 1},
{"pkgcfl", PLIST_PKGCFL, 1},
{"mtree", PLIST_MTREE, 1},
{"dirrm", PLIST_DIR_RM, 1},
{"option", PLIST_OPTION, 1},
{NULL, FAIL, 0}
};
/* Add an item to the end of a packing list */
/*
* Add an item to the end of a packing list
*/
void
add_plist(package_t *p, pl_ent_t type, char *arg)
{
@ -82,7 +84,9 @@ add_plist(package_t *p, pl_ent_t type, char *arg)
}
}
/* add an item to the start of a packing list */
/*
* Add an item to the start of a packing list
*/
void
add_plist_top(package_t *p, pl_ent_t type, char *arg)
{
@ -100,46 +104,56 @@ add_plist_top(package_t *p, pl_ent_t type, char *arg)
}
}
/* Return the last (most recent) entry in a packing list */
/*
* Return the last (most recent) entry in a packing list
*/
plist_t *
last_plist(package_t *p)
{
return p->tail;
}
/* Mark all items in a packing list to prevent iteration over them */
/*
* Mark all items in a packing list to prevent iteration over them
*/
void
mark_plist(package_t *pkg)
{
plist_t *pp;
plist_t *pp;
for (pp = pkg->head ; pp ; pp = pp->next) {
for (pp = pkg->head; pp; pp = pp->next) {
pp->marked = TRUE;
}
}
/* Find a given item in a packing list and, if so, return it (else NULL) */
/*
* Find a given item in a packing list and, if so, return it (else NULL)
*/
plist_t *
find_plist(package_t *pkg, pl_ent_t type)
{
plist_t *pp;
plist_t *pp;
for (pp = pkg->head ; pp && pp->type != type ; pp = pp->next) {
for (pp = pkg->head; pp && pp->type != type; pp = pp->next) {
}
return pp;
}
/* Look for a specific boolean option argument in the list */
char *
/*
* Look for a specific boolean option argument in the list
*/
char *
find_plist_option(package_t *pkg, char *name)
{
plist_t *p;
plist_t *p;
for (p = pkg->head ; p ; p = p->next) {
if (p->type == PLIST_OPTION && strcmp(p->name, name) == 0) {
for (p = pkg->head; p; p = p->next) {
if (p->type == PLIST_OPTION
&& strcmp(p->name, name) == 0) {
return p->name;
}
}
return (char *) NULL;
}
@ -150,77 +164,80 @@ find_plist_option(package_t *pkg, char *name)
void
delete_plist(package_t *pkg, Boolean all, pl_ent_t type, char *name)
{
plist_t *p = pkg->head;
plist_t *p = pkg->head;
while (p) {
plist_t *pnext = p->next;
while (p) {
plist_t *pnext = p->next;
if (p->type == type && (!name || !strcmp(name, p->name))) {
free(p->name);
if (p->prev)
p->prev->next = pnext;
else
pkg->head = pnext;
if (pnext)
pnext->prev = p->prev;
else
pkg->tail = p->prev;
free(p);
if (!all)
return;
p = pnext;
if (p->type == type && (!name || !strcmp(name, p->name))) {
free(p->name);
if (p->prev)
p->prev->next = pnext;
else
pkg->head = pnext;
if (pnext)
pnext->prev = p->prev;
else
pkg->tail = p->prev;
free(p);
if (!all)
return;
p = pnext;
} else
p = p->next;
}
else
p = p->next;
}
}
/* Allocate a new packing list entry */
/*
* Allocate a new packing list entry, and return a pointer to it.
*/
plist_t *
new_plist_entry(void)
{
plist_t *ret;
if ((ret = (plist_t *)malloc(sizeof(plist_t))) == (plist_t *) NULL) {
if ((ret = (plist_t *) malloc(sizeof(plist_t))) == (plist_t *) NULL) {
err(1, "can't allocate %ld bytes", (long) sizeof(plist_t));
}
memset(ret, 0, sizeof(plist_t));
return ret;
}
/* Free an entire packing list */
/*
* Free an entire packing list
*/
void
free_plist(package_t *pkg)
{
plist_t *p = pkg->head;
plist_t *p = pkg->head;
while (p) {
plist_t *p1 = p->next;
while (p) {
plist_t *p1 = p->next;
free(p->name);
free(p);
p = p1;
}
pkg->head = pkg->tail = NULL;
free(p->name);
free(p);
p = p1;
}
pkg->head = pkg->tail = NULL;
}
/*
* For an ascii string denoting a plist command, return its code and
* For an ASCII string denoting a plist command, return its code and
* optionally its argument(s)
*/
int
plist_cmd(char *s, char **arg)
{
cmd_t *cmdp;
char cmd[FILENAME_MAX + 20]; /* 20 == fudge for max cmd len */
char *cp;
char *sp;
cmd_t *cmdp;
char cmd[FILENAME_MAX + 20]; /* 20 == fudge for max cmd len */
char *cp;
char *sp;
(void) strcpy(cmd, s);
str_lowercase(cmd);
for (cp = cmd, sp = s ; *cp ; cp++, sp++) {
if (isspace((unsigned char)*cp)) {
for (*cp = '\0'; isspace((unsigned char)*sp); sp++) {
for (cp = cmd, sp = s; *cp; cp++, sp++) {
if (isspace((unsigned char) *cp)) {
for (*cp = '\0'; isspace((unsigned char) *sp); sp++) {
}
break;
}
@ -228,23 +245,25 @@ plist_cmd(char *s, char **arg)
if (arg) {
*arg = sp;
}
for (cmdp = cmdv ; cmdp->c_s && strcmp(cmdp->c_s, cmd) != 0 ; cmdp++) {
for (cmdp = cmdv; cmdp->c_s && strcmp(cmdp->c_s, cmd) != 0; cmdp++) {
}
return cmdp->c_type;
}
/* Read a packing list from a file */
/*
* Read a packing list from a file
*/
void
read_plist(package_t *pkg, FILE *fp)
read_plist(package_t *pkg, FILE * fp)
{
char pline[FILENAME_MAX];
char *cp;
int cmd;
int len;
char pline[FILENAME_MAX];
char *cp;
int cmd;
int len;
while (fgets(pline, FILENAME_MAX, fp) != (char *) NULL) {
for (len = strlen(pline); len &&
isspace((unsigned char)pline[len - 1]); ) {
isspace((unsigned char) pline[len - 1]);) {
pline[--len] = '\0';
}
if (len == 0) {
@ -265,20 +284,22 @@ read_plist(package_t *pkg, FILE *fp)
}
}
/* Write a packing list to a file, converting commands to ascii equivs */
/*
* Write a packing list to a file, converting commands to ASCII equivs
*/
void
write_plist(package_t *pkg, FILE *fp)
write_plist(package_t *pkg, FILE * fp)
{
plist_t *p;
cmd_t *cmdp;
plist_t *p;
cmd_t *cmdp;
for (p = pkg->head ; p ; p = p->next) {
for (p = pkg->head; p; p = p->next) {
if (p->type == PLIST_FILE) {
/* Fast-track files - these are the most common */
(void) fprintf(fp, "%s\n", p->name);
continue;
}
for (cmdp = cmdv ; cmdp->c_type != FAIL && cmdp->c_type != p->type ; cmdp++) {
for (cmdp = cmdv; cmdp->c_type != FAIL && cmdp->c_type != p->type; cmdp++) {
}
if (cmdp->c_type == FAIL) {
warnx("Unknown PLIST command type %d (%s)", p->type, p->name);
@ -286,7 +307,7 @@ write_plist(package_t *pkg, FILE *fp)
(void) fprintf(fp, "%c%s\n", CMD_CHAR, cmdp->c_s);
} else {
(void) fprintf(fp, "%c%s %s\n", CMD_CHAR, cmdp->c_s,
(p->name) ? p->name : "");
(p->name) ? p->name : "");
}
}
}
@ -300,131 +321,129 @@ write_plist(package_t *pkg, FILE *fp)
int
delete_package(Boolean ign_err, Boolean nukedirs, package_t *pkg)
{
plist_t *p;
char *Where = ".", *last_file = "";
int fail = SUCCESS;
Boolean preserve;
char tmp[FILENAME_MAX], *name = NULL;
plist_t *p;
char *Where = ".", *last_file = "";
int fail = SUCCESS;
Boolean preserve;
char tmp[FILENAME_MAX], *name = NULL;
if (pkgdb_open(0)==-1) {
err(1, "cannot open pkgdb");
}
preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;
for (p = pkg->head; p; p = p->next) {
switch (p->type) {
case PLIST_NAME:
name = p->name;
break;
case PLIST_IGNORE:
p = p->next;
break;
case PLIST_CWD:
Where = p->name;
if (Verbose)
printf("Change working directory to %s\n", Where);
break;
case PLIST_UNEXEC:
format_cmd(tmp, sizeof(tmp), p->name, Where, last_file);
if (Verbose)
printf("Execute `%s'\n", tmp);
if (!Fake && system(tmp)) {
warnx("unexec command for `%s' failed", tmp);
fail = FAIL;
}
break;
case PLIST_FILE:
last_file = p->name;
(void) snprintf(tmp, sizeof(tmp), "%s/%s", Where, p->name);
if (isdir(tmp)) {
warnx("attempting to delete directory `%s' as a file\n"
"this packing list is incorrect - ignoring delete request", tmp);
}
else {
if (p->next &&
p->next->type == PLIST_COMMENT &&
strncmp(p->next->name, CHECKSUM_HEADER, ChecksumHeaderLen) == 0) { /* || PLIST_MD5 - HF */
char *cp, buf[LegibleChecksumLen];
if ((cp = MD5File(tmp, buf)) != NULL) {
/* Mismatch? */
if (strcmp(cp, p->next->name + ChecksumHeaderLen) != 0) {
if (Verbose) {
printf("%s fails original MD5 checksum - %s\n",
tmp, Force ? "deleted anyway." : "not deleted.");
}
if (!Force) {
fail = FAIL;
continue;
}
}
}
}
if (Verbose)
printf("Delete file %s\n", tmp);
if (!Fake) {
int restored=0; /* restored from preserve? */
if (delete_hierarchy(tmp, ign_err, nukedirs))
fail = FAIL;
if (preserve && name) {
char tmp2[FILENAME_MAX];
if (make_preserve_name(tmp2, FILENAME_MAX, name, tmp)) {
if (fexists(tmp2)) {
if (rename(tmp2, tmp))
warn("preserve: unable to restore %s as %s",
tmp2, tmp);
else
restored=1;
}
}
}
if (!restored) {
#ifdef PKGDB_DEBUG
printf("pkgdb_remove(\"%s\")\n", tmp); /*HF*/
#endif
if (pkgdb_remove(tmp)) {
if (errno) {
perror ("pkgdb_remove");
}
} else {
#ifdef PKGDB_DEBUG
printf("pkgdb_remove: ok\n");
#endif
}
}
}
}
break;
case PLIST_DIR_RM:
(void) snprintf(tmp, sizeof(tmp), "%s/%s", Where, p->name);
if (!isdir(tmp)) {
warnx("attempting to delete file `%s' as a directory\n"
"this packing list is incorrect - ignoring delete request", tmp);
}
else {
if (Verbose)
printf("Delete directory %s\n", tmp);
if (!Fake && delete_hierarchy(tmp, ign_err, FALSE)) {
warnx("unable to completely remove directory '%s'", tmp);
fail = FAIL;
}
}
last_file = p->name;
break;
default:
break;
if (pkgdb_open(0) == -1) {
err(1, "cannot open pkgdb");
}
}
pkgdb_close();
return fail;
preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;
for (p = pkg->head; p; p = p->next) {
switch (p->type) {
case PLIST_NAME:
name = p->name;
break;
case PLIST_IGNORE:
p = p->next;
break;
case PLIST_CWD:
Where = p->name;
if (Verbose)
printf("Change working directory to %s\n", Where);
break;
case PLIST_UNEXEC:
format_cmd(tmp, sizeof(tmp), p->name, Where, last_file);
if (Verbose)
printf("Execute `%s'\n", tmp);
if (!Fake && system(tmp)) {
warnx("unexec command for `%s' failed", tmp);
fail = FAIL;
}
break;
case PLIST_FILE:
last_file = p->name;
(void) snprintf(tmp, sizeof(tmp), "%s/%s", Where, p->name);
if (isdir(tmp)) {
warnx("attempting to delete directory `%s' as a file\n"
"this packing list is incorrect - ignoring delete request", tmp);
} else {
if (p->next &&
p->next->type == PLIST_COMMENT &&
strncmp(p->next->name, CHECKSUM_HEADER, ChecksumHeaderLen) == 0) { /* || PLIST_MD5 - HF */
char *cp, buf[LegibleChecksumLen];
if ((cp = MD5File(tmp, buf)) != NULL) {
/* Mismatch? */
if (strcmp(cp, p->next->name + ChecksumHeaderLen) != 0) {
if (Verbose) {
printf("%s fails original MD5 checksum - %s\n",
tmp, Force ? "deleted anyway." : "not deleted.");
}
if (!Force) {
fail = FAIL;
continue;
}
}
}
}
if (Verbose)
printf("Delete file %s\n", tmp);
if (!Fake) {
int restored = 0; /* restored from preserve? */
if (delete_hierarchy(tmp, ign_err, nukedirs))
fail = FAIL;
if (preserve && name) {
char tmp2[FILENAME_MAX];
if (make_preserve_name(tmp2, FILENAME_MAX, name, tmp)) {
if (fexists(tmp2)) {
if (rename(tmp2, tmp))
warn("preserve: unable to restore %s as %s",
tmp2, tmp);
else
restored = 1;
}
}
}
if (!restored) {
#ifdef PKGDB_DEBUG
printf("pkgdb_remove(\"%s\")\n", tmp); /* HF */
#endif
if (pkgdb_remove(tmp)) {
if (errno) {
perror("pkgdb_remove");
}
} else {
#ifdef PKGDB_DEBUG
printf("pkgdb_remove: ok\n");
#endif
}
}
}
}
break;
case PLIST_DIR_RM:
(void) snprintf(tmp, sizeof(tmp), "%s/%s", Where, p->name);
if (!isdir(tmp)) {
warnx("attempting to delete file `%s' as a directory\n"
"this packing list is incorrect - ignoring delete request", tmp);
} else {
if (Verbose)
printf("Delete directory %s\n", tmp);
if (!Fake && delete_hierarchy(tmp, ign_err, FALSE)) {
warnx("unable to completely remove directory '%s'", tmp);
fail = FAIL;
}
}
last_file = p->name;
break;
default:
break;
}
}
pkgdb_close();
return fail;
}
#ifdef DEBUG
@ -435,49 +454,48 @@ delete_package(Boolean ign_err, Boolean nukedirs, package_t *pkg)
#define REMOVE(file,ie) (remove(file) && !(ie))
#endif
/* Selectively delete a hierarchy */
/*
* Selectively delete a hierarchy
*/
int
delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
{
char *cp1, *cp2;
char *cp1, *cp2;
cp1 = cp2 = dir;
if (!fexists(dir)) {
if (!ign_err)
warnx("%s `%s' doesn't really exist",
isdir(dir) ? "directory" : "file", dir);
return !ign_err;
}
else if (nukedirs) {
if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir))
return 1;
}
else if (isdir(dir)) {
if (RMDIR(dir) && !ign_err)
return 1;
}
else {
if (REMOVE(dir, ign_err))
return 1;
}
cp1 = cp2 = dir;
if (!fexists(dir)) {
if (!ign_err)
warnx("%s `%s' doesn't really exist",
isdir(dir) ? "directory" : "file", dir);
return !ign_err;
} else if (nukedirs) {
if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir))
return 1;
} else if (isdir(dir)) {
if (RMDIR(dir) && !ign_err)
return 1;
} else {
if (REMOVE(dir, ign_err))
return 1;
}
if (!nukedirs)
if (!nukedirs)
return 0;
while (cp2) {
if ((cp2 = strrchr(cp1, '/')) != NULL)
*cp2 = '\0';
if (!isemptydir(dir))
return 0;
if (RMDIR(dir) && !ign_err) {
if (!fexists(dir))
warnx("directory `%s' doesn't really exist", dir);
else
return 1;
}
/* back up the pathname one component */
if (cp2) {
cp1 = dir;
}
}
return 0;
while (cp2) {
if ((cp2 = strrchr(cp1, '/')) != NULL)
*cp2 = '\0';
if (!isemptydir(dir))
return 0;
if (RMDIR(dir) && !ign_err) {
if (!fexists(dir))
warnx("directory `%s' doesn't really exist", dir);
else
return 1;
}
/* back up the pathname one component */
if (cp2) {
cp1 = dir;
}
}
return 0;
}

View File

@ -1,11 +1,11 @@
/* $NetBSD: str.c,v 1.16 1999/08/19 13:30:02 agc Exp $ */
/* $NetBSD: str.c,v 1.17 1999/08/24 00:48:40 hubertf Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "Id: str.c,v 1.5 1997/10/08 07:48:21 charnier Exp";
#else
__RCSID("$NetBSD: str.c,v 1.16 1999/08/19 13:30:02 agc Exp $");
__RCSID("$NetBSD: str.c,v 1.17 1999/08/24 00:48:40 hubertf Exp $");
#endif
#endif
@ -33,22 +33,26 @@ __RCSID("$NetBSD: str.c,v 1.16 1999/08/19 13:30:02 agc Exp $");
#include <fnmatch.h>
#include "lib.h"
/* Return the filename portion of a path */
char *
/*
* Return the filename portion of a path
*/
char *
basename_of(char *str)
{
char *slash;
char *slash;
return ((slash = strrchr(str, '/')) == (char *) NULL) ? str : slash + 1;
}
/* Return the dirname portion of a path */
char *
/*
* Return the dirname portion of a path
*/
char *
dirname_of(const char *path)
{
size_t cc;
char *s;
char *t;
size_t cc;
char *s;
char *t;
if ((s = strrchr(path, '/')) == NULL) {
return ".";
@ -57,8 +61,8 @@ dirname_of(const char *path)
/* "/foo" -> return "/" */
return "/";
}
cc = (size_t)(s - path);
if ((t = (char *) malloc(cc+1)) == (char *) NULL) {
cc = (size_t) (s - path);
if ((t = (char *) malloc(cc + 1)) == (char *) NULL) {
errx(1, "out of memory in dirname_of");
}
(void) memcpy(t, path, cc);
@ -66,18 +70,22 @@ dirname_of(const char *path)
return t;
}
/* Get a string parameter as a file spec or as a "contents follow -" spec */
char *
/*
* Get a string parameter as a file spec or as a "contents follow -" spec
*/
char *
get_dash_string(char **s)
{
return *s = (**s == '-') ? strdup(*s + 1) : fileGetContents(*s);
}
/* Lowercase a whole string */
/*
* Lowercase a whole string
*/
void
str_lowercase(char *s)
{
for ( ; *s ; s++) {
for (; *s; s++) {
*s = tolower(*s);
}
}
@ -87,15 +95,17 @@ typedef enum deweyop_t {
GE,
LT,
LE
} deweyop_t;
} deweyop_t;
/* compare two dewey decimal numbers */
/*
* Compare two dewey decimal numbers
*/
static int
deweycmp(char *a, deweyop_t op, char *b)
{
int ad;
int bd;
int cmp;
int ad;
int bd;
int cmp;
for (;;) {
if (*a == 0 && *b == 0) {
@ -122,27 +132,29 @@ deweycmp(char *a, deweyop_t op, char *b)
return (op == GE) ? cmp >= 0 : (op == GT) ? cmp > 0 : (op == LE) ? cmp <= 0 : cmp < 0;
}
/* perform alternate match on "pkg" against "pattern", */
/* calling pmatch (recursively) to resolve any other patterns */
/* return 1 on match, 0 otherwise */
/*
* Perform alternate match on "pkg" against "pattern",
* calling pmatch (recursively) to resolve any other patterns.
* Return 1 on match, 0 otherwise
*/
static int
alternate_match(const char *pattern, const char *pkg)
{
char *sep;
char buf[FILENAME_MAX];
char *last;
char *alt;
char *cp;
int cnt;
int found;
char *sep;
char buf[FILENAME_MAX];
char *last;
char *alt;
char *cp;
int cnt;
int found;
if ((sep = strchr(pattern, '{')) == (char *) NULL) {
errx(1, "alternate_match(): '{' expected in `%s'", pattern);
}
(void) strncpy(buf, pattern, (size_t)(sep - pattern));
(void) strncpy(buf, pattern, (size_t) (sep - pattern));
alt = &buf[sep - pattern];
last = (char *) NULL;
for (cnt = 0, cp = sep; *cp && last == (char *) NULL ; cp++) {
for (cnt = 0, cp = sep; *cp && last == (char *) NULL; cp++) {
if (*cp == '{') {
cnt++;
} else if (*cp == '}' && --cnt == 0 && last == (char *) NULL) {
@ -168,17 +180,19 @@ alternate_match(const char *pattern, const char *pkg)
return found;
}
/* perform dewey match on "pkg" against "pattern" */
/* return 1 on match, 0 otherwise */
/*
* Perform dewey match on "pkg" against "pattern".
* Return 1 on match, 0 otherwise
*/
static int
dewey_match(const char *pattern, const char *pkg)
{
deweyop_t op;
char *cp;
char *sep;
char *ver;
char name[FILENAME_MAX];
int n;
deweyop_t op;
char *cp;
char *sep;
char *ver;
char name[FILENAME_MAX];
int n;
if ((sep = strpbrk(pattern, "<>")) == NULL) {
errx(1, "dewey_match(): '<' or '>' expected in `%s'", pattern);
@ -186,9 +200,9 @@ dewey_match(const char *pattern, const char *pkg)
(void) snprintf(name, sizeof(name), "%.*s", (int) (sep - pattern), pattern);
op = (*sep == '>') ? (*(sep + 1) == '=') ? GE : GT : (*(sep + 1) == '=') ? LE : LT;
ver = (op == GE || op == LE) ? sep + 2 : sep + 1;
n = (int)(sep - pattern);
n = (int) (sep - pattern);
if ((cp = strrchr(pkg, '-')) != (char *) NULL) {
if (strncmp(pkg, name, (size_t)(cp - pkg)) == 0 && n == cp - pkg) {
if (strncmp(pkg, name, (size_t) (cp - pkg)) == 0 && n == cp - pkg) {
if (deweycmp(cp + 1, op, ver)) {
return 1;
}
@ -197,24 +211,30 @@ dewey_match(const char *pattern, const char *pkg)
return 0;
}
/* perform glob match on "pkg" against "pattern" */
/* return 1 on match, 0 otherwise */
/*
* Perform glob match on "pkg" against "pattern".
* Return 1 on match, 0 otherwise
*/
static int
glob_match(const char *pattern, const char *pkg)
{
return fnmatch(pattern, pkg, FNM_PERIOD) == 0;
}
/* perform simple match on "pkg" against "pattern" */
/* return 1 on match, 0 otherwise */
/*
* Perform simple match on "pkg" against "pattern".
* Return 1 on match, 0 otherwise
*/
static int
simple_match(const char *pattern, const char *pkg)
{
return strcmp(pattern, pkg) == 0;
}
/* match pkg against pattern, return 1 if matching, 0 else */
int
/*
* Match pkg against pattern, return 1 if matching, 0 else
*/
int
pmatch(const char *pattern, const char *pkg)
{
if (strchr(pattern, '{') != (char *) NULL) {
@ -229,19 +249,21 @@ pmatch(const char *pattern, const char *pkg)
/* glob match */
return glob_match(pattern, pkg);
}
/* no alternate, dewey or glob match -> simple compare */
return simple_match(pattern, pkg);
}
/* search dir for pattern, calling match(pkg_found, data) for every match */
/* returns -1 on error, 1 if found, 0 otherwise. */
/*
* Search dir for pattern, calling match(pkg_found, data) for every match.
* Returns -1 on error, 1 if found, 0 otherwise.
*/
int
findmatchingname(const char *dir, const char *pattern, matchfn match, char *data)
{
struct dirent *dp;
DIR *dirp;
int found;
struct dirent *dp;
DIR *dirp;
int found;
found = 0;
if ((dirp = opendir(dir)) == (DIR *) NULL) {
@ -249,15 +271,15 @@ findmatchingname(const char *dir, const char *pattern, matchfn match, char *data
return -1;
}
while ((dp = readdir(dirp)) != (struct dirent *) NULL) {
char tmp[FILENAME_MAX];
char tmp[FILENAME_MAX];
if (strcmp(dp->d_name, ".") == 0 ||
strcmp(dp->d_name, "..") == 0)
continue;
(void) snprintf(tmp, sizeof(tmp), "%s/%s", dir, dp->d_name);
if (isfile(tmp)) /* pkgdb, ... */
continue;
if (isfile(tmp))/* pkgdb, ... */
continue;
if (pmatch(pattern, dp->d_name)) {
if (match) {
match(dp->d_name, data);
@ -267,23 +289,26 @@ findmatchingname(const char *dir, const char *pattern, matchfn match, char *data
}
}
(void) closedir(dirp);
return found;
return found;
}
/* does the pkgname contain any of the special chars ("{[]?*<>")? */
/* if so, return 1, else 0 */
/*
* Does the pkgname contain any of the special chars ("{[]?*<>")?
* If so, return 1, else 0
*/
int
ispkgpattern(const char *pkg)
{
return strpbrk(pkg, "<>[]?*{") != NULL;
}
/* auxiliary function called by findbestmatchingname() */
/* if pkg > data */
/*
* Auxiliary function called by findbestmatchingname() if pkg > data
*/
static int
findbestmatchingname_fn(const char *pkg, char *data)
{
char *s1, *s2;
char *s1, *s2;
s1 = strrchr(pkg, '-') + 1;
s2 = strrchr(data, '-') + 1;
@ -294,16 +319,18 @@ findbestmatchingname_fn(const char *pkg, char *data)
return 0;
}
/* find best matching filename, i.e. the pkg with the highest
* matching(!) version */
/* returns pointer to pkg name (which can be free(3)ed),
* or NULL if no match is available. */
char *
/*
* Find best matching filename, i.e. the pkg with the highest
* matching(!) version.
* Returns pointer to pkg name (which can be free(3)ed),
* or NULL if no match is available.
*/
char *
findbestmatchingname(const char *dir, const char *pattern)
{
char buf[FILENAME_MAX];
char buf[FILENAME_MAX];
buf[0]='\0';
buf[0] = '\0';
if (findmatchingname(dir, pattern, findbestmatchingname_fn, buf) > 0
&& buf[0] != '\0') {
return strdup(buf);
@ -311,11 +338,13 @@ findbestmatchingname(const char *dir, const char *pattern)
return NULL;
}
/* bounds-checking strncpy */
char *
/*
* Bounds-checking strncpy()
*/
char *
strnncpy(char *to, size_t tosize, char *from, size_t cc)
{
size_t len;
size_t len;
if ((len = cc) >= tosize - 1) {
len = tosize - 1;