*
*/
+#define _GNU_SOURCE
+#include <string.h>
+#include <fnmatch.h>
+
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
+
+
#include "repo.h"
#include "pool.h"
#include "poolid_private.h"
#include "util.h"
+#if 0
#include "attr_store_p.h"
+#endif
#define IDARRAY_BLOCK 4095
Repo *repo;
pool_freewhatprovides(pool);
- repo = (Repo *)xcalloc(1, sizeof(*repo));
- pool->repos = (Repo **)xrealloc(pool->repos, (pool->nrepos + 1) * sizeof(Repo *));
+ 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;
static void
repo_freedata(Repo *repo)
{
- xfree(repo->idarraydata);
- xfree(repo->rpmdbid);
- xfree((char *)repo->name);
- xfree(repo);
+ int i;
+ for (i = 0; i < repo->nrepodata; i++)
+ repodata_free(repo->repodata + i);
+ sat_free(repo->repodata);
+ sat_free(repo->idarraydata);
+ sat_free(repo->rpmdbid);
+ sat_free((char *)repo->name);
+ sat_free(repo);
}
/*
if (!idarray) /* alloc idarray if not done yet */
{
- idarray = (Id *)xmalloc((1 + IDARRAY_BLOCK) * sizeof(Id));
- idarray[0] = 0;
idarraysize = 1;
+ idarray = sat_extend_resize(0, 1, sizeof(Id), IDARRAY_BLOCK);
+ idarray[0] = 0;
repo->lastoff = 0;
}
if (!olddeps) /* no deps yet */
{
olddeps = idarraysize;
- if ((idarraysize & IDARRAY_BLOCK) == 0)
- idarray = (Id *)xrealloc(idarray, (idarraysize + 1 + IDARRAY_BLOCK) * sizeof(Id));
+ idarray = sat_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
}
else if (olddeps == repo->lastoff) /* extend at end */
idarraysize--;
olddeps = idarraysize;
for (; idarray[i]; i++)
{
- if ((idarraysize & IDARRAY_BLOCK) == 0)
- idarray = (Id *)xrealloc(idarray, (idarraysize + 1 + IDARRAY_BLOCK) * sizeof(Id));
+ idarray = sat_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
idarray[idarraysize++] = idarray[i];
}
- if ((idarraysize & IDARRAY_BLOCK) == 0)
- idarray = (Id *)xrealloc(idarray, (idarraysize + 1 + IDARRAY_BLOCK) * sizeof(Id));
+ idarray = sat_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
}
idarray[idarraysize++] = id; /* insert Id into array */
-
- if ((idarraysize & IDARRAY_BLOCK) == 0) /* realloc if at block boundary */
- idarray = (Id *)xrealloc(idarray, (idarraysize + 1 + IDARRAY_BLOCK) * sizeof(Id));
-
+ idarray = sat_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
idarray[idarraysize++] = 0; /* ensure NULL termination */
repo->idarraydata = idarray;
/*
- * add dependency (as Id) to repo
+ * add dependency (as Id) to repo, also unifies dependencies
* olddeps = offset into idarraydata
- * isreq = 0 for normal dep
- * isreq = 1 for requires
- * isreq = 2 for pre-requires
+ * marker= 0 for normal dep
+ * marker > 0 add dep after marker
+ * marker < 0 add dep after -marker
*
*/
-
Offset
-repo_addid_dep(Repo *repo, Offset olddeps, Id id, int isreq)
+repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker)
{
- Id oid, *oidp, *marker = 0;
+ Id oid, *oidp, *markerp;
+ int before;
if (!olddeps)
- return repo_addid(repo, olddeps, id);
+ {
+ if (marker > 0)
+ olddeps = repo_addid(repo, olddeps, marker);
+ return repo_addid(repo, olddeps, id);
+ }
- if (!isreq)
+ if (!marker)
{
for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != ID_NULL; oidp++)
{
return repo_addid(repo, olddeps, id);
}
+ before = 0;
+ markerp = 0;
+ if (marker < 0)
+ {
+ before = 1;
+ marker = -marker;
+ }
for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != ID_NULL; oidp++)
{
- if (oid == SOLVABLE_PREREQMARKER)
- marker = oidp;
+ if (oid == marker)
+ markerp = oidp;
else if (oid == id)
break;
}
if (oid)
{
- if (marker || isreq == 1)
+ if (markerp || before)
return olddeps;
- marker = oidp++;
+ /* we found it, but in the wrong half */
+ markerp = oidp++;
for (; (oid = *oidp) != ID_NULL; oidp++)
- if (oid == SOLVABLE_PREREQMARKER)
+ if (oid == marker)
break;
if (!oid)
{
+ /* no marker in array yet */
oidp--;
- if (marker < oidp)
- memmove(marker, marker + 1, (oidp - marker) * sizeof(Id));
- *oidp = SOLVABLE_PREREQMARKER;
+ if (markerp < oidp)
+ memmove(markerp, markerp + 1, (oidp - markerp) * sizeof(Id));
+ *oidp = marker;
return repo_addid(repo, olddeps, id);
}
while (oidp[1])
oidp++;
- memmove(marker, marker + 1, (oidp - marker) * sizeof(Id));
+ memmove(markerp, markerp + 1, (oidp - markerp) * sizeof(Id));
*oidp = id;
return olddeps;
}
- if (isreq == 2 && !marker)
- olddeps = repo_addid(repo, olddeps, SOLVABLE_PREREQMARKER);
- else if (isreq == 1 && marker)
+ /* id not yet in array */
+ if (!before && !markerp)
+ olddeps = repo_addid(repo, olddeps, marker);
+ else if (before && markerp)
{
- *marker++ = id;
+ *markerp++ = id;
id = *--oidp;
- if (marker < oidp)
- memmove(marker + 1, marker, (oidp - marker) * sizeof(Id));
- *marker = SOLVABLE_PREREQMARKER;
+ if (markerp < oidp)
+ memmove(markerp + 1, markerp, (oidp - markerp) * sizeof(Id));
+ *markerp = marker;
}
return repo_addid(repo, olddeps, id);
}
if (!repo->idarraysize) /* ensure buffer space */
{
repo->idarraysize = 1;
- repo->idarraydata = (Id *)xmalloc(((1 + num + IDARRAY_BLOCK) & ~IDARRAY_BLOCK) * sizeof(Id));
+ repo->idarraydata = sat_extend_resize(0, 1 + num, sizeof(Id), IDARRAY_BLOCK);
repo->idarraydata[0] = 0;
repo->lastoff = 1;
return 1;
;
count = idend - idstart - 1 + num; /* new size */
- /* realloc if crossing block boundary */
- if (((repo->idarraysize - 1) | IDARRAY_BLOCK) != ((repo->idarraysize + count - 1) | IDARRAY_BLOCK))
- repo->idarraydata = (Id *)xrealloc(repo->idarraydata, ((repo->idarraysize + count + IDARRAY_BLOCK) & ~IDARRAY_BLOCK) * sizeof(Id));
-
+ repo->idarraydata = sat_extend(repo->idarraydata, repo->idarraysize, count, sizeof(Id), IDARRAY_BLOCK);
/* move old deps to end */
olddeps = repo->lastoff = repo->idarraysize;
memcpy(repo->idarraydata + olddeps, idstart, count - num);
if (olddeps) /* appending */
repo->idarraysize--;
- /* realloc if crossing block boundary */
- if (((repo->idarraysize - 1) | IDARRAY_BLOCK) != ((repo->idarraysize + num - 1) | IDARRAY_BLOCK))
- repo->idarraydata = (Id *)xrealloc(repo->idarraydata, ((repo->idarraysize + num + IDARRAY_BLOCK) & ~IDARRAY_BLOCK) * sizeof(Id));
+ /* make room*/
+ repo->idarraydata = sat_extend(repo->idarraydata, repo->idarraysize, num, sizeof(Id), IDARRAY_BLOCK);
/* appending or new */
repo->lastoff = olddeps ? olddeps : repo->idarraysize;
int i;
pool_freewhatprovides(pool);
+ if (repo == pool->installed)
+ pool->installed = 0;
if (reuseids && repo->end == pool->nsolvables)
{
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 *));
+ {
+ 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);
}
pool_freewhatprovides(pool);
for (i = 0; i < pool->nrepos; i++)
repo_freedata(pool->repos[i]);
- pool->repos = xfree(pool->repos);
+ 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_legacy(Repo *repo, Offset provides, Offset supplements)
+repo_fix_supplements(Repo *repo, Offset provides, Offset supplements, Offset freshens)
{
Pool *pool = repo->pool;
- Id id, idp, idl, idns;
+ Id id, idp, idl;
char buf[1024], *p, *dep;
- int i;
+ int i, l;
if (provides)
{
dep = p + 1;
continue;
}
- strncpy(dep - 9, "language:", 9);
*p++ = 0;
+#if 0
+ strncpy(dep - 9, "language:", 9);
idl = str2id(pool, dep - 9, 1);
+#else
+ idl = str2id(pool, dep, 1);
+ idl = rel2id(pool, NAMESPACE_LANGUAGE, idl, REL_NAMESPACE, 1);
+#endif
if (id)
id = rel2id(pool, id, idl, REL_OR, 1);
else
for (p = dep; *p && *p != ')'; p++)
;
*p = 0;
+#if 0
strncpy(dep - 9, "language:", 9);
idl = str2id(pool, dep - 9, 1);
+#else
+ idl = str2id(pool, dep, 1);
+ idl = rel2id(pool, NAMESPACE_LANGUAGE, idl, REL_NAMESPACE, 1);
+#endif
if (id)
id = rel2id(pool, id, idl, REL_OR, 1);
else
p = buf + (p - dep);
*p++ = 0;
idp = str2id(pool, buf, 1);
- idns = str2id(pool, "namespace:installed", 1);
+ /* strip trailing slashes */
+ l = strlen(p);
+ while (l > 1 && p[l - 1] == '/')
+ p[--l] = 0;
id = str2id(pool, p, 1);
- id = rel2id(pool, idns, id, REL_NAMESPACE, 1);
- id = rel2id(pool, idp, id, REL_AND, 1);
+ id = rel2id(pool, idp, id, REL_WITH, 1);
+ id = rel2id(pool, NAMESPACE_SPLITPROVIDES, id, REL_NAMESPACE, 1);
supplements = repo_addid_dep(repo, supplements, id, 0);
}
}
}
- if (!supplements)
- return 0;
- for (i = supplements; repo->idarraydata[i]; i++)
+ if (supplements)
{
- id = repo->idarraydata[i];
- if (ISRELDEP(id))
- continue;
- dep = (char *)id2str(pool, id);
- if (!strncmp(dep, "system:modalias(", 16))
- dep += 7;
- if (!strncmp(dep, "modalias(", 9) && dep[9] && dep[10] && strlen(dep) < sizeof(buf))
+ for (i = supplements; repo->idarraydata[i]; i++)
{
- strcpy(buf, dep);
- p = strchr(buf + 9, ':');
- idns = str2id(pool, "namespace:modalias", 1);
- if (p && p != buf + 9 && strchr(p + 1, ':'))
- {
- *p++ = 0;
- idp = str2id(pool, buf + 9, 1);
- p[strlen(p) - 1] = 0;
- id = str2id(pool, p, 1);
- id = rel2id(pool, idns, id, REL_NAMESPACE, 1);
- id = rel2id(pool, idp, id, REL_AND, 1);
- }
- else
+ id = repo->idarraydata[i];
+ if (ISRELDEP(id))
+ continue;
+ dep = (char *)id2str(pool, id);
+ if (!strncmp(dep, "system:modalias(", 16))
+ dep += 7;
+ if (!strncmp(dep, "modalias(", 9) && dep[9] && dep[10] && strlen(dep) < sizeof(buf))
{
- p = buf + 9;
- p[strlen(p) - 1] = 0;
- id = str2id(pool, p, 1);
- id = rel2id(pool, idns, id, REL_NAMESPACE, 1);
+ strcpy(buf, dep);
+ p = strchr(buf + 9, ':');
+ if (p && p != buf + 9 && strchr(p + 1, ':'))
+ {
+ *p++ = 0;
+ idp = str2id(pool, buf + 9, 1);
+ p[strlen(p) - 1] = 0;
+ id = str2id(pool, p, 1);
+ id = rel2id(pool, NAMESPACE_MODALIAS, id, REL_NAMESPACE, 1);
+ id = rel2id(pool, idp, id, REL_AND, 1);
+ }
+ else
+ {
+ p = buf + 9;
+ p[strlen(p) - 1] = 0;
+ id = str2id(pool, p, 1);
+ id = rel2id(pool, NAMESPACE_MODALIAS, id, REL_NAMESPACE, 1);
+ }
+ if (id)
+ repo->idarraydata[i] = id;
}
- if (id)
- repo->idarraydata[i] = id;
- }
- else if (!strncmp(dep, "packageand(", 11) && strlen(dep) < sizeof(buf))
- {
- strcpy(buf, dep);
- id = 0;
- dep = buf + 11;
- while ((p = strchr(dep, ':')) != 0)
+ else if (!strncmp(dep, "packageand(", 11) && strlen(dep) < sizeof(buf))
{
- if (p == dep)
+ strcpy(buf, dep);
+ id = 0;
+ dep = buf + 11;
+ while ((p = strchr(dep, ':')) != 0)
{
- dep = p + 1;
- continue;
+ if (p == dep)
+ {
+ dep = p + 1;
+ continue;
+ }
+ *p++ = 0;
+ idp = str2id(pool, dep, 1);
+ if (id)
+ id = rel2id(pool, id, idp, REL_AND, 1);
+ else
+ id = idp;
+ dep = p;
+ }
+ if (dep[0] && dep[1])
+ {
+ dep[strlen(dep) - 1] = 0;
+ idp = str2id(pool, dep, 1);
+ if (id)
+ id = rel2id(pool, id, idp, REL_AND, 1);
+ else
+ id = idp;
}
- *p++ = 0;
- idp = str2id(pool, dep, 1);
if (id)
- id = rel2id(pool, id, idp, REL_AND, 1);
- else
- id = idp;
- dep = p;
+ repo->idarraydata[i] = id;
}
- if (dep[0] && dep[1])
+ else if (!strncmp(dep, "filesystem(", 11) && strlen(dep) < sizeof(buf))
{
- dep[strlen(dep) - 1] = 0;
- idp = str2id(pool, dep, 1);
- if (id)
- id = rel2id(pool, id, idp, REL_AND, 1);
- else
- id = idp;
+ strcpy(buf, dep + 11);
+ if ((p = strrchr(buf, ')')) != 0)
+ *p = 0;
+ id = str2id(pool, buf, 1);
+ id = rel2id(pool, NAMESPACE_FILESYSTEM, id, REL_NAMESPACE, 1);
+ repo->idarraydata[i] = id;
}
- if (id)
- repo->idarraydata[i] = id;
}
}
- return supplements;
-}
-
-static unsigned char *
-data_read_id(unsigned char *dp, Id *idp)
-{
- Id x = 0;
- unsigned char c;
- for (;;)
+ if (freshens && repo->idarraydata[freshens])
{
- c = *dp++;
- if (!(c & 0x80))
- {
- *idp = (x << 7) ^ c;
- return dp;
- }
- x = (x << 7) ^ c ^ 128;
- }
-}
-
-static unsigned char *
-data_skip(unsigned char *dp, int type)
-{
- switch (type)
- {
- case TYPE_VOID:
- return dp;
- case TYPE_ID:
- while ((*dp & 0x80) != 0)
- dp++;
- return dp;
- case TYPE_IDARRAY:
- case TYPE_REL_IDARRAY:
- case TYPE_IDVALUEARRAY:
- case TYPE_IDVALUEVALUEARRAY:
- while ((*dp & 0xc0) != 0)
- dp++;
- return dp;
- default:
- fprintf(stderr, "unknown type in data_skip\n");
- exit(1);
+ Id idsupp = 0, idfresh = 0;
+ if (!supplements)
+ return freshens;
+ for (i = supplements; repo->idarraydata[i]; i++)
+ {
+ if (!idsupp)
+ idsupp = repo->idarraydata[i];
+ else
+ idsupp = rel2id(pool, idsupp, repo->idarraydata[i], REL_OR, 1);
+ }
+ for (i = freshens; repo->idarraydata[i]; i++)
+ {
+ if (!idfresh)
+ idfresh = repo->idarraydata[i];
+ else
+ idfresh = rel2id(pool, idfresh, repo->idarraydata[i], REL_OR, 1);
+ }
+ if (!idsupp)
+ idsupp = idfresh;
+ else
+ idsupp = rel2id(pool, idsupp, idfresh, REL_AND, 1);
+ supplements = repo_addid_dep(repo, 0, idsupp, 0);
}
+ return supplements;
}
-static unsigned char *
-forward_to_key(Repodata *data, Id key, Id schema, unsigned char *dp)
+Offset
+repo_fix_conflicts(Repo *repo, Offset conflicts)
{
- Id k, *keyp;
+ char buf[1024], *p, *dep;
+ Pool *pool = repo->pool;
+ Id id;
+ int i;
- keyp = data->schemadata + schema;
- while ((k = *keyp++) != 0)
+ if (!conflicts)
+ return conflicts;
+ for (i = conflicts; repo->idarraydata[i]; i++)
{
- if (k == key)
- return dp;
- if (data->keys[k].storage == KEY_STORAGE_VERTICAL_OFFSET)
- {
- /* skip that offset */
- dp = data_skip(dp, TYPE_ID);
- continue;
- }
- if (data->keys[k].storage != KEY_STORAGE_INCORE)
+ id = repo->idarraydata[i];
+ if (ISRELDEP(id))
continue;
- dp = data_skip(dp, data->keys[k].type);
- }
- return 0;
-}
-
-static unsigned char *
-load_page_range(Repodata *data, unsigned int pstart, unsigned int pend)
-{
- /* add smart paging here */
- return 0;
-}
-
-static unsigned char *
-get_data(Repodata *data, Repokey *key, unsigned char **dpp)
-{
- Id off;
- unsigned char *dp = *dpp;
- int i, max;
- unsigned int pstart, pend, poff, plen;
-
- if (!dp)
- return 0;
- if (key->storage == KEY_STORAGE_INCORE)
- return dp;
- if (key->storage != KEY_STORAGE_VERTICAL_OFFSET)
- return 0;
- if (!data->fp)
- return 0;
- dp = data_read_id(dp, &off);
- *dpp = dp;
- if (key->type == TYPE_VOID)
- return 0;
- max = key->size - off;
- if (max <= 0)
- return 0;
- /* we now have the offset, go into vertical */
- for (i = key - data->keys - 1; i > 0; i--)
- if (data->keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
- off += data->keys[i].size;
- pstart = off / BLOB_PAGESIZE;
- pend = pstart;
- poff = off % BLOB_PAGESIZE;
- plen = BLOB_PAGESIZE - poff;
- for (;;)
- {
- if (plen > max)
- plen = max;
- dp = load_page_range(data, pstart, pend) + poff;
- if (!dp)
- return 0;
- switch (key->type)
+ dep = (char *)id2str(pool, id);
+ if (!strncmp(dep, "otherproviders(", 15) && strlen(dep) < sizeof(buf) - 2)
{
- case TYPE_STR:
- if (memchr(dp, 0, plen))
- return dp;
- break;
- case TYPE_ID:
- for (i = 0; i < plen; i++)
- if ((dp[i] & 0x80) == 0)
- return dp;
- break;
- case TYPE_IDARRAY:
- case TYPE_REL_IDARRAY:
- case TYPE_IDVALUEARRAY:
- case TYPE_IDVALUEVALUEARRAY:
- for (i = 0; i < plen; i++)
- if ((dp[i] & 0xc0) == 0)
- return dp;
- break;
+ strcpy(buf, dep + 15);
+ if ((p = strchr(buf, ')')) != 0)
+ *p = 0;
+ id = str2id(pool, buf, 1);
+ id = rel2id(pool, NAMESPACE_OTHERPROVIDERS, id, REL_NAMESPACE, 1);
+ repo->idarraydata[i] = id;
}
- if (plen == max)
- return 0;
- pend++;
- plen += BLOB_PAGESIZE;
}
-}
-
-
-const char *
-repodata_lookup_str(Repodata *data, Id entry, Id key)
-{
- Id schema;
- Id id, k, *kp, *keyp;
- unsigned char *dp;
-
- if (data->entryschemau8)
- schema = data->entryschemau8[entry];
- else
- schema = data->entryschema[entry];
- keyp = data->schemadata + schema;
- /* make sure the schema of this solvable contains the key */
- for (kp = keyp; (k = *kp++) != 0; )
- if (k == key)
- break;
- if (k == 0)
- return 0;
- dp = forward_to_key(data, key, schema, data->incoredata + data->incoreoffset[entry]);
- dp = get_data(data, data->keys + key, &dp);
- if (!dp)
- return 0;
- if (data->keys[key].type == TYPE_STR)
- return (const char *)dp;
- /* id type, must either use global or local string strore*/
- dp = data_read_id(dp, &id);
-#if 0
- /* not yet working */
- return data->ss.stringspace + data->ss.strings[id];
-#else
- return id2str(data->repo->pool, id);
-#endif
+ return conflicts;
}
struct matchdata
{
Pool *pool;
- const char *matchstr;
int flags;
-#if 0
- regex_t regex;
-#endif
+ Datamatcher matcher;
int stop;
- int (*callback)(void *data, Solvable *s, Id key, const char *str);
+ int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv);
void *callback_data;
};
-static void
-domatch(Id p, Id key, struct matchdata *md, const char *str)
+int
+repo_matchvalue(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
{
- /* fill match code here */
- md->callback(md->callback_data, md->pool->solvables + p, key, str);
+ struct matchdata *md = cbdata;
+
+ if (md->matcher.match)
+ {
+ if (!repodata_stringify(md->pool, data, key, kv, md->flags))
+ return 0;
+ if (!datamatcher_match(&md->matcher, kv->str))
+ return 0;
+ }
+ md->stop = md->callback(md->callback_data, s, data, key, kv);
+ return md->stop;
}
+
+static Repokey solvablekeys[RPM_RPMDBID - SOLVABLE_NAME + 1] = {
+ { SOLVABLE_NAME, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
+ { SOLVABLE_ARCH, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
+ { SOLVABLE_EVR, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
+ { SOLVABLE_VENDOR, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
+ { SOLVABLE_PROVIDES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
+ { SOLVABLE_OBSOLETES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
+ { SOLVABLE_CONFLICTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
+ { SOLVABLE_REQUIRES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
+ { SOLVABLE_RECOMMENDS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
+ { SOLVABLE_SUGGESTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
+ { SOLVABLE_SUPPLEMENTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
+ { SOLVABLE_ENHANCES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
+ { RPM_RPMDBID, REPOKEY_TYPE_U32, 0, KEY_STORAGE_SOLVABLE },
+};
+
static void
-repodata_search(Repodata *data, Id entry, Id key, struct matchdata *md)
+domatch_idarray(Solvable *s, Id keyname, struct matchdata *md, Id *ida)
{
- Id schema;
- Id id, k, *kp, *keyp;
- unsigned char *dp, *ddp;
- int onekey = 0;
-
- if (data->entryschemau8)
- schema = data->entryschemau8[entry];
- else
- schema = data->entryschema[entry];
- keyp = data->schemadata + schema;
- dp = data->incoredata + data->incoreoffset[entry];
- if (key)
+ KeyValue kv;
+ kv.entry = 0;
+ kv.parent = 0;
+ for (; *ida && !md->stop; ida++)
{
- /* search in a specific key */
- for (kp = keyp; (k = *kp++) != 0; )
- if (k == key)
- break;
- if (k == 0)
- return;
- dp = forward_to_key(data, key, schema, dp);
- if (!dp)
- return;
- keyp = kp - 1;
- onekey = 1;
- }
- while ((key = *keyp++) != 0)
- {
- ddp = get_data(data, data->keys + key, &dp);
- while (ddp)
- {
- switch (data->keys[key].type)
- {
- case TYPE_STR:
- domatch(data->start + entry, data->keys[key].name, md, (const char *)ddp);
- ddp = 0;
- break;
- case TYPE_ID:
- data_read_id(ddp, &id);
- /* domatch */
- ddp = 0;
- break;
- case TYPE_IDARRAY:
- ddp = data_read_id(ddp, &id);
- if ((id & 0x40) == 0)
- ddp = 0;
- id = (id & 0x3f) | ((id >> 1) & ~0x3f);
- /* domatch */
- break;
- default:
- ddp = 0;
- }
- }
- if (onekey || md->stop)
- return;
+ kv.id = *ida;
+ kv.eof = ida[1] ? 0 : 1;
+ repo_matchvalue(md, s, 0, solvablekeys + (keyname - SOLVABLE_NAME), &kv);
+ kv.entry++;
}
}
static void
-repo_search_md(Repo *repo, Id p, Id key, struct matchdata *md)
+repo_search_md(Repo *repo, Id p, Id keyname, struct matchdata *md)
{
+ KeyValue kv;
Pool *pool = repo->pool;
Repodata *data;
+ int i, j, flags;
Solvable *s;
- int i;
+ kv.parent = 0;
+ md->stop = 0;
if (!p)
{
for (p = repo->start, s = repo->pool->solvables + p; p < repo->end; p++, s++)
- if (s->repo == repo)
- repo_search_md(repo, p, key, md);
+ {
+ if (s->repo == repo)
+ repo_search_md(repo, p, keyname, md);
+ if (md->stop > SEARCH_NEXT_SOLVABLE)
+ break;
+ }
return;
}
- s = pool->solvables + p;
- if ((!key || key == SOLVABLE_NAME) && s->name)
- domatch(p, SOLVABLE_NAME, md, id2str(pool, s->name));
- if ((!key || key == SOLVABLE_ARCH) && s->arch)
- domatch(p, SOLVABLE_ARCH, md, id2str(pool, s->arch));
- if ((!key || key == SOLVABLE_EVR) && s->evr)
- domatch(p, SOLVABLE_EVR, md, id2str(pool, s->evr));
- if ((!key || key == SOLVABLE_VENDOR) && s->vendor)
- domatch(p, SOLVABLE_VENDOR, md, id2str(pool, s->vendor));
+ else if (p < 0)
+ /* The callback only supports solvables, so we can't iterate over the
+ extra things. */
+ return;
+ flags = md->flags;
+ if (!(flags & SEARCH_NO_STORAGE_SOLVABLE))
+ {
+ s = pool->solvables + p;
+ switch(keyname)
+ {
+ case 0:
+ case SOLVABLE_NAME:
+ if (s->name)
+ {
+ kv.id = s->name;
+ repo_matchvalue(md, s, 0, solvablekeys + 0, &kv);
+ }
+ if (keyname || md->stop > SEARCH_NEXT_KEY)
+ return;
+ case SOLVABLE_ARCH:
+ if (s->arch)
+ {
+ kv.id = s->arch;
+ repo_matchvalue(md, s, 0, solvablekeys + 1, &kv);
+ }
+ if (keyname || md->stop > SEARCH_NEXT_KEY)
+ return;
+ case SOLVABLE_EVR:
+ if (s->evr)
+ {
+ kv.id = s->evr;
+ repo_matchvalue(md, s, 0, solvablekeys + 2, &kv);
+ }
+ if (keyname || md->stop > SEARCH_NEXT_KEY)
+ return;
+ case SOLVABLE_VENDOR:
+ if (s->vendor)
+ {
+ kv.id = s->vendor;
+ repo_matchvalue(md, s, 0, solvablekeys + 3, &kv);
+ }
+ if (keyname || md->stop > SEARCH_NEXT_KEY)
+ return;
+ case SOLVABLE_PROVIDES:
+ if (s->provides)
+ domatch_idarray(s, SOLVABLE_PROVIDES, md, repo->idarraydata + s->provides);
+ if (keyname || md->stop > SEARCH_NEXT_KEY)
+ return;
+ case SOLVABLE_OBSOLETES:
+ if (s->obsoletes)
+ domatch_idarray(s, SOLVABLE_OBSOLETES, md, repo->idarraydata + s->obsoletes);
+ if (keyname || md->stop > SEARCH_NEXT_KEY)
+ return;
+ case SOLVABLE_CONFLICTS:
+ if (s->conflicts)
+ domatch_idarray(s, SOLVABLE_CONFLICTS, md, repo->idarraydata + s->conflicts);
+ if (keyname || md->stop > SEARCH_NEXT_KEY)
+ return;
+ case SOLVABLE_REQUIRES:
+ if (s->requires)
+ domatch_idarray(s, SOLVABLE_REQUIRES, md, repo->idarraydata + s->requires);
+ if (keyname || md->stop > SEARCH_NEXT_KEY)
+ return;
+ case SOLVABLE_RECOMMENDS:
+ if (s->recommends)
+ domatch_idarray(s, SOLVABLE_RECOMMENDS, md, repo->idarraydata + s->recommends);
+ if (keyname || md->stop > SEARCH_NEXT_KEY)
+ return;
+ case SOLVABLE_SUPPLEMENTS:
+ if (s->supplements)
+ domatch_idarray(s, SOLVABLE_SUPPLEMENTS, md, repo->idarraydata + s->supplements);
+ if (keyname || md->stop > SEARCH_NEXT_KEY)
+ return;
+ case SOLVABLE_SUGGESTS:
+ if (s->suggests)
+ domatch_idarray(s, SOLVABLE_SUGGESTS, md, repo->idarraydata + s->suggests);
+ if (keyname || md->stop > SEARCH_NEXT_KEY)
+ return;
+ case SOLVABLE_ENHANCES:
+ if (s->enhances)
+ domatch_idarray(s, SOLVABLE_ENHANCES, md, repo->idarraydata + s->enhances);
+ if (keyname || md->stop > SEARCH_NEXT_KEY)
+ return;
+ case RPM_RPMDBID:
+ if (repo->rpmdbid)
+ {
+ kv.num = repo->rpmdbid[p - repo->start];
+ repo_matchvalue(md, s, 0, solvablekeys + (RPM_RPMDBID - SOLVABLE_NAME), &kv);
+ }
+ if (keyname || md->stop > SEARCH_NEXT_KEY)
+ return;
+ break;
+ default:
+ break;
+ }
+ }
+
for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
{
if (p < data->start || p >= data->end)
continue;
- repodata_search(data, p - data->start, key, md);
+ if (keyname && !repodata_precheck_keyname(data, keyname))
+ continue;
+ if (data->state == REPODATA_STUB)
+ {
+ if (keyname)
+ {
+ for (j = 1; j < data->nkeys; j++)
+ if (keyname == data->keys[j].name)
+ break;
+ if (j == data->nkeys)
+ continue;
+ }
+ /* load it */
+ if (data->loadcallback)
+ data->loadcallback(data);
+ else
+ data->state = REPODATA_ERROR;
+ }
+ if (data->state == REPODATA_ERROR)
+ continue;
+ repodata_search(data, p, keyname, md->flags, repo_matchvalue, md);
+ if (md->stop > SEARCH_NEXT_KEY)
+ break;
}
}
void
-repo_search(Repo *repo, Id p, Id key, const char *match, int flags, int (*callback)(void *data, Solvable *s, Id key, const char *str), void *callback_data)
+repo_search(Repo *repo, Id p, Id keyname, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv), void *cbdata)
{
struct matchdata md;
memset(&md, 0, sizeof(md));
md.pool = repo->pool;
- md.matchstr = match;
md.flags = flags;
md.callback = callback;
- md.callback_data = callback_data;
- repo_search_md(repo, p, key, &md);
+ md.callback_data = cbdata;
+ if (match)
+ datamatcher_init(&md.matcher, match, flags);
+ repo_search_md(repo, p, keyname, &md);
+ if (match)
+ datamatcher_free(&md.matcher);
}
const char *
-repo_lookup_str(Solvable *s, Id key)
+repo_lookup_str(Repo *repo, Id entry, Id keyname)
{
- Repo *repo = s->repo;
Pool *pool = repo->pool;
Repodata *data;
- int i, j, n;
+ int i, j;
- switch(key)
+ switch(keyname)
{
case SOLVABLE_NAME:
- return id2str(pool, s->name);
+ return id2str(pool, pool->solvables[entry].name);
case SOLVABLE_ARCH:
- return id2str(pool, s->arch);
+ return id2str(pool, pool->solvables[entry].arch);
case SOLVABLE_EVR:
- return id2str(pool, s->evr);
+ return id2str(pool, pool->solvables[entry].evr);
case SOLVABLE_VENDOR:
- return id2str(pool, s->vendor);
+ return id2str(pool, pool->solvables[entry].vendor);
}
- n = s - pool->solvables;
for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
{
- if (n < data->start || n >= data->end)
+ 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 == key && (data->keys[j].type == TYPE_ID || data->keys[j].type == TYPE_STR))
- return repodata_lookup_str(data, n - data->start, 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);
}
}
return 0;
}
+unsigned int
+repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned int notfound)
+{
+ Repodata *data;
+ int i, j;
-static int
-key_cmp (const void *pa, const void *pb)
+ 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++)
+ {
+ 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_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;
+ }
+ }
+ }
+ return notfound;
+}
+
+Id
+repo_lookup_id(Repo *repo, Id entry, Id keyname)
{
- Repokey *a = (Repokey *)pa;
- Repokey *b = (Repokey *)pb;
- return a->name - b->name;
+ Repodata *data;
+ int i, j;
+
+ 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++)
+ {
+ 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_ID || data->keys[j].type == REPOKEY_TYPE_CONSTANTID))
+ {
+ Id id = repodata_lookup_id(data, entry, keyname);
+ if (id)
+ {
+ if (data->localpool)
+ id = repodata_globalize_id(data, id);
+ return id;
+ }
+ }
+ }
+ }
+ return 0;
}
-void
-repo_add_attrstore (Repo *repo, Attrstore *s, const char *location)
+const unsigned char *
+repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
{
- unsigned i;
Repodata *data;
- /* If this is meant to be the embedded attributes, make sure we don't
- have them already. */
- if (!location)
+ int i, j;
+ for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
{
- for (i = 0; i < repo->nrepodata; i++)
- if (repo->repodata[i].location == 0)
- break;
- if (i != repo->nrepodata)
- {
- pool_debug (repo->pool, SAT_FATAL, "embedded attribs added twice\n");
- exit (1);
+ 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;
+ }
}
}
- repo->nrepodata++;
- repo->repodata = xrealloc (repo->repodata, repo->nrepodata * sizeof (*data));
- data = repo->repodata + repo->nrepodata - 1;
- memset (data, 0, sizeof (*data));
- data->s = s;
- data->nkeys = s->nkeys;
- if (data->nkeys)
+ *typep = 0;
+ return 0;
+}
+
+int
+repo_lookup_void(Repo *repo, Id entry, Id keyname)
+{
+ Repodata *data;
+ int i, j;
+ for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
{
- data->keys = xmalloc(data->nkeys * sizeof(data->keys[0]));
- for (i = 1; i < data->nkeys; i++)
- {
- data->keys[i].name = s->keys[i].name;
- data->keys[i].type = s->keys[i].type;
+ 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;
+ }
}
- if (data->nkeys > 2)
- qsort(data->keys + 1, data->nkeys - 1, sizeof(data->keys[0]), key_cmp);
}
- if (location)
- data->location = strdup(location);
+ return 0;
+}
+
+/***********************************************************************/
+
+Repodata *
+repo_add_repodata(Repo *repo, int localpool)
+{
+ 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;
+}
+
+Repodata *
+repo_last_repodata(Repo *repo)
+{
+ int i;
+ for (i = repo->nrepodata - 1; i >= 0; i--)
+ if (repo->repodata[i].state != REPODATA_STUB)
+ return repo->repodata + i;
+ return repo_add_repodata(repo, 0);
+}
+
+void
+repo_set_id(Repo *repo, Id p, Id keyname, Id id)
+{
+ Repodata *data = repo_last_repodata(repo);
+ repodata_set_id(data, p, keyname, id);
+}
+
+void
+repo_set_num(Repo *repo, Id p, Id keyname, Id num)
+{
+ Repodata *data = repo_last_repodata(repo);
+ repodata_set_num(data, p, keyname, num);
+}
+
+void
+repo_set_str(Repo *repo, Id p, Id keyname, const char *str)
+{
+ Repodata *data = repo_last_repodata(repo);
+ repodata_set_str(data, p, keyname, str);
}
+void
+repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str)
+{
+ Repodata *data = repo_last_repodata(repo);
+ repodata_set_poolstr(data, p, keyname, str);
+}
+
+void
+repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str)
+{
+ Repodata *data = repo_last_repodata(repo);
+ repodata_add_poolstr_array(data, p, keyname, str);
+}
+
+void
+repo_internalize(Repo *repo)
+{
+ int i;
+ Repodata *data;
+
+ for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
+ if (data->attrs || data->xattrs)
+ repodata_internalize(data);
+}
+
+void
+repo_disable_paging(Repo *repo)
+{
+ int i;
+ Repodata *data;
+
+ for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
+ repodata_disable_paging(data);
+}
// EOF
+/*
+vim:cinoptions={.5s,g0,p5,t0,(0,^-0.5s,n-0.5s:tw=78:cindent:sw=4:
+*/