2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * Manage metadata coming from one repository
26 #include "poolid_private.h"
30 #define IDARRAY_BLOCK 4095
39 repo_create(Pool *pool, const char *name)
43 pool_freewhatprovides(pool);
44 repo = (Repo *)solv_calloc(1, sizeof(*repo));
45 pool->repos = (Repo **)solv_realloc2(pool->repos, pool->nrepos + 1, sizeof(Repo *));
46 pool->repos[pool->nrepos++] = repo;
47 repo->repoid = pool->nrepos;
48 repo->name = name ? strdup(name) : 0;
50 repo->start = pool->nsolvables;
51 repo->end = pool->nsolvables;
57 repo_freedata(Repo *repo)
60 for (i = 0; i < repo->nrepodata; i++)
61 repodata_freedata(repo->repodata + i);
62 solv_free(repo->repodata);
63 solv_free(repo->idarraydata);
64 solv_free(repo->rpmdbid);
65 solv_free((char *)repo->name);
69 /* delete all solvables and repodata blocks from this repo */
72 repo_empty(Repo *repo, int reuseids)
74 Pool *pool = repo->pool;
78 pool_freewhatprovides(pool);
79 if (reuseids && repo->end == pool->nsolvables)
81 /* it's ok to reuse the ids. As this is the last repo, we can
82 just shrink the solvable array */
83 for (i = repo->end - 1, s = pool->solvables + i; i >= repo->start; i--, s--)
86 pool_free_solvable_block(pool, i + 1, repo->end - (i + 1), reuseids);
88 /* zero out (i.e. free) solvables belonging to this repo */
89 for (i = repo->start, s = pool->solvables + i; i < repo->end; i++, s++)
91 memset(s, 0, sizeof(*s));
94 /* free all data belonging to this repo */
95 repo->idarraydata = solv_free(repo->idarraydata);
96 repo->idarraysize = 0;
98 repo->rpmdbid = solv_free(repo->rpmdbid);
99 for (i = 0; i < repo->nrepodata; i++)
100 repodata_freedata(repo->repodata + i);
101 solv_free(repo->repodata);
107 * remove repo from pool, delete solvables
112 repo_free(Repo *repo, int reuseids)
114 Pool *pool = repo->pool;
117 if (repo == pool->installed)
119 repo_empty(repo, reuseids);
120 for (i = 0; i < pool->nrepos; i++) /* find repo in pool */
121 if (pool->repos[i] == repo)
123 if (i == pool->nrepos) /* repo not in pool, return */
125 if (i < pool->nrepos - 1)
127 memmove(pool->repos + i, pool->repos + i + 1, (pool->nrepos - 1 - i) * sizeof(Repo *));
129 for (; i < pool->nrepos - 1; i++)
130 pool->repos[i]->repoid = i + 1;
137 repo_freeallrepos(Pool *pool, int reuseids)
141 pool_freewhatprovides(pool);
142 for (i = 0; i < pool->nrepos; i++)
143 repo_freedata(pool->repos[i]);
144 pool->repos = solv_free(pool->repos);
146 /* the first two solvables don't belong to a repo */
147 pool_free_solvable_block(pool, 2, pool->nsolvables - 2, reuseids);
150 Id repo_add_solvable(Repo *repo)
152 Id p = pool_add_solvable(repo->pool);
153 if (!repo->start || repo->start == repo->end)
154 repo->start = repo->end = p;
155 /* warning: sidedata must be extended before adapting start/end */
157 repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, 1);
160 if (p + 1 > repo->end)
163 repo->pool->solvables[p].repo = repo;
167 Id repo_add_solvable_block(Repo *repo, int count)
173 p = pool_add_solvable_block(repo->pool, count);
174 if (!repo->start || repo->start == repo->end)
175 repo->start = repo->end = p;
176 /* warning: sidedata must be extended before adapting start/end */
178 repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, count);
181 if (p + count > repo->end)
182 repo->end = p + count;
183 repo->nsolvables += count;
184 for (s = repo->pool->solvables + p; count--; s++)
189 void repo_free_solvable(Repo *repo, Id p, int reuseids)
191 repo_free_solvable_block(repo, p, 1, reuseids);
194 void repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids)
199 if (start + count == repo->end)
201 repo->nsolvables -= count;
202 for (s = repo->pool->solvables + start, i = count; i--; s++)
204 pool_free_solvable_block(repo->pool, start, count, reuseids);
205 FOR_REPODATAS(repo, i, data)
206 if (data->end > repo->end)
207 repodata_shrink(data, repo->end);
211 /* repository sidedata is solvable data allocated on demand.
212 * It is used for data that is normally not present
213 * in the solvable like the rpmdbid.
214 * The solvable allocation funcions need to make sure that
215 * the sidedata gets extended if new solvables get added.
218 #define REPO_SIDEDATA_BLOCK 63
221 repo_sidedata_create(Repo *repo, size_t size)
223 return solv_calloc_block(repo->end - repo->start, size, REPO_SIDEDATA_BLOCK);
227 repo_sidedata_extend(Repo *repo, void *b, size_t size, Id p, int count)
229 int n = repo->end - repo->start;
232 int d = repo->start - p;
233 b = solv_extend(b, n, d, size, REPO_SIDEDATA_BLOCK);
234 memmove((char *)b + d * size, b, n * size);
235 memset(b, 0, d * size);
238 if (p + count > repo->end)
240 int d = p + count - repo->end;
241 b = solv_extend(b, n, d, size, REPO_SIDEDATA_BLOCK);
242 memset((char *)b + n * size, 0, d * size);
248 * add Id to idarraydata used to store dependencies
249 * olddeps: old array offset to extend
250 * returns new array offset
254 repo_addid(Repo *repo, Offset olddeps, Id id)
260 idarray = repo->idarraydata;
261 idarraysize = repo->idarraysize;
263 if (!idarray) /* alloc idarray if not done yet */
266 idarray = solv_extend_resize(0, 1, sizeof(Id), IDARRAY_BLOCK);
271 if (!olddeps) /* no deps yet */
273 olddeps = idarraysize;
274 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
276 else if (olddeps == repo->lastoff) /* extend at end */
278 else /* can't extend, copy old */
281 olddeps = idarraysize;
282 for (; idarray[i]; i++)
284 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
285 idarray[idarraysize++] = idarray[i];
287 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
290 idarray[idarraysize++] = id; /* insert Id into array */
291 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
292 idarray[idarraysize++] = 0; /* ensure NULL termination */
294 repo->idarraydata = idarray;
295 repo->idarraysize = idarraysize;
296 repo->lastoff = olddeps;
303 * add dependency (as Id) to repo, also unifies dependencies
304 * olddeps = offset into idarraydata
305 * marker= 0 for normal dep
306 * marker > 0 add dep after marker
307 * marker < 0 add dep after -marker
308 * returns new start of dependency array
311 repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker)
313 Id oid, *oidp, *markerp;
319 olddeps = repo_addid(repo, olddeps, marker);
320 return repo_addid(repo, olddeps, id);
325 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != ID_NULL; oidp++)
330 return repo_addid(repo, olddeps, id);
340 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != ID_NULL; oidp++)
350 if (markerp || before)
352 /* we found it, but in the wrong half */
354 for (; (oid = *oidp) != ID_NULL; oidp++)
359 /* no marker in array yet */
362 memmove(markerp, markerp + 1, (oidp - markerp) * sizeof(Id));
364 return repo_addid(repo, olddeps, id);
368 memmove(markerp, markerp + 1, (oidp - markerp) * sizeof(Id));
372 /* id not yet in array */
373 if (!before && !markerp)
374 olddeps = repo_addid(repo, olddeps, marker);
375 else if (before && markerp)
380 memmove(markerp + 1, markerp, (oidp - markerp) * sizeof(Id));
383 return repo_addid(repo, olddeps, id);
389 * make space for 'num' more dependencies
390 * returns new start of dependency array
392 * reserved ids will always begin at offset idarraysize
396 repo_reserve_ids(Repo *repo, Offset olddeps, int num)
398 num++; /* room for trailing ID_NULL */
400 if (!repo->idarraysize) /* ensure buffer space */
402 repo->idarraysize = 1;
403 repo->idarraydata = solv_extend_resize(0, 1 + num, sizeof(Id), IDARRAY_BLOCK);
404 repo->idarraydata[0] = 0;
409 if (olddeps && olddeps != repo->lastoff) /* if not appending */
411 /* can't insert into idarray, this would invalidate all 'larger' offsets
412 * so create new space at end and move existing deps there.
413 * Leaving 'hole' at old position.
419 for (idstart = idend = repo->idarraydata + olddeps; *idend++; ) /* find end */
421 count = idend - idstart - 1 + num; /* new size */
423 repo->idarraydata = solv_extend(repo->idarraydata, repo->idarraysize, count, sizeof(Id), IDARRAY_BLOCK);
424 /* move old deps to end */
425 olddeps = repo->lastoff = repo->idarraysize;
426 memcpy(repo->idarraydata + olddeps, idstart, count - num);
427 repo->idarraysize = olddeps + count - num;
432 if (olddeps) /* appending */
436 repo->idarraydata = solv_extend(repo->idarraydata, repo->idarraysize, num, sizeof(Id), IDARRAY_BLOCK);
438 /* appending or new */
439 repo->lastoff = olddeps ? olddeps : repo->idarraysize;
441 return repo->lastoff;
447 repo_fix_supplements(Repo *repo, Offset provides, Offset supplements, Offset freshens)
449 Pool *pool = repo->pool;
451 char buf[1024], *p, *dep;
456 for (i = provides; repo->idarraydata[i]; i++)
458 id = repo->idarraydata[i];
461 dep = (char *)pool_id2str(pool, id);
462 if (!strncmp(dep, "locale(", 7) && strlen(dep) < sizeof(buf) - 2)
465 strcpy(buf + 2, dep);
467 if ((p = strchr(dep, ':')) != 0 && p != dep)
470 idp = pool_str2id(pool, dep, 1);
474 while ((p = strchr(dep, ';')) != 0)
483 strncpy(dep - 9, "language:", 9);
484 idl = pool_str2id(pool, dep - 9, 1);
486 idl = pool_str2id(pool, dep, 1);
487 idl = pool_rel2id(pool, NAMESPACE_LANGUAGE, idl, REL_NAMESPACE, 1);
490 id = pool_rel2id(pool, id, idl, REL_OR, 1);
495 if (dep[0] && dep[1])
497 for (p = dep; *p && *p != ')'; p++)
501 strncpy(dep - 9, "language:", 9);
502 idl = pool_str2id(pool, dep - 9, 1);
504 idl = pool_str2id(pool, dep, 1);
505 idl = pool_rel2id(pool, NAMESPACE_LANGUAGE, idl, REL_NAMESPACE, 1);
508 id = pool_rel2id(pool, id, idl, REL_OR, 1);
513 id = pool_rel2id(pool, idp, id, REL_AND, 1);
515 supplements = repo_addid_dep(repo, supplements, id, 0);
517 else if ((p = strchr(dep, ':')) != 0 && p != dep && p[1] == '/' && strlen(dep) < sizeof(buf))
522 idp = pool_str2id(pool, buf, 1);
523 /* strip trailing slashes */
525 while (l > 1 && p[l - 1] == '/')
527 id = pool_str2id(pool, p, 1);
528 id = pool_rel2id(pool, idp, id, REL_WITH, 1);
529 id = pool_rel2id(pool, NAMESPACE_SPLITPROVIDES, id, REL_NAMESPACE, 1);
530 supplements = repo_addid_dep(repo, supplements, id, 0);
536 for (i = supplements; repo->idarraydata[i]; i++)
538 id = repo->idarraydata[i];
541 dep = (char *)pool_id2str(pool, id);
542 if (!strncmp(dep, "system:modalias(", 16))
544 if (!strncmp(dep, "modalias(", 9) && dep[9] && dep[10] && strlen(dep) < sizeof(buf))
547 p = strchr(buf + 9, ':');
548 if (p && p != buf + 9 && strchr(p + 1, ':'))
551 idp = pool_str2id(pool, buf + 9, 1);
552 p[strlen(p) - 1] = 0;
553 id = pool_str2id(pool, p, 1);
554 id = pool_rel2id(pool, NAMESPACE_MODALIAS, id, REL_NAMESPACE, 1);
555 id = pool_rel2id(pool, idp, id, REL_AND, 1);
560 p[strlen(p) - 1] = 0;
561 id = pool_str2id(pool, p, 1);
562 id = pool_rel2id(pool, NAMESPACE_MODALIAS, id, REL_NAMESPACE, 1);
565 repo->idarraydata[i] = id;
567 else if (!strncmp(dep, "packageand(", 11) && strlen(dep) < sizeof(buf))
572 while ((p = strchr(dep, ':')) != 0)
580 idp = pool_str2id(pool, dep, 1);
582 id = pool_rel2id(pool, id, idp, REL_AND, 1);
587 if (dep[0] && dep[1])
589 dep[strlen(dep) - 1] = 0;
590 idp = pool_str2id(pool, dep, 1);
592 id = pool_rel2id(pool, id, idp, REL_AND, 1);
597 repo->idarraydata[i] = id;
599 else if (!strncmp(dep, "filesystem(", 11) && strlen(dep) < sizeof(buf))
601 strcpy(buf, dep + 11);
602 if ((p = strrchr(buf, ')')) != 0)
604 id = pool_str2id(pool, buf, 1);
605 id = pool_rel2id(pool, NAMESPACE_FILESYSTEM, id, REL_NAMESPACE, 1);
606 repo->idarraydata[i] = id;
610 if (freshens && repo->idarraydata[freshens])
612 Id idsupp = 0, idfresh = 0;
615 for (i = supplements; repo->idarraydata[i]; i++)
618 idsupp = repo->idarraydata[i];
620 idsupp = pool_rel2id(pool, idsupp, repo->idarraydata[i], REL_OR, 1);
622 for (i = freshens; repo->idarraydata[i]; i++)
625 idfresh = repo->idarraydata[i];
627 idfresh = pool_rel2id(pool, idfresh, repo->idarraydata[i], REL_OR, 1);
632 idsupp = pool_rel2id(pool, idsupp, idfresh, REL_AND, 1);
633 supplements = repo_addid_dep(repo, 0, idsupp, 0);
639 repo_fix_conflicts(Repo *repo, Offset conflicts)
641 char buf[1024], *p, *dep;
642 Pool *pool = repo->pool;
648 for (i = conflicts; repo->idarraydata[i]; i++)
650 id = repo->idarraydata[i];
653 dep = (char *)pool_id2str(pool, id);
654 if (!strncmp(dep, "otherproviders(", 15) && strlen(dep) < sizeof(buf) - 2)
656 strcpy(buf, dep + 15);
657 if ((p = strchr(buf, ')')) != 0)
659 id = pool_str2id(pool, buf, 1);
660 id = pool_rel2id(pool, NAMESPACE_OTHERPROVIDERS, id, REL_NAMESPACE, 1);
661 repo->idarraydata[i] = id;
673 int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv);
678 repo_matchvalue(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
680 struct matchdata *md = cbdata;
682 if (md->matcher.match)
684 if (!repodata_stringify(md->pool, data, key, kv, md->flags))
686 if (!datamatcher_match(&md->matcher, kv->str))
689 md->stop = md->callback(md->callback_data, s, data, key, kv);
694 static Repokey solvablekeys[RPM_RPMDBID - SOLVABLE_NAME + 1] = {
695 { SOLVABLE_NAME, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
696 { SOLVABLE_ARCH, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
697 { SOLVABLE_EVR, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
698 { SOLVABLE_VENDOR, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
699 { SOLVABLE_PROVIDES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
700 { SOLVABLE_OBSOLETES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
701 { SOLVABLE_CONFLICTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
702 { SOLVABLE_REQUIRES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
703 { SOLVABLE_RECOMMENDS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
704 { SOLVABLE_SUGGESTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
705 { SOLVABLE_SUPPLEMENTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
706 { SOLVABLE_ENHANCES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
707 { RPM_RPMDBID, REPOKEY_TYPE_U32, 0, KEY_STORAGE_SOLVABLE },
711 domatch_idarray(Solvable *s, Id keyname, struct matchdata *md, Id *ida)
716 for (; *ida && !md->stop; ida++)
719 kv.eof = ida[1] ? 0 : 1;
720 repo_matchvalue(md, s, 0, solvablekeys + (keyname - SOLVABLE_NAME), &kv);
726 repo_search_md(Repo *repo, Id p, Id keyname, struct matchdata *md)
729 Pool *pool = repo->pool;
738 for (p = repo->start, s = repo->pool->solvables + p; p < repo->end; p++, s++)
741 repo_search_md(repo, p, keyname, md);
742 if (md->stop > SEARCH_NEXT_SOLVABLE)
748 /* The callback only supports solvables, so we can't iterate over the
752 if (!(flags & SEARCH_NO_STORAGE_SOLVABLE))
754 s = pool->solvables + p;
762 repo_matchvalue(md, s, 0, solvablekeys + 0, &kv);
764 if (keyname || md->stop > SEARCH_NEXT_KEY)
770 repo_matchvalue(md, s, 0, solvablekeys + 1, &kv);
772 if (keyname || md->stop > SEARCH_NEXT_KEY)
778 repo_matchvalue(md, s, 0, solvablekeys + 2, &kv);
780 if (keyname || md->stop > SEARCH_NEXT_KEY)
782 case SOLVABLE_VENDOR:
786 repo_matchvalue(md, s, 0, solvablekeys + 3, &kv);
788 if (keyname || md->stop > SEARCH_NEXT_KEY)
790 case SOLVABLE_PROVIDES:
792 domatch_idarray(s, SOLVABLE_PROVIDES, md, repo->idarraydata + s->provides);
793 if (keyname || md->stop > SEARCH_NEXT_KEY)
795 case SOLVABLE_OBSOLETES:
797 domatch_idarray(s, SOLVABLE_OBSOLETES, md, repo->idarraydata + s->obsoletes);
798 if (keyname || md->stop > SEARCH_NEXT_KEY)
800 case SOLVABLE_CONFLICTS:
802 domatch_idarray(s, SOLVABLE_CONFLICTS, md, repo->idarraydata + s->conflicts);
803 if (keyname || md->stop > SEARCH_NEXT_KEY)
805 case SOLVABLE_REQUIRES:
807 domatch_idarray(s, SOLVABLE_REQUIRES, md, repo->idarraydata + s->requires);
808 if (keyname || md->stop > SEARCH_NEXT_KEY)
810 case SOLVABLE_RECOMMENDS:
812 domatch_idarray(s, SOLVABLE_RECOMMENDS, md, repo->idarraydata + s->recommends);
813 if (keyname || md->stop > SEARCH_NEXT_KEY)
815 case SOLVABLE_SUPPLEMENTS:
817 domatch_idarray(s, SOLVABLE_SUPPLEMENTS, md, repo->idarraydata + s->supplements);
818 if (keyname || md->stop > SEARCH_NEXT_KEY)
820 case SOLVABLE_SUGGESTS:
822 domatch_idarray(s, SOLVABLE_SUGGESTS, md, repo->idarraydata + s->suggests);
823 if (keyname || md->stop > SEARCH_NEXT_KEY)
825 case SOLVABLE_ENHANCES:
827 domatch_idarray(s, SOLVABLE_ENHANCES, md, repo->idarraydata + s->enhances);
828 if (keyname || md->stop > SEARCH_NEXT_KEY)
833 kv.num = repo->rpmdbid[p - repo->start];
834 repo_matchvalue(md, s, 0, solvablekeys + (RPM_RPMDBID - SOLVABLE_NAME), &kv);
836 if (keyname || md->stop > SEARCH_NEXT_KEY)
844 FOR_REPODATAS(repo, i, data)
846 if (p < data->start || p >= data->end)
848 if (keyname && !repodata_precheck_keyname(data, keyname))
850 if (keyname == SOLVABLE_FILELIST && !(md->flags & SEARCH_COMPLETE_FILELIST))
852 /* do not search filelist extensions */
853 if (data->state != REPODATA_AVAILABLE)
855 for (j = 1; j < data->nkeys; j++)
856 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
858 if (j == data->nkeys)
861 if (data->state == REPODATA_STUB)
865 for (j = 1; j < data->nkeys; j++)
866 if (keyname == data->keys[j].name)
868 if (j == data->nkeys)
872 if (data->loadcallback)
873 data->loadcallback(data);
875 data->state = REPODATA_ERROR;
877 if (data->state == REPODATA_ERROR)
879 repodata_search(data, p, keyname, md->flags, repo_matchvalue, md);
880 if (md->stop > SEARCH_NEXT_KEY)
886 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)
890 if (repo->disabled && !(flags & SEARCH_DISABLED_REPOS))
892 memset(&md, 0, sizeof(md));
893 md.pool = repo->pool;
895 md.callback = callback;
896 md.callback_data = cbdata;
898 datamatcher_init(&md.matcher, match, flags);
899 repo_search_md(repo, p, keyname, &md);
901 datamatcher_free(&md.matcher);
905 repo_lookup_str(Repo *repo, Id entry, Id keyname)
907 Pool *pool = repo->pool;
917 return pool_id2str(pool, pool->solvables[entry].name);
919 return pool_id2str(pool, pool->solvables[entry].arch);
921 return pool_id2str(pool, pool->solvables[entry].evr);
922 case SOLVABLE_VENDOR:
923 return pool_id2str(pool, pool->solvables[entry].vendor);
926 FOR_REPODATAS(repo, i, data)
928 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
930 if (!repodata_precheck_keyname(data, keyname))
932 str = repodata_lookup_str(data, entry, keyname);
935 if (repodata_lookup_type(data, entry, keyname))
943 repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned int notfound)
951 if (keyname == RPM_RPMDBID)
953 if (repo->rpmdbid && entry >= repo->start && entry < repo->end)
954 return repo->rpmdbid[entry - repo->start];
958 FOR_REPODATAS(repo, i, data)
960 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
962 if (!repodata_precheck_keyname(data, keyname))
964 if (repodata_lookup_num(data, entry, keyname, &value))
966 if (repodata_lookup_type(data, entry, keyname))
973 repo_lookup_id(Repo *repo, Id entry, Id keyname)
984 return repo->pool->solvables[entry].name;
986 return repo->pool->solvables[entry].arch;
988 return repo->pool->solvables[entry].evr;
989 case SOLVABLE_VENDOR:
990 return repo->pool->solvables[entry].vendor;
993 FOR_REPODATAS(repo, i, data)
995 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
997 if (!repodata_precheck_keyname(data, keyname))
999 id = repodata_lookup_id(data, entry, keyname);
1001 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1002 if (repodata_lookup_type(data, entry, keyname))
1009 lookup_idarray_solvable(Repo *repo, Offset off, Queue *q)
1015 for (p = repo->idarraydata + off; *p; p++)
1021 repo_lookup_idarray(Repo *repo, Id entry, Id keyname, Queue *q)
1029 case SOLVABLE_PROVIDES:
1030 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].provides, q);
1031 case SOLVABLE_OBSOLETES:
1032 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].obsoletes, q);
1033 case SOLVABLE_CONFLICTS:
1034 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].conflicts, q);
1035 case SOLVABLE_REQUIRES:
1036 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].requires, q);
1037 case SOLVABLE_RECOMMENDS:
1038 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].recommends, q);
1039 case SOLVABLE_SUGGESTS:
1040 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].suggests, q);
1041 case SOLVABLE_SUPPLEMENTS:
1042 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].supplements, q);
1043 case SOLVABLE_ENHANCES:
1044 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].enhances, q);
1047 FOR_REPODATAS(repo, i, data)
1049 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1051 if (!repodata_precheck_keyname(data, keyname))
1053 if (repodata_lookup_idarray(data, entry, keyname, q))
1055 if (data->localpool)
1057 for (i = 0; i < q->count; i++)
1058 q->elements[i] = repodata_globalize_id(data, q->elements[i], 1);
1062 if (repodata_lookup_type(data, entry, keyname))
1069 const unsigned char *
1070 repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
1074 const unsigned char *chk;
1076 FOR_REPODATAS(repo, i, data)
1078 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1080 if (!repodata_precheck_keyname(data, keyname))
1082 chk = repodata_lookup_bin_checksum(data, entry, keyname, typep);
1085 if (repodata_lookup_type(data, entry, keyname))
1093 repo_lookup_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
1095 const unsigned char *chk = repo_lookup_bin_checksum(repo, entry, keyname, typep);
1096 return chk ? pool_bin2hex(repo->pool, chk, solv_chksum_len(*typep)) : 0;
1100 repo_lookup_void(Repo *repo, Id entry, Id keyname)
1106 FOR_REPODATAS(repo, i, data)
1108 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1110 if (!repodata_precheck_keyname(data, keyname))
1112 type = repodata_lookup_type(data, entry, keyname);
1114 return type == REPOKEY_TYPE_VOID;
1120 repo_lookup_type(Repo *repo, Id entry, Id keyname)
1126 FOR_REPODATAS(repo, i, data)
1128 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1130 if (!repodata_precheck_keyname(data, keyname))
1132 type = repodata_lookup_type(data, entry, keyname);
1134 return type == REPOKEY_TYPE_DELETED ? 0 : type;
1139 /***********************************************************************/
1142 repo_add_repodata(Repo *repo, int flags)
1145 if ((flags & REPO_USE_LOADING) != 0)
1147 for (i = repo->nrepodata - 1; i >= 0; i--)
1148 if (repo->repodata[i].state == REPODATA_LOADING)
1150 Repodata *data = repo->repodata + i;
1152 /* hack: we mis-use REPO_REUSE_REPODATA here */
1153 if (!(flags & REPO_REUSE_REPODATA))
1154 repodata_empty(data, (flags & REPO_LOCALPOOL) ? 1 : 0);
1157 return 0; /* must not create a new repodata! */
1159 if ((flags & REPO_REUSE_REPODATA) != 0)
1161 for (i = repo->nrepodata - 1; i >= 0; i--)
1162 if (repo->repodata[i].state != REPODATA_STUB)
1163 return repo->repodata + i;
1165 return repodata_create(repo, (flags & REPO_LOCALPOOL) ? 1 : 0);
1169 repo_last_repodata(Repo *repo)
1172 for (i = repo->nrepodata - 1; i >= 0; i--)
1173 if (repo->repodata[i].state != REPODATA_STUB)
1174 return repo->repodata + i;
1175 return repo_add_repodata(repo, 0);
1179 repo_set_id(Repo *repo, Id p, Id keyname, Id id)
1187 repo->pool->solvables[p].name = id;
1190 repo->pool->solvables[p].arch = id;
1193 repo->pool->solvables[p].evr = id;
1195 case SOLVABLE_VENDOR:
1196 repo->pool->solvables[p].vendor = id;
1200 data = repo_last_repodata(repo);
1201 if (data->localpool)
1202 id = repodata_localize_id(data, id, 1);
1203 repodata_set_id(data, p, keyname, id);
1207 repo_set_num(Repo *repo, Id p, Id keyname, unsigned int num)
1212 if (keyname == RPM_RPMDBID)
1215 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1216 repo->rpmdbid[p] = num;
1220 data = repo_last_repodata(repo);
1221 repodata_set_num(data, p, keyname, num);
1225 repo_set_str(Repo *repo, Id p, Id keyname, const char *str)
1235 case SOLVABLE_VENDOR:
1236 repo_set_id(repo, p, keyname, pool_str2id(repo->pool, str, 1));
1240 data = repo_last_repodata(repo);
1241 repodata_set_str(data, p, keyname, str);
1245 repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str)
1255 case SOLVABLE_VENDOR:
1256 repo_set_id(repo, p, keyname, pool_str2id(repo->pool, str, 1));
1260 data = repo_last_repodata(repo);
1261 repodata_set_poolstr(data, p, keyname, str);
1265 repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str)
1267 Repodata *data = repo_last_repodata(repo);
1268 repodata_add_poolstr_array(data, p, keyname, str);
1272 repo_internalize(Repo *repo)
1277 FOR_REPODATAS(repo, i, data)
1278 if (data->attrs || data->xattrs)
1279 repodata_internalize(data);
1283 repo_disable_paging(Repo *repo)
1288 FOR_REPODATAS(repo, i, data)
1289 repodata_disable_paging(data);
1293 vim:cinoptions={.5s,g0,p5,t0,(0,^-0.5s,n-0.5s:tw=78:cindent:sw=4: