summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2000-03-27 15:55:07 +0000
committerjbj <devnull@localhost>2000-03-27 15:55:07 +0000
commit353a2811a4173728aae666217dde44880654531d (patch)
tree8cd356324e5dd5e58042e27ef0a1e33d5ec6bed5 /lib
parent62381feb62bc1980a24069386060bad917baf901 (diff)
downloadlibrpm-tizen-353a2811a4173728aae666217dde44880654531d.tar.gz
librpm-tizen-353a2811a4173728aae666217dde44880654531d.tar.bz2
librpm-tizen-353a2811a4173728aae666217dde44880654531d.zip
add db3 to the pile, isolate all with incremental link and vectors.
CVS patchset: 3643 CVS date: 2000/03/27 15:55:07
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am32
-rw-r--r--lib/db0.c92
-rw-r--r--lib/db0.h64
-rw-r--r--lib/db1.c97
-rw-r--r--lib/db1.h68
-rw-r--r--lib/db2.c122
-rw-r--r--lib/db2.h64
-rw-r--r--lib/db3.c128
-rw-r--r--lib/db3.h64
-rw-r--r--lib/dbindex.c168
-rw-r--r--lib/dbindex.h71
-rw-r--r--lib/rpmdb.c140
12 files changed, 460 insertions, 650 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 15a2c01d9..2bdecafbd 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -4,7 +4,7 @@ AUTOMAKE_OPTIONS = 1.4 foreign
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/build -I$(top_srcdir)/popt @INCPATH@
-EXTRA_DIST = db0.[ch] db1.[ch] db2.[ch] db2.[ch]
+EXTRA_DIST = db0.c db1.c db2.c db3.c
pkgincdir = $(pkgincludedir)
pkginc_HEADERS = \
@@ -29,24 +29,46 @@ librpm_la_SOURCES = \
librpm_la_LIBADD = $(subst .c,.lo,$(DBLIBOBJS))
#librpm_la_LIBADD = -lpopt
-db3.lo: db3.c $(top_srcdir)/system.h rpmlib.h dbindex.h db3.h
+db3.lo: db3.c $(top_srcdir)/system.h rpmlib.h dbindex.h
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
for F in $*.o $*.lo ; do \
@__LD@ -r -o $${F}.o $${F} -L/usr/lib -ldb-3.0 ; \
@__OBJCOPY@ `\
@__NM@ -g --defined-only $${F}.o | \
- sed -e '/ [TWD] /!d' -e 's/.* [TWD] /-L /' | \
+ sed -e '/ [DRTW] /!d' -e 's/.* [DRTW] /-L /' | \
grep -v '^-L $*'` $${F}.o $${F} ; \
rm -f $${F}.o ; \
done
-db0.lo: db0.c $(top_srcdir)/system.h rpmlib.h dbindex.h db0.h
+db2.lo: db2.c $(top_srcdir)/system.h rpmlib.h dbindex.h
+ $(LIBTOOL) --mode=compile $(COMPILE) -c $<
+ for F in $*.o $*.lo ; do \
+ @__LD@ -r -o $${F}.o $${F} -L/usr/lib -ldb ; \
+ @__OBJCOPY@ `\
+ @__NM@ -g --defined-only $${F}.o | \
+ sed -e '/ [DRTW] /!d' -e 's/.* [DRTW] /-L /' | \
+ grep -v '^-L $*'` $${F}.o $${F} ; \
+ rm -f $${F}.o ; \
+ done
+
+db1.lo: db1.c $(top_srcdir)/system.h rpmlib.h dbindex.h
+ $(LIBTOOL) --mode=compile $(COMPILE) -c $<
+ for F in $*.o $*.lo ; do \
+ @__LD@ -r -o $${F}.o $${F} -L/usr/lib -ldb ; \
+ @__OBJCOPY@ `\
+ @__NM@ -g --defined-only $${F}.o | \
+ sed -e '/ [DRTW] /!d' -e 's/.* [DRTW] /-L /' | \
+ grep -v '^-L $*'` $${F}.o $${F} ; \
+ rm -f $${F}.o ; \
+ done
+
+db0.lo: db0.c $(top_srcdir)/system.h rpmlib.h dbindex.h
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
for F in $*.o $*.lo ; do \
@__LD@ -r -o $${F}.o $${F} -L/usr/lib -ldb1 ; \
@__OBJCOPY@ `\
@__NM@ -g --defined-only $${F}.o | \
- sed -e '/ [TWD] /!d' -e 's/.* [TWD] /-L /' | \
+ sed -e '/ [DRTW] /!d' -e 's/.* [DRTW] /-L /' | \
grep -v '^-L $*'` $${F}.o $${F} ; \
rm -f $${F}.o ; \
done
diff --git a/lib/db0.c b/lib/db0.c
index 008967a43..fdcbf3659 100644
--- a/lib/db0.c
+++ b/lib/db0.c
@@ -14,8 +14,6 @@
/*@access dbiIndex@*/
/*@access dbiIndexSet@*/
-#include "db0.h"
-
static inline DBTYPE dbi_to_dbtype(DBI_TYPE dbitype)
{
switch(dbitype) {
@@ -70,46 +68,7 @@ errxit:
}
#endif
-int db0open(dbiIndex dbi)
-{
- int rc;
-
-#if defined(__USE_DB2)
- char * dbhome = NULL;
- DB_ENV * dbenv = NULL;
- DB_INFO * dbinfo = NULL;
- u_int32_t dbflags;
-
- dbflags = ( !(dbi->dbi_flags & O_RDWR) ? DB_RDONLY :
- ((dbi->dbi_flags & O_CREAT) ? DB_CREATE : 0));
-
- rc = db_init(dbhome, dbflags, &dbenv, &dbinfo);
- dbi->dbi_dbenv = dbenv;
- dbi->dbi_dbinfo = dbinfo;
-
- if (rc == 0)
- rc = db_open(dbi->dbi_file, dbi_to_dbtype(dbi->dbi_type), dbflags,
- dbi->dbi_perms, dbenv, dbinfo, &dbi->dbi_db);
-
- if (rc)
- dbi->dbi_db = NULL;
-#else
- dbi->dbi_db = dbopen(dbi->dbi_file, dbi->dbi_flags, dbi->dbi_perms,
- dbi_to_dbtype(dbi->dbi_type), dbi->dbi_openinfo);
-#endif
-
- if (dbi->dbi_db) {
- rc = 0;
- dbi->dbi_major = DB_VERSION_MAJOR;
- dbi->dbi_minor = DB_VERSION_MINOR;
- dbi->dbi_patch = DB_VERSION_PATCH;
- } else
- rc = 1;
-
- return rc;
-}
-
-int db0close(dbiIndex dbi, unsigned int flags) {
+static int db0close(dbiIndex dbi, unsigned int flags) {
DB * db = GetDB(dbi);
int rc;
@@ -155,7 +114,7 @@ int db0close(dbiIndex dbi, unsigned int flags) {
return rc;
}
-int db0sync(dbiIndex dbi, unsigned int flags) {
+static int db0sync(dbiIndex dbi, unsigned int flags) {
DB * db = GetDB(dbi);
int rc;
@@ -181,7 +140,7 @@ int db0sync(dbiIndex dbi, unsigned int flags) {
return rc;
}
-int db0GetFirstKey(dbiIndex dbi, const char ** keyp) {
+static int db0GetFirstKey(dbiIndex dbi, const char ** keyp) {
DBT key, data;
DB * db;
int rc;
@@ -228,7 +187,7 @@ int db0GetFirstKey(dbiIndex dbi, const char ** keyp) {
return rc;
}
-int db0SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) {
+static int db0SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) {
DBT key, data;
DB * db = GetDB(dbi);
int rc;
@@ -270,7 +229,7 @@ int db0SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) {
}
/*@-compmempass@*/
-int db0UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set) {
+static int db0UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set) {
DBT key;
DB * db = GetDB(dbi);
int rc;
@@ -325,3 +284,44 @@ int db0UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set) {
return rc;
}
/*@=compmempass@*/
+
+static int db0open(dbiIndex dbi)
+{
+ int rc;
+
+#if defined(__USE_DB2)
+ char * dbhome = NULL;
+ DB_ENV * dbenv = NULL;
+ DB_INFO * dbinfo = NULL;
+ u_int32_t dbflags;
+
+ dbflags = ( !(dbi->dbi_flags & O_RDWR) ? DB_RDONLY :
+ ((dbi->dbi_flags & O_CREAT) ? DB_CREATE : 0));
+
+ rc = db_init(dbhome, dbflags, &dbenv, &dbinfo);
+ dbi->dbi_dbenv = dbenv;
+ dbi->dbi_dbinfo = dbinfo;
+
+ if (rc == 0)
+ rc = db_open(dbi->dbi_file, dbi_to_dbtype(dbi->dbi_type), dbflags,
+ dbi->dbi_perms, dbenv, dbinfo, &dbi->dbi_db);
+
+ if (rc)
+ dbi->dbi_db = NULL;
+#else
+ dbi->dbi_db = dbopen(dbi->dbi_file, dbi->dbi_flags, dbi->dbi_perms,
+ dbi_to_dbtype(dbi->dbi_type), dbi->dbi_openinfo);
+#endif
+
+ if (dbi->dbi_db)
+ rc = 0;
+ else
+ rc = 1;
+
+ return rc;
+}
+
+struct _dbiVec db0vec = {
+ DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
+ db0open, db0close, db0sync, db0GetFirstKey, db0SearchIndex, db0UpdateIndex
+};
diff --git a/lib/db0.h b/lib/db0.h
deleted file mode 100644
index 08f038da5..000000000
--- a/lib/db0.h
+++ /dev/null
@@ -1,64 +0,0 @@
-#ifndef H_DB1
-#define H_DB1
-
-/** \file lib/db0.h
- * Access RPM indices using Berkeley db-1.85 format and API.
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Return handle for an index database.
- * @param dbi index database handle
- * @return 0 success 1 fail
- */
-int db0open(dbiIndex dbi);
-
-/**
- * Close index database.
- * @param dbi index database handle
- * @param flags
- */
-int db0close(dbiIndex dbi, unsigned int flags);
-
-/**
- * Flush pending operations to disk.
- * @param dbi index database handle
- * @param flags
- */
-int db0sync(dbiIndex dbi, unsigned int flags);
-
-/**
- * Return first index database key.
- * @param dbi index database handle
- * @param key address of first key
- * @return 0 success - fails if rec is not found
- */
-int db0GetFirstKey(dbiIndex dbi, const char ** keyp);
-
-/**
- * Return items that match criteria.
- * @param dbi index database handle
- * @param str search key
- * @param set items retrieved from index database
- * @return -1 error, 0 success, 1 not found
- */
-int db0SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set);
-
-/**
- * Change/delete items that match criteria.
- * @param dbi index database handle
- * @param str update key
- * @param set items to update in index database
- * @return 0 success, 1 not found
- */
-int db0UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_DB1 */
-
diff --git a/lib/db1.c b/lib/db1.c
index e57b9ec3f..6127a7353 100644
--- a/lib/db1.c
+++ b/lib/db1.c
@@ -1,8 +1,13 @@
#include "system.h"
#ifdef HAVE_DB_185_H
+
#include <db_185.h>
+#define DB_VERSION_MAJOR 1
+#define DB_VERSION_MINOR 85
+#define DB_VERSION_PATCH 0
+
#define _mymemset(_a, _b, _c)
#include <rpmlib.h>
@@ -11,8 +16,6 @@
/*@access dbiIndex@*/
/*@access dbiIndexSet@*/
-#include "db1.h"
-
static inline DBTYPE dbi_to_dbtype(DBI_TYPE dbitype)
{
switch(dbitype) {
@@ -67,46 +70,7 @@ errxit:
}
#endif
-int db1open(dbiIndex dbi)
-{
- int rc;
-
-#if defined(__USE_DB2)
- char * dbhome = NULL;
- DB_ENV * dbenv = NULL;
- DB_INFO * dbinfo = NULL;
- u_int32_t dbflags;
-
- dbflags = ( !(dbi->dbi_flags & O_RDWR) ? DB_RDONLY :
- ((dbi->dbi_flags & O_CREAT) ? DB_CREATE : 0));
-
- rc = db_init(dbhome, dbflags, &dbenv, &dbinfo);
- dbi->dbi_dbenv = dbenv;
- dbi->dbi_dbinfo = dbinfo;
-
- if (rc == 0)
- rc = db_open(dbi->dbi_file, dbi_to_dbtype(dbi->dbi_type), dbflags,
- dbi->dbi_perms, dbenv, dbinfo, &dbi->dbi_db);
-
- if (rc)
- dbi->dbi_db = NULL;
-#else
- dbi->dbi_db = dbopen(dbi->dbi_file, dbi->dbi_flags, dbi->dbi_perms,
- dbi_to_dbtype(dbi->dbi_type), dbi->dbi_openinfo);
-#endif
-
- if (dbi->dbi_db) {
- rc = 0;
- dbi->dbi_major = DB_VERSION_MAJOR;
- dbi->dbi_minor = DB_VERSION_MINOR;
- dbi->dbi_patch = DB_VERSION_PATCH;
- } else
- rc = 1;
-
- return rc;
-}
-
-int db1close(dbiIndex dbi, unsigned int flags) {
+static int db1close(dbiIndex dbi, unsigned int flags) {
DB * db = GetDB(dbi);
int rc;
@@ -152,7 +116,7 @@ int db1close(dbiIndex dbi, unsigned int flags) {
return rc;
}
-int db1sync(dbiIndex dbi, unsigned int flags) {
+static int db1sync(dbiIndex dbi, unsigned int flags) {
DB * db = GetDB(dbi);
int rc;
@@ -178,7 +142,7 @@ int db1sync(dbiIndex dbi, unsigned int flags) {
return rc;
}
-int db1GetFirstKey(dbiIndex dbi, const char ** keyp) {
+static int db1GetFirstKey(dbiIndex dbi, const char ** keyp) {
DBT key, data;
DB * db;
int rc;
@@ -225,7 +189,7 @@ int db1GetFirstKey(dbiIndex dbi, const char ** keyp) {
return rc;
}
-int db1SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) {
+static int db1SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) {
DBT key, data;
DB * db = GetDB(dbi);
int rc;
@@ -267,7 +231,7 @@ int db1SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) {
}
/*@-compmempass@*/
-int db1UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set) {
+static int db1UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set) {
DBT key;
DB * db = GetDB(dbi);
int rc;
@@ -323,4 +287,45 @@ int db1UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set) {
}
/*@=compmempass@*/
+static int db1open(dbiIndex dbi)
+{
+ int rc;
+
+#if defined(__USE_DB2)
+ char * dbhome = NULL;
+ DB_ENV * dbenv = NULL;
+ DB_INFO * dbinfo = NULL;
+ u_int32_t dbflags;
+
+ dbflags = ( !(dbi->dbi_flags & O_RDWR) ? DB_RDONLY :
+ ((dbi->dbi_flags & O_CREAT) ? DB_CREATE : 0));
+
+ rc = db_init(dbhome, dbflags, &dbenv, &dbinfo);
+ dbi->dbi_dbenv = dbenv;
+ dbi->dbi_dbinfo = dbinfo;
+
+ if (rc == 0)
+ rc = db_open(dbi->dbi_file, dbi_to_dbtype(dbi->dbi_type), dbflags,
+ dbi->dbi_perms, dbenv, dbinfo, &dbi->dbi_db);
+
+ if (rc)
+ dbi->dbi_db = NULL;
+#else
+ dbi->dbi_db = dbopen(dbi->dbi_file, dbi->dbi_flags, dbi->dbi_perms,
+ dbi_to_dbtype(dbi->dbi_type), dbi->dbi_openinfo);
+#endif
+
+ if (dbi->dbi_db)
+ rc = 0;
+ else
+ rc = 1;
+
+ return rc;
+}
+
+struct _dbiVec db1vec = {
+ DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
+ db1open, db1close, db1sync, db1GetFirstKey, db1SearchIndex, db1UpdateIndex
+};
+
#endif /* HABE_DB_185_H */
diff --git a/lib/db1.h b/lib/db1.h
deleted file mode 100644
index 35d9aa785..000000000
--- a/lib/db1.h
+++ /dev/null
@@ -1,68 +0,0 @@
-#ifndef H_DB185
-#define H_DB185
-
-/** \file lib/db1.h
- * Access RPM indices using Berkeley db2 with db-1.85 API.
- */
-
-#define DB_VERSION_MAJOR 1
-#define DB_VERSION_MINOR 85
-#define DB_VERSION_PATCH 0
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Return handle for an index database.
- * @param dbi index database handle
- * @return 0 success 1 fail
- */
-int db1open(dbiIndex dbi);
-
-/**
- * Close index database.
- * @param dbi index database handle
- * @param flags
- */
-int db1close(dbiIndex dbi, unsigned int flags);
-
-/**
- * Flush pending operations to disk.
- * @param dbi index database handle
- * @param flags
- */
-int db1sync(dbiIndex dbi, unsigned int flags);
-
-/**
- * Return first index database key.
- * @param dbi index database handle
- * @param key address of first key
- * @return 0 success - fails if rec is not found
- */
-int db1GetFirstKey(dbiIndex dbi, const char ** keyp);
-
-/**
- * Return items that match criteria.
- * @param dbi index database handle
- * @param str search key
- * @param set items retrieved from index database
- * @return -1 error, 0 success, 1 not found
- */
-int db1SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set);
-
-/**
- * Change/delete items that match criteria.
- * @param dbi index database handle
- * @param str update key
- * @param set items to update in index database
- * @return 0 success, 1 not found
- */
-int db1UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_DB185 */
-
diff --git a/lib/db2.c b/lib/db2.c
index f64fb1114..f7f869d6c 100644
--- a/lib/db2.c
+++ b/lib/db2.c
@@ -10,8 +10,6 @@ static int _debug = 1;
/*@access dbiIndex@*/
/*@access dbiIndexSet@*/
-#include "db2.h"
-
#if DB_VERSION_MAJOR == 2
#define __USE_DB2 1
#define _mymemset(_a, _b, _c) memset((_a), (_b), (_c))
@@ -194,59 +192,8 @@ errxit:
}
#endif /* __USE_DB2 || __USE_DB3 */
-int db2open(dbiIndex dbi)
+static int db2close(dbiIndex dbi, unsigned int flags)
{
- int rc = 0;
-
-#if defined(__USE_DB2) || defined(__USE_DB3)
- char * dbhome = NULL;
- DB * db = NULL;
- DB_ENV * dbenv = NULL;
- void * dbinfo = NULL;
- u_int32_t dbflags;
-
- dbflags = ( !(dbi->dbi_flags & O_RDWR) ? DB_RDONLY :
- ((dbi->dbi_flags & O_CREAT) ? DB_CREATE : 0));
-
- rc = db_init(dbi, dbhome, dbflags, &dbenv, &dbinfo);
-
- if (rc == 0) {
-#if defined(__USE_DB3)
- rc = db_create(&db, dbenv, 0);
- rc = cvtdberr(dbi, "db_create", rc, _debug);
- if (rc == 0) {
- rc = db->open(db, dbi->dbi_file, NULL, dbi_to_dbtype(dbi->dbi_type),
- dbflags, dbi->dbi_perms);
- rc = cvtdberr(dbi, "db->open", rc, _debug);
- }
-#else
- rc = db_open(dbi->dbi_file, dbi_to_dbtype(dbi->dbi_type), dbflags,
- dbi->dbi_perms, dbenv, dbinfo, &db);
- rc = cvtdberr(dbi, "db_open", rc, _debug);
-#endif /* __USE_DB3 */
- }
-
- dbi->dbi_db = db;
- dbi->dbi_dbenv = dbenv;
- dbi->dbi_dbinfo = dbinfo;
-
-#else
- dbi->dbi_db = dbopen(dbi->dbi_file, dbi->dbi_flags, dbi->dbi_perms,
- dbi_to_dbtype(dbi->dbi_type), dbi->dbi_openinfo);
-#endif /* __USE_DB2 || __USE_DB3 */
-
- if (rc == 0 && dbi->dbi_db != NULL) {
- rc = 0;
- dbi->dbi_major = DB_VERSION_MAJOR;
- dbi->dbi_minor = DB_VERSION_MINOR;
- dbi->dbi_patch = DB_VERSION_PATCH;
- } else
- rc = 1;
-
- return rc;
-}
-
-int db2close(dbiIndex dbi, unsigned int flags) {
DB * db = GetDB(dbi);
int rc = 0, xx;
@@ -288,7 +235,8 @@ int db2close(dbiIndex dbi, unsigned int flags) {
return rc;
}
-int db2sync(dbiIndex dbi, unsigned int flags) {
+static int db2sync(dbiIndex dbi, unsigned int flags)
+{
DB * db = GetDB(dbi);
int rc;
@@ -302,7 +250,8 @@ int db2sync(dbiIndex dbi, unsigned int flags) {
return rc;
}
-int db2GetFirstKey(dbiIndex dbi, const char ** keyp) {
+static int db2GetFirstKey(dbiIndex dbi, const char ** keyp)
+{
DBT key, data;
DB * db;
int rc, xx;
@@ -344,7 +293,8 @@ int db2GetFirstKey(dbiIndex dbi, const char ** keyp) {
return rc;
}
-int db2SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) {
+static int db2SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set)
+{
DBT key, data;
DB * db = GetDB(dbi);
int rc;
@@ -375,7 +325,8 @@ int db2SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) {
}
/*@-compmempass@*/
-int db2UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set) {
+static int db2UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set)
+{
DBT key;
DB * db = GetDB(dbi);
int rc;
@@ -412,4 +363,59 @@ int db2UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set) {
return rc;
}
/*@=compmempass@*/
+
+static int db2open(dbiIndex dbi)
+{
+ int rc = 0;
+
+#if defined(__USE_DB2) || defined(__USE_DB3)
+ char * dbhome = NULL;
+ DB * db = NULL;
+ DB_ENV * dbenv = NULL;
+ void * dbinfo = NULL;
+ u_int32_t dbflags;
+
+ dbflags = ( !(dbi->dbi_flags & O_RDWR) ? DB_RDONLY :
+ ((dbi->dbi_flags & O_CREAT) ? DB_CREATE : 0));
+
+ rc = db_init(dbi, dbhome, dbflags, &dbenv, &dbinfo);
+
+ if (rc == 0) {
+#if defined(__USE_DB3)
+ rc = db_create(&db, dbenv, 0);
+ rc = cvtdberr(dbi, "db_create", rc, _debug);
+ if (rc == 0) {
+ rc = db->open(db, dbi->dbi_file, NULL, dbi_to_dbtype(dbi->dbi_type),
+ dbflags, dbi->dbi_perms);
+ rc = cvtdberr(dbi, "db->open", rc, _debug);
+ }
+#else
+ rc = db_open(dbi->dbi_file, dbi_to_dbtype(dbi->dbi_type), dbflags,
+ dbi->dbi_perms, dbenv, dbinfo, &db);
+ rc = cvtdberr(dbi, "db_open", rc, _debug);
+#endif /* __USE_DB3 */
+ }
+
+ dbi->dbi_db = db;
+ dbi->dbi_dbenv = dbenv;
+ dbi->dbi_dbinfo = dbinfo;
+
+#else
+ dbi->dbi_db = dbopen(dbi->dbi_file, dbi->dbi_flags, dbi->dbi_perms,
+ dbi_to_dbtype(dbi->dbi_type), dbi->dbi_openinfo);
+#endif /* __USE_DB2 || __USE_DB3 */
+
+ if (rc == 0 && dbi->dbi_db != NULL)
+ rc = 0;
+ else
+ rc = 1;
+
+ return rc;
+}
+
+struct _dbiVec db2vec = {
+ DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
+ db2open, db2close, db2sync, db2GetFirstKey, db2SearchIndex, db2UpdateIndex
+};
+
#endif /* DB_VERSION_MAJOR == 2 */
diff --git a/lib/db2.h b/lib/db2.h
deleted file mode 100644
index 978371bda..000000000
--- a/lib/db2.h
+++ /dev/null
@@ -1,64 +0,0 @@
-#ifndef H_DB2
-#define H_DB2
-
-/** \file lib/db2.h
- * Access RPM indices using Berkeley db-2.x API.
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Return handle for an index database.
- * @param dbi index database handle
- * @return 0 success 1 fail
- */
-int db2open(dbiIndex dbi);
-
-/**
- * Close index database.
- * @param dbi index database handle
- * @param flags
- */
-int db2close(dbiIndex dbi, unsigned int flags);
-
-/**
- * Flush pending operations to disk.
- * @param dbi index database handle
- * @param flags
- */
-int db2sync(dbiIndex dbi, unsigned int flags);
-
-/**
- * Return first index database key.
- * @param dbi index database handle
- * @param key address of first key
- * @return 0 success - fails if rec is not found
- */
-int db2GetFirstKey(dbiIndex dbi, const char ** keyp);
-
-/**
- * Return items that match criteria.
- * @param dbi index database handle
- * @param str search key
- * @param set items retrieved from index database
- * @return -1 error, 0 success, 1 not found
- */
-int db2SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set);
-
-/**
- * Change/delete items that match criteria.
- * @param dbi index database handle
- * @param str update key
- * @param set items to update in index database
- * @return 0 success, 1 not found
- */
-int db2UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_DB2 */
-
diff --git a/lib/db3.c b/lib/db3.c
index ffd2f44bf..acc8f318d 100644
--- a/lib/db3.c
+++ b/lib/db3.c
@@ -10,8 +10,6 @@ static int _debug = 1;
/*@access dbiIndex@*/
/*@access dbiIndexSet@*/
-#include "db3.h"
-
static const char * dberrpfx = "rpmdb";
static int dbcachesize = 1024 * 1024;
static int dbpagesize = 32 * 1024; /* 0 - 64K */
@@ -192,62 +190,8 @@ errxit:
}
#endif /* __USE_DB2 || __USE_DB3 */
-int db3open(dbiIndex dbi)
+static int db3close(dbiIndex dbi, unsigned int flags)
{
- int rc = 0;
-
-#if defined(__USE_DB2) || defined(__USE_DB3)
- char * dbhome = NULL;
- DB * db = NULL;
- DB_ENV * dbenv = NULL;
- void * dbinfo = NULL;
- u_int32_t dbflags;
-
- dbflags = ( !(dbi->dbi_flags & O_RDWR) ? DB_RDONLY :
- ((dbi->dbi_flags & O_CREAT) ? DB_CREATE : 0));
-
- rc = db_init(dbi, dbhome, dbflags, &dbenv, &dbinfo);
-
- if (rc == 0) {
-#if defined(__USE_DB3)
- rc = db_create(&db, dbenv, 0);
- rc = cvtdberr(dbi, "db_create", rc, _debug);
- if (rc == 0) {
- int xx;
- rc = db->open(db, dbi->dbi_file, NULL, dbi_to_dbtype(dbi->dbi_type),
- dbflags, dbi->dbi_perms);
- rc = cvtdberr(dbi, "db->open", rc, _debug);
- xx = db->set_pagesize(db, dbpagesize);
- xx = cvtdberr(dbi, "db->set_pagesize", xx, _debug);
- }
-#else
- rc = db_open(dbi->dbi_file, dbi_to_dbtype(dbi->dbi_type), dbflags,
- dbi->dbi_perms, dbenv, dbinfo, &db);
- rc = cvtdberr(dbi, "db_open", rc, _debug);
-#endif /* __USE_DB3 */
- }
-
- dbi->dbi_db = db;
- dbi->dbi_dbenv = dbenv;
- dbi->dbi_dbinfo = dbinfo;
-
-#else
- dbi->dbi_db = dbopen(dbi->dbi_file, dbi->dbi_flags, dbi->dbi_perms,
- dbi_to_dbtype(dbi->dbi_type), dbi->dbi_openinfo);
-#endif /* __USE_DB2 || __USE_DB3 */
-
- if (rc == 0 && dbi->dbi_db != NULL) {
- rc = 0;
- dbi->dbi_major = DB_VERSION_MAJOR;
- dbi->dbi_minor = DB_VERSION_MINOR;
- dbi->dbi_patch = DB_VERSION_PATCH;
- } else
- rc = 1;
-
- return rc;
-}
-
-int db3close(dbiIndex dbi, unsigned int flags) {
DB * db = GetDB(dbi);
int rc = 0, xx;
@@ -289,7 +233,8 @@ int db3close(dbiIndex dbi, unsigned int flags) {
return rc;
}
-int db3sync(dbiIndex dbi, unsigned int flags) {
+static int db3sync(dbiIndex dbi, unsigned int flags)
+{
DB * db = GetDB(dbi);
int rc;
@@ -303,7 +248,8 @@ int db3sync(dbiIndex dbi, unsigned int flags) {
return rc;
}
-int db3GetFirstKey(dbiIndex dbi, const char ** keyp) {
+static int db3GetFirstKey(dbiIndex dbi, const char ** keyp)
+{
DBT key, data;
DB * db;
int rc, xx;
@@ -349,7 +295,8 @@ int db3GetFirstKey(dbiIndex dbi, const char ** keyp) {
return rc;
}
-int db3SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) {
+static int db3SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set)
+{
DBT key, data;
DB * db = GetDB(dbi);
int rc;
@@ -380,7 +327,8 @@ int db3SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) {
}
/*@-compmempass@*/
-int db3UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set) {
+static int db3UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set)
+{
DBT key;
DB * db = GetDB(dbi);
int rc;
@@ -417,4 +365,62 @@ int db3UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set) {
return rc;
}
/*@=compmempass@*/
+
+static int db3open(dbiIndex dbi)
+{
+ int rc = 0;
+
+#if defined(__USE_DB2) || defined(__USE_DB3)
+ char * dbhome = NULL;
+ DB * db = NULL;
+ DB_ENV * dbenv = NULL;
+ void * dbinfo = NULL;
+ u_int32_t dbflags;
+
+ dbflags = ( !(dbi->dbi_flags & O_RDWR) ? DB_RDONLY :
+ ((dbi->dbi_flags & O_CREAT) ? DB_CREATE : 0));
+
+ rc = db_init(dbi, dbhome, dbflags, &dbenv, &dbinfo);
+
+ if (rc == 0) {
+#if defined(__USE_DB3)
+ rc = db_create(&db, dbenv, 0);
+ rc = cvtdberr(dbi, "db_create", rc, _debug);
+ if (rc == 0) {
+ int xx;
+ rc = db->open(db, dbi->dbi_file, NULL, dbi_to_dbtype(dbi->dbi_type),
+ dbflags, dbi->dbi_perms);
+ rc = cvtdberr(dbi, "db->open", rc, _debug);
+ xx = db->set_pagesize(db, dbpagesize);
+ xx = cvtdberr(dbi, "db->set_pagesize", xx, _debug);
+ }
+#else
+ rc = db_open(dbi->dbi_file, dbi_to_dbtype(dbi->dbi_type), dbflags,
+ dbi->dbi_perms, dbenv, dbinfo, &db);
+ rc = cvtdberr(dbi, "db_open", rc, _debug);
+#endif /* __USE_DB3 */
+ }
+
+ dbi->dbi_db = db;
+ dbi->dbi_dbenv = dbenv;
+ dbi->dbi_dbinfo = dbinfo;
+
+#else
+ dbi->dbi_db = dbopen(dbi->dbi_file, dbi->dbi_flags, dbi->dbi_perms,
+ dbi_to_dbtype(dbi->dbi_type), dbi->dbi_openinfo);
+#endif /* __USE_DB2 || __USE_DB3 */
+
+ if (rc == 0 && dbi->dbi_db != NULL)
+ rc = 0;
+ else
+ rc = 1;
+
+ return rc;
+}
+
+struct _dbiVec db3vec = {
+ DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
+ db3open, db3close, db3sync, db3GetFirstKey, db3SearchIndex, db3UpdateIndex
+};
+
#endif /* DB_VERSION_MAJOR == 3 */
diff --git a/lib/db3.h b/lib/db3.h
deleted file mode 100644
index f3f725e73..000000000
--- a/lib/db3.h
+++ /dev/null
@@ -1,64 +0,0 @@
-#ifndef H_DB3
-#define H_DB3
-
-/** \file lib/db3.h
- * Access RPM indices using Berkeley db-3.x API.
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Return handle for an index database.
- * @param dbi index database handle
- * @return 0 success 1 fail
- */
-int db3open(dbiIndex dbi);
-
-/**
- * Close index database.
- * @param dbi index database handle
- * @param flags
- */
-int db3close(dbiIndex dbi, unsigned int flags);
-
-/**
- * Flush pending operations to disk.
- * @param dbi index database handle
- * @param flags
- */
-int db3sync(dbiIndex dbi, unsigned int flags);
-
-/**
- * Return first index database key.
- * @param dbi index database handle
- * @param key address of first key
- * @return 0 success - fails if rec is not found
- */
-int db3GetFirstKey(dbiIndex dbi, const char ** keyp);
-
-/**
- * Return items that match criteria.
- * @param dbi index database handle
- * @param str search key
- * @param set items retrieved from index database
- * @return -1 error, 0 success, 1 not found
- */
-int db3SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set);
-
-/**
- * Change/delete items that match criteria.
- * @param dbi index database handle
- * @param str update key
- * @param set items to update in index database
- * @return 0 success, 1 not found
- */
-int db3UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_DB3 */
-
diff --git a/lib/dbindex.c b/lib/dbindex.c
index 7ade63d9f..efd51e2fe 100644
--- a/lib/dbindex.c
+++ b/lib/dbindex.c
@@ -10,10 +10,29 @@ static int _debug = 0;
/*@access dbiIndexSet@*/
/*@access dbiIndexRecord@*/
-#include "db0.h"
-#include "db1.h"
-#include "db2.h"
-#include "db3.h"
+#if HAVE_DB1_DB_H
+extern struct _dbiVec db0vec;
+#define DB0vec &db0vec
+#else
+#define DB0vec NULL
+#endif
+
+#if HAVE_DB_185_H
+extern struct _dbiVec db1vec;
+#define DB1vec &db1vec
+#else
+#define DB1vec NULL
+#endif
+
+extern struct _dbiVec db2vec;
+#define DB2vec &db2vec
+
+#if HAVE_DB3_DB_H
+extern struct _dbiVec db3vec;
+#define DB3vec &db3vec
+#else
+#define DB3vec NULL
+#endif
unsigned int dbiIndexSetCount(dbiIndexSet set) {
return set->count;
@@ -59,30 +78,8 @@ static void freeDBI( /*@only@*/ /*@null@*/ dbiIndex dbi) {
int _preferDbiMajor = 0; /* XXX shared with rebuilddb.c */
int _useDbiMajor = -1;
-typedef int (*_dbopen) (dbiIndex dbi);
-
-static _dbopen mydbopens[] = {
-
-#if HAVE_DB1_DB_H
- db0open,
-#else
- NULL,
-#endif
-
-#if HAVE_DB_185_H
- db1open,
-#else
- NULL,
-#endif
-
- db2open,
-
-#if HAVE_DB3_DB_H
- db3open,
-#else
- NULL,
-#endif
- NULL
+static struct _dbiVec *mydbvecs[] = {
+ DB0vec, DB1vec, DB2vec, DB3vec, NULL
};
dbiIndex dbiOpenIndex(const char * urlfn, int flags, int perms, DBI_TYPE type) {
@@ -109,22 +106,30 @@ dbiIndex dbiOpenIndex(const char * urlfn, int flags, int perms, DBI_TYPE type) {
case 2:
case 1:
case 0:
- errno = 0;
- rc = (*(mydbopens[dbi->dbi_major])) (dbi);
- if (rc == 0)
- break;
+ if (mydbvecs[dbi->dbi_major] != NULL) {
+ errno = 0;
+ rc = (*mydbvecs[dbi->dbi_major]->open) (dbi);
+ if (rc == 0) {
+ dbi->dbi_vec = mydbvecs[dbi->dbi_major];
+ break;
+ }
+ }
/*@fallthrough@*/
case -1:
dbi->dbi_major = 4;
while (dbi->dbi_major-- > 0) {
- if (mydbopens[dbi->dbi_major] == NULL)
+if (_debug)
+fprintf(stderr, "*** loop db%d mydbvecs %p\n", dbi->dbi_major, mydbvecs[dbi->dbi_major]);
+ if (mydbvecs[dbi->dbi_major] == NULL)
continue;
errno = 0;
- rc = (*(mydbopens[dbi->dbi_major])) (dbi);
+ rc = (*mydbvecs[dbi->dbi_major]->open) (dbi);
if (_debug)
fprintf(stderr, "*** loop db%d rc %d errno %d %s\n", dbi->dbi_major, rc, errno, strerror(errno));
- if (rc == 0)
+ if (rc == 0) {
+ dbi->dbi_vec = mydbvecs[dbi->dbi_major];
break;
+ }
if (rc == 1 && dbi->dbi_major == 2) {
fprintf(stderr, "*** FIXME: <message about how to convert db>\n");
fprintf(stderr, _("\n\
@@ -139,34 +144,19 @@ fprintf(stderr, "*** loop db%d rc %d errno %d %s\n", dbi->dbi_major, rc, errno,
break;
}
- if (rc == 0)
- return dbi;
-
- rpmError(RPMERR_DBOPEN, _("cannot open file %s: %s"), urlfn,
- strerror(errno));
+ if (rc) {
+ rpmError(RPMERR_DBOPEN, _("cannot open file %s: %s"), urlfn, strerror(errno));
+ freeDBI(dbi);
+ dbi = NULL;
+ }
- freeDBI(dbi);
- return NULL;
+ return dbi;
}
int dbiCloseIndex(dbiIndex dbi) {
int rc;
- switch (dbi->dbi_major) {
- case 3:
- rc = db3close(dbi, 0);
- break;
- case 2:
- rc = db2close(dbi, 0);
- break;
- case 1:
- rc = db1close(dbi, 0);
- break;
- default:
- case 0:
- rc = db0close(dbi, 0);
- break;
- }
+ rc = (*dbi->dbi_vec->close) (dbi, 0);
freeDBI(dbi);
return rc;
}
@@ -174,21 +164,7 @@ int dbiCloseIndex(dbiIndex dbi) {
int dbiSyncIndex(dbiIndex dbi) {
int rc;
- switch (dbi->dbi_major) {
- case 3:
- rc = db3sync(dbi, 0);
- break;
- case 2:
- rc = db2sync(dbi, 0);
- break;
- case 1:
- rc = db1sync(dbi, 0);
- break;
- default:
- case 0:
- rc = db0sync(dbi, 0);
- break;
- }
+ rc = (*dbi->dbi_vec->sync) (dbi, 0);
return rc;
}
@@ -198,42 +174,14 @@ int dbiGetFirstKey(dbiIndex dbi, const char ** keyp) {
if (dbi == NULL)
return 1;
- switch (dbi->dbi_major) {
- case 3:
- rc = db3GetFirstKey(dbi, keyp);
- break;
- case 2:
- rc = db2GetFirstKey(dbi, keyp);
- break;
- case 1:
- rc = db1GetFirstKey(dbi, keyp);
- break;
- default:
- case 0:
- rc = db0GetFirstKey(dbi, keyp);
- break;
- }
+ rc = (*dbi->dbi_vec->GetFirstKey) (dbi, keyp);
return rc;
}
int dbiSearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) {
int rc;
- switch (dbi->dbi_major) {
- case 3:
- rc = db3SearchIndex(dbi, str, set);
- break;
- case 2:
- rc = db2SearchIndex(dbi, str, set);
- break;
- case 1:
- rc = db1SearchIndex(dbi, str, set);
- break;
- default:
- case 0:
- rc = db0SearchIndex(dbi, str, set);
- break;
- }
+ rc = (*dbi->dbi_vec->SearchIndex) (dbi, str, set);
switch (rc) {
case -1:
@@ -247,21 +195,7 @@ int dbiSearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) {
int dbiUpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set) {
int rc;
- switch (dbi->dbi_major) {
- case 3:
- rc = db3UpdateIndex(dbi, str, set);
- break;
- case 2:
- rc = db2UpdateIndex(dbi, str, set);
- break;
- case 1:
- rc = db1UpdateIndex(dbi, str, set);
- break;
- default:
- case 0:
- rc = db0UpdateIndex(dbi, str, set);
- break;
- }
+ rc = (*dbi->dbi_vec->UpdateIndex) (dbi, str, set);
if (set->count) {
if (rc) {
diff --git a/lib/dbindex.h b/lib/dbindex.h
index 694d39e54..8066ba36c 100644
--- a/lib/dbindex.h
+++ b/lib/dbindex.h
@@ -30,21 +30,78 @@ struct _dbiIndexSet {
};
/**
+ * Private methods for accessing an index database.
+ */
+struct _dbiVec {
+ int dbv_major; /*<! Berkeley db version major */
+ int dbv_minor; /*<! Berkeley db version minor */
+ int dbv_patch; /*<! Berkeley db version patch */
+
+/**
+ * Return handle for an index database.
+ * @param dbi index database handle
+ * @return 0 success 1 fail
+ */
+ int (*open) (dbiIndex dbi);
+
+/**
+ * Close index database.
+ * @param dbi index database handle
+ * @param flags
+ */
+ int (*close) (dbiIndex dbi, unsigned int flags);
+
+/**
+ * Flush pending operations to disk.
+ * @param dbi index database handle
+ * @param flags
+ */
+ int (*sync) (dbiIndex dbi, unsigned int flags);
+
+/**
+ * Return first index database key.
+ * @param dbi index database handle
+ * @param key address of first key
+ * @return 0 success - fails if rec is not found
+ */
+ int (*GetFirstKey) (dbiIndex dbi, const char ** keyp);
+
+/**
+ * Return items that match criteria.
+ * @param dbi index database handle
+ * @param str search key
+ * @param set items retrieved from index database
+ * @return -1 error, 0 success, 1 not found
+ */
+ int (*SearchIndex) (dbiIndex dbi, const char * str, dbiIndexSet * set);
+
+/**
+ * Change/delete items that match criteria.
+ * @param dbi index database handle
+ * @param str update key
+ * @param set items to update in index database
+ * @return 0 success, 1 not found
+ */
+ int (*UpdateIndex) (dbiIndex dbi, const char * str, dbiIndexSet set);
+};
+
+/**
* Describes an index database (implemented on Berkeley db[123] API).
*/
struct _dbiIndex {
+ const char * dbi_basename; /*<! last component of name */
+ DBI_TYPE dbi_type; /*<! type of access */
+ int dbi_flags; /*<! flags to use on open */
+ int dbi_perms; /*<! file permission to use on open */
+ int dbi_major; /*<! Berkeley db version major */
+ const char * dbi_file; /*<! name of index database */
void * dbi_db; /*<! Berkeley db[123] handle */
void * dbi_dbenv;
void * dbi_dbinfo;
void * dbi_dbcursor;
- const char * dbi_file; /*<! name of index database */
- int dbi_flags; /*<! flags to use on open */
- int dbi_perms; /*<! file permission to use on open */
- DBI_TYPE dbi_type; /*<! type of access */
const void * dbi_openinfo; /*<! private data passed on open */
- int dbi_major; /*<! Berkeley db version major */
- int dbi_minor; /*<! Berkeley db version minor */
- int dbi_patch; /*<! Berkeley db version patch */
+ FD_t dbi_fd; /*<! private data for fadio access */
+/*@observer@*/ const struct _dbiVec * dbi_vec; /*<! private methods */
};
#ifdef __cplusplus
diff --git a/lib/rpmdb.c b/lib/rpmdb.c
index ccb4f1777..eb61a18aa 100644
--- a/lib/rpmdb.c
+++ b/lib/rpmdb.c
@@ -19,16 +19,37 @@
extern int _noDirTokens;
-const char *rpmdb_filenames[] = {
- "packages.rpm",
- "nameindex.rpm",
- "fileindex.rpm",
- "groupindex.rpm",
- "requiredby.rpm",
- "providesindex.rpm",
- "conflictsindex.rpm",
- "triggerindex.rpm",
- NULL
+#define _DBI_FLAGS 0
+#define _DBI_PERMS 0644
+#define _DBI_MAJOR -1
+
+struct _dbiIndex rpmdbi[] = {
+ { "packages.rpm", DBI_RECNO, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL },
+#define RPMDBI_PACKAGES 0
+ { "nameindex.rpm", DBI_HASH, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL },
+#define RPMDBI_NAME 1
+ { "fileindex.rpm", DBI_HASH, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL },
+#define RPMDBI_FILE 2
+ { "groupindex.rpm", DBI_HASH, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL },
+#define RPMDBI_GROUP 3
+ { "requiredby.rpm", DBI_HASH, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL },
+#define RPMDBI_REQUIREDBY 4
+ { "providesindex.rpm", DBI_HASH, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL },
+#define RPMDBI_PROVIDES 5
+ { "conflictsindex.rpm", DBI_HASH, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL },
+#define RPMDBI_CONFLICTS 6
+ { "triggerindex.rpm", DBI_HASH, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL },
+#define RPMDBI_TRIGGER 7
+ { NULL }
+#define RPMDBI_MAX 8
};
/* XXX the signal handling in here is not thread safe */
@@ -44,8 +65,13 @@ const char *rpmdb_filenames[] = {
struct rpmdb_s {
FD_t pkgs;
- dbiIndex nameIndex, fileIndex, groupIndex, providesIndex;
- dbiIndex requiredbyIndex, conflictsIndex, triggerIndex;
+ dbiIndex nameIndex;
+ dbiIndex fileIndex;
+ dbiIndex groupIndex;
+ dbiIndex providesIndex;
+ dbiIndex requiredbyIndex;
+ dbiIndex conflictsIndex;
+ dbiIndex triggerIndex;
};
static sigset_t signalMask;
@@ -63,25 +89,40 @@ static void unblockSignals(void)
sigprocmask(SIG_SETMASK, &signalMask, NULL);
}
-static int openDbFile(const char * prefix, const char * dbpath, const char * shortName,
- int justCheck, int mode, int perms, dbiIndex * db, DBI_TYPE type)
+static int openDbFile(const char * prefix, const char * dbpath, int dbix,
+ int justCheck, int mode, dbiIndex * dbip)
{
- int len = (prefix ? strlen(prefix) : 0) + strlen(dbpath) + strlen(shortName) + 1;
- char * filename = alloca(len);
+ dbiIndex dbi;
+ char * filename, * fn;
+ int len;
- *filename = '\0';
+ if (dbix < 0 || dbix >= RPMDBI_MAX)
+ return 1;
+ if (dbip == NULL)
+ return 1;
+ *dbip = NULL;
+
+ dbi = rpmdbi + dbix;
+ len = (prefix ? strlen(prefix) : 0) +
+ strlen(dbpath) + strlen(dbi->dbi_basename) + 1;
+ fn = filename = alloca(len);
+ *fn = '\0';
switch (urlIsURL(dbpath)) {
case URL_IS_UNKNOWN:
- if (prefix && *prefix) strcat(filename, prefix);
+ if (prefix && *prefix &&
+ !(prefix[0] == '/' && prefix[1] == '\0' && dbpath[0] == '/'))
+ fn = stpcpy(fn, prefix);
break;
default:
break;
}
- strcat(filename, dbpath);
- strcat(filename, shortName);
+ fn = stpcpy(fn, dbpath);
+ if (fn > filename && !(fn[-1] == '/' || dbi->dbi_basename[0] == '/'))
+ fn = stpcpy(fn, "/");
+ fn = stpcpy(fn, dbi->dbi_basename);
if (!justCheck || !rpmfileexists(filename)) {
- if ((*db = dbiOpenIndex(filename, mode, perms, type)) == NULL)
+ if ((*dbip = dbiOpenIndex(filename, mode, dbi->dbi_perms, dbi->dbi_type)) == NULL)
return 1;
}
@@ -186,8 +227,8 @@ int openDatabase(const char * prefix, const char * dbpath, rpmdb *rpmdbp, int mo
}
}
- rc = openDbFile(prefix, dbpath, "nameindex.rpm", justcheck, mode, perms,
- &db->nameIndex, DBI_HASH);
+ rc = openDbFile(prefix, dbpath, RPMDBI_NAME, justcheck, mode,
+ &db->nameIndex);
if (minimal) {
*rpmdbp = xmalloc(sizeof(struct rpmdb_s));
@@ -199,8 +240,8 @@ int openDatabase(const char * prefix, const char * dbpath, rpmdb *rpmdbp, int mo
}
if (!rc)
- rc = openDbFile(prefix, dbpath, "fileindex.rpm", justcheck, mode, perms,
- &db->fileIndex, DBI_HASH);
+ rc = openDbFile(prefix, dbpath, RPMDBI_FILE, justcheck, mode,
+ &db->fileIndex);
/* We used to store the fileindexes as complete paths, rather then
plain basenames. Let's see which version we are... */
@@ -218,20 +259,20 @@ int openDatabase(const char * prefix, const char * dbpath, rpmdb *rpmdbp, int mo
}
if (!rc)
- rc = openDbFile(prefix, dbpath, "providesindex.rpm", justcheck, mode, perms,
- &db->providesIndex, DBI_HASH);
+ rc = openDbFile(prefix, dbpath, RPMDBI_GROUP, justcheck, mode,
+ &db->groupIndex);
if (!rc)
- rc = openDbFile(prefix, dbpath, "requiredby.rpm", justcheck, mode, perms,
- &db->requiredbyIndex, DBI_HASH);
+ rc = openDbFile(prefix, dbpath, RPMDBI_REQUIREDBY, justcheck, mode,
+ &db->requiredbyIndex);
if (!rc)
- rc = openDbFile(prefix, dbpath, "conflictsindex.rpm", justcheck, mode, perms,
- &db->conflictsIndex, DBI_HASH);
+ rc = openDbFile(prefix, dbpath, RPMDBI_PROVIDES, justcheck, mode,
+ &db->providesIndex);
if (!rc)
- rc = openDbFile(prefix, dbpath, "groupindex.rpm", justcheck, mode, perms,
- &db->groupIndex, DBI_HASH);
+ rc = openDbFile(prefix, dbpath, RPMDBI_CONFLICTS, justcheck, mode,
+ &db->conflictsIndex);
if (!rc)
- rc = openDbFile(prefix, dbpath, "triggerindex.rpm", justcheck, mode, perms,
- &db->triggerIndex, DBI_HASH);
+ rc = openDbFile(prefix, dbpath, RPMDBI_TRIGGER, justcheck, mode,
+ &db->triggerIndex);
if (rc || justcheck || rpmdbp == NULL)
rpmdbClose(db);
@@ -615,13 +656,13 @@ int rpmdbRemove(rpmdb db, unsigned int offset, int tolerant)
return 0;
}
-static int addIndexEntry(dbiIndex idx, const char *index, unsigned int offset,
+static int addIndexEntry(dbiIndex dbi, const char *index, unsigned int offset,
unsigned int fileNumber)
{
dbiIndexSet set = NULL;
int rc;
- rc = dbiSearchIndex(idx, index, &set);
+ rc = dbiSearchIndex(dbi, index, &set);
switch (rc) {
case -1: /* error */
if (set) {
@@ -638,7 +679,7 @@ static int addIndexEntry(dbiIndex idx, const char *index, unsigned int offset,
}
dbiAppendIndexRecord(set, offset, fileNumber);
- if (dbiUpdateIndex(idx, index, set))
+ if (dbiUpdateIndex(dbi, index, set))
exit(EXIT_FAILURE); /* XXX W2DO? return 1; */
if (set) {
@@ -709,7 +750,6 @@ int rpmdbAdd(rpmdb db, Header dbentry)
if (!dboffset) {
rc = 1;
} else {
- /* XXX TODO: set max. no. of bytes to write */
(void)Fseek(db->pkgs, dboffset, SEEK_SET);
fdSetContentLength(db->pkgs, newSize);
rc = headerWrite(db->pkgs, dbentry, HEADER_MAGIC_NO);
@@ -798,9 +838,7 @@ int rpmdbUpdateRecord(rpmdb db, int offset, Header newHeader)
} else {
blockSignals();
- /* XXX TODO: set max. no. of bytes to write */
(void)Fseek(db->pkgs, offset, SEEK_SET);
-
fdSetContentLength(db->pkgs, newSize);
rc = headerWrite(db->pkgs, newHeader, HEADER_MAGIC_NO);
fdSetContentLength(db->pkgs, -1);
@@ -814,7 +852,6 @@ int rpmdbUpdateRecord(rpmdb db, int offset, Header newHeader)
void rpmdbRemoveDatabase(const char * rootdir, const char * dbpath)
{
int i;
- const char **rpmdbfnp;
char * filename;
i = strlen(dbpath);
@@ -828,9 +865,11 @@ void rpmdbRemoveDatabase(const char * rootdir, const char * dbpath)
filename = alloca(strlen(rootdir) + strlen(dbpath) + 40);
- for (rpmdbfnp = rpmdb_filenames; *rpmdbfnp; rpmdbfnp++) {
- sprintf(filename, "%s/%s/%s", rootdir, dbpath, *rpmdbfnp);
- unlink(filename);
+ { dbiIndex dbi;
+ for (dbi = rpmdbi; dbi->dbi_basename != NULL; dbi++) {
+ sprintf(filename, "%s/%s/%s", rootdir, dbpath, dbi->dbi_basename);
+ unlink(filename);
+ }
}
sprintf(filename, "%s/%s", rootdir, dbpath);
@@ -841,7 +880,6 @@ void rpmdbRemoveDatabase(const char * rootdir, const char * dbpath)
int rpmdbMoveDatabase(const char * rootdir, const char * olddbpath, const char * newdbpath)
{
int i;
- const char **rpmdbfnp;
char * ofilename, * nfilename;
int rc = 0;
@@ -866,10 +904,12 @@ int rpmdbMoveDatabase(const char * rootdir, const char * olddbpath, const char *
ofilename = alloca(strlen(rootdir) + strlen(olddbpath) + 40);
nfilename = alloca(strlen(rootdir) + strlen(newdbpath) + 40);
- for (rpmdbfnp = rpmdb_filenames; *rpmdbfnp; rpmdbfnp++) {
- sprintf(ofilename, "%s/%s/%s", rootdir, olddbpath, *rpmdbfnp);
- sprintf(nfilename, "%s/%s/%s", rootdir, newdbpath, *rpmdbfnp);
- if (Rename(ofilename, nfilename)) rc = 1;
+ { dbiIndex dbi;
+ for (dbi = rpmdbi; dbi->dbi_basename != NULL; dbi++) {
+ sprintf(ofilename, "%s/%s/%s", rootdir, olddbpath, dbi->dbi_basename);
+ sprintf(nfilename, "%s/%s/%s", rootdir, newdbpath, dbi->dbi_basename);
+ if (Rename(ofilename, nfilename)) rc = 1;
+ }
}
return rc;