Skip to content

Commit

Permalink
rpmte: Move dependencies into an unordered_map
Browse files Browse the repository at this point in the history
Get rid of requires_ hack to avoid collision with requires keyword.

Also the dependencies are looked up by tag anyway. No need for a case
statements when we can use a container instead.

Related: #3537
Related: #3518
  • Loading branch information
ffesti committed Feb 4, 2025
1 parent 5901f16 commit 62e4d3c
Showing 1 changed file with 20 additions and 44 deletions.
64 changes: 20 additions & 44 deletions lib/rpmte.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "system.h"

#include <vector>
#include <unordered_map>

#include <rpm/rpmtypes.h>
#include <rpm/rpmlib.h> /* RPM_MACHTABLE_* */
Expand Down Expand Up @@ -49,16 +50,7 @@ struct rpmte_s {
unsigned int db_instance; /*!< Database instance (of removed pkgs) */
tsortInfo tsi; /*!< Dependency ordering chains. */

rpmds thisds; /*!< This package's provided NEVR. */
rpmds provides; /*!< Provides: dependencies. */
rpmds requires_; /*!< Requires: dependencies. */
rpmds conflicts; /*!< Conflicts: dependencies. */
rpmds obsoletes; /*!< Obsoletes: dependencies. */
rpmds order; /*!< Order: dependencies. */
rpmds recommends; /*!< Recommends: dependencies. */
rpmds suggests; /*!< Suggests: dependencies. */
rpmds supplements; /*!< Supplements: dependencies. */
rpmds enhances; /*!< Enhances: dependencies. */
std::unordered_map<rpmTagVal, rpmds> dependencies;
rpmfiles files; /*!< File information. */
rpmps probs; /*!< Problems (relocations) */
rpmts ts; /*!< Parent transaction */
Expand All @@ -85,22 +77,22 @@ struct rpmte_s {
rpmfs fs;
};

/* Does not include RPMTAG_NAME as it needs special handling */
auto dependency_tags = {
RPMTAG_PROVIDENAME, RPMTAG_SUPPLEMENTNAME, RPMTAG_ENHANCENAME,
RPMTAG_REQUIRENAME, RPMTAG_RECOMMENDNAME, RPMTAG_SUGGESTNAME,
RPMTAG_CONFLICTNAME, RPMTAG_OBSOLETENAME, RPMTAG_ORDERNAME };

/* forward declarations */
static void rpmteColorDS(rpmte te, rpmTag tag);
static int rpmteClose(rpmte te, int reset_fi);

void rpmteCleanDS(rpmte te)
{
te->thisds = rpmdsFree(te->thisds);
te->provides = rpmdsFree(te->provides);
te->requires_ = rpmdsFree(te->requires_);
te->conflicts = rpmdsFree(te->conflicts);
te->obsoletes = rpmdsFree(te->obsoletes);
te->recommends = rpmdsFree(te->recommends);
te->suggests = rpmdsFree(te->suggests);
te->supplements = rpmdsFree(te->supplements);
te->enhances = rpmdsFree(te->enhances);
te->order = rpmdsFree(te->order);
for (auto &pair : te->dependencies) {
rpmdsFree(pair.second);
}
te->dependencies.clear();
}

static rpmfiles getFiles(rpmte p, Header h)
Expand Down Expand Up @@ -190,16 +182,11 @@ static int addTE(rpmte p, Header h, fnpyKey key, rpmRelocation * relocs)
p->pkgFileSize = 0;
p->headerSize = headerSizeof(h, HEADER_MAGIC_NO);

p->thisds = rpmdsThisPool(tspool, h, RPMTAG_PROVIDENAME, RPMSENSE_EQUAL);
p->provides = rpmdsNewPool(tspool, h, RPMTAG_PROVIDENAME, 0);
p->requires_ = rpmdsNewPool(tspool, h, RPMTAG_REQUIRENAME, 0);
p->conflicts = rpmdsNewPool(tspool, h, RPMTAG_CONFLICTNAME, 0);
p->obsoletes = rpmdsNewPool(tspool, h, RPMTAG_OBSOLETENAME, 0);
p->order = rpmdsNewPool(tspool, h, RPMTAG_ORDERNAME, 0);
p->recommends = rpmdsNewPool(tspool, h, RPMTAG_RECOMMENDNAME, 0);
p->suggests = rpmdsNewPool(tspool, h, RPMTAG_SUGGESTNAME, 0);
p->supplements = rpmdsNewPool(tspool, h, RPMTAG_SUPPLEMENTNAME, 0);
p->enhances = rpmdsNewPool(tspool, h, RPMTAG_ENHANCENAME, 0);
p->dependencies[RPMTAG_NAME] = \
rpmdsThisPool(tspool, h, RPMTAG_PROVIDENAME, RPMSENSE_EQUAL);
for (rpmTagVal tag : dependency_tags) {
p->dependencies[tag] = rpmdsNewPool(tspool, h, tag, 0);
}

/* Relocation needs to know file count before rpmfiNew() */
headerGet(h, RPMTAG_BASENAMES, &bnames, HEADERGET_MINMEM);
Expand Down Expand Up @@ -466,21 +453,10 @@ rpmds rpmteDS(rpmte te, rpmTagVal tag)
{
if (te == NULL)
return NULL;
if (!te->dependencies.contains(tag))
return NULL;

switch (tag) {
case RPMTAG_NAME: return te->thisds;
case RPMTAG_PROVIDENAME: return te->provides;
case RPMTAG_REQUIRENAME: return te->requires_;
case RPMTAG_CONFLICTNAME: return te->conflicts;
case RPMTAG_OBSOLETENAME: return te->obsoletes;
case RPMTAG_ORDERNAME: return te->order;
case RPMTAG_RECOMMENDNAME: return te->recommends;
case RPMTAG_SUGGESTNAME: return te->suggests;
case RPMTAG_SUPPLEMENTNAME: return te->supplements;
case RPMTAG_ENHANCENAME: return te->enhances;
default: break;
}
return NULL;
return te->dependencies[tag];
}

void rpmteCleanFiles(rpmte te)
Expand Down

0 comments on commit 62e4d3c

Please sign in to comment.