From ee1687061c9236f3ce992b677862f548469b93d8 Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Tue, 13 Nov 2007 15:59:35 +0000 Subject: [PATCH] - cleanup repo handlin API --- examples/ruby/basic.rb | 8 +++++--- src/pool.c | 10 +--------- src/repo.c | 29 +++++++++++++++++++++++------ src/repo.h | 6 ++++-- src/repo_solv.c | 49 ++++++++++++++++++++++++------------------------- src/repo_solv.h | 2 +- tools/content2solv.c | 5 +++-- tools/dumpsolv.c | 3 ++- tools/helix2solv.c | 5 +++-- tools/mergesolv.c | 6 +++--- tools/patchxml2solv.c | 5 +++-- tools/repo_content.c | 15 ++++++--------- tools/repo_content.h | 2 +- tools/repo_helix.c | 20 ++++++++++---------- tools/repo_helix.h | 2 +- tools/repo_patchxml.c | 17 ++++++++++------- tools/repo_patchxml.h | 2 +- tools/repo_rpmdb.c | 28 +++++++++++++++------------- tools/repo_rpmdb.h | 2 +- tools/repo_rpmmd.c | 26 +++++++++++++++----------- tools/repo_rpmmd.h | 2 +- tools/repo_susetags.c | 21 ++++++++++++--------- tools/repo_susetags.h | 2 +- tools/repo_write.c | 3 ++- tools/repo_write.h | 2 +- tools/rpmdb2solv.c | 14 ++++++++------ tools/rpmmd2solv.c | 5 +++-- tools/susetags2solv.c | 5 +++-- 28 files changed, 163 insertions(+), 133 deletions(-) diff --git a/examples/ruby/basic.rb b/examples/ruby/basic.rb index c72558c..49b08cc 100644 --- a/examples/ruby/basic.rb +++ b/examples/ruby/basic.rb @@ -8,10 +8,12 @@ pool = Pool.new #s = pool.add_empty_repo f = File.open('../../testsuite/data.libzypp/basic-exercises/exercise-20-packages.solv', 'r') -s = pool.add_repo_solv(f, 'foo') +s = pool.create_repo('foo'); +s.add_solv(f); f = File.open('../../testsuite/data.libzypp/basic-exercises/exercise-20-system.solv', 'r') -installed = pool.add_repo_solv(f, 'system') +installed = pool.create_repo('system'); +installed.add_solv(f); pool.each_repo do |repo| puts repo.name @@ -54,4 +56,4 @@ end solv.each_to_remove do |i| puts "to remove #{i}" -end \ No newline at end of file +end diff --git a/src/pool.c b/src/pool.c index cb4c0a9..1e694e9 100644 --- a/src/pool.c +++ b/src/pool.c @@ -118,20 +118,12 @@ void pool_free(Pool *pool) { int i; - Repo *repo; pool_freewhatprovides(pool); pool_freeidhashes(pool); - for (i = 0; i < pool->nrepos; i++) - { - repo = pool->repos[i]; - xfree(repo->idarraydata); - xfree(repo->rpmdbid); - xfree(repo); - } + pool_freeallrepos(pool); xfree(pool->id2arch); xfree(pool->solvables); - xfree(pool->repos); xfree(pool->stringspace); xfree(pool->strings); xfree(pool->rels); diff --git a/src/repo.c b/src/repo.c index e212dad..b9bdc28 100644 --- a/src/repo.c +++ b/src/repo.c @@ -30,7 +30,7 @@ */ Repo * -pool_addrepo_empty(Pool *pool) +repo_create(Pool *pool, const char *name) { Repo *repo; @@ -38,13 +38,22 @@ pool_addrepo_empty(Pool *pool) repo = (Repo *)xcalloc(1, sizeof(*repo)); pool->repos = (Repo **)xrealloc(pool->repos, (pool->nrepos + 1) * sizeof(Repo *)); pool->repos[pool->nrepos++] = repo; - repo->name = "empty"; + repo->name = name ? strdup(name) : 0; repo->pool = pool; repo->start = pool->nsolvables; repo->nsolvables = 0; return repo; } +static void +repo_freedata(Repo *repo) +{ + xfree(repo->idarraydata); + xfree(repo->rpmdbid); + xfree((char *)repo->name); + xfree(repo); +} + /* * add Id to repo * olddeps = old array to extend @@ -242,8 +251,9 @@ repo_reserve_ids(Repo *repo, Offset olddeps, int num) */ void -pool_freerepo(Pool *pool, Repo *repo) +repo_free(Repo *repo) { + Pool *pool = repo->pool; int i, nsolvables; pool_freewhatprovides(pool); @@ -273,10 +283,17 @@ pool_freerepo(Pool *pool, Repo *repo) pool->repos[i]->start -= nsolvables; /* adapt start offset of remaining repos */ } pool->nrepos = i; + repo_freedata(repo); +} - xfree(repo->idarraydata); - xfree(repo->rpmdbid); - xfree(repo); +void +pool_freeallrepos(Pool *pool) +{ + int i; + for (i = 0; i < pool->nrepos; i++) + repo_freedata(pool->repos[i]); + pool->repos = xfree(pool->repos); + pool->nrepos = 0; } Offset diff --git a/src/repo.h b/src/repo.h index 1fa4f7b..85b011d 100644 --- a/src/repo.h +++ b/src/repo.h @@ -30,13 +30,15 @@ typedef struct _Repo { Id *rpmdbid; } Repo; +extern Repo *repo_create(Pool *pool, const char *name); +extern void repo_free(Repo *repo); + extern Offset repo_addid(Repo *repo, Offset olddeps, Id id); extern Offset repo_addid_dep(Repo *repo, Offset olddeps, Id id, int isreq); extern Offset repo_reserve_ids(Repo *repo, Offset olddeps, int num); extern Offset repo_fix_legacy(Repo *repo, Offset provides, Offset supplements); -extern Repo *pool_addrepo_empty(Pool *pool); -extern void pool_freerepo(Pool *pool, Repo *repo); +extern void pool_freeallrepos(Pool *pool); static inline const char *repo_name(const Repo *repo) { diff --git a/src/repo_solv.c b/src/repo_solv.c index 3f75f50..25c64e4 100644 --- a/src/repo_solv.c +++ b/src/repo_solv.c @@ -174,9 +174,10 @@ typedef struct solvdata { * and add it to pool */ -Repo * -pool_addrepo_solv(Pool *pool, FILE *fp, const char *reponame) +void +repo_add_solv(Repo *repo, FILE *fp) { + Pool *pool = repo->pool; int i, j, l; unsigned int numid, numrel, numsolv, numsrcdata, numsolvdata; int numsolvdatabits, type; @@ -194,7 +195,6 @@ pool_addrepo_solv(Pool *pool, FILE *fp, const char *reponame) Reldep *ran; SolvData *solvdata; unsigned int size, size_str, size_idarray; - Repo *repo; Id *idarraydatap, *idarraydataend; Offset ido; unsigned int databits; @@ -211,12 +211,8 @@ pool_addrepo_solv(Pool *pool, FILE *fp, const char *reponame) exit(1); } - /* create empty Repo */ - repo = pool_addrepo_empty(pool); pool_freeidhashes(pool); - repo->name = reponame; - numid = read_u32(fp); numrel = read_u32(fp); numsolv= read_u32(fp); @@ -232,9 +228,10 @@ pool_addrepo_solv(Pool *pool, FILE *fp, const char *reponame) /* * alloc buffers */ - /* alloc string buffer */ + + /* alloc string buffer */ strsp = (char *)xrealloc(pool->stringspace, pool->sstrings + sizeid + 1); - /* alloc string offsets (Id -> Offset into string space) */ + /* alloc string offsets (Id -> Offset into string space) */ str = (Offset *)xrealloc(pool->strings, (pool->nstrings + numid) * sizeof(Offset)); pool->stringspace = strsp; @@ -243,7 +240,8 @@ pool_addrepo_solv(Pool *pool, FILE *fp, const char *reponame) /* point to _BEHIND_ already allocated string/Id space */ strsp += pool->sstrings; - /* alloc id map for name and rel Ids */ + /* alloc id map for name and rel Ids. this maps ids in the solv files + * to the ids in our pool */ idmap = (Id *)xcalloc(numid + numrel, sizeof(Id)); /* @@ -412,7 +410,7 @@ pool_addrepo_solv(Pool *pool, FILE *fp, const char *reponame) } /* - * read (but dont store) repo data + * read (but dont store yet) repo data */ #if 0 @@ -485,30 +483,32 @@ pool_addrepo_solv(Pool *pool, FILE *fp, const char *reponame) fprintf(stderr, "too many data map bits\n"); exit(1); } + + /* make room for our idarrays */ if (size_idarray) { - size_idarray++; /* first entry is always zero */ - repo->idarraydata = (Id *)xmalloc(sizeof(Id) * size_idarray); - repo->idarraysize = size_idarray; - idarraydatap = repo->idarraydata; - *idarraydatap++ = 0; - idarraydataend = repo->idarraydata + size_idarray; + repo_reserve_ids(repo, 0, size_idarray); + idarraydatap = repo->idarraydata + repo->idarraysize; + repo->idarraysize += size_idarray; + idarraydataend = repo->idarraydata + repo->idarraysize; + repo->lastoff = 0; } else { - repo->idarraydata = 0; - repo->idarraysize = 0; idarraydatap = 0; idarraydataend = 0; } - /* alloc solvables */ + if (repo->start && repo->start + repo->nsolvables != pool->nsolvables) + abort(); + if (!repo->start) + repo->start = pool->nsolvables; + + /* alloc space for our solvables */ pool->solvables = (Solvable *)xrealloc(pool->solvables, (pool->nsolvables + numsolv) * sizeof(Solvable)); if (numsolv) /* clear newly allocated area */ memset(pool->solvables + pool->nsolvables, 0, numsolv * sizeof(Solvable)); - repo->start = pool->nsolvables; - repo->nsolvables = numsolv; /* * read solvables @@ -517,7 +517,7 @@ pool_addrepo_solv(Pool *pool, FILE *fp, const char *reponame) #if 0 printf("read solvables\n"); #endif - for (i = 0, s = pool->solvables + repo->start; i < numsolv; i++, s++) + for (i = 0, s = pool->solvables + repo->start + repo->nsolvables; i < numsolv; i++, s++) { s->repo = repo; databits = 0; @@ -613,9 +613,8 @@ pool_addrepo_solv(Pool *pool, FILE *fp, const char *reponame) xfree(idmap); xfree(solvdata); + repo->nsolvables += numsolv; pool->nsolvables += numsolv; - - return repo; } // EOF diff --git a/src/repo_solv.h b/src/repo_solv.h index da76a3b..75c1b51 100644 --- a/src/repo_solv.h +++ b/src/repo_solv.h @@ -20,7 +20,7 @@ extern "C" { #include "pool.h" #include "repo.h" -extern Repo *pool_addrepo_solv(Pool *pool, FILE *fp, const char *name); +extern void repo_add_solv(Repo *repo, FILE *fp); #ifdef __cplusplus } diff --git a/tools/content2solv.c b/tools/content2solv.c index c2362e0..ad69ef9 100644 --- a/tools/content2solv.c +++ b/tools/content2solv.c @@ -20,8 +20,9 @@ int main(int argc, char **argv) { Pool *pool = pool_create(); - Repo *repo = pool_addrepo_content(pool, stdin); - pool_writerepo(pool, repo, stdout); + Repo *repo = repo_create(pool, ""); + repo_add_content(repo, stdin); + repo_write(repo, stdout); pool_free(pool); return 0; } diff --git a/tools/dumpsolv.c b/tools/dumpsolv.c index 2ff4f96..64a02f4 100644 --- a/tools/dumpsolv.c +++ b/tools/dumpsolv.c @@ -42,7 +42,8 @@ int main(int argc, char **argv) } } pool = pool_create(); - repo = pool_addrepo_solv(pool, stdin, ""); + repo = repo_create(pool, argc != 1 ? argv[1] : ""); + repo_add_solv(repo, stdin); printf("repo contains %d solvables\n", repo->nsolvables); for (i = repo->start; i < repo->start + repo->nsolvables; i++) { diff --git a/tools/helix2solv.c b/tools/helix2solv.c index 1d039e2..a179952 100644 --- a/tools/helix2solv.c +++ b/tools/helix2solv.c @@ -29,8 +29,9 @@ int main(int argc, char **argv) { Pool *pool = pool_create(); - Repo *repo = pool_addrepo_helix(pool, stdin); - pool_writerepo(pool, repo, stdout); + Repo *repo = repo_create(pool, ""); + repo_add_helix(repo, stdin); + repo_write(repo, stdout); pool_free(pool); exit(0); } diff --git a/tools/mergesolv.c b/tools/mergesolv.c index d51dafe..1c0b629 100644 --- a/tools/mergesolv.c +++ b/tools/mergesolv.c @@ -39,7 +39,7 @@ main(int argc, char **argv) perror(argv[1]); exit(0); } - pool_addrepo_solv(pool, fp, ""); + repo_add_solv(repo_create(pool, ""), fp); fclose(fp); } if (!pool->nrepos) @@ -90,13 +90,13 @@ main(int argc, char **argv) } while (pool->nrepos > 1) { - pool_freerepo (pool, pool->repos[1]); + repo_free(pool->repos[1]); } free (pool->repos[0]->idarraydata); pool->repos[0]->idarraydata = new_id; pool->repos[0]->idarraysize = new_id_size; - pool_writerepo(pool, pool->repos[0], stdout); + repo_write(pool->repos[0], stdout); pool_free(pool); return 0; diff --git a/tools/patchxml2solv.c b/tools/patchxml2solv.c index e4a4e06..21dc0ff 100644 --- a/tools/patchxml2solv.c +++ b/tools/patchxml2solv.c @@ -20,8 +20,9 @@ int main(int argc, char **argv) { Pool *pool = pool_create(); - Repo *repo = pool_addrepo_patchxml(pool, stdin); - pool_writerepo(pool, repo, stdout); + Repo *repo = repo_create(pool, ""); + repo_add_patchxml(repo, stdin); + repo_write(repo, stdout); pool_free(pool); exit(0); } diff --git a/tools/repo_content.c b/tools/repo_content.c index 7ef0c27..bd35db8 100644 --- a/tools/repo_content.c +++ b/tools/repo_content.c @@ -160,17 +160,16 @@ adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, int i return olddeps; } -Repo * -pool_addrepo_content(Pool *pool, FILE *fp) +void +repo_add_content(Repo *repo, FILE *fp) { + Pool *pool = repo->pool; char *line, *linep; int aline; - Repo *repo; Solvable *s; int pack; struct parsedata pd; - repo = pool_addrepo_empty(pool); memset(&pd, 0, sizeof(pd)); line = xmalloc(1024); aline = 1024; @@ -223,9 +222,9 @@ pool_addrepo_content(Pool *pool, FILE *fp) if ((pack & PACK_BLOCK) == 0) { pool->solvables = realloc(pool->solvables, (pool->nsolvables + pack + PACK_BLOCK + 1) * sizeof(Solvable)); - memset(pool->solvables + repo->start + pack, 0, (PACK_BLOCK + 1) * sizeof(Solvable)); + memset(pool->solvables + pool->nsolvables + pack, 0, (PACK_BLOCK + 1) * sizeof(Solvable)); } - s = pool->solvables + repo->start + pack; + s = pool->solvables + pool->nsolvables + pack; s->repo = repo; s->name = str2id(pool, join(&pd, pd.kind, ":", value), 1); pack++; @@ -276,10 +275,8 @@ pool_addrepo_content(Pool *pool, FILE *fp) s->supplements = repo_fix_legacy(repo, s->provides, s->supplements); pool->nsolvables += pack; - repo->nsolvables = pack; + repo->nsolvables += pack; if (pd.tmp) free(pd.tmp); free(line); - - return repo; } diff --git a/tools/repo_content.h b/tools/repo_content.h index 0f1e48d..7e687c6 100644 --- a/tools/repo_content.h +++ b/tools/repo_content.h @@ -5,4 +5,4 @@ * for further information */ -Repo * pool_addrepo_content(Pool *pool, FILE *fp); +void repo_add_content(Repo *repo, FILE *fp); diff --git a/tools/repo_helix.c b/tools/repo_helix.c index 79f9e0e..0f2fdb2 100644 --- a/tools/repo_helix.c +++ b/tools/repo_helix.c @@ -443,7 +443,7 @@ startElement(void *userData, const char *name, const char **atts) if ((pd->pack & PACK_BLOCK) == 0) /* alloc new block ? */ { pool->solvables = (Solvable *)realloc(pool->solvables, (pool->nsolvables + pd->pack + PACK_BLOCK + 1) * sizeof(Solvable)); - pd->start = pool->solvables + pd->repo->start; + pd->start = pool->solvables + pool->nsolvables; memset(pd->start + pd->pack, 0, (PACK_BLOCK + 1) * sizeof(Solvable)); } @@ -817,19 +817,21 @@ characterData(void *userData, const XML_Char *s, int len) * */ -Repo * -pool_addrepo_helix(Pool *pool, FILE *fp) +void +repo_add_helix(Repo *repo, FILE *fp) { + Pool *pool = repo->pool; Parsedata pd; char buf[BUFF_SIZE]; int i, l; - Repo *repo; struct stateswitch *sw; - // create empty repo - repo = pool_addrepo_empty(pool); + if (repo->start && repo->start + repo->nsolvables != pool->nsolvables) + abort(); + if (!repo->start) + repo->start = pool->nsolvables; - // prepare parsedata + /* prepare parsedata */ memset(&pd, 0, sizeof(pd)); for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++) { @@ -872,10 +874,8 @@ pool_addrepo_helix(Pool *pool, FILE *fp) // adapt package count pool->nsolvables += pd.pack; - repo->nsolvables = pd.pack; + repo->nsolvables += pd.pack; free(pd.content); free(pd.evrspace); - - return repo; } diff --git a/tools/repo_helix.h b/tools/repo_helix.h index 9260709..59d3996 100644 --- a/tools/repo_helix.h +++ b/tools/repo_helix.h @@ -17,6 +17,6 @@ #include "pool.h" #include "repo.h" -extern Repo *pool_addrepo_helix(Pool *pool, FILE *fp); +extern void repo_add_helix(Repo *repo, FILE *fp); #endif /* REPO_HELIX_H */ diff --git a/tools/repo_patchxml.c b/tools/repo_patchxml.c index a046f6e..b50a781 100644 --- a/tools/repo_patchxml.c +++ b/tools/repo_patchxml.c @@ -303,7 +303,7 @@ startElement(void *userData, const char *name, const char **atts) if ((pd->pack & PACK_BLOCK) == 0) { pool->solvables = realloc(pool->solvables, (pool->nsolvables + pd->pack + PACK_BLOCK + 1) * sizeof(Solvable)); - pd->start = pool->solvables + pd->repo->start; + pd->start = pool->solvables + pool->nsolvables; memset(pd->start + pd->pack, 0, (PACK_BLOCK + 1) * sizeof(Solvable)); } #if 0 @@ -443,16 +443,20 @@ characterData(void *userData, const XML_Char *s, int len) #define BUFF_SIZE 8192 -Repo * -pool_addrepo_patchxml(Pool *pool, FILE *fp) +void +repo_add_patchxml(Repo *repo, FILE *fp) { + Pool *pool = repo->pool; struct parsedata pd; char buf[BUFF_SIZE]; int i, l; - Repo *repo; struct stateswitch *sw; - repo = pool_addrepo_empty(pool); + if (repo->start && repo->start + repo->nsolvables != pool->nsolvables) + abort(); + if (!repo->start) + repo->start = pool->nsolvables; + memset(&pd, 0, sizeof(pd)); for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++) { @@ -483,8 +487,7 @@ pool_addrepo_patchxml(Pool *pool, FILE *fp) XML_ParserFree(parser); pool->nsolvables += pd.pack; - repo->nsolvables = pd.pack; + repo->nsolvables += pd.pack; free(pd.content); - return repo; } diff --git a/tools/repo_patchxml.h b/tools/repo_patchxml.h index 6946305..ac29013 100644 --- a/tools/repo_patchxml.h +++ b/tools/repo_patchxml.h @@ -5,4 +5,4 @@ * for further information */ -extern Repo *pool_addrepo_patchxml(Pool *pool, FILE *fp); +extern void repo_add_patchxml(Repo *repo, FILE *fp); diff --git a/tools/repo_rpmdb.c b/tools/repo_rpmdb.c index e56b3f8..c947250 100644 --- a/tools/repo_rpmdb.c +++ b/tools/repo_rpmdb.c @@ -509,9 +509,10 @@ rpm2solv(Pool *pool, Repo *repo, Solvable *s, RpmHead *rpmhead) * */ -Repo * -pool_addrepo_rpmdb(Pool *pool, Repo *ref) +void +repo_add_rpmdb(Repo *repo, Repo *ref) { + Pool *pool = repo->pool; unsigned char buf[16]; DB *db = 0; DBC *dbc = 0; @@ -523,13 +524,15 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) int i; int rpmheadsize; RpmHead *rpmhead; - Repo *repo; Solvable *s; Id id, *refhash; unsigned int refmask, h; int asolv; - repo = pool_addrepo_empty(pool); + if (repo->start && repo->start + repo->nsolvables != pool->nsolvables) + abort(); + if (!repo->start) + repo->start = pool->nsolvables; if (ref && !(ref->nsolvables && ref->rpmdbid)) ref = 0; @@ -559,7 +562,7 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) } dbidp = (unsigned char *)&dbid; pool->solvables = xrealloc(pool->solvables, (pool->nsolvables + 256) * sizeof(Solvable)); - memset(pool->solvables + repo->start, 0, 256 * sizeof(Solvable)); + memset(pool->solvables + pool->nsolvables, 0, 256 * sizeof(Solvable)); repo->rpmdbid = xcalloc(256, sizeof(unsigned int)); asolv = 256; rpmheadsize = 0; @@ -570,12 +573,12 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) if (i >= asolv) { pool->solvables = xrealloc(pool->solvables, (pool->nsolvables + asolv + 256) * sizeof(Solvable)); - memset(pool->solvables + repo->start + asolv, 0, 256 * sizeof(Solvable)); + memset(pool->solvables + pool->nsolvables + asolv, 0, 256 * sizeof(Solvable)); repo->rpmdbid = xrealloc(repo->rpmdbid, (asolv + 256) * sizeof(unsigned int)); memset(repo->rpmdbid + asolv, 0, 256 * sizeof(unsigned int)); asolv += 256; } - pool->solvables[repo->start + i].repo = repo; + pool->solvables[pool->nsolvables + i].repo = repo; if (key.size != 4) { fprintf(stderr, "corrupt Packages database (key size)\n"); @@ -611,7 +614,7 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) memcpy(rpmhead->data, (unsigned char *)data.data + 8, rpmhead->cnt * 16 + rpmhead->dcnt); rpmhead->dp = rpmhead->data + rpmhead->cnt * 16; repo->rpmdbid[i] = dbid; - if (rpm2solv(pool, repo, pool->solvables + repo->start + i, rpmhead)) + if (rpm2solv(pool, repo, pool->solvables + pool->nsolvables + i, rpmhead)) i++; } nrpmids = i; @@ -676,8 +679,8 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) rpmheadsize = 0; rpmhead = 0; - pool->solvables = xrealloc(pool->solvables, (pool->nsolvables + nrpmids) * sizeof(Solvable)); - memset(pool->solvables + repo->start, 0, nrpmids * sizeof(Solvable)); + pool->solvables = xrealloc2(pool->solvables, (pool->nsolvables + nrpmids), sizeof(Solvable)); + memset(pool->solvables + pool->nsolvables, 0, nrpmids * sizeof(Solvable)); repo->rpmdbid = calloc(nrpmids, sizeof(unsigned int)); refhash = 0; @@ -694,7 +697,7 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) refhash[h] = i + 1; /* make it non-zero */ } } - s = pool->solvables + repo->start; + s = pool->solvables + pool->nsolvables; for (i = 0; i < nrpmids; i++, rp++, s++) { s->repo = repo; @@ -812,9 +815,8 @@ pool_addrepo_rpmdb(Pool *pool, Repo *ref) if (rpmhead) free(rpmhead); pool->nsolvables += nrpmids; - repo->nsolvables = nrpmids; + repo->nsolvables += nrpmids; if (db) db->close(db, 0); - return repo; } diff --git a/tools/repo_rpmdb.h b/tools/repo_rpmdb.h index e5b3b5c..4adb385 100644 --- a/tools/repo_rpmdb.h +++ b/tools/repo_rpmdb.h @@ -5,4 +5,4 @@ * for further information */ -extern Repo *pool_addrepo_rpmdb(Pool *pool, Repo *ref); +extern void repo_add_rpmdb(Repo *repo, Repo *ref); diff --git a/tools/repo_rpmmd.c b/tools/repo_rpmmd.c index 598d6bd..c1e33d4 100644 --- a/tools/repo_rpmmd.c +++ b/tools/repo_rpmmd.c @@ -14,6 +14,7 @@ #include #include "pool.h" +#include "util.h" #include "repo_rpmmd.h" @@ -138,7 +139,7 @@ makeevr_atts(Pool *pool, struct parsedata *pd, const char **atts) l += strlen(r) + 1; if (l > pd->acontent) { - pd->content = realloc(pd->content, l + 256); + pd->content = xrealloc(pd->content, l + 256); pd->acontent = l + 256; } c = pd->content; @@ -205,7 +206,7 @@ adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, const char **atts int l = strlen(k) + 1 + strlen(n) + 1; if (l > pd->acontent) { - pd->content = realloc(pd->content, l + 256); + pd->content = xrealloc(pd->content, l + 256); pd->acontent = l + 256; } sprintf(pd->content, "%s:%s", k, n); @@ -272,8 +273,8 @@ startElement(void *userData, const char *name, const char **atts) #if 0 fprintf(stderr, "numpacks: %d\n", pd->numpacks); #endif - pool->solvables = realloc(pool->solvables, (pool->nsolvables + pd->numpacks) * sizeof(Solvable)); - pd->start = pool->solvables + pd->repo->start; + pool->solvables = xrealloc2(pool->solvables, (pool->nsolvables + pd->numpacks), sizeof(Solvable)); + pd->start = pool->solvables + pool->nsolvables; memset(pd->start, 0, pd->numpacks * sizeof(Solvable)); } } @@ -410,7 +411,7 @@ characterData(void *userData, const XML_Char *s, int len) l = pd->lcontent + len + 1; if (l > pd->acontent) { - pd->content = realloc(pd->content, l + 256); + pd->content = xrealloc(pd->content, l + 256); pd->acontent = l + 256; } c = pd->content + pd->lcontent; @@ -423,16 +424,20 @@ characterData(void *userData, const XML_Char *s, int len) #define BUFF_SIZE 8192 -Repo * -pool_addrepo_rpmmd(Pool *pool, FILE *fp) +void +repo_add_rpmmd(Repo *repo, FILE *fp) { + Pool *pool = repo->pool; struct parsedata pd; char buf[BUFF_SIZE]; int i, l; - Repo *repo; struct stateswitch *sw; - repo = pool_addrepo_empty(pool); + if (repo->start && repo->start + repo->nsolvables != pool->nsolvables) + abort(); + if (!repo->start) + repo->start = pool->nsolvables; + memset(&pd, 0, sizeof(pd)); for (i = 0, sw = stateswitches; sw->from != NUMSTATES; i++, sw++) { @@ -463,8 +468,7 @@ pool_addrepo_rpmmd(Pool *pool, FILE *fp) XML_ParserFree(parser); pool->nsolvables += pd.pack; - repo->nsolvables = pd.pack; + repo->nsolvables += pd.pack; free(pd.content); - return repo; } diff --git a/tools/repo_rpmmd.h b/tools/repo_rpmmd.h index 93a6e9e..dc2b86c 100644 --- a/tools/repo_rpmmd.h +++ b/tools/repo_rpmmd.h @@ -5,4 +5,4 @@ * for further information */ -extern Repo *pool_addrepo_rpmmd(Pool *pool, FILE *fp); +extern void repo_add_rpmmd(Repo *repo, FILE *fp); diff --git a/tools/repo_susetags.c b/tools/repo_susetags.c index 05cb9ee..182b6ee 100644 --- a/tools/repo_susetags.c +++ b/tools/repo_susetags.c @@ -136,12 +136,12 @@ adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, int i Attrstore *attr; -Repo * -pool_addrepo_susetags(Pool *pool, FILE *fp, Id vendor, int with_attr) +void +repo_add_susetags(Repo *repo, FILE *fp, Id vendor, int with_attr) { + Pool *pool = repo->pool; char *line, *linep; int aline; - Repo *repo; Solvable *s; int intag = 0; int cummulate = 0; @@ -151,7 +151,11 @@ pool_addrepo_susetags(Pool *pool, FILE *fp, Id vendor, int with_attr) char *sp[5]; struct parsedata pd; - repo = pool_addrepo_empty(pool); + if (repo->start && repo->start + repo->nsolvables != pool->nsolvables) + abort(); + if (!repo->start) + repo->start = pool->nsolvables; + attr = new_store (pool); memset(&pd, 0, sizeof(pd)); line = malloc(1024); @@ -240,9 +244,9 @@ pool_addrepo_susetags(Pool *pool, FILE *fp, Id vendor, int with_attr) if ((pack & PACK_BLOCK) == 0) { pool->solvables = realloc(pool->solvables, (pool->nsolvables + pack + PACK_BLOCK + 1) * sizeof(Solvable)); - memset(pool->solvables + repo->start + pack, 0, (PACK_BLOCK + 1) * sizeof(Solvable)); + memset(pool->solvables + pool->nsolvables + pack, 0, (PACK_BLOCK + 1) * sizeof(Solvable)); } - s = pool->solvables + repo->start + pack; + s = pool->solvables + pool->nsolvables + pack; s->repo = repo; last_found_pack = pack; pack++; @@ -293,7 +297,7 @@ pool_addrepo_susetags(Pool *pool, FILE *fp, Id vendor, int with_attr) { if (nn >= pack) nn = 0; - s = pool->solvables + repo->start + nn; + s = pool->solvables + pool->nsolvables + nn; if (s->name == name && s->evr == evr && s->arch == arch) break; } @@ -425,9 +429,8 @@ pool_addrepo_susetags(Pool *pool, FILE *fp, Id vendor, int with_attr) s->supplements = repo_fix_legacy(repo, s->provides, s->supplements); pool->nsolvables += pack; - repo->nsolvables = pack; + repo->nsolvables += pack; if (pd.tmp) free(pd.tmp); free(line); - return repo; } diff --git a/tools/repo_susetags.h b/tools/repo_susetags.h index ba7064f..f764d0b 100644 --- a/tools/repo_susetags.h +++ b/tools/repo_susetags.h @@ -5,4 +5,4 @@ * for further information */ -extern Repo *pool_addrepo_susetags(Pool *pool, FILE *fp, Id vendor, int with_attr); +extern void repo_add_susetags(Repo *repo, FILE *fp, Id vendor, int with_attr); diff --git a/tools/repo_write.c b/tools/repo_write.c index 8171498..b66fd20 100644 --- a/tools/repo_write.c +++ b/tools/repo_write.c @@ -189,8 +189,9 @@ write_idarray(FILE *fp, Pool *pool, NeedId *needid, Id *ids) */ void -pool_writerepo(Pool *pool, Repo *repo, FILE *fp) +repo_write(Repo *repo, FILE *fp) { + Pool *pool = repo->pool; int i, numsolvdata; Solvable *s, *sstart; NeedId *needid; diff --git a/tools/repo_write.h b/tools/repo_write.h index db36bde..145a09a 100644 --- a/tools/repo_write.h +++ b/tools/repo_write.h @@ -18,6 +18,6 @@ #include "pool.h" #include "repo.h" -extern void pool_writerepo(Pool *pool, Repo *repo, FILE *fp); +extern void repo_write(Repo *repo, FILE *fp); #endif diff --git a/tools/rpmdb2solv.c b/tools/rpmdb2solv.c index bf77332..d8adfae 100644 --- a/tools/rpmdb2solv.c +++ b/tools/rpmdb2solv.c @@ -26,7 +26,7 @@ int main(int argc, char **argv) { Pool *pool = pool_create(); - Repo *ref = NULL; + Repo *repo, *ref = 0; FILE *fp; if (argc != 1) @@ -37,21 +37,23 @@ main(int argc, char **argv) perror(argv[1]); exit(0); } - ref = pool_addrepo_solv(refpool, fp, "rpmdb"); + ref = repo_create(refpool, "ref"); + repo_add_solv(ref, fp); fclose(fp); } - Repo *repo = pool_addrepo_rpmdb(pool, ref); + repo = repo_create(pool, "installed"); + repo_add_rpmdb(repo, ref); if (ref) { if (ref->pool != pool) pool_free(ref->pool); else - pool_freerepo(pool, ref); - ref = NULL; + repo_free(ref); + ref = 0; } - pool_writerepo(pool, repo, stdout); + repo_write(repo, stdout); pool_free(pool); exit(0); diff --git a/tools/rpmmd2solv.c b/tools/rpmmd2solv.c index becb3d2..ad7638a 100644 --- a/tools/rpmmd2solv.c +++ b/tools/rpmmd2solv.c @@ -20,8 +20,9 @@ int main(int argc, char **argv) { Pool *pool = pool_create(); - Repo *repo = pool_addrepo_rpmmd(pool, stdin); - pool_writerepo(pool, repo, stdout); + Repo *repo = repo_create(pool, ""); + repo_add_rpmmd(repo, stdin); + repo_write(repo, stdout); pool_free(pool); exit(0); } diff --git a/tools/susetags2solv.c b/tools/susetags2solv.c index 6982fce..321a51e 100644 --- a/tools/susetags2solv.c +++ b/tools/susetags2solv.c @@ -38,8 +38,9 @@ main(int argc, char **argv) argv++; } Pool *pool = pool_create(); - Repo *repo = pool_addrepo_susetags(pool, stdin, 0, with_attr); - pool_writerepo(pool, repo, stdout); + Repo *repo = repo_create(pool, ""); + repo_add_susetags(repo, stdin, 0, with_attr); + repo_write(repo, stdout); if (with_attr && attr) { FILE *fp = fopen ("test.attr", "w"); -- 2.7.4