#include "pool.h"
#include "poolid_private.h"
#include "util.h"
-#if 0
-#include "attr_store_p.h"
-#endif
+#include "chksum.h"
#define IDARRAY_BLOCK 4095
repo = (Repo *)sat_calloc(1, sizeof(*repo));
pool->repos = (Repo **)sat_realloc2(pool->repos, pool->nrepos + 1, sizeof(Repo *));
pool->repos[pool->nrepos++] = repo;
+ repo->repoid = pool->nrepos;
repo->name = name ? strdup(name) : 0;
repo->pool = pool;
repo->start = pool->nsolvables;
{
int i;
for (i = 0; i < repo->nrepodata; i++)
- repodata_free(repo->repodata + i);
+ repodata_freedata(repo->repodata + i);
sat_free(repo->repodata);
sat_free(repo->idarraydata);
sat_free(repo->rpmdbid);
sat_free(repo);
}
+/* delete all solvables and repodata blocks from this repo */
+
+void
+repo_empty(Repo *repo, int reuseids)
+{
+ Pool *pool = repo->pool;
+ Solvable *s;
+ int i;
+
+ pool_freewhatprovides(pool);
+ if (reuseids && repo->end == pool->nsolvables)
+ {
+ /* it's ok to reuse the ids. As this is the last repo, we can
+ just shrink the solvable array */
+ for (i = repo->end - 1, s = pool->solvables + i; i >= repo->start; i--, s--)
+ if (s->repo != repo)
+ break;
+ pool_free_solvable_block(pool, i + 1, repo->end - (i + 1), reuseids);
+ }
+ /* zero out (i.e. free) solvables belonging to this repo */
+ for (i = repo->start, s = pool->solvables + i; i < repo->end; i++, s++)
+ if (s->repo == repo)
+ memset(s, 0, sizeof(*s));
+ repo->nsolvables = 0;
+
+ /* free all data belonging to this repo */
+ repo->idarraydata = sat_free(repo->idarraydata);
+ repo->idarraysize = 0;
+ repo->lastoff = 0;
+ repo->rpmdbid = sat_free(repo->rpmdbid);
+ for (i = 0; i < repo->nrepodata; i++)
+ repodata_freedata(repo->repodata + i);
+ sat_free(repo->repodata);
+ repo->repodata = 0;
+ repo->nrepodata = 0;
+}
+
/*
- * add Id to repo
- * olddeps = old array to extend
+ * remove repo from pool, delete solvables
*
*/
+void
+repo_free(Repo *repo, int reuseids)
+{
+ Pool *pool = repo->pool;
+ int i;
+
+ if (repo == pool->installed)
+ pool->installed = 0;
+ repo_empty(repo, reuseids);
+ for (i = 0; i < pool->nrepos; i++) /* find repo in pool */
+ if (pool->repos[i] == repo)
+ break;
+ if (i == pool->nrepos) /* repo not in pool, return */
+ return;
+ if (i < pool->nrepos - 1)
+ {
+ memmove(pool->repos + i, pool->repos + i + 1, (pool->nrepos - 1 - i) * sizeof(Repo *));
+ /* fix repo ids */
+ for (; i < pool->nrepos - 1; i++)
+ pool->repos[i]->repoid = i + 1;
+ }
+ pool->nrepos--;
+ repo_freedata(repo);
+}
+
+void
+repo_freeallrepos(Pool *pool, int reuseids)
+{
+ int i;
+
+ pool_freewhatprovides(pool);
+ for (i = 0; i < pool->nrepos; i++)
+ repo_freedata(pool->repos[i]);
+ pool->repos = sat_free(pool->repos);
+ pool->nrepos = 0;
+ /* the first two solvables don't belong to a repo */
+ pool_free_solvable_block(pool, 2, pool->nsolvables - 2, reuseids);
+}
+
+void repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids)
+{
+ Solvable *s;
+ Repodata *data;
+ int i;
+ if (start + count == repo->end)
+ repo->end -= count;
+ repo->nsolvables -= count;
+ for (s = repo->pool->solvables + start, i = count; i--; s++)
+ s->repo = 0;
+ pool_free_solvable_block(repo->pool, start, count, reuseids);
+ for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
+ if (data->end > repo->end)
+ repodata_shrink(data, repo->end);
+}
+
+
+/* repository sidedata is solvable data allocated on demand.
+ * It is used for data that is normally not present
+ * in the solvable like the rpmdbid.
+ * The solvable allocation funcions need to make sure that
+ * the sidedata gets extended if new solvables get added.
+ */
+
+#define REPO_SIDEDATA_BLOCK 63
+
+void *
+repo_sidedata_create(Repo *repo, size_t size)
+{
+ return sat_calloc_block(repo->end - repo->start, size, REPO_SIDEDATA_BLOCK);
+}
+
+void *
+repo_sidedata_extend(Repo *repo, void *b, size_t size, Id p, int count)
+{
+ int n = repo->end - repo->start;
+ if (p < repo->start)
+ {
+ int d = repo->start - p;
+ b = sat_extend(b, n, d, size, REPO_SIDEDATA_BLOCK);
+ memmove((char *)b + d * size, b, n * size);
+ memset(b, 0, d * size);
+ n += d;
+ }
+ if (p + count > repo->end)
+ {
+ int d = p + count - repo->end;
+ b = sat_extend(b, n, d, size, REPO_SIDEDATA_BLOCK);
+ memset((char *)b + n * size, 0, d * size);
+ }
+ return b;
+}
+
+/*
+ * add Id to idarraydata used to store dependencies
+ * olddeps: old array offset to extend
+ * returns new array offset
+ */
+
Offset
repo_addid(Repo *repo, Offset olddeps, Id id)
{
* marker= 0 for normal dep
* marker > 0 add dep after marker
* marker < 0 add dep after -marker
- *
+ * returns new start of dependency array
*/
Offset
repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker)
/*
* reserve Ids
* make space for 'num' more dependencies
+ * returns new start of dependency array
+ *
+ * reserved ids will always begin at offset idarraysize
*/
Offset
}
-/*
- * remove repo from pool, zero out solvables
- *
- */
-
-void
-repo_free(Repo *repo, int reuseids)
-{
- Pool *pool = repo->pool;
- Solvable *s;
- int i;
-
- pool_freewhatprovides(pool);
- if (repo == pool->installed)
- pool->installed = 0;
-
- if (reuseids && repo->end == pool->nsolvables)
- {
- /* it's ok to reuse the ids. As this is the last repo, we can
- just shrink the solvable array */
- for (i = repo->end - 1, s = pool->solvables + i; i >= repo->start; i--, s--)
- if (s->repo != repo)
- break;
- repo->end = i + 1;
- pool->nsolvables = i + 1;
- }
- /* zero out solvables belonging to this repo */
- for (i = repo->start, s = pool->solvables + i; i < repo->end; i++, s++)
- if (s->repo == repo)
- memset(s, 0, sizeof(*s));
- for (i = 0; i < pool->nrepos; i++) /* find repo in pool */
- if (pool->repos[i] == repo)
- break;
- if (i == pool->nrepos) /* repo not in pool, return */
- return;
- if (i < pool->nrepos - 1)
- memmove(pool->repos + i, pool->repos + i + 1, (pool->nrepos - 1 - i) * sizeof(Repo *));
- pool->nrepos--;
- repo_freedata(repo);
-}
-
-void
-repo_freeallrepos(Pool *pool, int reuseids)
-{
- int i;
-
- pool_freewhatprovides(pool);
- for (i = 0; i < pool->nrepos; i++)
- repo_freedata(pool->repos[i]);
- pool->repos = sat_free(pool->repos);
- pool->nrepos = 0;
- /* the first two solvables don't belong to a repo */
- pool_free_solvable_block(pool, 2, pool->nsolvables - 2, reuseids);
-}
-
-
-#define REPO_SIDEDATA_BLOCK 63
-
-void *
-repo_sidedata_create(Repo *repo, size_t size)
-{
- return sat_calloc_block(repo->end - repo->start, size, REPO_SIDEDATA_BLOCK);
-}
-
-void *
-repo_sidedata_extend(Repo *repo, void *b, size_t size, Id p, int count)
-{
- int n = repo->end - repo->start;
- if (p < repo->start)
- {
- int d = repo->start - p;
- b = sat_extend(b, n, d, size, REPO_SIDEDATA_BLOCK);
- memmove((char*)b + d * size, b, n * size);
- memset(b, 0, d * size);
- n += d;
- }
- if (p + count > repo->end)
- {
- int d = p + count - repo->end;
- b = sat_extend(b, n, d, size, REPO_SIDEDATA_BLOCK);
- memset((char*)b + n * size, 0, d * size);
- }
- return b;
-}
Offset
repo_fix_supplements(Repo *repo, Offset provides, Offset supplements, Offset freshens)
continue;
if (keyname && !repodata_precheck_keyname(data, keyname))
continue;
+ if (keyname == SOLVABLE_FILELIST && !(md->flags & SEARCH_COMPLETE_FILELIST))
+ {
+ /* do not search filelist extensions */
+ if (data->state != REPODATA_AVAILABLE)
+ continue;
+ for (j = 1; j < data->nkeys; j++)
+ if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
+ break;
+ if (j == data->nkeys)
+ continue;
+ }
if (data->state == REPODATA_STUB)
{
if (keyname)
{
struct matchdata md;
+ if (repo->disabled && !(flags & SEARCH_DISABLED_REPOS))
+ return;
memset(&md, 0, sizeof(md));
md.pool = repo->pool;
md.flags = flags;
{
Pool *pool = repo->pool;
Repodata *data;
- int i, j;
+ int i;
+ const char *str;
- switch(keyname)
+ if (entry >= 0)
{
- case SOLVABLE_NAME:
- return id2str(pool, pool->solvables[entry].name);
- case SOLVABLE_ARCH:
- return id2str(pool, pool->solvables[entry].arch);
- case SOLVABLE_EVR:
- return id2str(pool, pool->solvables[entry].evr);
- case SOLVABLE_VENDOR:
- return id2str(pool, pool->solvables[entry].vendor);
+ switch (keyname)
+ {
+ case SOLVABLE_NAME:
+ return id2str(pool, pool->solvables[entry].name);
+ case SOLVABLE_ARCH:
+ return id2str(pool, pool->solvables[entry].arch);
+ case SOLVABLE_EVR:
+ return id2str(pool, pool->solvables[entry].evr);
+ case SOLVABLE_VENDOR:
+ return id2str(pool, pool->solvables[entry].vendor);
+ }
}
for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
{
continue;
if (!repodata_precheck_keyname(data, keyname))
continue;
- for (j = 1; j < data->nkeys; j++)
- {
- if (data->keys[j].name == keyname && (data->keys[j].type == REPOKEY_TYPE_ID || data->keys[j].type == REPOKEY_TYPE_CONSTANTID || data->keys[j].type == REPOKEY_TYPE_STR))
- return repodata_lookup_str(data, entry, keyname);
- }
+ str = repodata_lookup_str(data, entry, keyname);
+ if (str)
+ return str;
+ if (repodata_lookup_type(data, entry, keyname))
+ return 0;
}
return 0;
}
repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned int notfound)
{
Repodata *data;
- int i, j;
+ int i;
+ unsigned int value;
- if (keyname == RPM_RPMDBID)
+ if (entry >= 0)
{
- if (repo->rpmdbid && entry >= repo->start && entry < repo->end)
- return repo->rpmdbid[entry - repo->start];
- return notfound;
+ if (keyname == RPM_RPMDBID)
+ {
+ if (repo->rpmdbid && entry >= repo->start && entry < repo->end)
+ return repo->rpmdbid[entry - repo->start];
+ return notfound;
+ }
}
for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
{
continue;
if (!repodata_precheck_keyname(data, keyname))
continue;
- for (j = 1; j < data->nkeys; j++)
- {
- if (data->keys[j].name == keyname
- && (data->keys[j].type == REPOKEY_TYPE_U32
- || data->keys[j].type == REPOKEY_TYPE_NUM
- || data->keys[j].type == REPOKEY_TYPE_CONSTANT))
- {
- unsigned value;
- if (repodata_lookup_num(data, entry, keyname, &value))
- return value;
- }
- }
+ if (repodata_lookup_num(data, entry, keyname, &value))
+ return value;
+ if (repodata_lookup_type(data, entry, keyname))
+ return notfound;
}
return notfound;
}
repo_lookup_id(Repo *repo, Id entry, Id keyname)
{
Repodata *data;
- int i, j;
+ int i;
+ Id id;
- switch(keyname)
+ if (entry >= 0)
+ {
+ switch (keyname)
+ {
+ case SOLVABLE_NAME:
+ return repo->pool->solvables[entry].name;
+ case SOLVABLE_ARCH:
+ return repo->pool->solvables[entry].arch;
+ case SOLVABLE_EVR:
+ return repo->pool->solvables[entry].evr;
+ case SOLVABLE_VENDOR:
+ return repo->pool->solvables[entry].vendor;
+ }
+ }
+ for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
{
- case SOLVABLE_NAME:
- return repo->pool->solvables[entry].name;
- case SOLVABLE_ARCH:
- return repo->pool->solvables[entry].arch;
- case SOLVABLE_EVR:
- return repo->pool->solvables[entry].evr;
- case SOLVABLE_VENDOR:
- return repo->pool->solvables[entry].vendor;
+ if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
+ continue;
+ if (!repodata_precheck_keyname(data, keyname))
+ continue;
+ id = repodata_lookup_id(data, entry, keyname);
+ if (id)
+ return data->localpool ? repodata_globalize_id(data, id, 1) : id;
+ if (repodata_lookup_type(data, entry, keyname))
+ return 0;
}
+ return 0;
+}
+
+static int
+lookup_idarray_solvable(Repo *repo, Offset off, Queue *q)
+{
+ Id *p;
+
+ queue_empty(q);
+ if (off)
+ for (p = repo->idarraydata + off; *p; p++)
+ queue_push(q, *p);
+ return 1;
+}
+
+int
+repo_lookup_idarray(Repo *repo, Id entry, Id keyname, Queue *q)
+{
+ Repodata *data;
+ int i;
+ if (entry >= 0)
+ {
+ switch (keyname)
+ {
+ case SOLVABLE_PROVIDES:
+ return lookup_idarray_solvable(repo, repo->pool->solvables[entry].provides, q);
+ case SOLVABLE_OBSOLETES:
+ return lookup_idarray_solvable(repo, repo->pool->solvables[entry].obsoletes, q);
+ case SOLVABLE_CONFLICTS:
+ return lookup_idarray_solvable(repo, repo->pool->solvables[entry].conflicts, q);
+ case SOLVABLE_REQUIRES:
+ return lookup_idarray_solvable(repo, repo->pool->solvables[entry].requires, q);
+ case SOLVABLE_RECOMMENDS:
+ return lookup_idarray_solvable(repo, repo->pool->solvables[entry].recommends, q);
+ case SOLVABLE_SUGGESTS:
+ return lookup_idarray_solvable(repo, repo->pool->solvables[entry].suggests, q);
+ case SOLVABLE_SUPPLEMENTS:
+ return lookup_idarray_solvable(repo, repo->pool->solvables[entry].supplements, q);
+ case SOLVABLE_ENHANCES:
+ return lookup_idarray_solvable(repo, repo->pool->solvables[entry].enhances, q);
+ }
+ }
for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
{
if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
continue;
if (!repodata_precheck_keyname(data, keyname))
continue;
- for (j = 1; j < data->nkeys; j++)
+ if (repodata_lookup_idarray(data, entry, keyname, q))
{
- if (data->keys[j].name == keyname && (data->keys[j].type == REPOKEY_TYPE_ID || data->keys[j].type == REPOKEY_TYPE_CONSTANTID))
+ if (data->localpool)
{
- Id id = repodata_lookup_id(data, entry, keyname);
- if (id)
- {
- if (data->localpool)
- id = repodata_globalize_id(data, id);
- return id;
- }
+ for (i = 0; i < q->count; i++)
+ q->elements[i] = repodata_globalize_id(data, q->elements[i], 1);
}
+ return 1;
}
- }
+ if (repodata_lookup_type(data, entry, keyname))
+ break;
+ }
+ queue_empty(q);
return 0;
}
repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
{
Repodata *data;
- int i, j;
+ int i;
+ const unsigned char *chk;
+
for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
{
if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
continue;
if (!repodata_precheck_keyname(data, keyname))
continue;
- for (j = 1; j < data->nkeys; j++)
- {
- if (data->keys[j].name == keyname)
- {
- const unsigned char *chk = repodata_lookup_bin_checksum(data, entry, keyname, typep);
- if (chk)
- return chk;
- }
- }
+ chk = repodata_lookup_bin_checksum(data, entry, keyname, typep);
+ if (chk)
+ return chk;
+ if (repodata_lookup_type(data, entry, keyname))
+ return 0;
}
*typep = 0;
return 0;
}
+const char *
+repo_lookup_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
+{
+ const unsigned char *chk = repo_lookup_bin_checksum(repo, entry, keyname, typep);
+ return chk ? pool_bin2hex(repo->pool, chk, sat_chksum_len(*typep)) : 0;
+}
+
int
repo_lookup_void(Repo *repo, Id entry, Id keyname)
{
Repodata *data;
- int i, j;
+ int i;
+ Id type;
+
for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
{
if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
continue;
if (!repodata_precheck_keyname(data, keyname))
continue;
- for (j = 1; j < data->nkeys; j++)
- {
- if (data->keys[j].name == keyname
- && (data->keys[j].type == REPOKEY_TYPE_VOID))
- {
- if (repodata_lookup_void(data, entry, keyname))
- return 1;
- }
- }
+ type = repodata_lookup_type(data, entry, keyname);
+ if (type)
+ return type == REPOKEY_TYPE_VOID;
+ }
+ return 0;
+}
+
+Id
+repo_lookup_type(Repo *repo, Id entry, Id keyname)
+{
+ Repodata *data;
+ int i;
+ Id type;
+
+ for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
+ {
+ if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
+ continue;
+ if (!repodata_precheck_keyname(data, keyname))
+ continue;
+ type = repodata_lookup_type(data, entry, keyname);
+ if (type)
+ return type == REPOKEY_TYPE_DELETED ? 0 : type;
}
return 0;
}
/***********************************************************************/
Repodata *
-repo_add_repodata(Repo *repo, int localpool)
+repo_add_repodata(Repo *repo, int flags)
{
- Repodata *data;
-
- repo->nrepodata++;
- repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata, sizeof(*data));
- data = repo->repodata + repo->nrepodata - 1;
- repodata_init(data, repo, localpool);
- return data;
+ int i;
+ if ((flags & REPO_USE_LOADING) != 0)
+ {
+ for (i = repo->nrepodata - 1; i >= 0; i--)
+ if (repo->repodata[i].state == REPODATA_LOADING)
+ {
+ Repodata *data = repo->repodata + i;
+ /* re-init */
+ /* hack: we mis-use REPO_REUSE_REPODATA here */
+ if (!(flags & REPO_REUSE_REPODATA))
+ repodata_empty(data, (flags & REPO_LOCALPOOL) ? 1 : 0);
+ return data;
+ }
+ return 0; /* must not create a new repodata! */
+ }
+ if ((flags & REPO_REUSE_REPODATA) != 0)
+ {
+ for (i = repo->nrepodata - 1; i >= 0; i--)
+ if (repo->repodata[i].state != REPODATA_STUB)
+ return repo->repodata + i;
+ }
+ return repodata_create(repo, (flags & REPO_LOCALPOOL) ? 1 : 0);
}
Repodata *
repo_set_id(Repo *repo, Id p, Id keyname, Id id)
{
Repodata *data = repo_last_repodata(repo);
+ if (data->localpool)
+ id = repodata_localize_id(data, id, 1);
repodata_set_id(data, p, keyname, id);
}
void
-repo_set_num(Repo *repo, Id p, Id keyname, Id num)
+repo_set_num(Repo *repo, Id p, Id keyname, unsigned int num)
{
- Repodata *data = repo_last_repodata(repo);
+ Repodata *data;
+ if (p >= 0)
+ {
+ if (keyname == RPM_RPMDBID)
+ {
+ if (!repo->rpmdbid)
+ repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
+ repo->rpmdbid[p] = num;
+ return;
+ }
+ }
+ data = repo_last_repodata(repo);
repodata_set_num(data, p, keyname, num);
}