rpmdb.c File Reference
RPMDB Database API. | RPMDBI DataBase Index Element API.
`#include "system.h"`
`#include <sys/file.h>`
`#include <rpmiotypes.h>`
`#include <rpmlog.h>`
`#include <rpmpgp.h>`
`#include <rpmurl.h>`
`#include <rpmmacro.h>`
`#include <rpmsq.h>`
`#include <argv.h>`
`#include <rpmtypes.h>`
`#include "header_internal.h"`
`#include <rpmevr.h>`
`#include "rpmdb.h"`
`#include "pkgio.h"`
`#include "fprint.h"`
`#include "legacy.h"`
`#include "debug.h"`
Include dependency graph for rpmdb.c:

Go to the source code of this file.

## Data Structures

struct | pbm_set
union | _dbswap
struct | rpmmi_s

## Macros

#define | _MIRE_INTERNAL
#define | _RPMTAG_INTERNAL
#define | _RPMEVR_INTERNAL /* XXX isInstallPrereq */
#define | _RPMDB_INTERNAL
#define | UINT32_T rpmuint32_t
#define | _DB_TAGGED_FILE_INDICES 1
#define | _DB_TAGGED_FINDBYFILE 1
#define | _DBI_FLAGS 0
#define | _DBI_PERMS 0644
#define | _DBI_MAJOR -1
#define | __PBM_NBITS /*@-sizeoftype@*/(8 * sizeof(__pbm_bits))/*@=sizeoftype@*/
#define | __PBM_IX(d) ((d) / __PBM_NBITS)
#define | __PBM_MASK(d) ((__pbm_bits) 1 << (((unsigned)(d)) % __PBM_NBITS))
#define | __PBM_BITS(set) ((set)->bits)
#define | PBM_FREE(s) _free(s);
#define | PBM_SET(d, s) (__PBM_BITS (s)[__PBM_IX (d)] |= __PBM_MASK (d))
#define | PBM_CLR(d, s) (__PBM_BITS (s)[__PBM_IX (d)] &= ~__PBM_MASK (d))
#define | PBM_ISSET(d, s) ((__PBM_BITS (s)[__PBM_IX (d)] & __PBM_MASK (d)) != 0)
#define | PBM_ALLOC(d) xcalloc(__PBM_IX (d) + 1, __PBM_NBITS/8)
#define | DB1vec NULL
#define | DB2vec NULL
#define | DB3vec NULL
#define | SQLITEvec 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 rpmmiInstance(mi)

## Typedefs

typedef unsigned int | __pbm_bits

## Functions

