summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES1
-rw-r--r--lib/db2.c145
-rw-r--r--lib/db2.h4
-rw-r--r--lib/dbindex.c75
-rw-r--r--lib/rebuilddb.c11
-rw-r--r--po/rpm.pot56
6 files changed, 226 insertions, 66 deletions
diff --git a/CHANGES b/CHANGES
index 7b5af4279..9a43285d3 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,7 @@
- configure.in fiddles for BSD systems (Patrick Schoo).
- API: change dbi to pass by reference, not value.
- cram all of db1, db_185, and db2 interfaces into rpmlib.
+ - convert db1 -> db2 on-disk format using --rebuilddb.
3.0.3 -> 3.0.4
- use compressed filenames on install side.
diff --git a/lib/db2.c b/lib/db2.c
index fa5e01f0e..037133a2b 100644
--- a/lib/db2.c
+++ b/lib/db2.c
@@ -1,7 +1,8 @@
#include "system.h"
-#include <db.h>
+static int _debug = 0;
+#include <db.h>
#include <rpmlib.h>
@@ -49,7 +50,8 @@ static int db_init(dbiIndex dbi, const char *home, int dbflags,
if (rc)
goto errxit;
- dbinfo->db_pagesize = 1024;
+ /* XXX W2DO? */
+ dbinfo->db_pagesize = 32 * 1024;
if (dbenvp)
*dbenvp = dbenv;
@@ -85,10 +87,15 @@ int db2open(dbiIndex dbi)
((dbi->dbi_flags & O_CREAT) ? DB_CREATE : 0));
rc = db_init(dbi, dbhome, dbflags, &dbenv, &dbinfo);
+if (_debug)
+fprintf(stderr, "*** db%d db_init rc %d errno %d\n", dbi->dbi_major, rc, errno);
- if (rc == 0)
+ if (rc == 0) {
rc = db_open(dbi->dbi_file, dbi_to_dbtype(dbi->dbi_type), dbflags,
dbi->dbi_perms, dbenv, dbinfo, &db);
+if (_debug)
+fprintf(stderr, "*** db%d db_open rc %d errno %d\n", dbi->dbi_major, rc, errno);
+ }
dbi->dbi_db = db;
dbi->dbi_dbenv = dbenv;
@@ -112,7 +119,7 @@ int db2open(dbiIndex dbi)
int db2close(dbiIndex dbi, unsigned int flags) {
DB * db = GetDB(dbi);
- int rc;
+ int rc, xx;
#if defined(__USE_DB2)
DB_ENV * dbenv = (DB_ENV *)dbi->dbi_dbenv;
@@ -120,11 +127,15 @@ int db2close(dbiIndex dbi, unsigned int flags) {
DBC * dbcursor = (DBC *)dbi->dbi_dbcursor;
if (dbcursor) {
- (void)dbcursor->c_close(dbcursor);
+ xx = dbcursor->c_close(dbcursor);
+if (_debug)
+fprintf(stderr, "*** db%d db->c_close rc %d errno %d\n", dbi->dbi_major, xx, errno);
dbi->dbi_dbcursor = NULL;
}
rc = db->close(db, 0);
+if (_debug)
+fprintf(stderr, "*** db%d db->close rc %d errno %d\n", dbi->dbi_major, rc, errno);
dbi->dbi_db = NULL;
if (dbinfo) {
@@ -132,7 +143,9 @@ int db2close(dbiIndex dbi, unsigned int flags) {
dbi->dbi_dbinfo = NULL;
}
if (dbenv) {
- (void) db_appexit(dbenv);
+ xx = db_appexit(dbenv);
+if (_debug)
+fprintf(stderr, "*** db%d db_appexit rc %d errno %d\n", dbi->dbi_major, xx, errno);
free(dbenv);
dbi->dbi_dbenv = NULL;
}
@@ -142,13 +155,23 @@ int db2close(dbiIndex dbi, unsigned int flags) {
switch (rc) {
default:
- case RET_ERROR: /* -1 */
rc = -1;
break;
- case RET_SPECIAL: /* 1 */
+ case DB_INCOMPLETE:
+ case DB_KEYEMPTY:
+ case DB_KEYEXIST:
+ case DB_LOCK_DEADLOCK:
+ case DB_LOCK_NOTGRANTED:
+ case DB_LOCK_NOTHELD:
+ case DB_NOTFOUND:
+ case DB_DELETED:
+ case DB_NEEDSPLIT:
+ case DB_REGISTERED:
+ case DB_SWAPBYTES:
+ case DB_TXN_CKP:
rc = 1;
break;
- case RET_SUCCESS: /* 0 */
+ case 0:
rc = 0;
break;
}
@@ -162,19 +185,31 @@ int db2sync(dbiIndex dbi, unsigned int flags) {
#if defined(__USE_DB2)
rc = db->sync(db, flags);
+if (_debug)
+fprintf(stderr, "*** db%d db->sync rc %d errno %d\n", dbi->dbi_major, rc, errno);
#else
rc = db->sync(db, flags);
#endif
switch (rc) {
default:
- case RET_ERROR: /* -1 */
rc = -1;
break;
- case RET_SPECIAL: /* 1 */
+ case DB_INCOMPLETE:
+ case DB_KEYEMPTY:
+ case DB_KEYEXIST:
+ case DB_LOCK_DEADLOCK:
+ case DB_LOCK_NOTGRANTED:
+ case DB_LOCK_NOTHELD:
+ case DB_NOTFOUND:
+ case DB_DELETED:
+ case DB_NEEDSPLIT:
+ case DB_REGISTERED:
+ case DB_SWAPBYTES:
+ case DB_TXN_CKP:
rc = 1;
break;
- case RET_SUCCESS: /* 0 */
+ case 0:
rc = 0;
break;
}
@@ -185,7 +220,7 @@ int db2sync(dbiIndex dbi, unsigned int flags) {
int db2GetFirstKey(dbiIndex dbi, const char ** keyp) {
DBT key, data;
DB * db;
- int rc;
+ int rc, xx;
if (dbi == NULL || dbi->dbi_db == NULL)
return 1;
@@ -200,10 +235,18 @@ int db2GetFirstKey(dbiIndex dbi, const char ** keyp) {
#if defined(__USE_DB2)
{ DBC * dbcursor = NULL;
rc = db->cursor(db, NULL, &dbcursor);
- if (rc == 0)
+if (_debug)
+fprintf(stderr, "*** db%d db->cursor rc %d errno %d\n", dbi->dbi_major, rc, errno);
+ if (rc == 0) {
rc = dbcursor->c_get(dbcursor, &key, &data, DB_FIRST);
- if (dbcursor)
- (void)dbcursor->c_close(dbcursor);
+if (_debug)
+fprintf(stderr, "*** db%d dbcursor->c_get rc %d errno %d\n", dbi->dbi_major, rc, errno);
+ }
+ if (dbcursor) {
+ xx = dbcursor->c_close(dbcursor);
+if (_debug)
+fprintf(stderr, "*** db%d dbcursor->c_close rc %d errno %d\n", dbi->dbi_major, xx, errno);
+ }
}
#else
rc = db->seq(db, &key, &data, R_FIRST);
@@ -211,11 +254,21 @@ int db2GetFirstKey(dbiIndex dbi, const char ** keyp) {
switch (rc) {
default:
- case RET_ERROR: /* -1 */
- case RET_SPECIAL: /* 1 */
+ case DB_INCOMPLETE:
+ case DB_KEYEMPTY:
+ case DB_KEYEXIST:
+ case DB_LOCK_DEADLOCK:
+ case DB_LOCK_NOTGRANTED:
+ case DB_LOCK_NOTHELD:
+ case DB_NOTFOUND:
+ case DB_DELETED:
+ case DB_NEEDSPLIT:
+ case DB_REGISTERED:
+ case DB_SWAPBYTES:
+ case DB_TXN_CKP:
rc = 1;
break;
- case RET_SUCCESS: /* 0 */
+ case 0:
rc = 0;
if (keyp) {
char *k = xmalloc(key.size + 1);
@@ -245,19 +298,31 @@ int db2SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) {
#if defined(__USE_DB2)
rc = db->get(db, NULL, &key, &data, 0);
+if (_debug)
+fprintf(stderr, "*** db%d db->get rc %d errno %d\n", dbi->dbi_major, rc, errno);
#else
rc = db->get(db, &key, &data, 0);
#endif
switch (rc) {
default:
- case RET_ERROR: /* -1 */
rc = -1;
break;
- case RET_SPECIAL: /* 1 */
+ case DB_INCOMPLETE:
+ case DB_KEYEMPTY:
+ case DB_KEYEXIST:
+ case DB_LOCK_DEADLOCK:
+ case DB_LOCK_NOTGRANTED:
+ case DB_LOCK_NOTHELD:
+ case DB_NOTFOUND:
+ case DB_DELETED:
+ case DB_NEEDSPLIT:
+ case DB_REGISTERED:
+ case DB_SWAPBYTES:
+ case DB_TXN_CKP:
rc = 1;
break;
- case RET_SUCCESS: /* 0 */
+ case 0:
rc = 0;
if (set) {
*set = dbiCreateIndexSet();
@@ -289,17 +354,29 @@ int db2UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set) {
#if defined(__USE_DB2)
rc = db->put(db, NULL, &key, &data, 0);
+if (_debug)
+fprintf(stderr, "*** db%d db->put rc %d errno %d\n", dbi->dbi_major, rc, errno);
#else
rc = db->put(db, &key, &data, 0);
#endif
switch (rc) {
default:
- case RET_ERROR: /* -1 */
- case RET_SPECIAL: /* 1 */
+ case DB_INCOMPLETE:
+ case DB_KEYEMPTY:
+ case DB_KEYEXIST:
+ case DB_LOCK_DEADLOCK:
+ case DB_LOCK_NOTGRANTED:
+ case DB_LOCK_NOTHELD:
+ case DB_NOTFOUND:
+ case DB_DELETED:
+ case DB_NEEDSPLIT:
+ case DB_REGISTERED:
+ case DB_SWAPBYTES:
+ case DB_TXN_CKP:
rc = 1;
break;
- case RET_SUCCESS: /* 0 */
+ case 0: /* 0 */
rc = 0;
break;
}
@@ -307,17 +384,29 @@ int db2UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set) {
#if defined(__USE_DB2)
rc = db->del(db, NULL, &key, 0);
+if (_debug)
+fprintf(stderr, "*** db%d db->del rc %d errno %d\n", dbi->dbi_major, rc, errno);
#else
rc = db->del(db, &key, 0);
#endif
switch (rc) {
default:
- case RET_ERROR: /* -1 */
- case RET_SPECIAL: /* 1 */
+ case DB_INCOMPLETE:
+ case DB_KEYEMPTY:
+ case DB_KEYEXIST:
+ case DB_LOCK_DEADLOCK:
+ case DB_LOCK_NOTGRANTED:
+ case DB_LOCK_NOTHELD:
+ case DB_NOTFOUND:
+ case DB_DELETED:
+ case DB_NEEDSPLIT:
+ case DB_REGISTERED:
+ case DB_SWAPBYTES:
+ case DB_TXN_CKP:
rc = 1;
break;
- case RET_SUCCESS: /* 0 */
+ case 0:
rc = 0;
break;
}
diff --git a/lib/db2.h b/lib/db2.h
index eeaff4509..978371bda 100644
--- a/lib/db2.h
+++ b/lib/db2.h
@@ -5,10 +5,6 @@
* Access RPM indices using Berkeley db-2.x API.
*/
-#define RET_ERROR 1
-#define RET_SUCCESS 0
-#define RET_SPECIAL -1
-
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/lib/dbindex.c b/lib/dbindex.c
index 3a497113c..843005416 100644
--- a/lib/dbindex.c
+++ b/lib/dbindex.c
@@ -1,5 +1,7 @@
#include "system.h"
+static int _debug = 0;
+
#include <rpmlib.h>
#include <rpmurl.h>
@@ -53,10 +55,31 @@ static void freeDBI( /*@only@*/ /*@null@*/ dbiIndex dbi) {
}
}
+int prefer_dbi_major = 2; /* XXX shared with rebuilddb.c */
+int use_dbi_major = -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,
+ NULL,
+ NULL
+};
+
dbiIndex dbiOpenIndex(const char * urlfn, int flags, int perms, DBI_TYPE type) {
dbiIndex dbi;
const char * filename;
- int rc;
+ int rc = 0;
(void) urlPath(urlfn, &filename);
if (*filename == '\0') {
@@ -70,17 +93,51 @@ dbiIndex dbiOpenIndex(const char * urlfn, int flags, int perms, DBI_TYPE type) {
dbi->dbi_perms = perms;
dbi->dbi_type = type;
dbi->dbi_openinfo = NULL;
- dbi->dbi_major = 1;
+ dbi->dbi_major = use_dbi_major;
+
+ switch (dbi->dbi_major) {
+ case 3:
+ case 2:
+ case 1:
+ case 0:
+ errno = 0;
+ rc = (*(mydbopens[dbi->dbi_major])) (dbi);
+ if (rc == 0)
+ break;
+ /*@fallthrough@*/
+ case -1:
+ dbi->dbi_major = 4;
+ while (dbi->dbi_major-- > 0) {
+ if (mydbopens[dbi->dbi_major] == NULL)
+ continue;
+ errno = 0;
+ rc = (*(mydbopens[dbi->dbi_major])) (dbi);
+if (_debug)
+fprintf(stderr, "*** loop db%d rc %d errno %d %s\n", dbi->dbi_major, rc, errno, strerror(errno));
+ if (rc == 0)
+ break;
+ if (rc == 1 && dbi->dbi_major == 2) {
+ fprintf(stderr, "*** FIXME: <message about how to convert db>\n");
+ fprintf(stderr, _("\n\
+--> Please run \"rpm --rebuilddb\" as root to convert your database from\n\
+ db1 to db2 on-disk format.\n\
+\n\
+"));
+ dbi->dbi_major--; /* XXX don't bother with db_185 */
+ }
+ }
+ use_dbi_major = dbi->dbi_major;
+ break;
+ }
- rc = db0open(dbi);
+ if (rc == 0)
+ return dbi;
- if (rc) {
- freeDBI(dbi);
- rpmError(RPMERR_DBOPEN, _("cannot open file %s: %s"), urlfn,
+ rpmError(RPMERR_DBOPEN, _("cannot open file %s: %s"), urlfn,
strerror(errno));
- return NULL;
- }
- return dbi;
+
+ freeDBI(dbi);
+ return NULL;
}
int dbiCloseIndex(dbiIndex dbi) {
diff --git a/lib/rebuilddb.c b/lib/rebuilddb.c
index e909419c9..de646bbe8 100644
--- a/lib/rebuilddb.c
+++ b/lib/rebuilddb.c
@@ -5,6 +5,9 @@
#include "rpmdb.h"
+extern int prefer_dbi_major; /* XXX shared with rebuilddb.c */
+extern int use_dbi_major;
+
/** */
int rpmdbRebuild(const char * rootdir)
{
@@ -66,14 +69,18 @@ int rpmdbRebuild(const char * rootdir)
goto exit;
}
- rpmMessage(RPMMESS_DEBUG, _("opening old database\n"));
+ use_dbi_major = prefer_dbi_major;
+ rpmMessage(RPMMESS_DEBUG, _("opening old database with dbi_major %d\n"),
+ use_dbi_major);
if (openDatabase(rootdir, dbpath, &olddb, O_RDONLY, 0644,
RPMDB_FLAG_MINIMAL)) {
rc = 1;
goto exit;
}
- rpmMessage(RPMMESS_DEBUG, _("opening new database\n"));
+ use_dbi_major = prefer_dbi_major;
+ rpmMessage(RPMMESS_DEBUG, _("opening new database with dbi_major %d\n"),
+ use_dbi_major);
if (openDatabase(rootdir, newdbpath, &newdb, O_RDWR | O_CREAT, 0644, 0)) {
rc = 1;
goto exit;
diff --git a/po/rpm.pot b/po/rpm.pot
index c5d2bf5fb..7079229a9 100644
--- a/po/rpm.pot
+++ b/po/rpm.pot
@@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
-"POT-Creation-Date: 2000-03-23 09:14-0500\n"
+"POT-Creation-Date: 2000-03-23 15:52-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -1986,27 +1986,35 @@ msgstr ""
msgid " failed - "
msgstr ""
-#: lib/dbindex.c:63
+#: lib/dbindex.c:86
#, c-format
msgid "bad db file %s"
msgstr ""
-#: lib/dbindex.c:79
+#: lib/dbindex.c:121
+msgid ""
+"\n"
+"--> Please run \"rpm --rebuilddb\" as root to convert your database from\n"
+" db1 to db2 on-disk format.\n"
+"\n"
+msgstr ""
+
+#: lib/dbindex.c:136
#, c-format
msgid "cannot open file %s: %s"
msgstr ""
-#: lib/dbindex.c:162
+#: lib/dbindex.c:219
#, c-format
msgid "error getting record %s from %s"
msgstr ""
-#: lib/dbindex.c:187
+#: lib/dbindex.c:244
#, c-format
msgid "error storing record %s into %s"
msgstr ""
-#: lib/dbindex.c:192
+#: lib/dbindex.c:249
#, c-format
msgid "error removing record %s into %s"
msgstr ""
@@ -2705,72 +2713,74 @@ msgstr ""
msgid "display a verbose file listing"
msgstr ""
-#: lib/rebuilddb.c:26 lib/rpmdb.c:251
+#: lib/rebuilddb.c:29 lib/rpmdb.c:251
msgid "no dbpath has been set"
msgstr ""
-#: lib/rebuilddb.c:51
+#: lib/rebuilddb.c:54
#, c-format
msgid "rebuilding database %s into %s\n"
msgstr ""
-#: lib/rebuilddb.c:55
+#: lib/rebuilddb.c:58
#, c-format
msgid "temporary database %s already exists"
msgstr ""
-#: lib/rebuilddb.c:61
+#: lib/rebuilddb.c:64
#, c-format
msgid "creating directory: %s\n"
msgstr ""
-#: lib/rebuilddb.c:63
+#: lib/rebuilddb.c:66
#, c-format
msgid "error creating directory %s: %s"
msgstr ""
-#: lib/rebuilddb.c:69
-msgid "opening old database\n"
+#: lib/rebuilddb.c:73
+#, c-format
+msgid "opening old database with dbi_major %d\n"
msgstr ""
-#: lib/rebuilddb.c:76
-msgid "opening new database\n"
+#: lib/rebuilddb.c:82
+#, c-format
+msgid "opening new database with dbi_major %d\n"
msgstr ""
-#: lib/rebuilddb.c:86
+#: lib/rebuilddb.c:93
#, c-format
msgid "record number %d in database is bad -- skipping it"
msgstr ""
-#: lib/rebuilddb.c:104
+#: lib/rebuilddb.c:111
#, c-format
msgid "duplicated database entry: %s-%s-%s -- skipping."
msgstr ""
-#: lib/rebuilddb.c:116
+#: lib/rebuilddb.c:123
#, c-format
msgid "cannot add record originally at %d"
msgstr ""
-#: lib/rebuilddb.c:122
+#: lib/rebuilddb.c:129
#, c-format
msgid "record number %d in database is bad -- skipping."
msgstr ""
-#: lib/rebuilddb.c:135
+#: lib/rebuilddb.c:142
msgid "failed to rebuild database; original database remains in place\n"
msgstr ""
-#: lib/rebuilddb.c:143
+#: lib/rebuilddb.c:150
msgid "failed to replace old database with new database!\n"
msgstr ""
-#: lib/rebuilddb.c:145
+#: lib/rebuilddb.c:152
#, c-format
msgid "replaces files in %s with files from %s to recover"
msgstr ""
-#: lib/rebuilddb.c:151
+#: lib/rebuilddb.c:158
#, c-format
msgid "failed to remove directory %s: %s\n"
msgstr ""