Introduce a pkgdb_dump() function, which dumps the cache file of

(filename, package) pairs.

Modify calling functions to use pkgdb_dump() directly, rather than
sequences of
	pkgdb_open
	{ pkgdb_iter, pkgdb_retrieve }
	pkgdb_close
calls.

Remove the now unnecessary pkgdb_iter function.
This commit is contained in:
agc 2003-03-15 20:49:25 +00:00
parent 640bee3010
commit 2c442ad8d2
4 changed files with 31 additions and 62 deletions

View File

@ -1,8 +1,8 @@
/* $NetBSD: main.c,v 1.32 2003/01/10 10:17:21 agc Exp $ */
/* $NetBSD: main.c,v 1.33 2003/03/15 20:49:25 agc Exp $ */
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: main.c,v 1.32 2003/01/10 10:17:21 agc Exp $");
__RCSID("$NetBSD: main.c,v 1.33 2003/03/15 20:49:25 agc Exp $");
#endif
/*
@ -509,21 +509,7 @@ main(int argc, char *argv[])
} else if (strcasecmp(argv[1], "list") == 0 ||
strcasecmp(argv[1], "dump") == 0) {
char *key, *val;
char cachename[FILENAME_MAX];
printf("Dumping pkgdb %s:\n", _pkgdb_getPKGDB_FILE(cachename, sizeof(cachename)));
if (!pkgdb_open(ReadOnly)) {
err(EXIT_FAILURE, "cannot open %s", cachename);
}
while ((key = pkgdb_iter())) {
val = pkgdb_retrieve(key);
printf("file: %-50s pkg: %s\n", key, val);
}
pkgdb_close();
pkgdb_dump();
}
#ifdef PKGDB_DEBUG

View File

@ -1,11 +1,11 @@
/* $NetBSD: perform.c,v 1.43 2003/01/10 11:55:46 agc Exp $ */
/* $NetBSD: perform.c,v 1.44 2003/03/15 20:49:26 agc 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.43 2003/01/10 11:55:46 agc Exp $");
__RCSID("$NetBSD: perform.c,v 1.44 2003/03/15 20:49:26 agc Exp $");
#endif
#endif
@ -325,18 +325,10 @@ pkg_perform(lpkg_head_t *pkghead)
return 1;
if (File2Pkg) {
/* Show all files with the package they belong to */
char *file, *pkg;
/* pkg_info -Fa => Dump pkgdb */
if (!pkgdb_open(ReadOnly)) {
err(EXIT_FAILURE, "cannot open pkgdb");
}
while ((file = pkgdb_iter())) {
pkg = pkgdb_retrieve(file);
printf("%-50s %s\n", file, pkg);
}
pkgdb_close();
/* Show all files with the package they belong to */
pkgdb_dump();
} else {
/* Show all packges with description */
if ((dirp = opendir(tmp)) != (DIR *) NULL) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: lib.h,v 1.48 2003/01/10 11:55:46 agc Exp $ */
/* $NetBSD: lib.h,v 1.49 2003/03/15 20:49:27 agc Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@ -276,9 +276,9 @@ int pkgdb_open(int);
void pkgdb_close(void);
int pkgdb_store(const char *, const char *);
char *pkgdb_retrieve(const char *);
void pkgdb_dump(void);
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);

View File

@ -1,8 +1,8 @@
/* $NetBSD: pkgdb.c,v 1.13 2003/01/10 10:17:24 agc Exp $ */
/* $NetBSD: pkgdb.c,v 1.14 2003/03/15 20:49:27 agc Exp $ */
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: pkgdb.c,v 1.13 2003/01/10 10:17:24 agc Exp $");
__RCSID("$NetBSD: pkgdb.c,v 1.14 2003/03/15 20:49:27 agc Exp $");
#endif
/*
@ -47,7 +47,6 @@ __RCSID("$NetBSD: pkgdb.c,v 1.13 2003/01/10 10:17:24 agc Exp $");
#define PKGDB_FILE "pkgdb.byfile.db" /* indexed by filename */
static DB *pkgdbp;
static int pkgdb_iter_flag;
/*
* Open the pkg-database
@ -61,8 +60,6 @@ pkgdb_open(int mode)
BTREEINFO info;
char cachename[FILENAME_MAX];
pkgdb_iter_flag = 0; /* used in pkgdb_iter() */
/* try our btree format first */
info.flags = 0;
info.cachesize = 2*1024*1024;
@ -146,6 +143,25 @@ pkgdb_retrieve(const char *key)
return vald.data;
}
/* dump contents of the database to stdout */
void
pkgdb_dump(void)
{
DBT key;
DBT val;
int type;
if (pkgdb_open(ReadOnly)) {
for (type = R_FIRST ; (*pkgdbp->seq)(pkgdbp, &key, &val, type) == 0 ; type = R_NEXT) {
printf("file: %.*s pkg: %.*s\n",
(int) key.size, (char *) key.data,
(int) val.size, (char *) val.data);
}
pkgdb_close();
}
}
/*
* Remove data set from pkgdb
* Return value as ypdb_delete:
@ -204,31 +220,6 @@ pkgdb_remove_pkg(const char *pkg)
return ret;
}
/*
* Iterate all pkgdb keys (which can then be handled to pkgdb_retrieve())
* Return value:
* NULL if no more data is available
* !NULL else
*/
char *
pkgdb_iter(void)
{
DBT key, val;
int type;
if (pkgdb_iter_flag == 0) {
pkgdb_iter_flag = 1;
type = R_FIRST;
} else
type = R_NEXT;
if ((*pkgdbp->seq)(pkgdbp, &key, &val, type) != 0) {
key.data = NULL;
}
return (char *) key.data;
}
/*
* Return name of cache file in the buffer that was passed.
*/