diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2003-08-21 20:24:58 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2003-08-21 20:24:58 +0000 |
commit | 03d67a3935b2050b48deeab6469966f06c031caf (patch) | |
tree | 50fccdd2300185f8392381e56713eb30c4f97a3b | |
parent | b53e4696177e3a83ac76f431b90d3bc1be2befcb (diff) |
New keywords: @extra and @extraunexec.
Used to record extra files (configuration) and action, that will only
be taken with pkg_delete -c.
-rw-r--r-- | usr.sbin/pkg_install/add/perform.c | 6 | ||||
-rw-r--r-- | usr.sbin/pkg_install/create/pkg_create.1 | 16 | ||||
-rw-r--r-- | usr.sbin/pkg_install/delete/delete.h | 3 | ||||
-rw-r--r-- | usr.sbin/pkg_install/delete/main.c | 12 | ||||
-rw-r--r-- | usr.sbin/pkg_install/delete/perform.c | 8 | ||||
-rw-r--r-- | usr.sbin/pkg_install/delete/pkg_delete.1 | 10 | ||||
-rw-r--r-- | usr.sbin/pkg_install/info/show.c | 10 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/file.c | 18 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/lib.h | 22 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/plist.c | 61 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/pwarnx.c | 25 |
11 files changed, 152 insertions, 39 deletions
diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c index d8f02bcd12c..4970cc91545 100644 --- a/usr.sbin/pkg_install/add/perform.c +++ b/usr.sbin/pkg_install/add/perform.c @@ -1,7 +1,7 @@ -/* $OpenBSD: perform.c,v 1.31 2003/08/16 17:31:56 deraadt Exp $ */ +/* $OpenBSD: perform.c,v 1.32 2003/08/21 20:24:56 espie Exp $ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: perform.c,v 1.31 2003/08/16 17:31:56 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: perform.c,v 1.32 2003/08/21 20:24:56 espie Exp $"; #endif /* @@ -558,7 +558,7 @@ pkg_do(char *pkg) fail: /* Nuke the whole (installed) show, XXX but don't clean directories */ if (!Fake) - delete_package(FALSE, FALSE, FALSE, &Plist); + delete_package(FALSE, FALSE, FALSE, FALSE, &Plist); success: /* delete the packing list contents */ diff --git a/usr.sbin/pkg_install/create/pkg_create.1 b/usr.sbin/pkg_install/create/pkg_create.1 index 408247686d3..09a3c768a49 100644 --- a/usr.sbin/pkg_install/create/pkg_create.1 +++ b/usr.sbin/pkg_install/create/pkg_create.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pkg_create.1,v 1.27 2003/08/15 00:03:22 espie Exp $ +.\" $OpenBSD: pkg_create.1,v 1.28 2003/08/21 20:24:56 espie Exp $ .\" .\" FreeBSD install - a package for the installation and maintenance .\" of non-core utilities. @@ -376,6 +376,20 @@ directive is used, the directories are removed in the order specified. The .Pa name directory will not be removed unless it is empty. +.It Cm @extra Ar file +Declare extra file +.Pa file +to be deleted at deinstall time, if user sets +.Fl c +option. +Those files are extra configuration files that are normally not deleted. +If +.Pa file +ends with a slash, it is a directory. +.It Cm @extraunexec Ar command +Extra +.Ar command +to execute when removing extra files. .It Cm @mtree Ar name Declare .Pa name diff --git a/usr.sbin/pkg_install/delete/delete.h b/usr.sbin/pkg_install/delete/delete.h index ff3f7f151ac..f6d9231c4aa 100644 --- a/usr.sbin/pkg_install/delete/delete.h +++ b/usr.sbin/pkg_install/delete/delete.h @@ -1,4 +1,4 @@ -/* $OpenBSD: delete.h,v 1.2 2003/08/01 08:56:01 espie Exp $ */ +/* $OpenBSD: delete.h,v 1.3 2003/08/21 20:24:56 espie Exp $ */ /* * FreeBSD install - a package for the installation and maintainance @@ -26,6 +26,7 @@ extern char *Prefix; extern Boolean NoDeInstall; extern Boolean CleanDirs; +extern Boolean CleanConf; extern Boolean CheckMD5; extern Boolean Force; extern char *Directory; diff --git a/usr.sbin/pkg_install/delete/main.c b/usr.sbin/pkg_install/delete/main.c index e587f5f5069..fa45b5dfa3e 100644 --- a/usr.sbin/pkg_install/delete/main.c +++ b/usr.sbin/pkg_install/delete/main.c @@ -1,8 +1,8 @@ -/* $OpenBSD: main.c,v 1.11 2003/08/01 08:56:01 espie Exp $ */ +/* $OpenBSD: main.c,v 1.12 2003/08/21 20:24:56 espie Exp $ */ #include <sys/cdefs.h> #ifndef lint -static const char rcsid[] = "$OpenBSD: main.c,v 1.11 2003/08/01 08:56:01 espie Exp $"; +static const char rcsid[] = "$OpenBSD: main.c,v 1.12 2003/08/21 20:24:56 espie Exp $"; #endif /* @@ -30,11 +30,12 @@ static const char rcsid[] = "$OpenBSD: main.c,v 1.11 2003/08/01 08:56:01 espie E #include "lib.h" #include "delete.h" -static char Options[] = "hvDdnfp:q"; +static char Options[] = "chvDdnfp:q"; char *Prefix = NULL; Boolean NoDeInstall = FALSE; Boolean CleanDirs = FALSE; +Boolean CleanConf = FALSE; Boolean CheckMD5 = TRUE; static void usage(void); @@ -77,6 +78,9 @@ main(int argc, char **argv) CheckMD5 = FALSE; break; + case 'c': + CleanConf = TRUE; + break; case 'h': case '?': default: @@ -110,6 +114,6 @@ main(int argc, char **argv) static void usage() { - fprintf(stderr, "usage: pkg_delete [-vDdhnfq] [-p prefix] pkg-name ...\n"); + fprintf(stderr, "usage: pkg_delete [-cvDdhnfq] [-p prefix] pkg-name ...\n"); exit(1); } diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c index 802e5c99ed3..2cf4716bf8e 100644 --- a/usr.sbin/pkg_install/delete/perform.c +++ b/usr.sbin/pkg_install/delete/perform.c @@ -1,7 +1,7 @@ -/* $OpenBSD: perform.c,v 1.15 2003/08/01 08:56:01 espie Exp $ */ +/* $OpenBSD: perform.c,v 1.16 2003/08/21 20:24:56 espie Exp $ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: perform.c,v 1.15 2003/08/01 08:56:01 espie Exp $"; +static const char rcsid[] = "$OpenBSD: perform.c,v 1.16 2003/08/21 20:24:56 espie Exp $"; #endif /* @@ -34,6 +34,7 @@ static int pkg_do(char *); static void sanity_check(char *); static int undepend(const char *, char *, int); static char LogDir[FILENAME_MAX]; +extern Boolean CleanConf; int @@ -192,6 +193,7 @@ try_again: } setenv(PKG_PREFIX_VNAME, p->name, 1); + setenv("PKG_DELETE_EXTRA", (CleanConf ? "Yes" : "No"), 1); if (fexists(REQUIRE_FNAME)) { if (Verbose) printf("Executing 'require' script.\n"); @@ -221,7 +223,7 @@ try_again: } if (!Fake) { /* Some packages aren't packed right, so we need to just ignore delete_package()'s status. Ugh! :-( */ - if (delete_package(FALSE, CleanDirs, CheckMD5, &Plist) == FAIL) + if (delete_package(FALSE, CleanDirs, CleanConf, CheckMD5, &Plist) == FAIL) pwarnx( "couldn't entirely delete package (perhaps the packing list is\n" "incorrectly specified?)"); diff --git a/usr.sbin/pkg_install/delete/pkg_delete.1 b/usr.sbin/pkg_install/delete/pkg_delete.1 index 10582b52afa..89431bdbeb3 100644 --- a/usr.sbin/pkg_install/delete/pkg_delete.1 +++ b/usr.sbin/pkg_install/delete/pkg_delete.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pkg_delete.1,v 1.16 2003/08/01 08:56:01 espie Exp $ +.\" $OpenBSD: pkg_delete.1,v 1.17 2003/08/21 20:24:56 espie Exp $ .\" .\" FreeBSD install - a package for the installation and maintenance .\" of non-core utilities. @@ -25,7 +25,7 @@ .Nd a utility for deleting previously installed software package distributions .Sh SYNOPSIS .Nm pkg_delete -.Op Fl vDdnfq +.Op Fl cvDdnfq .Op Fl p Ar prefix .Ar pkg-name Op Ar ... .Sh DESCRIPTION @@ -77,6 +77,12 @@ the package. .It Fl f Force removal of the package, even if a dependency is recorded or the deinstall or require script fails. +.It Fl c +Delete extra configuration file, mentioned as +.Bd -literal +@extra file +.Ed +in the packing-list. .It Fl q Delete package quickly, do not bother checking md5s before removing files. .El diff --git a/usr.sbin/pkg_install/info/show.c b/usr.sbin/pkg_install/info/show.c index f6c65ab862b..6e5fdd3f5e7 100644 --- a/usr.sbin/pkg_install/info/show.c +++ b/usr.sbin/pkg_install/info/show.c @@ -1,7 +1,7 @@ -/* $OpenBSD: show.c,v 1.12 2003/07/04 17:31:19 avsm Exp $ */ +/* $OpenBSD: show.c,v 1.13 2003/08/21 20:24:56 espie Exp $ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: show.c,v 1.12 2003/07/04 17:31:19 avsm Exp $"; +static const char rcsid[] = "$OpenBSD: show.c,v 1.13 2003/08/21 20:24:56 espie Exp $"; #endif /* @@ -55,6 +55,10 @@ static show_t showv[] = { { PLIST_DIR_RM, "@dirrm %s", "\tDeinstall directory remove: %s" }, { PLIST_OPTION, "@option %s", "\tPackage has option: %s" }, { PLIST_PKGCFL, "@pkgcfl %s", "\tPackage conflicts with: %s" }, + { PLIST_EXTRA, "@extra %s", "\tExtra files: %s" }, + { PLIST_EXTRAUNEXEC, + "@extraunexec %s", + "\tExtra UNEXEC: %s" }, { -1, NULL, NULL } }; @@ -150,6 +154,8 @@ show_plist(char *title, package_t *plist, pl_ent_t type) case PLIST_DIR_RM: case PLIST_OPTION: case PLIST_PKGCFL: + case PLIST_EXTRA: + case PLIST_EXTRAUNEXEC: printf(Quiet ? showv[p->type].sh_quiet : showv[p->type].sh_verbose, p->name); break; default: diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c index aff2263fa8c..ffed6a427c8 100644 --- a/usr.sbin/pkg_install/lib/file.c +++ b/usr.sbin/pkg_install/lib/file.c @@ -1,7 +1,7 @@ -/* $OpenBSD: file.c,v 1.25 2003/08/06 20:46:36 millert Exp $ */ +/* $OpenBSD: file.c,v 1.26 2003/08/21 20:24:57 espie Exp $ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: file.c,v 1.25 2003/08/06 20:46:36 millert Exp $"; +static const char rcsid[] = "$OpenBSD: file.c,v 1.26 2003/08/21 20:24:57 espie Exp $"; #endif /* @@ -105,7 +105,7 @@ ftpGetURL(char *url, int *retcode) /* Quick check to see if a file exists */ Boolean -fexists(char *fname) +fexists(const char *fname) { struct stat dummy; if (!lstat(fname, &dummy)) @@ -115,7 +115,7 @@ fexists(char *fname) /* Quick check to see if something is a directory */ Boolean -isdir(char *fname) +isdir(const char *fname) { struct stat sb; @@ -127,7 +127,7 @@ isdir(char *fname) /* Check if something is a link to a directory */ Boolean -islinktodir(char *fname) +islinktodir(const char *fname) { struct stat sb; @@ -142,7 +142,7 @@ islinktodir(char *fname) /* Check to see if file is a dir, and is empty */ Boolean -isemptydir(char *fname) +isemptydir(const char *fname) { if (isdir(fname) || islinktodir(fname)) { DIR *dirp; @@ -164,7 +164,7 @@ isemptydir(char *fname) } Boolean -isfile(char *fname) +isfile(const char *fname) { struct stat sb; if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode)) @@ -175,7 +175,7 @@ isfile(char *fname) /* 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) +isemptyfile(const char *fname) { struct stat sb; if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode)) { @@ -187,7 +187,7 @@ isemptyfile(char *fname) /* Returns TRUE if file is a URL specification */ Boolean -isURL(char *fname) +isURL(const char *fname) { /* * Hardcode url types... not perfect, but working. diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index 215489a7298..67ebf7f442b 100644 --- a/usr.sbin/pkg_install/lib/lib.h +++ b/usr.sbin/pkg_install/lib/lib.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lib.h,v 1.13 2003/08/01 08:56:01 espie Exp $ */ +/* $OpenBSD: lib.h,v 1.14 2003/08/21 20:24:57 espie Exp $ */ /* * FreeBSD install - a package for the installation and maintainance @@ -103,6 +103,8 @@ typedef enum pl_ent_t { PLIST_DIR_RM, PLIST_OPTION, PLIST_PKGCFL, + PLIST_EXTRA, + PLIST_EXTRAUNEXEC, PLIST_NEWDEP, PLIST_LIBDEP } pl_ent_t; @@ -161,14 +163,13 @@ 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 *); -Boolean isURL(char *); +Boolean fexists(const char *); +Boolean isdir(const char *); +Boolean islinktodir(const char *); +Boolean isemptydir(const char *fname); +Boolean isemptyfile(const char *fname); +Boolean isfile(const char *); +Boolean isURL(const char *); char *ensure_tgz(char *); char *fileGetURL(char *, char *); char *fileURLFilename(char *, char *, int); @@ -200,7 +201,7 @@ 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, Boolean, package_t *); +int delete_package(Boolean, Boolean, Boolean, Boolean, package_t *); /* For all */ int pkg_perform(char **); @@ -208,6 +209,7 @@ int pkg_perform(char **); void set_pkg(char *); void pwarnx(const char *, ...); +void pwarn(const char *, ...); /* Externs */ extern Boolean Verbose; diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c index d0f74efa6f6..0098aeecc10 100644 --- a/usr.sbin/pkg_install/lib/plist.c +++ b/usr.sbin/pkg_install/lib/plist.c @@ -1,6 +1,6 @@ -/* $OpenBSD: plist.c,v 1.16 2003/08/01 08:56:01 espie Exp $ */ +/* $OpenBSD: plist.c,v 1.17 2003/08/21 20:24:57 espie Exp $ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: plist.c,v 1.16 2003/08/01 08:56:01 espie Exp $"; +static const char rcsid[] = "$OpenBSD: plist.c,v 1.17 2003/08/21 20:24:57 espie Exp $"; #endif /* @@ -55,9 +55,13 @@ static cmd_t cmdv[] = { { "option", PLIST_OPTION, 1 }, { "newdepend", PLIST_NEWDEP, 1 }, { "libdepend", PLIST_LIBDEP, 1 }, + { "extra", PLIST_EXTRA, 1 }, + { "extraunexec", PLIST_EXTRAUNEXEC, 1 }, { NULL, FAIL, 0 } }; +static void delete_files(const char *); + /* Add an item to the end of a packing list */ void add_plist(package_t *p, pl_ent_t type, char *arg) @@ -290,7 +294,7 @@ write_plist(package_t *pkg, FILE *fp) * run it too in cases of failure. */ int -delete_package(Boolean ign_err, Boolean nukedirs, +delete_package(Boolean ign_err, Boolean nukedirs, Boolean remove_config, Boolean check_md5, package_t *pkg) { plist_t *p; @@ -314,6 +318,10 @@ delete_package(Boolean ign_err, Boolean nukedirs, printf("Change working directory to %s\n", Where); break; + case PLIST_EXTRAUNEXEC: + if (!remove_config) + break; + /*FALLTHRU*/ case PLIST_UNEXEC: if (!format_cmd(tmp, sizeof(tmp), p->name, Where, last_file)) { pwarnx("unexec command `%s' could not expand", p->name); @@ -360,6 +368,18 @@ delete_package(Boolean ign_err, Boolean nukedirs, } break; + case PLIST_EXTRA: + if (!remove_config) + break; + if (!p->name) + break; + if (p->name[0] == '/') + delete_files(p->name); + else { + (void) snprintf(tmp, sizeof(tmp), "%s/%s", Where, p->name); + delete_files(tmp); + } + break; case PLIST_DIR_RM: (void) snprintf(tmp, sizeof(tmp), "%s/%s", Where, p->name); if (!isdir(tmp)) { @@ -442,3 +462,38 @@ delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs) } return 0; } + +static void +delete_files(const char *fname) +{ + size_t len; + Boolean b; + + len = strlen(fname); + if (len == 0) { + pwarnx("empty extra file"); + return; + } + /* don't warn if stuff does not exist */ + if (!fexists(fname)) + return; + + b = isdir(fname); + if (fname[len-1] == '/') { + if (b) { + if (rmdir(fname) == -1) + pwarn("problem removing directory %s", + fname); + } else { + pwarnx("extra directory %s is not a directory", + fname); + } + } else { + if (b) { + pwarnx("extra file %s is a directory", fname); + } else { + if (unlink(fname) == -1) + pwarn("problem removing %s", fname); + } + } +} diff --git a/usr.sbin/pkg_install/lib/pwarnx.c b/usr.sbin/pkg_install/lib/pwarnx.c index 191ad3c0d81..439fa2b195b 100644 --- a/usr.sbin/pkg_install/lib/pwarnx.c +++ b/usr.sbin/pkg_install/lib/pwarnx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pwarnx.c,v 1.3 2003/06/02 23:36:54 millert Exp $ */ +/* $OpenBSD: pwarnx.c,v 1.4 2003/08/21 20:24:57 espie Exp $ */ /*- * Copyright (c) 1993 @@ -32,6 +32,7 @@ #include <stdarg.h> #include <stdio.h> #include <string.h> +#include <errno.h> #include "lib.h" static char pkgname[60]; @@ -79,3 +80,25 @@ pwarnx(const char *fmt, ...) (void)fprintf(stderr, "\n"); va_end(ap); } + +void +pwarn(const char *fmt, ...) +{ + va_list ap; + int sverrno; + + sverrno = errno; + va_start(ap, fmt); + + if (pkgname[0] == '\0') + (void)fprintf(stderr, "%s: ", __progname); + else + (void)fprintf(stderr, "%s(%s): ", __progname, pkgname); + if (fmt != NULL) { + (void)vfprintf(stderr, fmt, ap); + (void)fprintf(stderr, ": "); + } + (void)fprintf(stderr, "%s\n", strerror(sverrno)); + (void)fprintf(stderr, "\n"); + va_end(ap); +} |