From 555a08b276116a939f9343445e1c0939c7da4db2 Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Tue, 30 Oct 2007 11:27:12 +0000 Subject: [PATCH] - add vendor id to solvables --- src/pool.c | 1 + src/pool.h | 37 +++++++++++++++++----------------- src/repo_solv.c | 8 +++++--- src/solvable.h | 1 + src/solver.c | 3 ++- tools/dumpsolv.c | 2 ++ tools/repo_content.c | 4 +++- tools/repo_helix.c | 5 +++++ tools/repo_rpmdb.c | 55 +++++++++++++++++++++------------------------------ tools/repo_rpmmd.c | 5 +++++ tools/repo_susetags.c | 3 ++- tools/repo_susetags.h | 2 +- tools/repo_write.c | 7 +++++++ tools/susetags2solv.c | 2 +- 14 files changed, 76 insertions(+), 59 deletions(-) diff --git a/src/pool.c b/src/pool.c index 771ad7a..9e72894 100644 --- a/src/pool.c +++ b/src/pool.c @@ -39,6 +39,7 @@ static char *initpool_data[] = { "solvable:name", "solvable:arch", "solvable:evr", + "solvable:vendor", "solvable:provides", "solvable:obsoletes", "solvable:conflicts", diff --git a/src/pool.h b/src/pool.h index 30d29d7..1222256 100644 --- a/src/pool.h +++ b/src/pool.h @@ -24,24 +24,25 @@ extern "C" { #define SOLVABLE_NAME 2 #define SOLVABLE_ARCH 3 #define SOLVABLE_EVR 4 -#define SOLVABLE_PROVIDES 5 -#define SOLVABLE_OBSOLETES 6 -#define SOLVABLE_CONFLICTS 7 -#define SOLVABLE_REQUIRES 8 -#define SOLVABLE_RECOMMENDS 9 -#define SOLVABLE_SUGGESTS 10 -#define SOLVABLE_SUPPLEMENTS 11 -#define SOLVABLE_ENHANCES 12 -#define SOLVABLE_FRESHENS 13 -#define RPM_RPMDBID 14 -#define SOLVABLE_PREREQMARKER 15 // normal requires before this, prereqs after this -#define SOLVABLE_FILEMARKER 16 // normal provides before this, generated file provides after this -#define NAMESPACE_INSTALLED 17 -#define NAMESPACE_MODALIAS 18 -#define SYSTEM_SYSTEM 19 -#define ARCH_SRC 20 -#define ARCH_NOSRC 21 -#define ARCH_NOARCH 22 +#define SOLVABLE_VENDOR 5 +#define SOLVABLE_PROVIDES 6 +#define SOLVABLE_OBSOLETES 7 +#define SOLVABLE_CONFLICTS 8 +#define SOLVABLE_REQUIRES 9 +#define SOLVABLE_RECOMMENDS 10 +#define SOLVABLE_SUGGESTS 11 +#define SOLVABLE_SUPPLEMENTS 12 +#define SOLVABLE_ENHANCES 13 +#define SOLVABLE_FRESHENS 14 +#define RPM_RPMDBID 15 +#define SOLVABLE_PREREQMARKER 16 // normal requires before this, prereqs after this +#define SOLVABLE_FILEMARKER 17 // normal provides before this, generated file provides after this +#define NAMESPACE_INSTALLED 18 +#define NAMESPACE_MODALIAS 19 +#define SYSTEM_SYSTEM 20 +#define ARCH_SRC 21 +#define ARCH_NOSRC 22 +#define ARCH_NOARCH 23 /* well known solvable */ #define SYSTEMSOLVABLE 1 diff --git a/src/repo_solv.c b/src/repo_solv.c index c416bf5..b0555c4 100644 --- a/src/repo_solv.c +++ b/src/repo_solv.c @@ -19,8 +19,8 @@ #include "repo_solv.h" #include "util.h" -#define INTERESTED_START 2 -#define INTERESTED_END 13 +#define INTERESTED_START SOLVABLE_NAME +#define INTERESTED_END SOLVABLE_FRESHENS /*-----------------------------------------------------------------*/ /* .solv read functions */ @@ -542,7 +542,9 @@ pool_addrepo_solv(Pool *pool, FILE *fp, const char *reponame) else if (id == SOLVABLE_ARCH) s->arch = did; else if (id == SOLVABLE_EVR) - s->evr= did; + s->evr = did; + else if (id == SOLVABLE_VENDOR) + s->vendor = did; #if 0 printf("%s -> %s\n", id2str(pool, id), id2str(pool, did)); #endif diff --git a/src/solvable.h b/src/solvable.h index 0c643ad..b9b15f7 100644 --- a/src/solvable.h +++ b/src/solvable.h @@ -14,6 +14,7 @@ typedef struct _Solvable { Id name; Id arch; Id evr; /* epoch:version-release */ + Id vendor; Repo *repo; /* repo we belong to */ diff --git a/src/solver.c b/src/solver.c index 8cb8646..8e5c56d 100644 --- a/src/solver.c +++ b/src/solver.c @@ -274,7 +274,6 @@ prune_to_recommended(Solver *solv, Queue *plist) * */ -/* FIXME: must also look at update packages */ /* FIXME: should prefer installed if identical version */ void @@ -322,6 +321,8 @@ prune_best_version_arch(Pool *pool, Queue *plist) qsort(plist->elements, plist->count, sizeof(Id), prune_best_version_arch_sortcmp); /* delete obsoleted. hmm, looks expensive! */ + /* FIXME maybe also check provides depending on noupdateprovide? */ + /* FIXME do not prune cycles */ for (i = 0; i < plist->count; i++) { Id p, *pp, obs, *obsp; diff --git a/tools/dumpsolv.c b/tools/dumpsolv.c index f196a13..cde1971 100644 --- a/tools/dumpsolv.c +++ b/tools/dumpsolv.c @@ -43,6 +43,8 @@ int main(int argc, char **argv) printf("\n"); printf("solvable %d:\n", i); printf("name: %s %s %s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch)); + if (s->vendor) + printf("vendor: %s\n", id2str(pool, s->vendor)); printids(repo, "provides", s->provides); printids(repo, "obsoletes", s->obsoletes); printids(repo, "conflicts", s->conflicts); diff --git a/tools/repo_content.c b/tools/repo_content.c index 2e215c9..3f5c409 100644 --- a/tools/repo_content.c +++ b/tools/repo_content.c @@ -228,11 +228,13 @@ pool_addrepo_content(Pool *pool, FILE *fp) s->name = str2id(pool, join(&pd, pd.kind, ":", value), 1); else if (istag ("DISTVERSION")) s->evr = makeevr(pool, value); + else if (istag ("VENDOR")) + s->vendor = str2id(pool, value, 1); else if (istag ("ARCH")) /* Theoretically we want to have the best arch of the given modifiers which still is compatible with the system arch. We don't know the latter here, though. */ - s->arch = str2id (pool, "noarch" , 1); + s->arch = ARCH_NOARCH; else if (istag ("PREREQUIRES")) s->requires = adddep(pool, &pd, s->requires, value, 2); else if (istag ("REQUIRES")) diff --git a/tools/repo_helix.c b/tools/repo_helix.c index 0a5d139..b8c58de 100644 --- a/tools/repo_helix.c +++ b/tools/repo_helix.c @@ -27,6 +27,7 @@ enum state { STATE_SUBCHANNEL, STATE_PACKAGE, STATE_NAME, + STATE_VENDOR, STATE_HISTORY, STATE_UPDATE, STATE_EPOCH, @@ -85,6 +86,7 @@ static struct stateswitch stateswitches[] = { { STATE_SUBCHANNEL, "patch", STATE_PACKAGE, 0 }, { STATE_SUBCHANNEL, "product", STATE_PACKAGE, 0 }, { STATE_PACKAGE, "name", STATE_NAME, 1 }, + { STATE_PACKAGE, "vendor", STATE_VENDOR, 1 }, { STATE_PACKAGE, "epoch", STATE_PEPOCH, 1 }, { STATE_PACKAGE, "version", STATE_PVERSION, 1 }, { STATE_PACKAGE, "release", STATE_PRELEASE, 1 }, @@ -717,6 +719,9 @@ endElement(void *userData, const char *name) case STATE_NAME: s->name = str2id(pool, pd->content, 1); break; + case STATE_VENDOR: + s->vendor = str2id(pool, pd->content, 1); + break; case STATE_UPDATE: /* new version, keeping all other metadata */ evr = evr2id(pool, pd, pd->epoch ? pd->evrspace + pd->epoch : 0, diff --git a/tools/repo_rpmdb.c b/tools/repo_rpmdb.c index 2697a64..b08cd2b 100644 --- a/tools/repo_rpmdb.c +++ b/tools/repo_rpmdb.c @@ -16,6 +16,7 @@ #include "pool.h" #include "hash.h" +#include "util.h" #include "repo_rpmdb.h" #define TAG_NAME 1000 @@ -94,7 +95,7 @@ headint32(RpmHead *h, int tag, int *cnt) if (o + 4 * i > h->dcnt) return 0; d = h->dp + o; - r = calloc(i ? i : 1, sizeof(unsigned int)); + r = xcalloc(i ? i : 1, sizeof(unsigned int)); if (cnt) *cnt = i; for (o = 0; o < i; o++, d += 4) @@ -144,7 +145,7 @@ headstringarray(RpmHead *h, int tag, int *cnt) return 0; o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11]; i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15]; - r = calloc(i ? i : 1, sizeof(char *)); + r = xcalloc(i ? i : 1, sizeof(char *)); if (cnt) *cnt = i; d = h->dp + o; @@ -185,12 +186,12 @@ static char *headtoevr(RpmHead *h) { char epochbuf[11]; /* 32bit decimal will fit in */ sprintf(epochbuf, "%u", epoch); - evr = malloc(strlen(epochbuf) + 1 + strlen(version) + 1 + strlen(release) + 1); + evr = xmalloc(strlen(epochbuf) + 1 + strlen(version) + 1 + strlen(release) + 1); sprintf(evr, "%s:%s-%s", epochbuf, version, release); } else { - evr = malloc(strlen(version) + 1 + strlen(release) + 1); + evr = xmalloc(strlen(version) + 1 + strlen(release) + 1); sprintf(evr, "%s-%s", version, release); } if (epochp) @@ -441,11 +442,8 @@ addfileprovides(Pool *pool, Repo *repo, RpmHead *rpmhead, unsigned int olddeps) j = strlen(bn[i]) + strlen(dn[di[i]]) + 1; if (j > fna) { - if (fn) - fn = realloc(fn, j + 256); - else - fn = malloc(j + 256); fna = j + 256; + fn = xrealloc(fn, fna); } strcpy(fn, dn[di[i]]); strcat(fn, bn[i]); @@ -476,13 +474,11 @@ rpm2solv(Pool *pool, Repo *repo, Solvable *s, RpmHead *rpmhead) } s->arch = str2id(pool, headstring(rpmhead, TAG_ARCH), 1); if (!s->arch) - { - fprintf(stderr, "package %s has no arch\n", id2str(pool, s->name)); - exit(1); - } + s->arch = ARCH_NOARCH; evr = headtoevr(rpmhead); s->evr = str2id(pool, evr, 1); free(evr); + s->vendor = str2id(pool, headstring(rpmhead, TAG_VENDOR), 1); s->provides = makedeps(pool, repo, rpmhead, TAG_PROVIDENAME, TAG_PROVIDEVERSION, TAG_PROVIDEFLAGS, 0); s->provides = addfileprovides(pool, repo, rpmhead, s->provides); @@ -555,9 +551,9 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) exit(1); } dbidp = (unsigned char *)&dbid; - pool->solvables = realloc(pool->solvables, (pool->nsolvables + 256) * sizeof(Solvable)); + pool->solvables = xrealloc(pool->solvables, (pool->nsolvables + 256) * sizeof(Solvable)); memset(pool->solvables + repo->start, 0, 256 * sizeof(Solvable)); - repo->rpmdbid = calloc(256, sizeof(unsigned int)); + repo->rpmdbid = xcalloc(256, sizeof(unsigned int)); asolv = 256; rpmheadsize = 0; rpmhead = 0; @@ -566,9 +562,9 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) { if (i >= asolv) { - pool->solvables = realloc(pool->solvables, (pool->nsolvables + asolv + 256) * sizeof(Solvable)); + pool->solvables = xrealloc(pool->solvables, (pool->nsolvables + asolv + 256) * sizeof(Solvable)); memset(pool->solvables + repo->start + asolv, 0, 256 * sizeof(Solvable)); - repo->rpmdbid = realloc(repo->rpmdbid, (asolv + 256) * sizeof(unsigned int)); + repo->rpmdbid = xrealloc(repo->rpmdbid, (asolv + 256) * sizeof(unsigned int)); memset(repo->rpmdbid + asolv, 0, 256 * sizeof(unsigned int)); asolv += 256; } @@ -595,10 +591,8 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) fprintf(stderr, "corrupt rpm database (size %u)\n", data.size); exit(1); } - if (!rpmhead) - rpmhead = malloc(sizeof(*rpmhead) + data.size); - else if (data.size > rpmheadsize) - rpmhead = realloc(rpmhead, sizeof(*rpmhead) + data.size); + if (data.size > rpmheadsize) + rpmhead = xrealloc(rpmhead, sizeof(*rpmhead) + data.size); memcpy(buf, data.data, 8); rpmhead->cnt = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]; rpmhead->dcnt = buf[4] << 24 | buf[5] << 16 | buf[6] << 8 | buf[7]; @@ -656,12 +650,7 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) else memcpy(dbidp, dp, 4); if ((nrpmids & 255) == 0) - { - if (rpmids) - rpmids = realloc(rpmids, sizeof(*rpmids) * (nrpmids + 256)); - else - rpmids = malloc(sizeof(*rpmids) * 256); - } + rpmids = xrealloc(rpmids, sizeof(*rpmids) * (nrpmids + 256)); rpmids[nrpmids].dbid = dbid; rpmids[nrpmids].name = malloc((int)key.size + 1); memcpy(rpmids[nrpmids].name, key.data, (int)key.size); @@ -670,7 +659,6 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) dp += 8; dl -= 8; } - } dbc->c_close(dbc); db->close(db, 0); @@ -681,7 +669,7 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) rpmheadsize = 0; rpmhead = 0; - pool->solvables = realloc(pool->solvables, (pool->nsolvables + nrpmids) * sizeof(Solvable)); + pool->solvables = xrealloc(pool->solvables, (pool->nsolvables + nrpmids) * sizeof(Solvable)); memset(pool->solvables + repo->start, 0, nrpmids * sizeof(Solvable)); repo->rpmdbid = calloc(nrpmids, sizeof(unsigned int)); @@ -690,7 +678,7 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) if (ref) { refmask = mkmask(ref->nsolvables); - refhash = calloc(refmask + 1, sizeof(Id)); + refhash = xcalloc(refmask + 1, sizeof(Id)); for (i = 0; i < ref->nsolvables; i++) { h = ref->rpmdbid[i] & refmask; @@ -722,6 +710,7 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) s->name = r->name; s->evr = r->evr; s->arch = r->arch; + s->vendor = r->vendor; } else { @@ -731,6 +720,8 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) s->evr = str2id(pool, id2str(ref->pool, r->evr), 1); if (r->arch) s->arch = str2id(pool, id2str(ref->pool, r->arch), 1); + if (r->vendor) + s->vendor = str2id(pool, id2str(ref->pool, r->vendor), 1); } s->provides = copydeps(pool, repo, r->provides, ref); s->requires = copydeps(pool, repo, r->requires, ref); @@ -786,10 +777,8 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) fprintf(stderr, "corrupt rpm database (size)\n"); exit(1); } - if (!rpmhead) - rpmhead = malloc(sizeof(*rpmhead) + data.size); - else if (data.size > rpmheadsize) - rpmhead = realloc(rpmhead, sizeof(*rpmhead) + data.size); + if (data.size > rpmheadsize) + rpmhead = xrealloc(rpmhead, sizeof(*rpmhead) + data.size); memcpy(buf, data.data, 8); rpmhead->cnt = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]; rpmhead->dcnt = buf[4] << 24 | buf[5] << 16 | buf[6] << 8 | buf[7]; diff --git a/tools/repo_rpmmd.c b/tools/repo_rpmmd.c index b9b65f9..2aada6d 100644 --- a/tools/repo_rpmmd.c +++ b/tools/repo_rpmmd.c @@ -18,6 +18,7 @@ enum state { STATE_ARCH, STATE_VERSION, STATE_FORMAT, + STATE_VENDOR, STATE_PROVIDES, STATE_PROVIDESENTRY, STATE_REQUIRES, @@ -55,6 +56,7 @@ static struct stateswitch stateswitches[] = { { STATE_PACKAGE, "arch", STATE_ARCH, 1 }, { STATE_PACKAGE, "version", STATE_VERSION, 0 }, { STATE_PACKAGE, "format", STATE_FORMAT, 0 }, + { STATE_FORMAT, "rpm:vendor", STATE_VENDOR, 1 }, { STATE_FORMAT, "rpm:provides", STATE_PROVIDES, 0 }, { STATE_FORMAT, "rpm:requires", STATE_REQUIRES, 0 }, { STATE_FORMAT, "rpm:obsoletes", STATE_OBSOLETES , 0 }, @@ -374,6 +376,9 @@ endElement(void *userData, const char *name) case STATE_ARCH: s->arch = str2id(pool, pd->content, 1); break; + case STATE_VENDOR: + s->vendor = str2id(pool, pd->content, 1); + break; case STATE_FILE: id = str2id(pool, pd->content, 1); s->provides = repo_addid(pd->repo, s->provides, id); diff --git a/tools/repo_susetags.c b/tools/repo_susetags.c index 36d8f66..7678ea9 100644 --- a/tools/repo_susetags.c +++ b/tools/repo_susetags.c @@ -131,7 +131,7 @@ adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, int i Attrstore *attr; Repo * -pool_addrepo_susetags(Pool *pool, FILE *fp, int with_attr) +pool_addrepo_susetags(Pool *pool, FILE *fp, Id vendor, int with_attr) { char *line, *linep; int aline; @@ -247,6 +247,7 @@ pool_addrepo_susetags(Pool *pool, FILE *fp, int with_attr) s->name = str2id(pool, sp[0], 1); s->evr = makeevr(pool, join(&pd, sp[1], "-", sp[2])); s->arch = str2id(pool, sp[3], 1); + s->vendor = vendor; continue; } if (!strncmp(line, "=Prv:", 5)) diff --git a/tools/repo_susetags.h b/tools/repo_susetags.h index 06b220c..1731f65 100644 --- a/tools/repo_susetags.h +++ b/tools/repo_susetags.h @@ -1 +1 @@ -extern Repo *pool_addrepo_susetags(Pool *pool, FILE *fp, int with_attr); +extern Repo *pool_addrepo_susetags(Pool *pool, FILE *fp, Id vendor, int with_attr); diff --git a/tools/repo_write.c b/tools/repo_write.c index 78c0069..9104cc3 100644 --- a/tools/repo_write.c +++ b/tools/repo_write.c @@ -210,6 +210,11 @@ pool_writerepo(Pool *pool, Repo *repo, FILE *fp) needid[s->name].need++; needid[s->arch].need++; needid[s->evr].need++; + if (s->vendor) + { + needid[s->vendor].need++; + idsizes[SOLVABLE_VENDOR] = 1; + } if (s->provides) idsizes[SOLVABLE_PROVIDES] += incneedid(pool, idarraydata + s->provides, needid); if (s->requires) @@ -386,6 +391,8 @@ pool_writerepo(Pool *pool, Repo *repo, FILE *fp) write_id(fp, needid[s->name].need); write_id(fp, needid[s->arch].need); write_id(fp, needid[s->evr].need); + if (idsizes[SOLVABLE_VENDOR]) + write_id(fp, needid[s->vendor].need); if (s->provides) write_idarray(fp, pool, needid, idarraydata + s->provides); diff --git a/tools/susetags2solv.c b/tools/susetags2solv.c index f83bf69..91f73a8 100644 --- a/tools/susetags2solv.c +++ b/tools/susetags2solv.c @@ -31,7 +31,7 @@ main(int argc, char **argv) argv++; } Pool *pool = pool_create(); - Repo *repo = pool_addrepo_susetags(pool, stdin, with_attr); + Repo *repo = pool_addrepo_susetags(pool, stdin, 0, with_attr); pool_writerepo(pool, repo, stdout); if (with_attr && attr) { -- 2.7.4