#include "system.h"
#include <sys/file.h>
#include <signal.h>
#include <sys/signal.h>
#include <fnmatch.h>
#include <regex.h>
#include <rpmcli.h>
#include "rpmdb.h"
#include "fprint.h"
#include "misc.h"
#include "debug.h"
Go to the source code of this file.
Data Structures | |
union | _dbswap |
struct | miRE_s |
struct | _rpmdbMatchIterator |
Defines | |
#define | INLINE |
#define | _DBI_FLAGS 0 |
#define | _DBI_PERMS 0644 |
#define | _DBI_MAJOR -1 |
#define | DB1vec NULL |
#define | DB2vec NULL |
#define | DB3vec NULL |
#define | _DBSWAP(_a) |
#define | _DB_ROOT "/" |
#define | _DB_HOME "%{_dbpath}" |
#define | _DB_FLAGS 0 |
#define | _DB_MODE 0 |
#define | _DB_PERMS 0644 |
#define | _DB_MAJOR -1 |
#define | _DB_ERRPFX "rpmdb" |
#define | _RECNUM rpmdbGetIteratorOffset(mi) |
Typedefs | |
typedef miRE_s * | miRE |
Functions | |
static int | dbiTagToDbix (int rpmtag) |
Return dbi index used for rpm tag. | |
static void | dbiTagsInit (void) |
Initialize database (index, tag) tuple from configuration. | |
int | dbiSync (dbiIndex dbi, unsigned int flags) |
Flush pending operations to disk. | |
int | dbiByteSwapped (dbiIndex dbi) |
Is database byte swapped? | |
int | dbiCopen (dbiIndex dbi, void **dbcp, unsigned int flags) |
int | dbiCclose (dbiIndex dbi, void *dbcursor, unsigned int flags) |
static int | printable (const void *ptr, size_t len) |
int | dbiDel (dbiIndex dbi, void *dbcursor, const void *keyp, size_t keylen, unsigned int flags) |
Delete (key,data) pair(s) from index database. | |
int | dbiGet (dbiIndex dbi, void *dbcursor, void **keypp, size_t *keylenp, void **datapp, size_t *datalenp, unsigned int flags) |
Retrieve (key,data) pair from index database. | |
int | dbiPut (dbiIndex dbi, void *dbcursor, const void *keyp, size_t keylen, const void *datap, size_t datalen, unsigned int flags) |
Store (key,data) pair in index database. | |
int | dbiCount (dbiIndex dbi, void *dbcursor, unsigned int *countp, unsigned int flags) |
Retrieve count of (possible) duplicate items. | |
int | dbiVerify (dbiIndex dbi, unsigned int flags) |
Verify (and close) index database. | |
int | dbiClose (dbiIndex dbi, unsigned int flags) |
Close index database. | |
dbiIndex | dbiOpen (rpmdb db, int rpmtag, unsigned int flags) |
Return handle for an index database. | |
static dbiIndexItem | dbiIndexNewItem (unsigned int hdrNum, unsigned int tagNum) |
Create and initialize item for index database set. | |
static int | dbiSearch (dbiIndex dbi, void *dbcursor, const char *keyp, size_t keylen, dbiIndexSet *setp) |
Return items that match criteria. | |
static int | dbiUpdateIndex (dbiIndex dbi, void *dbcursor, const void *keyp, size_t keylen, dbiIndexSet set) |
Change/delete items that match criteria. | |
static int | hdrNumCmp (const void *one, const void *two) |
static int | dbiAppendSet (dbiIndexSet set, const void *recs, int nrecs, size_t recsize, int sortset) |
Append element(s) to set of index database items. | |
static int | dbiPruneSet (dbiIndexSet set, void *recs, int nrecs, size_t recsize, int sorted) |
Remove element(s) from set of index database items. | |
unsigned int | dbiIndexSetCount (dbiIndexSet set) |
Count items in index database set. | |
unsigned int | dbiIndexRecordOffset (dbiIndexSet set, int recno) |
Return record offset of header from element in index database set. | |
unsigned int | dbiIndexRecordFileNumber (dbiIndexSet set, int recno) |
Return file index from element in index database set. | |
dbiIndexSet | dbiFreeIndexSet (dbiIndexSet set) |
Destroy set of index database items. | |
static int | blockSignals (rpmdb db, sigset_t *oldMask) |
Disable all signals, returning previous signal mask. | |
static int | unblockSignals (rpmdb db, sigset_t *oldMask) |
Restore signal mask. | |
int | rpmdbOpenAll (rpmdb db) |
Open all database indices. | |
int | rpmdbClose (rpmdb db) |
Close all database indices and free rpmdb. | |
int | rpmdbSync (rpmdb db) |
Sync all database indices. | |
static rpmdb | newRpmdb (const char *root, const char *home, int mode, int perms, int flags) |
static int | openDatabase (const char *prefix, const char *dbpath, int _dbapi, rpmdb *dbp, int mode, int perms, int flags) |
int | rpmdbOpen (const char *prefix, rpmdb *dbp, int mode, int perms) |
Open rpm database. | |
int | rpmdbInit (const char *prefix, int perms) |
Initialize database. | |
int | rpmdbVerify (const char *prefix) |
Verify database components. | |
static int | rpmdbFindByFile (rpmdb db, const char *filespec, dbiIndexSet *matches) |
int | rpmdbCountPackages (rpmdb db, const char *name) |
Return number of instances of package in rpm database. | |
static int | dbiFindMatches (dbiIndex dbi, void *dbcursor, const char *name, const char *version, const char *release, dbiIndexSet *matches) |
Attempt partial matches on name[-version[-release]] strings. | |
static int | dbiFindByLabel (dbiIndex dbi, void *dbcursor, const char *arg, dbiIndexSet *matches) |
Lookup by name, name-version, and finally by name-version-release. | |
static int | dbiUpdateRecord (dbiIndex dbi, void *dbcursor, int offset, Header h) |
Rewrite a header in the database. | |
rpmdbMatchIterator | rpmdbFreeIterator (rpmdbMatchIterator mi) |
Destroy rpm database iterator. | |
rpmdb | rpmdbGetIteratorRpmDB (rpmdbMatchIterator mi) |
Return rpm database used by iterator. | |
unsigned int | rpmdbGetIteratorOffset (rpmdbMatchIterator mi) |
Return join key for current position of rpm database iterator. | |
unsigned int | rpmdbGetIteratorFileNum (rpmdbMatchIterator mi) |
int | rpmdbGetIteratorCount (rpmdbMatchIterator mi) |
Return number of elements in rpm database iterator. | |
static int | miregexec (miRE mire, const char *val) |
Return pattern match. | |
static int | mireCmp (const void *a, const void *b) |
Compare iterator selctors by rpm tag (qsort/bsearch). | |
static char * | mireDup (rpmTag tag, rpmMireMode *modep, const char *pattern) |
Copy pattern, escaping for appropriate mode. | |
int | rpmdbSetIteratorRE (rpmdbMatchIterator mi, rpmTag tag, rpmMireMode mode, const char *pattern) |
Add pattern to iterator selector. | |
static int | mireSkip (const rpmdbMatchIterator mi) |
Return iterator selector match. | |
int | rpmdbSetIteratorRelease (rpmdbMatchIterator mi, const char *release) |
Modify iterator to filter out headers that do not match release. | |
int | rpmdbSetIteratorVersion (rpmdbMatchIterator mi, const char *version) |
Modify iterator to filter out headers that do not match version. | |
int | rpmdbSetIteratorRewrite (rpmdbMatchIterator mi, int rewrite) |
Prepare iterator for lazy writes. | |
int | rpmdbSetIteratorModified (rpmdbMatchIterator mi, int modified) |
Modify iterator to mark header for lazy write. | |
Header | XrpmdbNextIterator (rpmdbMatchIterator mi, const char *f, unsigned int l) |
Header | rpmdbNextIterator (rpmdbMatchIterator mi) |
Return next package header from iteration. | |
static void | rpmdbSortIterator (rpmdbMatchIterator mi) |
static int | rpmdbGrowIterator (rpmdbMatchIterator mi, const void *keyp, size_t keylen, int fpNum) |
int | rpmdbPruneIterator (rpmdbMatchIterator mi, int *hdrNums, int nHdrNums, int sorted) |
Remove items from set of package instances to iterate. | |
int | rpmdbAppendIterator (rpmdbMatchIterator mi, const int *hdrNums, int nHdrNums) |
Append items to set of package instances to iterate. | |
rpmdbMatchIterator | rpmdbInitIterator (rpmdb db, int rpmtag, const void *keyp, size_t keylen) |
Return database iterator. | |
static int | removeIndexEntry (dbiIndex dbi, void *dbcursor, const void *keyp, size_t keylen, dbiIndexItem rec) |
Remove entry from database index. | |
int | rpmdbRemove (rpmdb db, int rid, unsigned int hdrNum) |
Remove package header from rpm database and indices. | |
static int | addIndexEntry (dbiIndex dbi, void *dbcursor, const char *keyp, size_t keylen, dbiIndexItem rec) |
Add entry to database index. | |
int | rpmdbAdd (rpmdb db, int iid, Header h) |
Add package header to rpm database and indices. | |
int | rpmdbFindFpList (rpmdb db, fingerPrint *fpList, dbiIndexSet *matchList, int numItems) |
Find fingerprint matches in database. | |
char * | db1basename (int rpmtag) |
Return base file name for db1 database (legacy). | |
static int | rpmioFileExists (const char *urlfn) |
Check if file esists using stat(2). | |
static int | rpmdbRemoveDatabase (const char *prefix, const char *dbpath, int _dbapi) |
static int | rpmdbMoveDatabase (const char *prefix, const char *olddbpath, int _olddbapi, const char *newdbpath, int _newdbapi) |
int | rpmdbRebuild (const char *prefix) |
Rebuild database indices from package headers. | |
Variables | |
static int | _debug = 0 |
int | _noDirTokens |
Should version 3 packages be produced? | |
static int | _rebuildinprogress = 0 |
static int | _db_filter_dups = 0 |
int * | dbiTags = NULL |
Tags for which rpmdb indices will be built. | |
int | dbiTagsMax = 0 |
static struct _dbiVec * | mydbvecs [] |
static struct rpmdb_s | dbTemplate |
Definition in file rpmdb.c.
|
Definition at line 786 of file rpmdb.c. Referenced by newRpmdb(). |
|
|
|
Definition at line 780 of file rpmdb.c. Referenced by newRpmdb(). |
|
|
|
|
|
|
|
Definition at line 779 of file rpmdb.c. Referenced by newRpmdb(). |
|
|
|
|
|
|
|
Value: { unsigned char _b, *_c = (_a).uc; \ _b = _c[3]; _c[3] = _c[0]; _c[0] = _b; \ _b = _c[2]; _c[2] = _c[1]; _c[1] = _b; \ } Definition at line 462 of file rpmdb.c. Referenced by dbiSearch(), and dbiUpdateIndex(). |
|
Referenced by main(), and rpmdbRebuild(). |
|
|
|
|
|
|
|
|
|
|
|
Add entry to database index.
Definition at line 2558 of file rpmdb.c. References _dbiIndex::dbi_permit_dups, dbiAppendSet(), dbiFreeIndexSet(), dbiSearch(), dbiUpdateIndex(), and xcalloc(). |
|
Disable all signals, returning previous signal mask.
Definition at line 759 of file rpmdb.c. Referenced by dbiUpdateRecord(), rpmdbAdd(), and rpmdbRemove(). |
|
Append element(s) to set of index database items.
Definition at line 665 of file rpmdb.c. References _dbiIndexSet::count, hdrNumCmp(), _dbiIndexSet::recs, and xrealloc(). Referenced by addIndexEntry(), rpmdbAppendIterator(), and rpmdbFindByFile(). |
|
Lookup by name, name-version, and finally by name-version-release. Both version and release can be patterns.
Definition at line 1396 of file rpmdb.c. References alloca(), dbiFindMatches(), dbiFreeIndexSet(), and stpcpy(). Referenced by rpmdbInitIterator(). |
|
Attempt partial matches on name[-version[-release]] strings.
Definition at line 1303 of file rpmdb.c. References _dbiIndex::dbi_rpmdb, dbiIndexRecordOffset(), dbiIndexSetCount(), dbiSearch(), headerFree(), headerLink(), rpmdbFreeIterator(), RPMDBI_PACKAGES, rpmdbInitIterator(), rpmdbNextIterator(), rpmdbSetIteratorRE(), RPMMIRE_DEFAULT, RPMTAG_RELEASE, and RPMTAG_VERSION. Referenced by dbiFindByLabel(). |
|
Create and initialize item for index database set.
Definition at line 448 of file rpmdb.c. References xcalloc(). Referenced by rpmdbAdd(), rpmdbFindByFile(), and rpmdbRemove(). |
|
Remove element(s) from set of index database items.
Definition at line 706 of file rpmdb.c. References _dbiIndexSet::count, hdrNumCmp(), and _dbiIndexSet::recs. Referenced by removeIndexEntry(), and rpmdbPruneIterator(). |
|
Return items that match criteria.
Definition at line 477 of file rpmdb.c. References _, _DBSWAP, _dbiIndex::dbi_jlen, _dbiIndex::dbi_rpmtag, dbiByteSwapped(), dbiGet(), RPMERR_DBGETINDEX, rpmError, tagName(), _dbswap::ui, and xmalloc(). Referenced by addIndexEntry(), dbiFindMatches(), removeIndexEntry(), rpmdbCountPackages(), rpmdbFindByFile(), rpmdbGrowIterator(), and rpmdbInitIterator(). |
|
Initialize database (index, tag) tuple from configuration.
Definition at line 86 of file rpmdb.c. References _free(), dbiTags, dbiTagsMax, RPMDBI_PACKAGES, rpmExpand(), xcalloc(), xisspace(), and xstrdup(). Referenced by openDatabase(). |
|
Return dbi index used for rpm tag.
Definition at line 70 of file rpmdb.c. References dbiTags, and dbiTagsMax. Referenced by dbiOpen(). |
|
Change/delete items that match criteria.
Definition at line 567 of file rpmdb.c. References _DBSWAP, alloca(), _dbiIndexSet::count, _dbiIndex::dbi_jlen, dbiByteSwapped(), _dbiIndexItem::hdrNum, _dbiIndexSet::recs, and _dbiIndexItem::tagNum. Referenced by addIndexEntry(), and removeIndexEntry(). |
|
Rewrite a header in the database. Note: this is called from a markReplacedFiles iteration, and *must* preserve the "join key" (i.e. offset) for the header.
Definition at line 1486 of file rpmdb.c. References _free(), _noDirTokens, blockSignals(), _dbiIndex::dbi_rpmdb, dbiPut(), dbiSync(), expandFilelist(), HEADER_MAGIC_NO, headerSizeof(), headerUnload(), and unblockSignals(). Referenced by rpmdbAdd(), rpmdbFreeIterator(), and rpmdbNextIterator(). |
|
Definition at line 649 of file rpmdb.c. Referenced by dbiAppendSet(), dbiPruneSet(), and rpmdbSortIterator(). |
|
Compare iterator selctors by rpm tag (qsort/bsearch).
Definition at line 1673 of file rpmdb.c. References miRE_s::tag. Referenced by rpmdbSetIteratorRE(). |
|
Copy pattern, escaping for appropriate mode.
Definition at line 1687 of file rpmdb.c. References RPMMIRE_DEFAULT, RPMMIRE_GLOB, RPMTAG_BASENAMES, RPMTAG_DIRNAMES, and xstrdup(). Referenced by rpmdbSetIteratorRE(). |
|
Return pattern match.
Definition at line 1629 of file rpmdb.c. References miRE_s::eflags, miRE_s::fnflags, miRE_s::mode, miRE_s::pattern, miRE_s::preg, RPMERR_REGEXEC, rpmError, RPMMIRE_DEFAULT, RPMMIRE_GLOB, RPMMIRE_REGEX, and RPMMIRE_STRCMP. Referenced by mireSkip(). |
|
Return iterator selector match.
Definition at line 1886 of file rpmdb.c. References headerFreeData(), headerGetEntryMinMemory(), miregexec(), miRE_s::notmatch, RPM_CHAR_TYPE, RPM_I18NSTRING_TYPE, RPM_INT16_TYPE, RPM_INT32_TYPE, RPM_INT8_TYPE, RPM_STRING_ARRAY_TYPE, RPM_STRING_TYPE, and miRE_s::tag. Referenced by rpmdbNextIterator(). |
|
Definition at line 858 of file rpmdb.c. References _, _DB_ERRPFX, _db_filter_dups, _DB_HOME, _DB_ROOT, rpmdb_s::_dbi, _free(), dbiTagsMax, dbTemplate, RPMERR_DBOPEN, rpmError, rpmExpand(), rpmExpandNumeric(), rpmGetPath(), and xcalloc(). Referenced by openDatabase(). |
|
Definition at line 906 of file rpmdb.c. References alloca(), dbiTagsInit(), dbiTagsMax, newRpmdb(), rpmCleanPath(), RPMDB_FLAG_JUSTCHECK, RPMDB_FLAG_MINIMAL, and rpmExpandNumeric(). Referenced by rpmdbInit(), rpmdbOpen(), rpmdbRebuild(), and rpmdbVerify(). |
|
|
|
Remove entry from database index.
Definition at line 2339 of file rpmdb.c. References dbiFreeIndexSet(), dbiPruneSet(), dbiSearch(), and dbiUpdateIndex(). Referenced by rpmdbRemove(). |
|
Definition at line 1124 of file rpmdb.c. References _free(), alloca(), DBC, dbiAppendSet(), dbiCclose(), dbiCopen(), dbiFreeIndexSet(), dbiIndexNewItem(), dbiIndexRecordFileNumber(), dbiIndexRecordOffset(), dbiOpen(), dbiSearch(), dirName, FP_EQUAL, fpCacheCreate(), fpCacheFree(), fpLookup(), _dbiIndexItem::hdrNum, headerFree(), headerFreeData(), headerGetEntryMinMemory(), headerLink(), rpmdbFreeIterator(), RPMDBI_PACKAGES, rpmdbInitIterator(), rpmdbNextIterator(), RPMTAG_BASENAMES, RPMTAG_DIRINDEXES, RPMTAG_DIRNAMES, _dbiIndexItem::tagNum, and xcalloc(). Referenced by rpmdbInitIterator(). |
|
Definition at line 2159 of file rpmdb.c. References _dbiIndexSet::count, DBC, dbiCclose(), dbiCopen(), dbiOpen(), dbiSearch(), _dbiIndexItem::fpNum, _dbiIndexSet::recs, and xrealloc(). Referenced by rpmdbFindFpList(). |
|
Definition at line 3098 of file rpmdb.c. References alloca(), dbiTags, Rename(), rpmCleanPath(), RPMDBI_ADDED, RPMDBI_AVAILABLE, RPMDBI_DEPENDS, RPMDBI_REMOVED, rpmioFileExists(), and tagName(). Referenced by rpmdbRebuild(). |
|
Definition at line 3034 of file rpmdb.c. References alloca(), dbiTags, rpmCleanPath(), rpmioFileExists(), and tagName(). Referenced by rpmdbRebuild(). |
|
Definition at line 2149 of file rpmdb.c. References hdrNumCmp(). |
|
Check if file esists using stat(2).
Definition at line 3001 of file rpmdb.c. References errno, Stat(), URL_IS_DASH, URL_IS_FTP, URL_IS_HTTP, URL_IS_PATH, URL_IS_UNKNOWN, and urlPath(). Referenced by rpmdbMoveDatabase(), and rpmdbRemoveDatabase(). |
|
Restore signal mask.
Definition at line 772 of file rpmdb.c. Referenced by dbiUpdateRecord(). |
|
Definition at line 2013 of file rpmdb.c. References rpmdbNextIterator(). |
|
Definition at line 54 of file rpmdb.c. Referenced by newRpmdb(), and rpmdbRebuild(). |
|
|
|
Definition at line 52 of file rpmdb.c. Referenced by dbiOpen(), and rpmdbRebuild(). |
|
Definition at line 63 of file rpmdb.c. Referenced by dbiOpen(), dbiTagsInit(), dbiTagToDbix(), newRpmdb(), openDatabase(), rpmdbCloseDBI(), and rpmdbOpenAll(). |
|
Initial value: { "/" , "%{_dbpath}" , 0 , 0 , 0644 , -1 , "rpmdb" } Definition at line 790 of file rpmdb.c. Referenced by newRpmdb(). |
|
Initial value: { NULL , NULL , NULL , NULL , NULL } Definition at line 171 of file rpmdb.c. Referenced by dbiOpen(). |