pgpDig | rpmtsDig (void *ts)
void | rpmtsCleanDig (void *ts)
static pbm_set * | PBM_REALLOC (pbm_set **sp, int *odp, int nd)
| Reallocate a bit map. More...
static unsigned char | nibble (char c)
| Convert hex to binary nibble. More...
static char * | bin2hex (const void *data, size_t size)
| Convert binary blob to printable hex string. More...
static size_t | dbiTagToDbix (rpmdb db, rpmTag tag)
| Return dbi index used for rpm tag. More...
static void | dbiTagsInit (tagStore_t *dbiTagsP, size_t *dbiNTagsP)
| Initialize database (index, tag) tuple from configuration. More...
static int | checkfd (const char *devnull, int fdno, int flags)
dbiIndex | dbiOpen (rpmdb db, rpmTag tag, unsigned int flags)
static dbiIndexItem | dbiIndexNewItem (unsigned int hdrNum, unsigned int tagNum)
| Create and initialize item for index database set. More...
static int | dbt2set (dbiIndex dbi, DBT *data, dbiIndexSet *setp)
| Convert retrieved data to index set. More...
static int | set2dbt (dbiIndex dbi, DBT *data, dbiIndexSet set)
| Convert index set to database representation. More...
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. More...
static int | dbiPruneSet (dbiIndexSet set, void *recs, int nrecs, size_t recsize, int sorted)
| Remove element(s) from set of index database items. More...
unsigned int | dbiIndexSetCount (dbiIndexSet set)
unsigned int | dbiIndexRecordOffset (dbiIndexSet set, int recno)
unsigned int | dbiIndexRecordFileNumber (dbiIndexSet set, int recno)
dbiIndexSet | dbiFreeIndexSet (dbiIndexSet set)
int | rpmdbCheckTerminate (int terminate)
| Check rpmdb signal handler for trapped signal and/or requested exit. More...
int | rpmdbCheckSignals (void)
| Check for and exit on termination signals. More...
static int | blockSignals (rpmdb db, sigset_t *oldMask)
| Block all signals, returning previous signal mask. More...
static int | unblockSignals (rpmdb db, sigset_t *oldMask)
| Restore signal mask. More...
static const char * | queryHeader (Header h, const char *qfmt)
| Return header query string. More...
static int | rpmdbExportInfo (rpmdb db, Header h, int adding)
| Write added/removed header info. More...
static rpmdb | rpmdbGetPool (rpmioPool pool)
int | rpmdbOpenAll (rpmdb db)
| Open all database indices. More...
int | rpmdbBlockDBI (rpmdb db, int tag)
| Block access to a single database index. More...
int | rpmdbCloseDBI (rpmdb db, int tag)
| Close a single database index. More...
int | rpmdbClose (rpmdb db)
| Close all database indices and free rpmdb. More...
int | rpmdbSync (rpmdb db)
| Sync all database indices. More...
static const char * | rpmdbURIPath (const char *uri)
| Return macro expanded absolute path to rpmdb. More...
rpmdb | rpmdbNew (const char *root, const char *home, int mode, int perms, int flags)
int | rpmdbOpenDatabase (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. More...
int | rpmdbInit (const char *prefix, int perms)
| Initialize database. More...
int | rpmdbVerifyAllDBI (rpmdb db)
| Verify all database components. More...
int | rpmdbVerify (const char *prefix)
| Open and verify all database components. More...
static unsigned | taghash (const char *s)
| Return a tagnum with hash on the (directory) path in upper 16 bits. More...
static int | dbiIntersect (unsigned int tag, dbiIndexSet dnset, dbiIndexSet bnset, dbiIndexSet *matches)
| Return the intersection of dirName <=> baseName index sets. More...
static int | rpmdbFindByFile (rpmdb db, const char *filespec, DBT *key, DBT *data, dbiIndexSet *matches)
| Find file matches in database. More...
int | rpmdbCount (rpmdb db, rpmTag tag, const void *keyp, size_t keylen)
| Return number of instances of key in a tag index. More...
int | rpmdbCountPackages (rpmdb db, const char *name)
| Return number of instances of package in Name index. More...
static rpmRC | dbiFindMatches (dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *data, const char *name, const char *version, const char *release, dbiIndexSet *matches)
| Attempt partial matches on name[-version[-release]] strings. More...
static rpmRC | dbiFindByLabel (dbiIndex dbi, DBC *dbcursor, DBT *key, DBT *data, const char *arg, dbiIndexSet *matches)
| Lookup by name, name-version, and finally by name-version-release. More...
void * | dbiStatsAccumulator (dbiIndex dbi, int opx)
static int | miFreeHeader (rpmmi mi, dbiIndex dbi)
| Rewrite a header into packages (if necessary) and free the header. More...
static void | rpmmiFini (void *_mi)
static rpmmi | rpmmiGetPool (rpmioPool pool)
unsigned int | rpmmiInstance (rpmmi mi)
| Return header instance join key for current position of rpmdb iterator. More...
unsigned int | rpmmiFilenum (rpmmi mi)
| Return header tag index join key for current position of rpmdb iterator. More...
int | rpmmiCount (rpmmi mi)
| Return number of elements in rpm database iterator. More...
static int | mireCmp (const void *a, const void *b)
| Compare iterator selectors by rpm tag (qsort/bsearch). More...
static char * | mireDup (rpmTag tag, rpmMireMode *modep, const char *pattern)
| Copy pattern, escaping for appropriate mode. More...
int | rpmmiAddPattern (rpmmi mi, rpmTag tag, rpmMireMode mode, const char *pattern)
| Add pattern to iterator selector. More...
static int | mireSkip (const rpmmi mi)
| Return iterator selector match. More...
int | rpmmiSetRewrite (rpmmi mi, int rewrite)
| Prepare iterator for lazy writes. More...
int | rpmmiSetModified (rpmmi mi, int modified)
| Modify iterator to mark header for lazy write on release. More...
int | rpmmiSetHdrChk (rpmmi mi, rpmts ts)
| Modify iterator to verify retrieved header blobs. More...
static int | rpmmiGet (dbiIndex dbi, DBC *dbcursor, DBT *kp, DBT *vp, unsigned int flags)
Header | rpmmiNext (rpmmi mi)
| Return next package header from iteration. More...
static void | rpmdbSortIterator (rpmmi mi)
static int | rpmdbGrowIterator (rpmmi mi, int fpNum, unsigned int exclude, unsigned int tag)
int | rpmmiPrune (rpmmi mi, int *hdrNums, int nHdrNums, int sorted)
| Remove items from set of package instances to iterate. More...
int | rpmmiGrow (rpmmi mi, const int *hdrNums, int nHdrNums)
| Append items to set of package instances to iterate. More...
rpmmi | rpmmiInit (rpmdb db, rpmTag tag, const void *keyp, size_t keylen)
| Return database iterator. More...
int | rpmdbMireApply (rpmdb db, rpmTag tag, rpmMireMode mode, const char *pat, const char ***argvp)
| Return array of keys matching a pattern. More...
int | rpmdbRemove (rpmdb db, int rid, unsigned int hdrNum, rpmts ts)
| Remove package header from rpm database and indices. More...
int | rpmdbAdd (rpmdb db, int iid, Header h, rpmts ts)
| Add package header to rpm database and indices. More...
int | rpmdbFindFpList (void *_db, fingerPrint *fpList, void *_matchList, int numItems, unsigned int exclude)
| Find fingerprint matches in database. More...
static int | rpmioFileExists (const char *urlfn)
| Check if file exists using stat(2). More...
static int | rpmdbRemoveDatabase (const char *prefix, const char *dbpath, int _dbapi, const tagStore_t dbiTags, size_t dbiNTags)
static int | rpmdbMoveDatabase (const char *prefix, const char *olddbpath, int _olddbapi, const char *newdbpath, int _newdbapi, const tagStore_t dbiTags, size_t dbiNTags)
int | rpmdbRebuild (const char *prefix, rpmts ts)
| Rebuild database indices from package headers. More...

## Variables

int | _rpmdb_debug = 0
static int | _rebuildinprogress = 0
static int | _db_filter_dups = 0
static int | _db_tagged_file_indices = 1
static int | _db_tagged_findbyfile = 1
static struct _dbiVec * | mydbvecs []
static rpmdb | rpmdbRock
static rpmmi | rpmmiRock
rpmioPool | _rpmdbPool
int | _rpmmi_debug = 0
rpmioPool | _rpmmiPool
static int | _rpmmi_usermem = 1

## Macro Definition Documentation

#define __PBM_BITS | ( |  | set | ) | ((set)->bits)

Definition at line 95 of file rpmdb.c.

Referenced by PBM_REALLOC().

#define __PBM_IX | ( |  | d | ) | ((d) / __PBM_NBITS)

Definition at line 88 of file rpmdb.c.

Referenced by PBM_REALLOC().

#define __PBM_MASK | ( |  | d | ) | ((__pbm_bits) 1 << (((unsigned)(d)) % __PBM_NBITS))

Definition at line 89 of file rpmdb.c.

#define __PBM_NBITS /*@-sizeoftype@*/(8 * sizeof(__pbm_bits))/*@=sizeoftype@*/

Definition at line 87 of file rpmdb.c.

Referenced by PBM_REALLOC().

#define _DB_ERRPFX "rpmdb"

Definition at line 1167 of file rpmdb.c.

Referenced by rpmdbNew().

#define _DB_FLAGS 0

Definition at line 1162 of file rpmdb.c.

Referenced by rpmdbNew().

#define _DB_HOME "%{?_dbpath}"

Definition at line 1161 of file rpmdb.c.

Referenced by rpmdbNew().

#define _DB_MAJOR -1

Definition at line 1166 of file rpmdb.c.

Referenced by rpmdbNew().

#define _DB_MODE 0

Definition at line 1163 of file rpmdb.c.

Referenced by rpmdbNew().

#define _DB_PERMS 0644

Definition at line 1164 of file rpmdb.c.

Referenced by rpmdbNew().

#define _DB_ROOT "/"

Definition at line 1160 of file rpmdb.c.

Referenced by rpmdbNew().

#define _DB_TAGGED_FILE_INDICES 1

Definition at line 70 of file rpmdb.c.

#define _DB_TAGGED_FINDBYFILE 1

Definition at line 75 of file rpmdb.c.

#define _DBI_FLAGS 0

Definition at line 79 of file rpmdb.c.

#define _DBI_MAJOR -1

Definition at line 81 of file rpmdb.c.

#define _DBI_PERMS 0644

Definition at line 80 of file rpmdb.c.

#define _DBSWAP | ( |  | _a | ) |

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 474 of file rpmdb.c.

Referenced by dbt2set(), rpmdbAdd(), rpmdbRemove(), rpmmiNext(), and set2dbt().

#define _MIRE_INTERNAL

Definition at line 13 of file rpmdb.c.

#define _RECNUM rpmmiInstance(mi)

Referenced by rpmdbRebuild().

#define _RPMDB_INTERNAL

Definition at line 34 of file rpmdb.c.

#define _RPMEVR_INTERNAL /* XXX isInstallPrereq */

Definition at line 23 of file rpmdb.c.

#define _RPMTAG_INTERNAL

Definition at line 20 of file rpmdb.c.

#define DB1vec NULL

Definition at line 287 of file rpmdb.c.

#define DB2vec NULL

Definition at line 288 of file rpmdb.c.

#define DB3vec NULL

Definition at line 298 of file rpmdb.c.

#define PBM_ALLOC | ( |  | d | ) | xcalloc(__PBM_IX (d) + 1, __PBM_NBITS/8)

Definition at line 102 of file rpmdb.c.

Referenced by dbiOpen().

#define PBM_CLR | ( |  | d,
|  |  | s
| ) |  | (__PBM_BITS (s)[__PBM_IX (d)] &= ~__PBM_MASK (d))

Definition at line 99 of file rpmdb.c.

#define PBM_FREE | ( |  | s | ) | _free(s);

Definition at line 97 of file rpmdb.c.

Referenced by rpmdbClose().

#define PBM_ISSET | ( |  | d,
|  |  | s
| ) |  | ((__PBM_BITS (s)[__PBM_IX (d)] & __PBM_MASK (d)) != 0)

Definition at line 100 of file rpmdb.c.

Referenced by rpmmiNext().

#define PBM_SET | ( |  | d,
|  |  | s
| ) |  | (__PBM_BITS (s)[__PBM_IX (d)] |= __PBM_MASK (d))

Definition at line 98 of file rpmdb.c.

Referenced by rpmmiNext().

#define SQLITEvec NULL

Definition at line 310 of file rpmdb.c.

#define UINT32_T rpmuint32_t

Definition at line 45 of file rpmdb.c.

Referenced by dbiFindMatches(), miFreeHeader(), rpmdbAdd(), rpmdbCount(), rpmdbFindByFile(), rpmdbFindFpList(), rpmdbRemove(), rpmmiInit(), and set2dbt().

## Typedef Documentation

typedef unsigned int __pbm_bits

Definition at line 85 of file rpmdb.c.

## Function Documentation

static char* bin2hex | ( | const void * | data,
|  | size_t | size
| ) |  |

static

Convert binary blob to printable hex string.

Parameters

  data | binary data
  size | size of data in bytes

Returns
  malloc'd hex string

Definition at line 155 of file rpmdb.c.

References xmalloc().

Referenced by mireSkip().

static int blockSignals | ( | rpmdb | db,
|  | sigset_t * | oldMask
| ) |  |

static

Block all signals, returning previous signal mask.

Parameters

  db | rpm database

Return values

  *oldMask | previous sigset

Returns
  0 on success

Definition at line 822 of file rpmdb.c.

Referenced by miFreeHeader(), rpmdbAdd(), rpmdbMoveDatabase(), and rpmdbRemove().

static int checkfd | ( | const char * | devnull,
|  | int | fdno,
|  | int | flags
| ) |  |

inlinestatic

Definition at line 320 of file rpmdb.c.

References errno.

Referenced by dbiOpen().

static int dbiAppendSet | ( | dbiIndexSet | set,
|  | const void * | recs,
|  | int | nrecs,
|  | size_t | recsize,
|  | int | sortset
| ) |  |

static

Append element(s) to set of index database items.

Parameters

  set | set of index database items
  recs | array of items to append to set
  nrecs | number of items
  recsize | size of an array item
  sortset | should resulting set be sorted?

Returns
  0 success, 1 failure (bad args)

Definition at line 634 of file rpmdb.c.

References hdrNumCmp(), recs, set(), and xrealloc().

Referenced by dbiIntersect(), rpmdbAdd(), rpmdbFindByFile(), rpmdbFindFpList(), and rpmmiGrow().

static rpmRC dbiFindByLabel | ( | dbiIndex | dbi,
|  | DBC * | dbcursor,
|  | DBT * | key,
|  | DBT * | data,
|  | const char * | arg,
|  | dbiIndexSet * | matches
| ) |  |

static

Lookup by name, name-version, and finally by name-version-release.

Both version and release can be patterns.

Todo:
  Name must be an exact match, as name is a db key.

Parameters

  dbi | index database handle (always RPMTAG_NAME)
  dbcursor | index database cursor
  key | search key/length/flags
  data | search data/length/flags
  arg | name[-version[-release]] string

Return values

  matches | set of header instances that match

Returns
  RPMRC_OK on match, RPMRC_NOMATCH or RPMRC_FAIL

Definition at line 1849 of file rpmdb.c.

References alloca(), dbiFindMatches(), dbiFreeIndexSet(), RPMRC_NOTFOUND, and stpcpy().

Referenced by rpmmiInit().

static rpmRC dbiFindMatches | ( | dbiIndex | dbi,
|  | DBC * | dbcursor,
|  | DBT * | key,
|  | DBT * | data,
|  | const char * | name,
|  | const char * | version,
|  | const char * | release,
|  | dbiIndexSet * | matches
| ) |  |

static

Attempt partial matches on name[-version[-release]] strings.

Parameters

  dbi | index database handle (always RPMTAG_NAME)
  dbcursor | index database cursor
  key | search key/length/flags
  data | search data/length/flags
  name | package name
  version | package version (can be a pattern)
  release | package release (can be a pattern)

Return values

  matches | set of header instances that match

Returns
  RPMRC_OK on match, RPMRC_NOMATCH or RPMRC_FAIL

Definition at line 1753 of file rpmdb.c.

References _, __db_dbt::data, DB_NOTFOUND, DB_SET, dbiFreeIndexSet(), dbiIndexRecordOffset(), dbiIndexSetCount(), dbt2set(), RPMDBI_PACKAGES, rpmlog(), RPMLOG_ERR, rpmmiAddPattern(), rpmmiFree(), rpmmiInit(), rpmmiNext(), RPMMIRE_DEFAULT, RPMRC_FAIL, RPMRC_NOTFOUND, RPMRC_OK, RPMTAG_RELEASE, RPMTAG_VERSION, __db_dbt::size, tagName(), and UINT32_T.

Referenced by dbiFindByLabel().

dbiIndexSet dbiFreeIndexSet | ( | dbiIndexSet | set | ) |

Definition at line 715 of file rpmdb.c.

References _free(), and set().

Referenced by dbiFindByLabel(), dbiFindMatches(), rpmdbAdd(), rpmdbCount(), rpmdbFindByFile(), rpmdbGrowIterator(), rpmdbRemove(), rpmmiFini(), rpmmiInit(), and rpmtsRun().

static dbiIndexItem dbiIndexNewItem | ( | unsigned int | hdrNum,
|  | unsigned int | tagNum
| ) |  |

static

Create and initialize item for index database set.

Parameters

  hdrNum | header instance in db
  tagNum | tag index in header

Returns
  new item

Definition at line 460 of file rpmdb.c.

References xcalloc().

Referenced by rpmdbAdd(), and rpmdbRemove().

unsigned int dbiIndexRecordFileNumber | ( | dbiIndexSet | set,
|  | int | recno
| ) |  |

Definition at line 710 of file rpmdb.c.

Referenced by rpmdbFindByFile(), rpmmiNext(), and rpmtsRun().

unsigned int dbiIndexRecordOffset | ( | dbiIndexSet | set,
|  | int | recno
| ) |  |

Definition at line 705 of file rpmdb.c.

Referenced by dbiFindMatches(), rpmmiNext(), and rpmtsRun().

unsigned int dbiIndexSetCount | ( | dbiIndexSet | set | ) |

Definition at line 700 of file rpmdb.c.

