1993-08-26 01:19:55 +00:00
|
|
|
#ifndef lint
|
1997-10-08 07:48:21 +00:00
|
|
|
static const char rcsid[] =
|
1998-09-01 06:58:11 +00:00
|
|
|
"$Id: plist.c,v 1.25 1998/07/18 22:19:11 hoek Exp $";
|
1993-08-26 01:19:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FreeBSD install - a package for the installation and maintainance
|
|
|
|
* of non-core utilities.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* Jordan K. Hubbard
|
|
|
|
* 18 July 1993
|
|
|
|
*
|
|
|
|
* General packing list routines.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lib.h"
|
1997-10-08 07:48:21 +00:00
|
|
|
#include <err.h>
|
1996-07-30 10:48:20 +00:00
|
|
|
#include <md5.h>
|
1993-08-26 01:19:55 +00:00
|
|
|
|
|
|
|
/* Add an item to a packing list */
|
|
|
|
void
|
1993-09-03 23:01:17 +00:00
|
|
|
add_plist(Package *p, plist_t type, char *arg)
|
1993-08-26 01:19:55 +00:00
|
|
|
{
|
|
|
|
PackingList tmp;
|
|
|
|
|
|
|
|
tmp = new_plist_entry();
|
|
|
|
tmp->name = copy_string(arg);
|
|
|
|
tmp->type = type;
|
|
|
|
|
|
|
|
if (!p->head)
|
|
|
|
p->head = p->tail = tmp;
|
|
|
|
else {
|
|
|
|
tmp->prev = p->tail;
|
|
|
|
p->tail->next = tmp;
|
|
|
|
p->tail = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-09-03 23:01:17 +00:00
|
|
|
void
|
|
|
|
add_plist_top(Package *p, plist_t type, char *arg)
|
|
|
|
{
|
|
|
|
PackingList tmp;
|
|
|
|
|
|
|
|
tmp = new_plist_entry();
|
|
|
|
tmp->name = copy_string(arg);
|
|
|
|
tmp->type = type;
|
|
|
|
|
|
|
|
if (!p->head)
|
|
|
|
p->head = p->tail = tmp;
|
|
|
|
else {
|
|
|
|
tmp->next = p->head;
|
|
|
|
p->head->prev = tmp;
|
|
|
|
p->head = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
/* Return the last (most recent) entry in a packing list */
|
|
|
|
PackingList
|
|
|
|
last_plist(Package *p)
|
|
|
|
{
|
|
|
|
return p->tail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark all items in a packing list to prevent iteration over them */
|
|
|
|
void
|
|
|
|
mark_plist(Package *pkg)
|
|
|
|
{
|
|
|
|
PackingList p = pkg->head;
|
|
|
|
|
|
|
|
while (p) {
|
|
|
|
p->marked = TRUE;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-25 06:27:24 +00:00
|
|
|
/* Find a given item in a packing list and, if so, return it (else NULL) */
|
|
|
|
PackingList
|
|
|
|
find_plist(Package *pkg, plist_t type)
|
1993-09-03 23:01:17 +00:00
|
|
|
{
|
|
|
|
PackingList p = pkg->head;
|
|
|
|
|
|
|
|
while (p) {
|
|
|
|
if (p->type == type)
|
1994-05-25 06:27:24 +00:00
|
|
|
return p;
|
1993-09-03 23:01:17 +00:00
|
|
|
p = p->next;
|
|
|
|
}
|
1994-05-25 06:27:24 +00:00
|
|
|
return NULL;
|
1993-09-03 23:01:17 +00:00
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-04-22 07:41:02 +00:00
|
|
|
/* Look for a specific boolean option argument in the list */
|
|
|
|
char *
|
|
|
|
find_plist_option(Package *pkg, char *name)
|
|
|
|
{
|
|
|
|
PackingList p = pkg->head;
|
|
|
|
|
|
|
|
while (p) {
|
|
|
|
if (p->type == PLIST_OPTION && !strcmp(p->name, name))
|
|
|
|
return p->name;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1993-09-05 04:54:24 +00:00
|
|
|
/*
|
|
|
|
* Delete plist item 'type' in the list (if 'name' is non-null, match it
|
|
|
|
* too.) If 'all' is set, delete all items, not just the first occurance.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
delete_plist(Package *pkg, Boolean all, plist_t type, char *name)
|
|
|
|
{
|
|
|
|
PackingList p = pkg->head;
|
|
|
|
|
|
|
|
while (p) {
|
|
|
|
PackingList 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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
/* Allocate a new packing list entry */
|
|
|
|
PackingList
|
|
|
|
new_plist_entry(void)
|
|
|
|
{
|
|
|
|
PackingList ret;
|
|
|
|
|
|
|
|
ret = (PackingList)malloc(sizeof(struct _plist));
|
|
|
|
bzero(ret, sizeof(struct _plist));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free an entire packing list */
|
|
|
|
void
|
|
|
|
free_plist(Package *pkg)
|
|
|
|
{
|
|
|
|
PackingList p = pkg->head;
|
|
|
|
|
|
|
|
while (p) {
|
|
|
|
PackingList p1 = p->next;
|
|
|
|
|
|
|
|
free(p->name);
|
|
|
|
free(p);
|
|
|
|
p = p1;
|
|
|
|
}
|
|
|
|
pkg->head = pkg->tail = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For an ascii string denoting a plist command, return its code and
|
|
|
|
* optionally its argument(s)
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
plist_cmd(char *s, char **arg)
|
|
|
|
{
|
|
|
|
char cmd[FILENAME_MAX + 20]; /* 20 == fudge for max cmd len */
|
|
|
|
char *cp, *sp;
|
|
|
|
|
|
|
|
strcpy(cmd, s);
|
|
|
|
str_lowercase(cmd);
|
|
|
|
cp = cmd;
|
|
|
|
sp = s;
|
|
|
|
while (*cp) {
|
|
|
|
if (isspace(*cp)) {
|
|
|
|
*cp = '\0';
|
|
|
|
while (isspace(*sp)) /* Never sure if macro, increment later */
|
|
|
|
++sp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++cp, ++sp;
|
|
|
|
}
|
|
|
|
if (arg)
|
|
|
|
*arg = sp;
|
|
|
|
if (!strcmp(cmd, "cwd"))
|
|
|
|
return PLIST_CWD;
|
1994-08-28 14:15:30 +00:00
|
|
|
else if (!strcmp(cmd, "srcdir"))
|
|
|
|
return PLIST_SRC;
|
1993-09-03 23:01:17 +00:00
|
|
|
else if (!strcmp(cmd, "cd"))
|
|
|
|
return PLIST_CWD;
|
1993-08-26 01:19:55 +00:00
|
|
|
else if (!strcmp(cmd, "exec"))
|
|
|
|
return PLIST_CMD;
|
1993-09-18 03:39:50 +00:00
|
|
|
else if (!strcmp(cmd, "unexec"))
|
|
|
|
return PLIST_UNEXEC;
|
1993-08-26 01:19:55 +00:00
|
|
|
else if (!strcmp(cmd, "mode"))
|
|
|
|
return PLIST_CHMOD;
|
|
|
|
else if (!strcmp(cmd, "owner"))
|
|
|
|
return PLIST_CHOWN;
|
|
|
|
else if (!strcmp(cmd, "group"))
|
|
|
|
return PLIST_CHGRP;
|
|
|
|
else if (!strcmp(cmd, "comment"))
|
|
|
|
return PLIST_COMMENT;
|
|
|
|
else if (!strcmp(cmd, "ignore"))
|
|
|
|
return PLIST_IGNORE;
|
1994-12-06 00:51:50 +00:00
|
|
|
else if (!strcmp(cmd, "ignore_inst"))
|
|
|
|
return PLIST_IGNORE_INST;
|
1993-08-26 01:19:55 +00:00
|
|
|
else if (!strcmp(cmd, "name"))
|
|
|
|
return PLIST_NAME;
|
1994-12-06 00:51:50 +00:00
|
|
|
else if (!strcmp(cmd, "display"))
|
|
|
|
return PLIST_DISPLAY;
|
|
|
|
else if (!strcmp(cmd, "pkgdep"))
|
|
|
|
return PLIST_PKGDEP;
|
|
|
|
else if (!strcmp(cmd, "mtree"))
|
|
|
|
return PLIST_MTREE;
|
|
|
|
else if (!strcmp(cmd, "dirrm"))
|
|
|
|
return PLIST_DIR_RM;
|
1995-04-22 07:41:02 +00:00
|
|
|
else if (!strcmp(cmd, "option"))
|
|
|
|
return PLIST_OPTION;
|
1993-08-26 01:19:55 +00:00
|
|
|
else
|
|
|
|
return FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read a packing list from a file */
|
|
|
|
void
|
|
|
|
read_plist(Package *pkg, FILE *fp)
|
|
|
|
{
|
|
|
|
char *cp, pline[FILENAME_MAX];
|
|
|
|
int cmd;
|
|
|
|
|
|
|
|
while (fgets(pline, FILENAME_MAX, fp)) {
|
1996-07-30 10:48:20 +00:00
|
|
|
int len = strlen(pline);
|
1993-08-26 01:19:55 +00:00
|
|
|
|
1996-07-30 10:48:20 +00:00
|
|
|
while (len && isspace(pline[len - 1]))
|
|
|
|
pline[--len] = '\0';
|
|
|
|
if (!len)
|
1993-08-26 01:19:55 +00:00
|
|
|
continue;
|
|
|
|
cp = pline;
|
|
|
|
if (pline[0] == CMD_CHAR) {
|
|
|
|
cmd = plist_cmd(pline + 1, &cp);
|
|
|
|
if (cmd == FAIL)
|
1997-10-08 07:48:21 +00:00
|
|
|
cleanup(0), errx(2, "bad command '%s'", pline);
|
1993-09-18 03:39:50 +00:00
|
|
|
if (*cp == '\0')
|
|
|
|
cp = NULL;
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
else
|
1995-05-30 03:57:47 +00:00
|
|
|
cmd = PLIST_FILE;
|
1993-08-26 01:19:55 +00:00
|
|
|
add_plist(pkg, cmd, cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write a packing list to a file, converting commands to ascii equivs */
|
|
|
|
void
|
|
|
|
write_plist(Package *pkg, FILE *fp)
|
|
|
|
{
|
|
|
|
PackingList plist = pkg->head;
|
|
|
|
|
|
|
|
while (plist) {
|
|
|
|
switch(plist->type) {
|
|
|
|
case PLIST_FILE:
|
|
|
|
fprintf(fp, "%s\n", plist->name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_CWD:
|
|
|
|
fprintf(fp, "%ccwd %s\n", CMD_CHAR, plist->name);
|
|
|
|
break;
|
|
|
|
|
1994-08-28 14:15:30 +00:00
|
|
|
case PLIST_SRC:
|
|
|
|
fprintf(fp, "%csrcdir %s\n", CMD_CHAR, plist->name);
|
|
|
|
break;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
case PLIST_CMD:
|
|
|
|
fprintf(fp, "%cexec %s\n", CMD_CHAR, plist->name);
|
|
|
|
break;
|
|
|
|
|
1993-09-18 03:39:50 +00:00
|
|
|
case PLIST_UNEXEC:
|
|
|
|
fprintf(fp, "%cunexec %s\n", CMD_CHAR, plist->name);
|
|
|
|
break;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
case PLIST_CHMOD:
|
1995-11-12 04:55:40 +00:00
|
|
|
fprintf(fp, "%cmode %s\n", CMD_CHAR, plist->name ? plist->name : "");
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_CHOWN:
|
1995-11-12 04:55:40 +00:00
|
|
|
fprintf(fp, "%cowner %s\n", CMD_CHAR, plist->name ? plist->name : "");
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_CHGRP:
|
1995-11-12 04:55:40 +00:00
|
|
|
fprintf(fp, "%cgroup %s\n", CMD_CHAR, plist->name ? plist->name : "");
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_COMMENT:
|
|
|
|
fprintf(fp, "%ccomment %s\n", CMD_CHAR, plist->name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_IGNORE:
|
1994-12-06 00:51:50 +00:00
|
|
|
case PLIST_IGNORE_INST: /* a one-time non-ignored file */
|
1993-08-26 01:19:55 +00:00
|
|
|
fprintf(fp, "%cignore\n", CMD_CHAR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_NAME:
|
|
|
|
fprintf(fp, "%cname %s\n", CMD_CHAR, plist->name);
|
|
|
|
break;
|
|
|
|
|
1994-12-06 00:51:50 +00:00
|
|
|
case PLIST_DISPLAY:
|
|
|
|
fprintf(fp, "%cdisplay %s\n", CMD_CHAR, plist->name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_PKGDEP:
|
|
|
|
fprintf(fp, "%cpkgdep %s\n", CMD_CHAR, plist->name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_MTREE:
|
|
|
|
fprintf(fp, "%cmtree %s\n", CMD_CHAR, plist->name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_DIR_RM:
|
|
|
|
fprintf(fp, "%cdirrm %s\n", CMD_CHAR, plist->name);
|
|
|
|
break;
|
|
|
|
|
1995-04-22 07:41:02 +00:00
|
|
|
case PLIST_OPTION:
|
|
|
|
fprintf(fp, "%coption %s\n", CMD_CHAR, plist->name);
|
|
|
|
break;
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
default:
|
1997-10-08 07:48:21 +00:00
|
|
|
cleanup(0);
|
|
|
|
errx(2, "unknown command type %d (%s)", plist->type, plist->name);
|
1993-08-26 01:19:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
plist = plist->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-04-22 07:41:02 +00:00
|
|
|
/*
|
|
|
|
* Delete the results of a package installation.
|
|
|
|
*
|
|
|
|
* This is here rather than in the pkg_delete code because pkg_add needs to
|
|
|
|
* run it too in cases of failure.
|
|
|
|
*/
|
1994-09-29 13:19:43 +00:00
|
|
|
int
|
1994-12-06 00:51:50 +00:00
|
|
|
delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
|
1993-08-26 01:19:55 +00:00
|
|
|
{
|
1996-07-30 10:48:20 +00:00
|
|
|
PackingList p;
|
1993-09-18 03:39:50 +00:00
|
|
|
char *Where = ".", *last_file = "";
|
1994-09-29 13:19:43 +00:00
|
|
|
Boolean fail = SUCCESS;
|
1997-06-29 10:41:49 +00:00
|
|
|
Boolean preserve;
|
|
|
|
char tmp[FILENAME_MAX], *name = NULL;
|
1993-08-26 01:19:55 +00:00
|
|
|
|
1997-06-29 10:41:49 +00:00
|
|
|
preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;
|
1996-07-30 10:48:20 +00:00
|
|
|
for (p = pkg->head; p; p = p->next) {
|
|
|
|
switch (p->type) {
|
1997-06-29 10:41:49 +00:00
|
|
|
case PLIST_NAME:
|
|
|
|
name = p->name;
|
|
|
|
break;
|
|
|
|
|
1996-07-30 10:48:20 +00:00
|
|
|
case PLIST_IGNORE:
|
|
|
|
p = p->next;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_CWD:
|
1993-08-26 01:19:55 +00:00
|
|
|
Where = p->name;
|
|
|
|
if (Verbose)
|
1995-07-28 01:50:35 +00:00
|
|
|
printf("Change working directory to %s\n", Where);
|
1996-07-30 10:48:20 +00:00
|
|
|
break;
|
1993-09-18 03:39:50 +00:00
|
|
|
|
1996-07-30 10:48:20 +00:00
|
|
|
case PLIST_UNEXEC:
|
|
|
|
format_cmd(tmp, p->name, Where, last_file);
|
1993-09-18 03:39:50 +00:00
|
|
|
if (Verbose)
|
1996-07-30 10:48:20 +00:00
|
|
|
printf("Execute `%s'\n", tmp);
|
|
|
|
if (!Fake && system(tmp)) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("unexec command for `%s' failed", tmp);
|
1994-09-29 13:19:43 +00:00
|
|
|
fail = FAIL;
|
|
|
|
}
|
1996-07-30 10:48:20 +00:00
|
|
|
break;
|
1993-08-26 01:19:55 +00:00
|
|
|
|
1996-07-30 10:48:20 +00:00
|
|
|
case PLIST_FILE:
|
1997-06-30 03:15:40 +00:00
|
|
|
last_file = p->name;
|
1996-07-30 10:48:20 +00:00
|
|
|
sprintf(tmp, "%s/%s", Where, p->name);
|
|
|
|
if (isdir(tmp)) {
|
1998-07-18 22:19:11 +00:00
|
|
|
warnx("cannot delete specified file `%s' - it is a directory!\n"
|
1997-10-08 07:48:21 +00:00
|
|
|
"this packing list is incorrect - ignoring delete request", tmp);
|
1995-11-12 04:55:40 +00:00
|
|
|
}
|
|
|
|
else {
|
1996-07-30 10:48:20 +00:00
|
|
|
if (p->next && p->next->type == PLIST_COMMENT && !strncmp(p->next->name, "MD5:", 4)) {
|
|
|
|
char *cp, buf[33];
|
|
|
|
|
|
|
|
if ((cp = MD5File(tmp, buf)) != NULL) {
|
|
|
|
/* Mismatch? */
|
|
|
|
if (strcmp(cp, p->next->name + 4)) {
|
|
|
|
if (Verbose)
|
|
|
|
printf("%s fails original MD5 checksum - %s\n",
|
|
|
|
tmp, Force ? "deleted anyway." : "not deleted.");
|
|
|
|
if (!Force) {
|
|
|
|
fail = FAIL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1995-11-12 04:55:40 +00:00
|
|
|
if (Verbose)
|
1996-07-30 10:48:20 +00:00
|
|
|
printf("Delete file %s\n", tmp);
|
1997-06-30 03:15:40 +00:00
|
|
|
if (!Fake) {
|
1997-09-02 08:48:47 +00:00
|
|
|
if (delete_hierarchy(tmp, ign_err, nukedirs))
|
1997-06-30 03:15:40 +00:00
|
|
|
fail = FAIL;
|
1997-07-01 06:13:51 +00:00
|
|
|
if (preserve && name) {
|
|
|
|
char tmp2[FILENAME_MAX];
|
1997-06-30 03:15:40 +00:00
|
|
|
|
1997-07-01 06:13:51 +00:00
|
|
|
if (make_preserve_name(tmp2, FILENAME_MAX, name, tmp)) {
|
1997-06-30 03:15:40 +00:00
|
|
|
if (fexists(tmp2)) {
|
|
|
|
if (rename(tmp2, tmp))
|
1997-10-08 07:48:21 +00:00
|
|
|
warn("preserve: unable to restore %s as %s",
|
|
|
|
tmp2, tmp);
|
1997-06-30 03:15:40 +00:00
|
|
|
}
|
1997-06-29 10:41:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1996-07-30 10:48:20 +00:00
|
|
|
}
|
|
|
|
break;
|
1995-11-12 04:55:40 +00:00
|
|
|
|
1996-07-30 10:48:20 +00:00
|
|
|
case PLIST_DIR_RM:
|
|
|
|
sprintf(tmp, "%s/%s", Where, p->name);
|
1998-09-01 06:58:11 +00:00
|
|
|
if (!isdir(tmp) && fexists(tmp)) {
|
1998-07-18 22:19:11 +00:00
|
|
|
warnx("cannot delete specified directory `%s' - it is a file!\n"
|
1997-10-08 07:48:21 +00:00
|
|
|
"this packing list is incorrect - ignoring delete request", tmp);
|
1996-07-30 10:48:20 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (Verbose)
|
|
|
|
printf("Delete directory %s\n", tmp);
|
|
|
|
if (!Fake && delete_hierarchy(tmp, ign_err, FALSE)) {
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("unable to completely remove directory '%s'", tmp);
|
1995-11-12 04:55:40 +00:00
|
|
|
fail = FAIL;
|
|
|
|
}
|
1994-09-29 13:19:43 +00:00
|
|
|
}
|
1993-09-18 03:39:50 +00:00
|
|
|
last_file = p->name;
|
1996-07-30 10:48:20 +00:00
|
|
|
break;
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
}
|
1994-09-29 13:19:43 +00:00
|
|
|
return fail;
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
|
1994-12-06 00:51:50 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
#define RMDIR(dir) vsystem("%s %s", RMDIR_CMD, dir)
|
|
|
|
#define REMOVE(dir,ie) vsystem("%s %s%s", REMOVE_CMD, (ie ? "-f " : ""), dir)
|
|
|
|
#else
|
|
|
|
#define RMDIR rmdir
|
1995-04-22 00:14:20 +00:00
|
|
|
#define REMOVE(file,ie) (remove(file) && !(ie))
|
1994-12-06 00:51:50 +00:00
|
|
|
#endif
|
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
/* Selectively delete a hierarchy */
|
|
|
|
int
|
1994-12-06 00:51:50 +00:00
|
|
|
delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
|
1993-08-26 01:19:55 +00:00
|
|
|
{
|
|
|
|
char *cp1, *cp2;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1993-08-26 01:19:55 +00:00
|
|
|
cp1 = cp2 = dir;
|
1995-04-22 00:14:20 +00:00
|
|
|
if (!fexists(dir)) {
|
|
|
|
if (!ign_err)
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("%s `%s' doesn't really exist",
|
|
|
|
isdir(dir) ? "directory" : "file", dir);
|
1997-06-30 03:15:40 +00:00
|
|
|
return !ign_err;
|
|
|
|
}
|
|
|
|
else if (nukedirs) {
|
1994-12-06 00:51:50 +00:00
|
|
|
if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir))
|
|
|
|
return 1;
|
1997-06-30 03:15:40 +00:00
|
|
|
}
|
|
|
|
else if (isdir(dir)) {
|
1995-04-22 00:14:20 +00:00
|
|
|
if (RMDIR(dir) && !ign_err)
|
1994-12-06 00:51:50 +00:00
|
|
|
return 1;
|
1997-06-30 03:15:40 +00:00
|
|
|
}
|
|
|
|
else {
|
1994-12-06 00:51:50 +00:00
|
|
|
if (REMOVE(dir, ign_err))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nukedirs)
|
|
|
|
return 0;
|
1993-08-26 01:19:55 +00:00
|
|
|
while (cp2) {
|
|
|
|
if ((cp2 = rindex(cp1, '/')) != NULL)
|
|
|
|
*cp2 = '\0';
|
1994-12-06 00:51:50 +00:00
|
|
|
if (!isemptydir(dir))
|
1993-08-26 01:19:55 +00:00
|
|
|
return 0;
|
1995-04-22 00:14:20 +00:00
|
|
|
if (RMDIR(dir) && !ign_err)
|
|
|
|
if (!fexists(dir))
|
1997-10-08 07:48:21 +00:00
|
|
|
warnx("directory `%s' doesn't really exist", dir);
|
1995-04-22 00:14:20 +00:00
|
|
|
else
|
|
|
|
return 1;
|
1994-12-06 00:51:50 +00:00
|
|
|
/* back up the pathname one component */
|
1993-08-26 01:19:55 +00:00
|
|
|
if (cp2) {
|
1994-12-06 00:51:50 +00:00
|
|
|
cp1 = dir;
|
1993-08-26 01:19:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|