diff options
author | jbj <devnull@localhost> | 2002-05-21 00:00:39 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2002-05-21 00:00:39 +0000 |
commit | 0b61bf14759ea3c8f8ff1442ddad8bd309906e4e (patch) | |
tree | dc28f63be37c168f78cc35a7eadb18e05295a2dd /rpmdb | |
parent | 386882db7a38f24e0222a2ae94d4c93a34af0d37 (diff) | |
download | librpm-tizen-0b61bf14759ea3c8f8ff1442ddad8bd309906e4e.tar.gz librpm-tizen-0b61bf14759ea3c8f8ff1442ddad8bd309906e4e.tar.bz2 librpm-tizen-0b61bf14759ea3c8f8ff1442ddad8bd309906e4e.zip |
Always use cursors.
Use DB_KEYLAST with db->c_put for now, just like rpm-4.0.x.
Make sure that db->c_get is done before doing db->c_del.
Check that CDB access is still functional.
CVS patchset: 5441
CVS date: 2002/05/21 00:00:39
Diffstat (limited to 'rpmdb')
-rw-r--r-- | rpmdb/db3.c | 81 | ||||
-rw-r--r-- | rpmdb/dbconfig.c | 21 | ||||
-rw-r--r-- | rpmdb/rpmdb.c | 49 | ||||
-rw-r--r-- | rpmdb/rpmdb.h | 8 |
4 files changed, 127 insertions, 32 deletions
diff --git a/rpmdb/db3.c b/rpmdb/db3.c index 0d835cbff..a50051359 100644 --- a/rpmdb/db3.c +++ b/rpmdb/db3.c @@ -72,6 +72,77 @@ struct dbiBStats_s { }; /*@=fielduse@*/ +#ifdef NOTNOW +static const char * bfstring(unsigned int x, const char * xbf) +{ + const char * s = xbf; + static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; + static char buf[256]; + char * t, * te; + unsigned radix; + unsigned c, i, k; + + radix = (s != NULL ? *s++ : 16); + + if (radix <= 1 || radix >= 32) + radix = 16; + + t = buf; + switch (radix) { + case 8: *t++ = '0'; break; + case 16: *t++ = '0'; *t++ = 'x'; break; + } + + i = 0; + k = x; + do { i++; k /= radix; } while (k); + + te = t + i; + + k = x; + do { --i; t[i] = digits[k % radix]; k /= radix; } while (k); + + t = te; + i = '<'; + if (s != NULL) + while ((c = *s++) != '\0') { + if (c > ' ') continue; + + k = (1 << (c - 1)); + if (!(x & k)) continue; + + if (t == te) *t++ = '='; + + *t++ = i; + i = ','; + while (*s > ' ') + *t++ = *s++; + } + if (t > te) *t++ = '>'; + *t = '\0'; + return buf; +} + +static const char * dbtFlags = + "\20\1APPMALLOC\2ISSET\3MALLOC\4PARTIAL\5REALLOC\6USERMEM\7DUPOK"; + +static const char * dbenvOpenFlags = + "\20\1CREATE\2NO_EXCEPTIONS\3FORCE\4NOMMAP\5RDONLY\6RECOVER\7THREAD\10TXN_NOSYNC\11USE_ENVIRON\12USE_ENVIRON_ROOT\13CDB\14LOCK\15LOG\16MPOOL\17TXN\20JOINENV\21LOCKDOWN\22PRIVATE\23RECOVER_FATAL\24SYSTEM_MEM"; + +static const char * dbOpenFlags = + "\20\1CREATE\2NO_EXCEPTIONS\3FORCE\4NOMMAP\5RDONLY\6RECOVER\7THREAD\10TXN_NOSYNC\11USE_ENVIRON\12USE_ENVIRON_ROOT\13EXCL\14FCNTL_LOCKING\15RDWRMASTER\16TRUNCATE\17EXTENT\20APPLY_LOGREG"; + +static const char * dbenvSetFlags = + "\20\1CREATE\2NO_EXCEPTIONS\3FORCE\4NOMMAP\5RDONLY\6RECOVER\7THREAD\10TXN_NOSYNC\11USE_ENVIRON\12USE_ENVIRON_ROOT\13CDB_ALLDB\14NOLOCKING\15NOPANIC\16PANIC_ENV\17REGION_INIT\20YIELDCPU"; + +static const char * dbSetFlags = + "\20\1DUP\2DUPSORT\3RECNUM\4RENUMBER\5REVSPLITOFF\6SNAPSHOT"; + +static const char * dbiModeFlags = + "\20\1WRONLY\2RDWR\7CREAT\10EXCL\11NOCTTY\12TRUNC\13APPEND\14NONBLOCK\15SYNC\16ASYNC\17DIRECT\20LARGEFILE\21DIRECTORY\22NOFOLLOW"; +#endif /* NOTNOW */ + + /*@-globuse -mustmod @*/ /* FIX: rpmError not annotated yet. */ static int cvtdberr(dbiIndex dbi, const char * msg, int error, int printit) /*@globals fileSystem @*/ @@ -320,11 +391,13 @@ static int db3cclose(dbiIndex dbi, /*@only@*/ /*@null@*/ DBC * dbcursor, /*@globals fileSystem @*/ /*@modifies dbi, fileSystem @*/ { - int rc; + int rc = -2; - assert(dbcursor != NULL); - rc = dbcursor->c_close(dbcursor); - rc = cvtdberr(dbi, "dbcursor->c_close", rc, _debug); + /* XXX db3copen error pathways come through here. */ + if (dbcursor != NULL) { + rc = dbcursor->c_close(dbcursor); + rc = cvtdberr(dbi, "dbcursor->c_close", rc, _debug); + } return rc; } diff --git a/rpmdb/dbconfig.c b/rpmdb/dbconfig.c index 55d5a1a04..3e65138ab 100644 --- a/rpmdb/dbconfig.c +++ b/rpmdb/dbconfig.c @@ -26,15 +26,21 @@ struct _dbiIndex db3dbi; * Analogue to struct poptOption */ struct dbOption { -/*@observer@*/ /*@null@*/const char * longName; /* may be NULL */ - const char shortName; /* may be '\0' */ +/*@observer@*/ /*@null@*/ + const char * longName; /*!< may be NULL */ + const char shortName; /*!< may be '\0' */ int argInfo; -/*@null@*/ void * arg; /* depends on argInfo */ - int val; /* 0 means don't return, just update flag */ -/*@observer@*/ /*@null@*/ const char * descrip; /*!< description for autohelp -- may be NULL */ -/*@observer@*/ /*@null@*/ const char * argDescrip; /*!< argument description for autohelp */ +/*@null@*/ void * arg; /*!< depends on argInfo */ + int val; /*!< 0 means don't return, just update flag */ +/*@observer@*/ /*@null@*/ + const char * descrip; /*!< description for autohelp -- may be NULL */ +/*@observer@*/ /*@null@*/ + const char * argDescrip; /*!< argument description for autohelp */ }; +/*@unchecked@*/ +static int dbi_use_cursors; + /*@-compmempass -immediatetrans -exportlocal -exportheadervar@*/ /** \ingroup db3 */ @@ -140,7 +146,7 @@ struct dbOption rdbOptions[] = { NULL, NULL }, { "teardown", 0,POPT_ARG_NONE, &db3dbi.dbi_tear_down, 0, NULL, NULL }, - { "usecursors",0,POPT_ARG_NONE, &db3dbi.dbi_use_cursors, 0, + { "usecursors",0,POPT_ARG_NONE, &dbi_use_cursors, 0, NULL, NULL }, { "usedbenv", 0,POPT_ARG_NONE, &db3dbi.dbi_use_dbenv, 0, NULL, NULL }, @@ -488,7 +494,6 @@ dbiIndex db3New(rpmdb rpmdb, rpmTag rpmtag) /*@=sizeoftype@*/ dbi->dbi_byteswapped = 0; /* -1 unknown, 0 native order, 1 alien order */ - dbi->dbi_use_cursors = 1; /* db3 cursors are always used now. */ if (!dbi->dbi_use_dbenv) { /* db3 dbenv is always used now. */ dbi->dbi_use_dbenv = 1; diff --git a/rpmdb/rpmdb.c b/rpmdb/rpmdb.c index cea77fcb0..2665cf163 100644 --- a/rpmdb/rpmdb.c +++ b/rpmdb/rpmdb.c @@ -5,6 +5,8 @@ #include "system.h" +#define _USE_COPY_LOAD /* XXX don't use DB_DBT_MALLOC (yet) */ + /*@unchecked@*/ static int _rpmdb_debug = 0; @@ -1366,7 +1368,7 @@ static int miFreeHeader(rpmdbMatchIterator mi, dbiIndex dbi) if (mi == NULL || mi->mi_h == NULL) return 0; - if (mi->mi_modified && mi->mi_prevoffset) { + if (dbi && mi->mi_dbc && mi->mi_modified && mi->mi_prevoffset) { DBT * key = &mi->mi_key; DBT * data = &mi->mi_data; sigset_t signalMask; @@ -1378,7 +1380,7 @@ static int miFreeHeader(rpmdbMatchIterator mi, dbiIndex dbi) data->size = headerSizeof(mi->mi_h, HEADER_MAGIC_NO); if (data->data != NULL) { (void) blockSignals(dbi->dbi_rpmdb, &signalMask); - rc = dbiPut(dbi, mi->mi_dbc, key, data, 0); + rc = dbiPut(dbi, mi->mi_dbc, key, data, DB_KEYLAST); if (rc) { rpmError(RPMERR_DBPUTINDEX, _("error(%d) storing record #%d into %s\n"), @@ -1888,7 +1890,9 @@ top: key->size = keylen = mi->mi_keylen; data->data = uh; data->size = uhlen; +#if !defined(_USE_COPY_LOAD) data->flags |= DB_DBT_MALLOC; +#endif rc = dbiGet(dbi, mi->mi_dbc, key, data, (key->data == NULL ? DB_NEXT : DB_SET)); data->flags = 0; @@ -1928,7 +1932,9 @@ top: if (uh == NULL) { key->data = keyp; key->size = keylen; +#if !defined(_USE_COPY_LOAD) data->flags |= DB_DBT_MALLOC; +#endif rc = dbiGet(dbi, mi->mi_dbc, key, data, DB_SET); data->flags = 0; keyp = key->data; @@ -1948,16 +1954,21 @@ top: return NULL; /* Did the header blob load correctly? */ +#if !defined(_USE_COPY_LOAD) /*@-onlytrans@*/ mi->mi_h = headerLoad(uh); /*@=onlytrans@*/ + if (mi->mi_h) + mi->mi_h->flags |= HEADERFLAG_ALLOCATED; +#else + mi->mi_h = headerCopyLoad(uh); +#endif if (mi->mi_h == NULL || !headerIsEntry(mi->mi_h, RPMTAG_NAME)) { rpmError(RPMERR_BADHEADER, _("rpmdb: damaged header instance #%u retrieved, skipping.\n"), mi->mi_offset); goto top; } - mi->mi_h->flags |= HEADERFLAG_ALLOCATED; /* * Skip this header if iterator selector (if any) doesn't match. @@ -2267,21 +2278,27 @@ memset(data, 0, sizeof(*data)); continue; /*@notreached@*/ /*@switchbreak@*/ break; case RPMDBI_PACKAGES: - dbi = dbiOpen(db, rpmtag, 0); - if (dbi != NULL) { - + dbi = dbiOpen(db, rpmtag, 0); + if (dbi == NULL) /* XXX shouldn't happen */ + continue; + /*@-immediatetrans@*/ key->data = &hdrNum; /*@=immediatetrans@*/ key->size = sizeof(hdrNum); rc = dbiCopen(dbi, dbi->dbi_txnid, &dbcursor, DB_WRITECURSOR); - rc = dbiDel(dbi, dbcursor, key, data, 0); + rc = dbiGet(dbi, dbcursor, key, data, DB_SET); + if (rc) { + rpmError(RPMERR_DBGETINDEX, + _("error(%d) setting header #%d record for %s removal\n"), + rc, hdrNum, tagName(dbi->dbi_rpmtag)); + } else + rc = dbiDel(dbi, dbcursor, key, data, 0); xx = dbiCclose(dbi, dbcursor, DB_WRITECURSOR); dbcursor = NULL; if (!dbi->dbi_no_dbsync) xx = dbiSync(dbi, 0); - } continue; /*@notreached@*/ /*@switchbreak@*/ break; } @@ -2416,7 +2433,7 @@ if (key->size == 0) key->size++; /* XXX "/" fixup. */ /*@innercontinue@*/ continue; } else { /* error */ rpmError(RPMERR_DBGETINDEX, - _("error(%d) getting \"%s\" records from %s index\n"), + _("error(%d) setting \"%s\" records from %s index\n"), rc, key->data, tagName(dbi->dbi_rpmtag)); ret += 1; /*@innercontinue@*/ continue; @@ -2434,7 +2451,7 @@ if (key->size == 0) key->size++; /* XXX "/" fixup. */ if (set->count > 0) { (void) set2dbt(dbi, data, set); - rc = dbiPut(dbi, dbcursor, key, data, 0); + rc = dbiPut(dbi, dbcursor, key, data, DB_KEYLAST); if (rc) { rpmError(RPMERR_DBPUTINDEX, _("error(%d) storing record \"%s\" into %s\n"), @@ -2577,7 +2594,7 @@ memset(data, 0, sizeof(*data)); /*@=kepttrans@*/ data->size = datalen; - ret = dbiPut(dbi, dbcursor, key, data, 0); + ret = dbiPut(dbi, dbcursor, key, data, DB_KEYLAST); xx = dbiSync(dbi, 0); xx = dbiCclose(dbi, dbcursor, DB_WRITECURSOR); @@ -2621,15 +2638,16 @@ memset(data, 0, sizeof(*data)); continue; /*@notreached@*/ /*@switchbreak@*/ break; case RPMDBI_PACKAGES: - dbi = dbiOpen(db, rpmtag, 0); - if (dbi != NULL) { + dbi = dbiOpen(db, rpmtag, 0); + if (dbi == NULL) /* XXX shouldn't happen */ + continue; xx = dbiCopen(dbi, dbi->dbi_txnid, &dbcursor, DB_WRITECURSOR); key->data = (void *) &hdrNum; key->size = sizeof(hdrNum); data->data = headerUnload(h); data->size = headerSizeof(h, HEADER_MAGIC_NO); if (data->data != NULL) { - xx = dbiPut(dbi, dbcursor, key, data, 0); + xx = dbiPut(dbi, dbcursor, key, data, DB_KEYLAST); xx = dbiSync(dbi, 0); } data->data = _free(data->data); @@ -2642,7 +2660,6 @@ data->size = 0; xx = headerNVR(h, &n, &v, &r); rpmMessage(RPMMESS_DEBUG, " +++ %10u %s-%s-%s\n", hdrNum, n, v, r); } - } continue; /*@notreached@*/ /*@switchbreak@*/ break; /* XXX preserve legacy behavior */ @@ -2829,7 +2846,7 @@ if (key->size == 0) key->size++; /* XXX "/" fixup. */ (void) dbiAppendSet(set, rec, 1, sizeof(*rec), 0); (void) set2dbt(dbi, data, set); - rc = dbiPut(dbi, dbcursor, key, data, 0); + rc = dbiPut(dbi, dbcursor, key, data, DB_KEYLAST); if (rc) { rpmError(RPMERR_DBPUTINDEX, diff --git a/rpmdb/rpmdb.h b/rpmdb/rpmdb.h index 5a43f7e98..815264c3b 100644 --- a/rpmdb/rpmdb.h +++ b/rpmdb/rpmdb.h @@ -290,7 +290,6 @@ struct _dbiIndex { int dbi_verify_on_close; int dbi_tear_down; /*!< tear down dbenv on close */ - int dbi_use_cursors; /*!< access with cursors? (always) */ int dbi_use_dbenv; /*!< use db environment? */ int dbi_permit_dups; /*!< permit duplicate entries? */ int dbi_no_fsync; /*!< no-op fsync for db */ @@ -300,9 +299,10 @@ struct _dbiIndex { int dbi_debug; int dbi_byteswapped; -/*@null@*/ char * dbi_host; - long dbi_cl_timeout; - long dbi_sv_timeout; +/*@null@*/ + char * dbi_host; + unsigned long dbi_cl_timeout; + unsigned long dbi_sv_timeout; /* dbenv parameters */ int dbi_lorder; |