Referenced by dbiFindMatches(), rpmdbCount(), and rpmtsRun().

static int dbiIntersect | ( | unsigned int | tag,
|  | dbiIndexSet | dnset,
|  | dbiIndexSet | bnset,
|  | dbiIndexSet * | matches
| ) |  |

static

Return the intersection of dirName <=> baseName index sets.

Parameters

  tag | dirName hash tag.
  dnset | dirName's set. bnset baseName's set.

Return values

  *matches | intersection of dnset and bnset (NULL if disjoint).

Returns
  no. of matches

Definition at line 1430 of file rpmdb.c.

References alloca(), dbiAppendSet(), and xcalloc().

Referenced by rpmdbFindByFile().

dbiIndex dbiOpen | ( | rpmdb | db,
|  | rpmTag | tag,
|  | unsigned int | flags
| ) |  |

Definition at line 331 of file rpmdb.c.

References _, _rebuildinprogress, _rpmdb_debug, checkfd(), D_, DB_FAST_STAT, dbiTagToDbix(), errno, __db_h_stat::hash_nkeys, PBM_ALLOC, RPMDBI_PACKAGES, rpmExpandNumeric(), rpmlog(), RPMLOG_DEBUG, RPMLOG_ERR, and tagName().

Referenced by rpmdbAdd(), rpmdbCount(), rpmdbFindByFile(), rpmdbGrowIterator(), rpmdbMireApply(), rpmdbOpenAll(), rpmdbOpenDatabase(), rpmdbRemove(), rpmmiFini(), rpmmiInit(), rpmmiNext(), rpmpsmStage(), and unsatisfiedDepend().

static int dbiPruneSet | ( | dbiIndexSet | set,
|  | void * | recs,
|  | int | nrecs,
|  | size_t | recsize,
|  | int | sorted
| ) |  |

static

Remove element(s) from set of index database items.

Parameters

  set | set of index database items
  recs | array of items to remove from set
  nrecs | number of items
  recsize | size of an array item
  sorted | array is already sorted?

Returns
  0 success, 1 failure (no items found)

Definition at line 673 of file rpmdb.c.

References hdrNumCmp(), and set().

Referenced by rpmdbRemove(), and rpmmiPrune().

void* dbiStatsAccumulator | ( | dbiIndex | dbi,
|  | int | opx
| ) |  |

Definition at line 1933 of file rpmdb.c.

static void dbiTagsInit | ( | tagStore_t * | dbiTagsP,
|  | size_t * | dbiNTagsP
| ) |  |

static

Initialize database (index, tag) tuple from configuration.

Definition at line 214 of file rpmdb.c.

References _free(), RPMDBI_PACKAGES, rpmExpand(), tagStoreFree(), tagValue(), xcalloc(), xisspace(), xrealloc(), and xstrdup().

Referenced by rpmdbNew(), and rpmdbRebuild().

static size_t dbiTagToDbix | ( | rpmdb | db,
|  | rpmTag | tag
| ) |  |

static

Return dbi index used for rpm tag.

Parameters

  db | rpm database
  tag | rpm tag

Returns
  dbi index, 0xffffffff on error

Definition at line 196 of file rpmdb.c.

Referenced by dbiOpen().

static int dbt2set | ( | dbiIndex | dbi,
|  | DBT * | data,
|  | dbiIndexSet * | setp
| ) |  |

static

Convert retrieved data to index set.

Parameters

  dbi | index database handle
  data | retrieved data

