header.c: backported headerSetInstance() and headerGetInstance() from rpm.org

Header instance is its number in /var/lib/rpm/Packages database.
When a header comes from the database, it is sometimes useful to know
its instance (I need this to adjust verify.c:verifyDependencies() for
self-conflicting packages).  On the contrary, setting instance numbers
should happen only within librpmdb, which is why headerSetInstance()
comes with hidden visibility.
This commit is contained in:
Alexey Tourbin 2010-08-19 02:03:03 +04:00
parent e8c5b7ad21
commit de60ab01a3
4 changed files with 33 additions and 0 deletions

View File

@ -712,6 +712,21 @@ void * headerFreeData( /*@only@*/ /*@null@*/ const void * data, rpmTagType type)
return NULL;
}
/** \ingroup header
* Return header instance, ie is the header from rpmdb.
* @param h header
* @return rpmdb record number or 0
*/
unsigned int headerGetInstance(Header h);
/** \ingroup header
* Set header instance (rpmdb record number)
* @param h header
* @param instance record number
*/
__attribute__((visibility("hidden")))
void headerSetInstance(Header h, unsigned int instance);
#if !defined(__HEADER_PROTOTYPES__)
#include "hdrinline.h"
#endif

View File

@ -57,6 +57,7 @@ struct headerToken {
/*@owned@*/ indexEntry index; /*!< Array of tags. */
int indexUsed; /*!< Current size of tag array. */
int indexAlloced; /*!< Allocated size of tag array. */
unsigned int instance; /*!< Rpmdb instance (offset) */
int flags;
#define HEADERFLAG_SORTED (1 << 0) /*!< Are header entries sorted? */
#define HEADERFLAG_ALLOCATED (1 << 1) /*!< Is 1st header region allocated? */

View File

@ -180,6 +180,7 @@ Header headerNew(void)
h->blob = NULL;
h->indexAlloced = INDEX_MALLOC_SIZE;
h->indexUsed = 0;
h->instance = 0;
h->flags = HEADERFLAG_SORTED;
h->index = (h->indexAlloced
@ -906,6 +907,7 @@ Header headerLoad(/*@kept@*/ void * uh)
/*@=assignexpose =kepttrans@*/
h->indexAlloced = il + 1;
h->indexUsed = il;
h->instance = 0;
h->index = xcalloc(h->indexAlloced, sizeof(*h->index));
h->flags = HEADERFLAG_SORTED;
h->nrefs = 0;
@ -3362,6 +3364,16 @@ int headerNextIterator(HeaderIterator hi,
return ((rc == 1) ? 1 : 0);
}
unsigned int headerGetInstance(Header h)
{
return h ? h->instance : 0;
}
void headerSetInstance(Header h, unsigned int instance)
{
h->instance = instance;
}
/** \ingroup header
* Duplicate a header.
* @param h header

View File

@ -2034,6 +2034,7 @@ top:
goto top;
return NULL;
}
headerSetInstance(mi->mi_h, mi->mi_offset);
mi->mi_prevoffset = mi->mi_offset;
mi->mi_modified = 0;
@ -2856,6 +2857,10 @@ int rpmdbAdd(rpmdb db, int iid, Header h)
/*@=nullpass =nullptrarith =nullderef @*/
rec = _free(rec);
/* If everthing ok, mark header as installed now */
if (rc == 0)
headerSetInstance(h, hdrNum);
}
exit: