1998-10-09 23:51:21 +04:00
|
|
|
/* $NetBSD: plist.c,v 1.13 1998/10/09 19:51:21 agc Exp $ */
|
1997-06-05 16:59:18 +04:00
|
|
|
|
1997-10-17 18:53:18 +04:00
|
|
|
#include <sys/cdefs.h>
|
1997-06-05 12:54:23 +04:00
|
|
|
#ifndef lint
|
1997-06-05 16:59:18 +04:00
|
|
|
#if 0
|
1997-10-16 04:31:32 +04:00
|
|
|
static const char *rcsid = "from FreeBSD Id: plist.c,v 1.24 1997/10/08 07:48:15 charnier Exp";
|
1997-06-05 16:59:18 +04:00
|
|
|
#else
|
1998-10-09 23:51:21 +04:00
|
|
|
__RCSID("$NetBSD: plist.c,v 1.13 1998/10/09 19:51:21 agc Exp $");
|
1997-06-05 16:59:18 +04:00
|
|
|
#endif
|
1997-06-05 12:54:23 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FreeBSD install - a package for the installation and maintainance
|
|
|
|
* of non-core utilities.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* Jordan K. Hubbard
|
|
|
|
* 18 July 1993
|
|
|
|
*
|
|
|
|
* General packing list routines.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lib.h"
|
1997-10-16 04:31:32 +04:00
|
|
|
#include <err.h>
|
1997-06-05 12:54:23 +04:00
|
|
|
#include <md5.h>
|
|
|
|
|
1998-10-09 23:51:21 +04:00
|
|
|
/* 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;
|
|
|
|
|
|
|
|
/* 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 }
|
|
|
|
};
|
|
|
|
|
1998-10-09 22:27:31 +04:00
|
|
|
/* Add an item to the end of a packing list */
|
1997-06-05 12:54:23 +04:00
|
|
|
void
|
1998-10-09 22:27:31 +04:00
|
|
|
add_plist(package_t *p, pl_ent_t type, char *arg)
|
1997-06-05 12:54:23 +04:00
|
|
|
{
|
1998-10-09 22:27:31 +04:00
|
|
|
plist_t *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;
|
|
|
|
}
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
|
1998-10-09 22:27:31 +04:00
|
|
|
/* add an item to the start of a packing list */
|
1997-06-05 12:54:23 +04:00
|
|
|
void
|
1998-10-09 22:27:31 +04:00
|
|
|
add_plist_top(package_t *p, pl_ent_t type, char *arg)
|
1997-06-05 12:54:23 +04:00
|
|
|
{
|
1998-10-09 22:27:31 +04:00
|
|
|
plist_t *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;
|
|
|
|
}
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the last (most recent) entry in a packing list */
|
1998-10-09 22:27:31 +04:00
|
|
|
plist_t *
|
|
|
|
last_plist(package_t *p)
|
1997-06-05 12:54:23 +04:00
|
|
|
{
|
1998-10-09 22:27:31 +04:00
|
|
|
return p->tail;
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark all items in a packing list to prevent iteration over them */
|
|
|
|
void
|
1998-10-09 22:27:31 +04:00
|
|
|
mark_plist(package_t *pkg)
|
1997-06-05 12:54:23 +04:00
|
|
|
{
|
1998-10-09 22:27:31 +04:00
|
|
|
plist_t *pp;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1998-10-09 22:27:31 +04:00
|
|
|
for (pp = pkg->head ; pp ; pp = pp->next) {
|
|
|
|
pp->marked = TRUE;
|
|
|
|
}
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find a given item in a packing list and, if so, return it (else NULL) */
|
1998-10-09 22:27:31 +04:00
|
|
|
plist_t *
|
|
|
|
find_plist(package_t *pkg, pl_ent_t type)
|
1997-06-05 12:54:23 +04:00
|
|
|
{
|
1998-10-09 22:27:31 +04:00
|
|
|
plist_t *pp;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1998-10-09 22:27:31 +04:00
|
|
|
for (pp = pkg->head ; pp && pp->type != type ; pp = pp->next) {
|
|
|
|
}
|
|
|
|
return pp;
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Look for a specific boolean option argument in the list */
|
|
|
|
char *
|
1998-10-09 22:27:31 +04:00
|
|
|
find_plist_option(package_t *pkg, char *name)
|
1997-06-05 12:54:23 +04:00
|
|
|
{
|
1998-10-09 23:51:21 +04:00
|
|
|
plist_t *p;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1998-10-09 23:51:21 +04:00
|
|
|
for (p = pkg->head ; p ; p = p->next) {
|
|
|
|
if (p->type == PLIST_OPTION && strcmp(p->name, name) == 0) {
|
1998-10-09 22:27:31 +04:00
|
|
|
return p->name;
|
1998-10-09 23:51:21 +04:00
|
|
|
}
|
1998-10-09 22:27:31 +04:00
|
|
|
}
|
1998-10-09 23:51:21 +04:00
|
|
|
return (char *) NULL;
|
1997-06-05 12:54:23 +04: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
|
1998-10-09 22:27:31 +04:00
|
|
|
delete_plist(package_t *pkg, Boolean all, pl_ent_t type, char *name)
|
1997-06-05 12:54:23 +04:00
|
|
|
{
|
1998-10-09 22:27:31 +04:00
|
|
|
plist_t *p = pkg->head;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
|
|
|
while (p) {
|
1998-10-09 22:27:31 +04:00
|
|
|
plist_t *pnext = p->next;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a new packing list entry */
|
1998-10-09 22:27:31 +04:00
|
|
|
plist_t *
|
1997-06-05 12:54:23 +04:00
|
|
|
new_plist_entry(void)
|
|
|
|
{
|
1998-10-09 23:51:21 +04:00
|
|
|
plist_t *ret;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1998-10-09 23:51:21 +04:00
|
|
|
if ((ret = (plist_t *)malloc(sizeof(plist_t))) == (plist_t *) NULL) {
|
|
|
|
err(1, "can't allocate %d bytes", sizeof(plist_t));
|
|
|
|
}
|
|
|
|
memset(ret, 0, sizeof(plist_t));
|
|
|
|
return ret;
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free an entire packing list */
|
|
|
|
void
|
1998-10-09 22:27:31 +04:00
|
|
|
free_plist(package_t *pkg)
|
1997-06-05 12:54:23 +04:00
|
|
|
{
|
1998-10-09 22:27:31 +04:00
|
|
|
plist_t *p = pkg->head;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
|
|
|
while (p) {
|
1998-10-09 22:27:31 +04:00
|
|
|
plist_t *p1 = p->next;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
1998-10-09 22:27:31 +04:00
|
|
|
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(*cp)) {
|
|
|
|
for (*cp = '\0'; isspace(*sp) ; sp++) {
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
1998-10-09 22:27:31 +04:00
|
|
|
if (arg) {
|
|
|
|
*arg = sp;
|
|
|
|
}
|
|
|
|
for (cmdp = cmdv ; cmdp->c_s && strcmp(cmdp->c_s, cmd) != 0 ; cmdp++) {
|
|
|
|
}
|
|
|
|
return cmdp->c_type;
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read a packing list from a file */
|
|
|
|
void
|
1998-10-09 22:27:31 +04:00
|
|
|
read_plist(package_t *pkg, FILE *fp)
|
1997-06-05 12:54:23 +04:00
|
|
|
{
|
|
|
|
char *cp, pline[FILENAME_MAX];
|
|
|
|
int cmd;
|
|
|
|
|
|
|
|
while (fgets(pline, FILENAME_MAX, fp)) {
|
|
|
|
int len = strlen(pline);
|
|
|
|
|
|
|
|
while (len && isspace(pline[len - 1]))
|
|
|
|
pline[--len] = '\0';
|
|
|
|
if (!len)
|
|
|
|
continue;
|
|
|
|
cp = pline;
|
|
|
|
if (pline[0] == CMD_CHAR) {
|
|
|
|
cmd = plist_cmd(pline + 1, &cp);
|
1998-03-27 15:16:26 +03:00
|
|
|
if (cmd == FAIL) {
|
|
|
|
warnx("Unrecognised PLIST command `%s'", pline);
|
|
|
|
continue;
|
|
|
|
}
|
1997-06-05 12:54:23 +04:00
|
|
|
if (*cp == '\0')
|
|
|
|
cp = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cmd = PLIST_FILE;
|
|
|
|
add_plist(pkg, cmd, cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write a packing list to a file, converting commands to ascii equivs */
|
|
|
|
void
|
1998-10-09 22:27:31 +04:00
|
|
|
write_plist(package_t *pkg, FILE *fp)
|
1997-06-05 12:54:23 +04:00
|
|
|
{
|
1998-10-09 23:51:21 +04:00
|
|
|
plist_t *p;
|
|
|
|
cmd_t *cmdp;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1998-10-09 23:51:21 +04:00
|
|
|
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++) {
|
|
|
|
}
|
|
|
|
if (cmdp->c_type == FAIL) {
|
|
|
|
warnx("Unknown PLIST command type %d (%s)", p->type, p->name);
|
|
|
|
} else if (cmdp->c_argc == 0) {
|
|
|
|
(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 : "");
|
|
|
|
}
|
1997-06-05 12:54:23 +04: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.
|
|
|
|
*/
|
|
|
|
int
|
1998-10-09 22:27:31 +04:00
|
|
|
delete_package(Boolean ign_err, Boolean nukedirs, package_t *pkg)
|
1997-06-05 12:54:23 +04:00
|
|
|
{
|
1998-10-09 22:27:31 +04:00
|
|
|
plist_t *p;
|
1997-06-05 12:54:23 +04:00
|
|
|
char *Where = ".", *last_file = "";
|
1998-10-08 16:15:24 +04:00
|
|
|
int fail = SUCCESS;
|
1997-10-16 04:50:20 +04:00
|
|
|
Boolean preserve;
|
|
|
|
char tmp[FILENAME_MAX], *name = NULL;
|
1997-06-05 12:54:23 +04:00
|
|
|
|
1997-10-16 04:50:20 +04:00
|
|
|
preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;
|
1997-06-05 12:54:23 +04:00
|
|
|
for (p = pkg->head; p; p = p->next) {
|
|
|
|
switch (p->type) {
|
1997-10-16 04:50:20 +04:00
|
|
|
case PLIST_NAME:
|
|
|
|
name = p->name;
|
|
|
|
break;
|
|
|
|
|
1997-06-05 12:54:23 +04:00
|
|
|
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:
|
1998-10-08 16:57:58 +04:00
|
|
|
format_cmd(tmp, sizeof(tmp), p->name, Where, last_file);
|
1997-06-05 12:54:23 +04:00
|
|
|
if (Verbose)
|
|
|
|
printf("Execute `%s'\n", tmp);
|
|
|
|
if (!Fake && system(tmp)) {
|
1997-10-16 04:31:32 +04:00
|
|
|
warnx("unexec command for `%s' failed", tmp);
|
1997-06-05 12:54:23 +04:00
|
|
|
fail = FAIL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_FILE:
|
1997-10-16 04:50:20 +04:00
|
|
|
last_file = p->name;
|
1998-10-08 16:57:58 +04:00
|
|
|
(void) snprintf(tmp, sizeof(tmp), "%s/%s", Where, p->name);
|
1997-06-05 12:54:23 +04:00
|
|
|
if (isdir(tmp)) {
|
1997-10-16 04:31:32 +04:00
|
|
|
warnx("attempting to delete directory `%s' as a file\n"
|
|
|
|
"this packing list is incorrect - ignoring delete request", tmp);
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (p->next && p->next->type == PLIST_COMMENT && !strncmp(p->next->name, "MD5:", 4)) {
|
1998-10-09 22:27:31 +04:00
|
|
|
char *cp, buf[LegibleChecksumLen];
|
1997-06-05 12:54:23 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Verbose)
|
|
|
|
printf("Delete file %s\n", tmp);
|
1997-10-16 04:50:20 +04:00
|
|
|
if (!Fake) {
|
|
|
|
if (delete_hierarchy(tmp, ign_err, nukedirs))
|
1997-06-05 12:54:23 +04:00
|
|
|
fail = FAIL;
|
1997-10-16 04:50:20 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLIST_DIR_RM:
|
1998-10-08 16:57:58 +04:00
|
|
|
(void) snprintf(tmp, sizeof(tmp), "%s/%s", Where, p->name);
|
1997-06-05 12:54:23 +04:00
|
|
|
if (!isdir(tmp)) {
|
1997-10-16 04:31:32 +04:00
|
|
|
warnx("attempting to delete file `%s' as a directory\n"
|
|
|
|
"this packing list is incorrect - ignoring delete request", tmp);
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (Verbose)
|
|
|
|
printf("Delete directory %s\n", tmp);
|
|
|
|
if (!Fake && delete_hierarchy(tmp, ign_err, FALSE)) {
|
1997-10-16 04:31:32 +04:00
|
|
|
warnx("unable to completely remove directory '%s'", tmp);
|
1997-06-05 12:54:23 +04:00
|
|
|
fail = FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last_file = p->name;
|
|
|
|
break;
|
1997-10-17 18:53:18 +04:00
|
|
|
default:
|
|
|
|
break;
|
1997-06-05 12:54:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
#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
|
|
|
|
#define REMOVE(file,ie) (remove(file) && !(ie))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Selectively delete a hierarchy */
|
|
|
|
int
|
|
|
|
delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
|
|
|
|
{
|
|
|
|
char *cp1, *cp2;
|
|
|
|
|
|
|
|
cp1 = cp2 = dir;
|
|
|
|
if (!fexists(dir)) {
|
|
|
|
if (!ign_err)
|
1997-10-16 04:31:32 +04:00
|
|
|
warnx("%s `%s' doesn't really exist",
|
|
|
|
isdir(dir) ? "directory" : "file", dir);
|
|
|
|
return !ign_err;
|
|
|
|
}
|
|
|
|
else if (nukedirs) {
|
1997-06-05 12:54:23 +04:00
|
|
|
if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir))
|
|
|
|
return 1;
|
1997-10-16 04:31:32 +04:00
|
|
|
}
|
|
|
|
else if (isdir(dir)) {
|
1997-06-05 12:54:23 +04:00
|
|
|
if (RMDIR(dir) && !ign_err)
|
|
|
|
return 1;
|
1997-10-16 04:31:32 +04:00
|
|
|
}
|
|
|
|
else {
|
1997-06-05 12:54:23 +04:00
|
|
|
if (REMOVE(dir, ign_err))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nukedirs)
|
|
|
|
return 0;
|
|
|
|
while (cp2) {
|
1997-10-18 15:05:34 +04:00
|
|
|
if ((cp2 = strrchr(cp1, '/')) != NULL)
|
1997-06-05 12:54:23 +04:00
|
|
|
*cp2 = '\0';
|
|
|
|
if (!isemptydir(dir))
|
|
|
|
return 0;
|
1998-08-28 00:31:00 +04:00
|
|
|
if (RMDIR(dir) && !ign_err) {
|
1997-06-05 12:54:23 +04:00
|
|
|
if (!fexists(dir))
|
1997-10-16 04:31:32 +04:00
|
|
|
warnx("directory `%s' doesn't really exist", dir);
|
1997-06-05 12:54:23 +04:00
|
|
|
else
|
|
|
|
return 1;
|
1998-08-28 00:31:00 +04:00
|
|
|
}
|
1997-06-05 12:54:23 +04:00
|
|
|
/* back up the pathname one component */
|
|
|
|
if (cp2) {
|
|
|
|
cp1 = dir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|