Return values

  setp | (malloc'ed) index set

Returns
  0 on success

Definition at line 487 of file rpmdb.c.

References _DBSWAP, __db_dbt::data, set(), __db_dbt::size, _dbswap::ui, and xmalloc().

Referenced by dbiFindMatches(), rpmdbAdd(), rpmdbCount(), rpmdbFindByFile(), rpmdbGrowIterator(), rpmdbRemove(), and rpmmiInit().

static int hdrNumCmp | ( | const void * | one,
|  | const void * | two
| ) |  |

static

Definition at line 618 of file rpmdb.c.

Referenced by dbiAppendSet(), dbiPruneSet(), and rpmdbSortIterator().

static int miFreeHeader | ( | rpmmi | mi,
|  | dbiIndex | dbi
| ) |  |

static

Rewrite a header into packages (if necessary) and free the header.

Note: this is called from a markReplacedFiles iteration, and must preserve the "join key" (i.e. offset) for the header.

Parameters

  mi | database iterator
  dbi | index database handle

Returns
  0 on success

Definition at line 1959 of file rpmdb.c.

References _, _free(), blockSignals(), __db_dbt::data, DB_KEYLAST, headerCheck(), headerFree(), headerUnload(), rpmmi_s::mi_dbc, rpmmi_s::mi_h, rpmmi_s::mi_modified, rpmmi_s::mi_prevoffset, rpmmi_s::mi_ts, rpmlog(), RPMLOG_DEBUG, RPMLOG_ERR, RPMRC_FAIL, RPMRC_NOTFOUND, rpmtsCleanDig(), rpmtsDig(), __db_dbt::size, tagName(), UINT32_T, and unblockSignals().

Referenced by rpmmiFini(), and rpmmiNext().

static int mireCmp | ( | const void * | a,
|  | const void * | b
| ) |  |

static

Compare iterator selectors by rpm tag (qsort/bsearch).

Parameters

  a | 1st iterator selector
  b | 2nd iterator selector

Returns
  result of comparison

Definition at line 2100 of file rpmdb.c.

Referenced by rpmmiAddPattern().

static char* mireDup | ( | rpmTag | tag,
|  | rpmMireMode * | modep,
|  | const char * | pattern
| ) |  |

static

Copy pattern, escaping for appropriate mode.

Parameters

  tag | rpm tag

Return values

  modep | type of pattern match

Parameters

  pattern | pattern to duplicate

Returns
  duplicated pattern

Definition at line 2116 of file rpmdb.c.

References RPMMIRE_DEFAULT, RPMMIRE_GLOB, RPMMIRE_REGEX, RPMMIRE_STRCMP, RPMTAG_BASENAMES, RPMTAG_DIRNAMES, xmalloc(), and xstrdup().

Referenced by rpmmiAddPattern().

static int mireSkip | ( | const rpmmi | mi | ) |

static

Return iterator selector match.

Parameters

  mi | rpm database iterator

Returns
  1 if header should be skipped

Definition at line 2297 of file rpmdb.c.

References _free(), alloca(), rpmDataType_u::argv, bin2hex(), _HE_s::c, headerGet(), rpmmi_s::mi_h, rpmmi_s::mi_nre, rpmmi_s::mi_re, mireRegexec(), _HE_s::p, rpmDataType_u::ptr, RPM_BIN_TYPE, RPM_I18NSTRING_TYPE, RPM_STRING_ARRAY_TYPE, RPM_STRING_TYPE, RPM_UINT16_TYPE, RPM_UINT32_TYPE, RPM_UINT64_TYPE, RPM_UINT8_TYPE, RPMTAG_EPOCH, rpmDataType_u::str, _HE_s::t, _HE_s::tag, rpmDataType_u::ui16p, rpmDataType_u::ui32p, rpmDataType_u::ui64p, rpmDataType_u::ui8p, and xcalloc().

Referenced by rpmmiNext().

static unsigned char nibble | ( | char | c | ) |

inlinestatic

Convert hex to binary nibble.

Parameters

  c | hex character

Returns
  binary nibble

Definition at line 136 of file rpmdb.c.

Referenced by rpmdbAdd(), and rpmdbRemove().

static pbm_set* PBM_REALLOC | ( | pbm_set ** | sp,
|  | int * | odp,
|  | int | nd
| ) |  |

inlinestatic

Reallocate a bit map.

Return values

  sp | address of bit map pointer
  odp | no. of bits in map

Parameters

  nd | desired no. of bits

Definition at line 111 of file rpmdb.c.

References __PBM_BITS, __PBM_IX, __PBM_NBITS, and xrealloc().

Referenced by rpmmiNext().

static const char* queryHeader | ( | Header | h,
|  | const char * | qfmt
| ) |  |

inlinestatic

Return header query string.

Warning
  Only compound header extensions are available here.

Parameters

  h | header
  qfmt | header sprintf format

Returns
  header query string

Definition at line 860 of file rpmdb.c.

References _, headerCompoundFormats, headerSprintf(), rpmlog(), and RPMLOG_ERR.

Referenced by rpmdbExportInfo().

int rpmdbBlockDBI | ( | rpmdb | db,
|  | int | tag
| ) |  |

Block access to a single database index.

Parameters

  db | rpm database
  tag | rpm tag (negative to block)

Returns
  0 on success

Definition at line 974 of file rpmdb.c.

Referenced by rpmgiNext().

int rpmdbCloseDBI | ( | rpmdb | db,
|  | int | tag
| ) |  |

Close a single database index.

Parameters

  db | rpm database
  tag | rpm tag

Returns
  0 on success

Definition at line 992 of file rpmdb.c.

Referenced by rpmtsCheck().

static int rpmdbExportInfo | ( | rpmdb | db,
|  | Header | h,
|  | int | adding
| ) |  |

static

Write added/removed header info.

Parameters

  db | rpm database
  h | header
  adding | adding an rpmdb header?

Returns
  0 on success

Definition at line 882 of file rpmdb.c.

References _free(), alloca(), Fclose(), Fopen(), headerGet(), _HE_s::p, rpmDataType_u::ptr, queryHeader(), rpmGetPath(), rpmlog(), RPMLOG_DEBUG, RPMTAG_INSTALLTID, _HE_s::tag, rpmDataType_u::ui32p, Unlink(), and Utime().

Referenced by rpmdbNew().

static int rpmdbFindByFile | ( | rpmdb | db,
|  | const char * | filespec,
|  | DBT * | key,
|  | DBT * | data,
|  | dbiIndexSet * | matches
| ) |  |

static

Find file matches in database.

Parameters

  db | rpm database
  filespec |
  key |
  data |
  matches |

Returns
  0 on success, 1 on not found, -2 on error

Definition at line 1478 of file rpmdb.c.

References _, _db_tagged_file_indices, _db_tagged_findbyfile, _free(), alloca(), rpmDataType_u::argv, _HE_s::c, __db_dbt::data, DB_SET, dbiAppendSet(), dbiFreeIndexSet(), dbiIndexRecordFileNumber(), dbiIntersect(), dbiOpen(), dbt2set(), dirName, FP_EQUAL, fpCacheCreate(), fpCacheFree(), fpLookup(), headerGet(), rpmmi_s::mi_set, rpmmi_s::mi_setx, _HE_s::p, rpmDataType_u::ptr, RPMDBI_PACKAGES, rpmlog(), RPMLOG_ERR, rpmmiFree(), rpmmiInit(), rpmmiInstance(), rpmmiNext(), RPMTAG_BASENAMES, RPMTAG_DIRINDEXES, RPMTAG_DIRNAMES, __db_dbt::size, _HE_s::tag, taghash(), tagName(), rpmDataType_u::ui32p, UINT32_T, and xcalloc().

Referenced by rpmmiInit().

static rpmdb rpmdbGetPool | ( | rpmioPool | pool | ) |

static

Definition at line 930 of file rpmdb.c.

References _rpmdb_debug, _rpmdbPool, rpmioGetPool(), and rpmioNewPool().

Referenced by rpmdbNew().

static int rpmdbGrowIterator | ( | rpmmi | mi,
|  | int | fpNum,
|  | unsigned int | exclude,
|  | unsigned int | tag
| ) |  |

static

Definition at line 2690 of file rpmdb.c.

References _, _db_tagged_file_indices, __db_dbt::data, DB_NOTFOUND, DB_SET, dbiFreeIndexSet(), dbiOpen(), dbt2set(), rpmmi_s::mi_data, rpmmi_s::mi_db, rpmmi_s::mi_dbc, rpmmi_s::mi_key, rpmmi_s::mi_rpmtag, rpmmi_s::mi_set, rpmlog(), RPMLOG_ERR, set(), tagName(), and xrealloc().

Referenced by rpmdbFindFpList().

static int rpmdbMoveDatabase | ( | const char * | prefix,
|  | const char * | olddbpath,
|  | int | _olddbapi,
|  | const char * | newdbpath,
|  | int | _newdbapi,
|  | const tagStore_t | dbiTags,
|  | size_t | dbiNTags
| ) |  |

static

Definition at line 3952 of file rpmdb.c.

References _free(), blockSignals(), Chmod(), Chown(), D_, freecon, is_selinux_enabled, matchpathcon, matchpathcon_fini, matchpathcon_init, Rename(), RPMDBI_ADDED, RPMDBI_AVAILABLE, RPMDBI_DEPENDS, RPMDBI_REMOVED, rpmGetPath(), rpmioFileExists(), rpmlog(), RPMLOG_DEBUG, setfilecon, snprintf(), Stat(), tagName(), unblockSignals(), Unlink(), and Utime().

Referenced by rpmdbRebuild().

rpmdb rpmdbNew | ( | const char * | root,
|  | const char * | home,
|  | int | mode,
|  | int | perms,
|  | int | flags
| ) |  |

Todo:
  document rpmdbNew

Definition at line 1171 of file rpmdb.c.

References _, _DB_ERRPFX, _db_filter_dups, _DB_FLAGS, _DB_HOME, _DB_MAJOR, _DB_MODE, _DB_PERMS, _DB_ROOT, _free(), _rpmdb_debug, dbiTagsInit(), rpmdbExportInfo(), rpmdbGetPool(), rpmdbLink(), rpmdbURIPath(), rpmExpand(), rpmExpandNumeric(), rpmioPutPool(), rpmlog(), RPMLOG_ERR, and xcalloc().

Referenced by rpmdbOpenDatabase().

int rpmdbOpenDatabase | ( | const char * | prefix,
|  | const char * | dbpath,
|  | int | _dbapi,
|  | rpmdb * | dbp,
|  | int | mode,
|  | int | perms,
|  | int | flags
| ) |  |

Todo:
  document rpmdbOpenDatabase

Definition at line 1225 of file rpmdb.c.

References dbiOpen(), RPMDB_FLAG_JUSTCHECK, RPMDB_FLAG_MINIMAL, rpmdbClose(), RPMDBI_ADDED, RPMDBI_AVAILABLE, RPMDBI_DEPENDS, RPMDBI_PACKAGES, RPMDBI_REMOVED, rpmdbNew(), rpmdbRock, rpmsqEnable(), and RPMTAG_NAME.

Referenced by rpmdbInit(), rpmdbOpen(), rpmdbRebuild(), and rpmdbVerify().

static int rpmdbRemoveDatabase | ( | const char * | prefix,
|  | const char * | dbpath,
|  | int | _dbapi,
|  | const tagStore_t | dbiTags,
|  | size_t | dbiNTags
| ) |  |

static

Definition at line 3902 of file rpmdb.c.

References _free(), Rmdir(), rpmGetPath(), rpmioFileExists(), snprintf(), tagName(), and Unlink().

Referenced by rpmdbRebuild().

static void rpmdbSortIterator | ( | rpmmi | mi | ) |

static

Definition at line 2671 of file rpmdb.c.

References hdrNumCmp(), rpmmi_s::mi_set, rpmmi_s::mi_sorted, and rpm_mergesort().

Referenced by rpmdbFindFpList().

static const char* rpmdbURIPath | ( | const char * | uri | ) |

static

Return macro expanded absolute path to rpmdb.

Parameters

  uri | desired path

Returns
  macro expanded absolute path

Definition at line 1113 of file rpmdb.c.

References _free(), PATH_MAX, Realpath(), rpmGetPath(), stpncpy(), URL_IS_DASH, URL_IS_FTP, URL_IS_HKP, URL_IS_HTTP, URL_IS_HTTPS, URL_IS_PATH, URL_IS_UNKNOWN, and urlPath().

Referenced by rpmdbNew().

static int rpmioFileExists | ( | const char * | urlfn | ) |

static

Check if file exists using stat(2).

Parameters

  urlfn | file name (may be URL)

Returns
  1 if file exists, 0 if not

Definition at line 3873 of file rpmdb.c.

References Stat(), URL_IS_DASH, URL_IS_FTP, URL_IS_HKP, URL_IS_HTTP, URL_IS_HTTPS, URL_IS_PATH, URL_IS_UNKNOWN, and urlPath().

Referenced by rpmdbMoveDatabase(), and rpmdbRemoveDatabase().

static void rpmmiFini | ( | void * | _mi | ) |

static

Definition at line 2020 of file rpmdb.c.

References dbiFreeIndexSet(), dbiOpen(), rpmmi_s::mi_db, rpmmi_s::mi_dbc, rpmmi_s::mi_next, rpmmi_s::mi_nre, rpmmi_s::mi_re, rpmmi_s::mi_set, miFreeHeader(), mireFreeAll(), rpmdbCheckSignals(), rpmdbClose(), RPMDBI_PACKAGES, and rpmmiRock.

Referenced by rpmmiGetPool().

static int rpmmiGet | ( | dbiIndex | dbi,
|  | DBC * | dbcursor,
|  | DBT * | kp,
|  | DBT * | vp,
|  | unsigned int | flags
| ) |  |

static

Definition at line 2454 of file rpmdb.c.

References _rpmmi_usermem, __db_dbt::data, DB_SET, errno, __db_dbt::flags, and __db_dbt::size.

Referenced by rpmmiNext().

static rpmmi rpmmiGetPool | ( | rpmioPool | pool | ) |

static

Definition at line 2068 of file rpmdb.c.

References _rpmmiPool, rpmioGetPool(), rpmioNewPool(), and rpmmiFini().

Referenced by rpmmiInit().

void rpmtsCleanDig | ( | void * | ts | ) |

pgpDig rpmtsDig | ( | void * | ts | ) |

static int set2dbt | ( | dbiIndex | dbi,
|  | DBT * | data,
|  | dbiIndexSet | set
| ) |  |

static

Convert index set to database representation.

Parameters

  dbi | index database handle
  data | retrieved data
  set | index set

Returns
  0 on success

Definition at line 557 of file rpmdb.c.

References _DBSWAP, __db_dbt::data, set(), __db_dbt::size, _dbswap::ui, UINT32_T, and xmalloc().

Referenced by rpmdbAdd(), and rpmdbRemove().

static unsigned taghash | ( | const char * | s | ) |

inlinestatic

Return a tagnum with hash on the (directory) path in upper 16 bits.

Parameters

  s | (directory) path

Returns
  tagnum with (directory) path hash

Definition at line 1409 of file rpmdb.c.

Referenced by rpmdbAdd(), rpmdbFindByFile(), and rpmdbFindFpList().

static int unblockSignals | ( | rpmdb | db,
|  | sigset_t * | oldMask
| ) |  |

static

Restore signal mask.

Parameters

  db | rpm database
  oldMask | previous sigset

Returns
  0 on success

Definition at line 845 of file rpmdb.c.

References rpmdbCheckSignals().

Referenced by miFreeHeader(), rpmdbAdd(), rpmdbMoveDatabase(), and rpmdbRemove().

## Variable Documentation

int _db_filter_dups = 0

static

Definition at line 66 of file rpmdb.c.

Referenced by rpmdbNew(), and rpmdbRebuild().

int _db_tagged_file_indices = 1

static

Definition at line 72 of file rpmdb.c.

Referenced by rpmdbAdd(), rpmdbFindByFile(), rpmdbFindFpList(), and rpmdbGrowIterator().

int _db_tagged_findbyfile = 1

static

Definition at line 77 of file rpmdb.c.

Referenced by rpmdbFindByFile().

int _rebuildinprogress = 0

static

Definition at line 64 of file rpmdb.c.

Referenced by dbiOpen(), and rpmdbRebuild().

int _rpmdb_debug = 0

Definition at line 61 of file rpmdb.c.

Referenced by dbiOpen(), rpmdbClose(), rpmdbGetPool(), and rpmdbNew().

rpmioPool _rpmdbPool

Definition at line 928 of file rpmdb.c.

Referenced by rpmcliFini(), and rpmdbGetPool().

int _rpmmi_debug = 0

Definition at line 2063 of file rpmdb.c.

int _rpmmi_usermem = 1

static

Definition at line 2452 of file rpmdb.c.

Referenced by rpmmiGet(), and rpmmiNext().

rpmioPool _rpmmiPool

Definition at line 2066 of file rpmdb.c.

Referenced by rpmcliFini(), and rpmmiGetPool().

struct _dbiVec* mydbvecs[]

static

Initial value:
= {
NULL , NULL , NULL , NULL , NULL , NULL
}

Definition at line 315 of file rpmdb.c.

rpmdb rpmdbRock

static

Definition at line 752 of file rpmdb.c.

Referenced by rpmdbClose(), and rpmdbOpenDatabase().

rpmmi rpmmiRock

static

Definition at line 755 of file rpmdb.c.

Referenced by rpmmiFini(), and rpmmiInit().