From de60ab01a387ba0f6da5d927ada1df91918a7ae3 Mon Sep 17 00:00:00 2001 From: Alexey Tourbin Date: Thu, 19 Aug 2010 02:03:03 +0400 Subject: [PATCH] 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. --- lib/header.h | 15 +++++++++++++++ lib/header_internal.h | 1 + rpmdb/header.c | 12 ++++++++++++ rpmdb/rpmdb.c | 5 +++++ 4 files changed, 33 insertions(+) diff --git a/lib/header.h b/lib/header.h index 296203c..53a568d 100644 --- a/lib/header.h +++ b/lib/header.h @@ -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 diff --git a/lib/header_internal.h b/lib/header_internal.h index fe4dd02..7cd414d 100644 --- a/lib/header_internal.h +++ b/lib/header_internal.h @@ -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? */ diff --git a/rpmdb/header.c b/rpmdb/header.c index 90aac32..a8dfe87 100644 --- a/rpmdb/header.c +++ b/rpmdb/header.c @@ -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 diff --git a/rpmdb/rpmdb.c b/rpmdb/rpmdb.c index 0781e3b..abdaa6e 100644 --- a/rpmdb/rpmdb.c +++ b/rpmdb/rpmdb.c @@ -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: