summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorjschauma <jschauma>2003-01-14 15:18:32 +0000
committerjschauma <jschauma>2003-01-14 15:18:32 +0000
commit28654681eb2c315e44ed239ae5b17c92dd5bbbe3 (patch)
tree820aee80b497d4a5fda47b6f770e05f38cfedd78 /pkgtools
parent2228b5fed185f718b4c26cdad784a6beed3cf55e (diff)
downloadpkgsrc-28654681eb2c315e44ed239ae5b17c92dd5bbbe3.tar.gz
Synch with latest changes from src (changes by agc, synch ok'd by agc)
---------------------------------------------------------------------- Add a pkgdb_remove_pkg() function and use it in pkg_delete(1). Bump lib/version.h due to added functionality. Order the getopt(3) options alphabetically. Introduce the notion of "preserving" an installed package. A preserved package may not be deleted by pkg_delete(1) (unless the -f option is given), and the preserved capability will be carried into any binary package. pkg_add(1) will also keep the preserved capability if it was present in the binary package. The "preserve" capability can be given to a package by using the PKG_PRESERVE definition in a package Makefile in pkgsrc. Ride on the recently-bumped lib/version.h for new functionality.
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/pkg_install/files/add/main.c6
-rw-r--r--pkgtools/pkg_install/files/add/perform.c6
-rw-r--r--pkgtools/pkg_install/files/admin/main.c10
-rw-r--r--pkgtools/pkg_install/files/create/create.h3
-rw-r--r--pkgtools/pkg_install/files/create/main.c11
-rw-r--r--pkgtools/pkg_install/files/create/perform.c12
-rw-r--r--pkgtools/pkg_install/files/create/pkg_create.111
-rw-r--r--pkgtools/pkg_install/files/delete/main.c97
-rw-r--r--pkgtools/pkg_install/files/delete/perform.c10
-rw-r--r--pkgtools/pkg_install/files/delete/pkg_delete.19
-rw-r--r--pkgtools/pkg_install/files/info/perform.c10
-rw-r--r--pkgtools/pkg_install/files/lib/lib.h.in4
-rw-r--r--pkgtools/pkg_install/files/lib/pkgdb.c43
13 files changed, 144 insertions, 88 deletions
diff --git a/pkgtools/pkg_install/files/add/main.c b/pkgtools/pkg_install/files/add/main.c
index 8a4bb49fff9..aa9cf02d215 100644
--- a/pkgtools/pkg_install/files/add/main.c
+++ b/pkgtools/pkg_install/files/add/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.1.1.1 2002/12/20 18:13:55 schmonz Exp $ */
+/* $NetBSD: main.c,v 1.2 2003/01/14 15:18:32 jschauma Exp $ */
#if 0
#include <sys/cdefs.h>
@@ -6,7 +6,7 @@
#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.1.1.1 2002/12/20 18:13:55 schmonz Exp $");
+__RCSID("$NetBSD: main.c,v 1.2 2003/01/14 15:18:32 jschauma Exp $");
#endif
#endif
#endif
@@ -56,7 +56,7 @@ __RCSID("$NetBSD: main.c,v 1.1.1.1 2002/12/20 18:13:55 schmonz Exp $");
#include "add.h"
#include "verify.h"
-static char Options[] = "hVvIRfnp:SMs:t:u";
+static char Options[] = "IMRSVfhnp:s:t:uv";
char *Prefix = NULL;
Boolean NoInstall = FALSE;
diff --git a/pkgtools/pkg_install/files/add/perform.c b/pkgtools/pkg_install/files/add/perform.c
index ddab188ca57..437f91e4e42 100644
--- a/pkgtools/pkg_install/files/add/perform.c
+++ b/pkgtools/pkg_install/files/add/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.2 2003/01/06 04:34:15 jschauma Exp $ */
+/* $NetBSD: perform.c,v 1.3 2003/01/14 15:18:32 jschauma Exp $ */
#if 0
#include <sys/cdefs.h>
@@ -6,7 +6,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp";
#else
-__RCSID("$NetBSD: perform.c,v 1.2 2003/01/06 04:34:15 jschauma Exp $");
+__RCSID("$NetBSD: perform.c,v 1.3 2003/01/14 15:18:32 jschauma Exp $");
#endif
#endif
#endif
@@ -608,6 +608,8 @@ pkg_do(const char *pkg)
move_file(".", BUILD_INFO_FNAME, LogDir);
if (fexists(DISPLAY_FNAME))
move_file(".", DISPLAY_FNAME, LogDir);
+ if (fexists(PRESERVE_FNAME))
+ move_file(".", PRESERVE_FNAME, LogDir);
/* register dependencies */
/* we could save some cycles here if we remembered what we
diff --git a/pkgtools/pkg_install/files/admin/main.c b/pkgtools/pkg_install/files/admin/main.c
index 93869ddf05c..f006ecf6cef 100644
--- a/pkgtools/pkg_install/files/admin/main.c
+++ b/pkgtools/pkg_install/files/admin/main.c
@@ -1,9 +1,9 @@
-/* $NetBSD: main.c,v 1.4 2003/01/07 16:43:56 jschauma Exp $ */
+/* $NetBSD: main.c,v 1.5 2003/01/14 15:18:33 jschauma Exp $ */
#if 0
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.4 2003/01/07 16:43:56 jschauma Exp $");
+__RCSID("$NetBSD: main.c,v 1.5 2003/01/14 15:18:33 jschauma Exp $");
#endif
#endif
@@ -616,14 +616,14 @@ usage(void)
" 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"
+ " add key value - add key and value\n"
" delete key - delete reference to key\n"
#endif
" lsall /path/to/pkgpattern - list all pkgs matching the pattern\n"
" lsbest /path/to/pkgpattern - list pkgs matching the pattern best\n"
" dump - dump database\n"
- " pmatch pattern pkg - returns true if pkg matches pattern, false else\n");
- exit(1);
+ " pmatch pattern pkg - returns true if pkg matches pattern, otherwise false\n");
+ exit(EXIT_FAILURE);
}
void
diff --git a/pkgtools/pkg_install/files/create/create.h b/pkgtools/pkg_install/files/create/create.h
index 1877f7ac7cc..33a9e9609b6 100644
--- a/pkgtools/pkg_install/files/create/create.h
+++ b/pkgtools/pkg_install/files/create/create.h
@@ -1,4 +1,4 @@
-/* $NetBSD: create.h,v 1.1.1.1 2002/12/20 18:14:09 schmonz Exp $ */
+/* $NetBSD: create.h,v 1.2 2003/01/14 15:18:33 jschauma Exp $ */
/* from FreeBSD Id: create.h,v 1.13 1997/10/08 07:46:19 charnier Exp */
@@ -41,6 +41,7 @@ extern char *BuildVersion;
extern char *BuildInfo;
extern char *SizePkg;
extern char *SizeAll;
+extern char *Preserve;
extern char *SrcDir;
extern char *realprefix;
extern char PlayPen[];
diff --git a/pkgtools/pkg_install/files/create/main.c b/pkgtools/pkg_install/files/create/main.c
index c4d94393d64..7743e7faaaa 100644
--- a/pkgtools/pkg_install/files/create/main.c
+++ b/pkgtools/pkg_install/files/create/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.1.1.1 2002/12/20 18:14:09 schmonz Exp $ */
+/* $NetBSD: main.c,v 1.2 2003/01/14 15:18:34 jschauma Exp $ */
#if 0
#include <sys/cdefs.h>
@@ -6,7 +6,7 @@
#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.1.1.1 2002/12/20 18:14:09 schmonz Exp $");
+__RCSID("$NetBSD: main.c,v 1.2 2003/01/14 15:18:34 jschauma Exp $");
#endif
#endif
#endif
@@ -32,7 +32,7 @@ __RCSID("$NetBSD: main.c,v 1.1.1.1 2002/12/20 18:14:09 schmonz Exp $");
#include "lib.h"
#include "create.h"
-static const char Options[] = "ORhlVvFf:p:P:C:c:d:i:k:L:r:t:X:D:m:s:S:b:B:UI:";
+static const char Options[] = "B:C:D:FI:L:OP:RS:UVX:b:c:d:f:hi:k:lm:n:p:r:s:t:v";
char *Prefix = NULL;
char *Comment = NULL;
@@ -50,6 +50,7 @@ char *BuildVersion = NULL;
char *BuildInfo = NULL;
char *SizePkg = NULL;
char *SizeAll = NULL;
+char *Preserve = NULL;
char *SrcDir = NULL;
char *realprefix = NULL;
char PlayPen[FILENAME_MAX];
@@ -169,6 +170,10 @@ main(int argc, char **argv)
Mtree = optarg;
break;
+ case 'n':
+ Preserve = optarg;
+ break;
+
case 'P':
Pkgdeps = optarg;
break;
diff --git a/pkgtools/pkg_install/files/create/perform.c b/pkgtools/pkg_install/files/create/perform.c
index 7e61890175a..5b5785f607e 100644
--- a/pkgtools/pkg_install/files/create/perform.c
+++ b/pkgtools/pkg_install/files/create/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.1.1.1 2002/12/20 18:14:10 schmonz Exp $ */
+/* $NetBSD: perform.c,v 1.2 2003/01/14 15:18:34 jschauma Exp $ */
#if 0
#include <sys/cdefs.h>
@@ -6,7 +6,7 @@
#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.1.1.1 2002/12/20 18:14:10 schmonz Exp $");
+__RCSID("$NetBSD: perform.c,v 1.2 2003/01/14 15:18:34 jschauma Exp $");
#endif
#endif
#endif
@@ -147,6 +147,9 @@ make_dist(const char *home, const char *pkg, const char *suffix, const package_t
if (SizeAll) {
(void) fprintf(totar, "%s\n", SIZE_ALL_FNAME);
}
+ if (Preserve) {
+ (void) fprintf(totar, "%s\n", PRESERVE_FNAME);
+ }
for (p = plist->head; p; p = p->next) {
if (p->type == PLIST_FILE) {
@@ -391,6 +394,11 @@ pkg_perform(lpkg_head_t *pkgs)
add_plist(&plist, PLIST_IGNORE, NULL);
add_plist(&plist, PLIST_FILE, SIZE_ALL_FNAME);
}
+ if (Preserve) {
+ copy_file(Home, Preserve, PRESERVE_FNAME);
+ add_plist(&plist, PLIST_IGNORE, NULL);
+ add_plist(&plist, PLIST_FILE, PRESERVE_FNAME);
+ }
/* Finally, write out the packing list */
fp = fopen(CONTENTS_FNAME, "w");
diff --git a/pkgtools/pkg_install/files/create/pkg_create.1 b/pkgtools/pkg_install/files/create/pkg_create.1
index 71c07f0421d..ec62ee4342b 100644
--- a/pkgtools/pkg_install/files/create/pkg_create.1
+++ b/pkgtools/pkg_install/files/create/pkg_create.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: pkg_create.1,v 1.1.1.1 2002/12/20 18:14:10 schmonz Exp $
+.\" $NetBSD: pkg_create.1,v 1.2 2003/01/14 15:18:34 jschauma Exp $
.\"
.\" FreeBSD install - a package for the installation and maintainance
.\" of non-core utilities.
@@ -24,7 +24,7 @@
.\" [jkh] Took John's changes back and made some additional extensions for
.\" better integration with FreeBSD's new ports collection.
.\"
-.Dd April 21, 1995
+.Dd January 10, 2003
.Dt PKG_CREATE 1
.Os
.Sh NAME
@@ -82,6 +82,9 @@
.Op Fl S Ar size-all-file
.Ek
.Bk -words
+.Op Fl n Ar preserve-file
+.Ek
+.Bk -words
.Op Fl t Ar template
.Ek
.Bk -words
@@ -253,6 +256,10 @@ flag.
The file is expected to contain the size (in bytes) of all files of
this package plus any required packages added up and stored as a
ASCII string, terminated by a newline.
+.It Fl n Ar preserve-file
+The file is used to denote that the package should not be deleted.
+This is intended for use where the deletion of packages may present
+a bootstrap problem.
.It Fl s Ar size-pkg-file
Store the given file for later querying with the
.Xr pkg_info 1
diff --git a/pkgtools/pkg_install/files/delete/main.c b/pkgtools/pkg_install/files/delete/main.c
index 2fd3c47f5f7..2c72f8459a8 100644
--- a/pkgtools/pkg_install/files/delete/main.c
+++ b/pkgtools/pkg_install/files/delete/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.4 2003/01/07 16:43:57 jschauma Exp $ */
+/* $NetBSD: main.c,v 1.5 2003/01/14 15:18:34 jschauma Exp $ */
#if 0
#include <sys/cdefs.h>
@@ -6,7 +6,7 @@
#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.4 2003/01/07 16:43:57 jschauma Exp $");
+__RCSID("$NetBSD: main.c,v 1.5 2003/01/14 15:18:34 jschauma Exp $");
#endif
#endif
#endif
@@ -43,7 +43,7 @@ __RCSID("$NetBSD: main.c,v 1.4 2003/01/07 16:43:57 jschauma Exp $");
#include "lib.h"
#include "delete.h"
-static char Options[] = "hVvDdnfFp:OrR";
+static char Options[] = "DFORVdfhnp:rv";
char *Prefix = NULL;
char *ProgramPath = NULL;
@@ -65,8 +65,9 @@ usage(void)
int
main(int argc, char **argv)
{
- int ch, error;
lpkg_t *lpp;
+ int ex;
+ int ch;
setprogname(argv[0]);
@@ -132,95 +133,71 @@ main(int argc, char **argv)
TAILQ_INIT(&pkgs);
/* Get all the remaining package names, if any */
- if (File2Pkg)
- if (!pkgdb_open(ReadOnly)) {
+ if (File2Pkg && !pkgdb_open(ReadOnly)) {
err(EXIT_FAILURE, "cannot open pkgdb");
}
+
/* Get all the remaining package names, if any */
- while (*argv) {
+ for ( ; *argv ; 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;
- s = pkgdb_retrieve(*argv);
-
- if (s) {
+ if ((s = pkgdb_retrieve(*argv)) == NULL) {
+ errx(EXIT_FAILURE, "No matching pkg for %s in pkgdb.", *argv);
+ }
lpp = alloc_lpkg(s);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
- } else
- errx(EXIT_FAILURE, "No matching pkg for %s in pkgdb.", *argv);
- } else {
- if (ispkgpattern(*argv)) {
- int rc;
- rc = findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, add_to_list_fn, &pkgs);
- if (rc == 0)
+ } else if (ispkgpattern(*argv)) {
+ switch(findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, add_to_list_fn, &pkgs)) {
+ case 0:
errx(EXIT_FAILURE, "No matching pkg for %s.", *argv);
- else if (rc == -1)
- errx(EXIT_FAILURE, "error expanding '%s' ('%s' nonexistant?)", *argv, _pkgdb_getPKGDB_DIR());
+ case -1:
+ errx(EXIT_FAILURE, "error expanding '%s' ('%s' nonexistent?)", *argv, _pkgdb_getPKGDB_DIR());
+ }
} else {
lpp = alloc_lpkg(*argv);
TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link);
}
}
- argv++;
- }
- if (File2Pkg)
+ if (File2Pkg) {
pkgdb_close();
+ }
/* If no packages, yelp */
- if (TAILQ_FIRST(&pkgs) == NULL)
- warnx("missing package name(s)"), usage();
- if (!Fake && getuid() != 0)
+ if (TAILQ_FIRST(&pkgs) == NULL) {
+ warnx("missing package name(s)");
+ usage();
+ }
+ if (!Fake && getuid() != 0) {
errx(EXIT_FAILURE, "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;
char cachename[FILENAME_MAX];
if (!pkgdb_open(ReadWrite)) {
err(EXIT_FAILURE, "cannot open %s", _pkgdb_getPKGDB_FILE(cachename, sizeof(cachename)));
}
-
- error = 0;
- while ((key = pkgdb_iter())) {
- val = pkgdb_retrieve(key);
- if (val == NULL || *val == '\0')
- continue;
-
- 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;
+ ex = EXIT_SUCCESS;
+ for (lpp = TAILQ_FIRST(&pkgs); lpp ; lpp = TAILQ_NEXT(lpp, lp_link)) {
+ if (!pkgdb_remove_pkg(lpp->lp_name)) {
+ ex = EXIT_FAILURE;
}
}
-
- lpp = TAILQ_NEXT(lpp, lp_link);
- } while (lpp != NULL);
+ pkgdb_close();
+ return ex;
}
+ if ((ex = pkg_perform(&pkgs)) != 0) {
+ if (Verbose) {
+ warnx("%d package deletion(s) failed", ex);
}
- 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;
+ return EXIT_FAILURE;
+ }
+ return EXIT_SUCCESS;
}
diff --git a/pkgtools/pkg_install/files/delete/perform.c b/pkgtools/pkg_install/files/delete/perform.c
index 3ee3ecf001c..6fca0c8a4e6 100644
--- a/pkgtools/pkg_install/files/delete/perform.c
+++ b/pkgtools/pkg_install/files/delete/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $ */
+/* $NetBSD: perform.c,v 1.3 2003/01/14 15:18:34 jschauma Exp $ */
#if 0
#include <sys/cdefs.h>
@@ -6,7 +6,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.15 1997/10/13 15:03:52 jkh Exp";
#else
-__RCSID("$NetBSD: perform.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $");
+__RCSID("$NetBSD: perform.c,v 1.3 2003/01/14 15:18:34 jschauma Exp $");
#endif
#endif
#endif
@@ -559,6 +559,12 @@ pkg_do(char *pkg)
warnx("unable to change directory to %s! deinstall failed", LogDir);
return 1;
}
+ if (fexists(PRESERVE_FNAME)) {
+ printf("Package `%s' is marked as not for deletion\n", pkg);
+ if (!Force) {
+ return 1;
+ }
+ }
if (!isemptyfile(REQUIRED_BY_FNAME)) {
/* This package is required by others. Either nuke
* them (-r), or stop. */
diff --git a/pkgtools/pkg_install/files/delete/pkg_delete.1 b/pkgtools/pkg_install/files/delete/pkg_delete.1
index 39569ff3c7d..3426bca45e4 100644
--- a/pkgtools/pkg_install/files/delete/pkg_delete.1
+++ b/pkgtools/pkg_install/files/delete/pkg_delete.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: pkg_delete.1,v 1.1.1.1 2002/12/20 18:14:08 schmonz Exp $
+.\" $NetBSD: pkg_delete.1,v 1.2 2003/01/14 15:18:34 jschauma Exp $
.\"
.\" FreeBSD install - a package for the installation and maintainance
.\" of non-core utilities.
@@ -148,6 +148,13 @@ will list those dependent packages and refuse to delete the package
.Fl f
option is given).
.Pp
+If a package has been marked as a
+.Cm preserved
+package, it will not be able to be deleted
+(unless the
+.Fl f
+option is given).
+.Pp
If a filename is given instead of a package name, the package of which
the given file belongs to can be deleted if the
.Fl F
diff --git a/pkgtools/pkg_install/files/info/perform.c b/pkgtools/pkg_install/files/info/perform.c
index de96bcb8713..9b34702faba 100644
--- a/pkgtools/pkg_install/files/info/perform.c
+++ b/pkgtools/pkg_install/files/info/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.4 2003/01/07 16:43:57 jschauma Exp $ */
+/* $NetBSD: perform.c,v 1.5 2003/01/14 15:18:34 jschauma Exp $ */
#if 0
#include <sys/cdefs.h>
@@ -6,7 +6,7 @@
#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.4 2003/01/07 16:43:57 jschauma Exp $");
+__RCSID("$NetBSD: perform.c,v 1.5 2003/01/14 15:18:34 jschauma Exp $");
#endif
#endif
#endif
@@ -190,6 +190,9 @@ pkg_do(char *pkg)
/* Start showing the package contents */
if (!Quiet) {
printf("%sInformation for %s:\n\n", InfoPrefix, pkg);
+ if (fexists(PRESERVE_FNAME)) {
+ printf("*** PACKAGE MAY NOT BE DELETED ***\n");
+ }
}
if (Flags & SHOW_COMMENT) {
show_file("Comment:\n", COMMENT_FNAME);
@@ -240,6 +243,9 @@ pkg_do(char *pkg)
show_file("Size in bytes including required pkgs: ", SIZE_ALL_FNAME);
}
if (!Quiet) {
+ if (fexists(PRESERVE_FNAME)) {
+ printf("*** PACKAGE MAY NOT BE DELETED ***\n\n");
+ }
puts(InfoPrefix);
}
free_plist(&plist);
diff --git a/pkgtools/pkg_install/files/lib/lib.h.in b/pkgtools/pkg_install/files/lib/lib.h.in
index 82ab40f50f1..63d6dea3f2b 100644
--- a/pkgtools/pkg_install/files/lib/lib.h.in
+++ b/pkgtools/pkg_install/files/lib/lib.h.in
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.h.in,v 1.2 2003/01/06 04:34:17 jschauma Exp $ */
+/* $NetBSD: lib.h.in,v 1.3 2003/01/14 15:18:35 jschauma Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@@ -145,6 +145,7 @@ enum {
#define BUILD_INFO_FNAME "+BUILD_INFO"
#define SIZE_PKG_FNAME "+SIZE_PKG"
#define SIZE_ALL_FNAME "+SIZE_ALL"
+#define PRESERVE_FNAME "+PRESERVE"
#define CMD_CHAR '@' /* prefix for extended PLIST cmd */
@@ -430,6 +431,7 @@ void pkgdb_close(void);
int pkgdb_store(const char *, const char *);
char *pkgdb_retrieve(const char *);
int pkgdb_remove(const char *);
+int pkgdb_remove_pkg(const char *);
char *pkgdb_iter(void);
char *_pkgdb_getPKGDB_FILE(char *, unsigned);
char *_pkgdb_getPKGDB_DIR(void);
diff --git a/pkgtools/pkg_install/files/lib/pkgdb.c b/pkgtools/pkg_install/files/lib/pkgdb.c
index 48be03fcd10..e45d0b02091 100644
--- a/pkgtools/pkg_install/files/lib/pkgdb.c
+++ b/pkgtools/pkg_install/files/lib/pkgdb.c
@@ -1,9 +1,9 @@
-/* $NetBSD: pkgdb.c,v 1.4 2003/01/07 16:43:57 jschauma Exp $ */
+/* $NetBSD: pkgdb.c,v 1.5 2003/01/14 15:18:35 jschauma Exp $ */
#if 0
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: pkgdb.c,v 1.4 2003/01/07 16:43:57 jschauma Exp $");
+__RCSID("$NetBSD: pkgdb.c,v 1.5 2003/01/14 15:18:35 jschauma Exp $");
#endif
#endif
@@ -141,7 +141,7 @@ pkgdb_store(const char *key, const char *val)
return (*pkgdbp->put) (pkgdbp, &keyd, &vald, R_NOOVERWRITE);
#else
- return 0;
+ return EXIT_SUCCESS;
#endif /* HAVE_DBOPEN */
}
@@ -202,10 +202,45 @@ pkgdb_remove(const char *key)
return (*pkgdbp->del) (pkgdbp, &keyd, 0);
#else
- return 0;
+ return EXIT_SUCCESS;
#endif /* HAVE_DBOPEN */
}
+/* remove any entry from the cache which has a data field of `pkg' */
+int
+pkgdb_remove_pkg(const char *pkg)
+{
+ DBT data;
+ DBT key;
+ int type;
+ int ret;
+ int cc;
+
+ if (pkgdbp == NULL) {
+ return 0;
+ }
+ cc = strlen(pkg);
+ for (ret = 1, type = R_FIRST; (*pkgdbp->seq)(pkgdbp, &key, &data, type) == 0 ; type = R_NEXT) {
+ if (cc == data.size && strncmp(data.data, pkg, cc) == 0) {
+ if (Verbose) {
+ printf("Removing file %s from pkgdb\n", (char *)key.data);
+ }
+ switch ((*pkgdbp->del)(pkgdbp, &key, 0)) {
+ case -1:
+ warn("Error removing %s from pkgdb", (char *) key.data);
+ ret = 0;
+ break;
+ case 1:
+ warn("Key %s not present in pkgdb", (char *) key.data);
+ ret = 0;
+ break;
+
+ }
+ }
+ }
+ return ret;
+}
+
/*
* Iterate all pkgdb keys (which can then be handled to pkgdb_retrieve())
* Return value: