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));
47 pool->nrepos = 1; /* start with repoid 1 */
48 pool->repos = (Repo **)solv_calloc(2, sizeof(Repo *));
51 pool->repos = (Repo **)solv_realloc2(pool->repos, pool->nrepos + 1, sizeof(Repo *));
52 pool->repos[pool->nrepos] = repo;
54 repo->repoid = pool->nrepos++;
55 repo->name = name ? solv_strdup(name) : 0;
57 repo->start = pool->nsolvables;
58 repo->end = pool->nsolvables;
64 repo_freedata(Repo *repo)
67 for (i = 1; i < repo->nrepodata; i++)
68 repodata_freedata(repo->repodata + i);
69 solv_free(repo->repodata);
70 solv_free(repo->idarraydata);
71 solv_free(repo->rpmdbid);
72 solv_free(repo->lastidhash);
73 solv_free((char *)repo->name);
77 /* delete all solvables and repodata blocks from this repo */
80 repo_empty(Repo *repo, int reuseids)
82 Pool *pool = repo->pool;
86 pool_freewhatprovides(pool);
87 if (reuseids && repo->end == pool->nsolvables)
89 /* it's ok to reuse the ids. As this is the last repo, we can
90 just shrink the solvable array */
91 for (i = repo->end - 1, s = pool->solvables + i; i >= repo->start; i--, s--)
94 pool_free_solvable_block(pool, i + 1, repo->end - (i + 1), reuseids);
96 /* zero out (i.e. free) solvables belonging to this repo */
97 for (i = repo->start, s = pool->solvables + i; i < repo->end; i++, s++)
99 memset(s, 0, sizeof(*s));
100 repo->nsolvables = 0;
102 /* free all data belonging to this repo */
103 repo->idarraydata = solv_free(repo->idarraydata);
104 repo->idarraysize = 0;
106 repo->rpmdbid = solv_free(repo->rpmdbid);
107 for (i = 1; i < repo->nrepodata; i++)
108 repodata_freedata(repo->repodata + i);
109 solv_free(repo->repodata);
115 * remove repo from pool, delete solvables
120 repo_free(Repo *repo, int reuseids)
122 Pool *pool = repo->pool;
125 if (repo == pool->installed)
127 repo_empty(repo, reuseids);
128 for (i = 1; i < pool->nrepos; i++) /* find repo in pool */
129 if (pool->repos[i] == repo)
131 if (i == pool->nrepos) /* repo not in pool, return */
133 if (i == pool->nrepos - 1 && reuseids)
142 repo_add_solvable(Repo *repo)
144 Id p = pool_add_solvable(repo->pool);
145 if (!repo->start || repo->start == repo->end)
146 repo->start = repo->end = p;
147 /* warning: sidedata must be extended before adapting start/end */
149 repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, 1);
152 if (p + 1 > repo->end)
155 repo->pool->solvables[p].repo = repo;
160 repo_add_solvable_block(Repo *repo, int count)
166 p = pool_add_solvable_block(repo->pool, count);
167 if (!repo->start || repo->start == repo->end)
168 repo->start = repo->end = p;
169 /* warning: sidedata must be extended before adapting start/end */
171 repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, count);
174 if (p + count > repo->end)
175 repo->end = p + count;
176 repo->nsolvables += count;
177 for (s = repo->pool->solvables + p; count--; s++)
183 repo_free_solvable(Repo *repo, Id p, int reuseids)
185 repo_free_solvable_block(repo, p, 1, reuseids);
189 repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids)
194 if (start + count == repo->end)
196 repo->nsolvables -= count;
197 for (s = repo->pool->solvables + start, i = count; i--; s++)
199 pool_free_solvable_block(repo->pool, start, count, reuseids);
200 FOR_REPODATAS(repo, i, data)
201 if (data->end > repo->end)
202 repodata_shrink(data, repo->end);
206 /* repository sidedata is solvable data allocated on demand.
207 * It is used for data that is normally not present
208 * in the solvable like the rpmdbid.
209 * The solvable allocation funcions need to make sure that
210 * the sidedata gets extended if new solvables get added.
213 #define REPO_SIDEDATA_BLOCK 63
216 repo_sidedata_create(Repo *repo, size_t size)
218 return solv_calloc_block(repo->end - repo->start, size, REPO_SIDEDATA_BLOCK);
222 repo_sidedata_extend(Repo *repo, void *b, size_t size, Id p, int count)
224 int n = repo->end - repo->start;
227 int d = repo->start - p;
228 b = solv_extend(b, n, d, size, REPO_SIDEDATA_BLOCK);
229 memmove((char *)b + d * size, b, n * size);
230 memset(b, 0, d * size);
233 if (p + count > repo->end)
235 int d = p + count - repo->end;
236 b = solv_extend(b, n, d, size, REPO_SIDEDATA_BLOCK);
237 memset((char *)b + n * size, 0, d * size);
243 * add Id to idarraydata used to store dependencies
244 * olddeps: old array offset to extend
245 * returns new array offset
249 repo_addid(Repo *repo, Offset olddeps, Id id)
255 idarray = repo->idarraydata;
256 idarraysize = repo->idarraysize;
258 if (!idarray) /* alloc idarray if not done yet */
261 idarray = solv_extend_resize(0, 1, sizeof(Id), IDARRAY_BLOCK);
266 if (!olddeps) /* no deps yet */
268 olddeps = idarraysize;
269 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
271 else if (olddeps == repo->lastoff) /* extend at end */
273 else /* can't extend, copy old */
276 olddeps = idarraysize;
277 for (; idarray[i]; i++)
279 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
280 idarray[idarraysize++] = idarray[i];
282 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
285 idarray[idarraysize++] = id; /* insert Id into array */
286 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
287 idarray[idarraysize++] = 0; /* ensure NULL termination */
289 repo->idarraydata = idarray;
290 repo->idarraysize = idarraysize;
291 repo->lastoff = olddeps;
296 #define REPO_ADDID_DEP_HASHTHRES 64
297 #define REPO_ADDID_DEP_HASHMIN 128
300 * Optimization for packages with an excessive amount of provides/requires:
301 * if the number of deps exceed a threshold, we build a hash of the already
305 repo_addid_dep_hash(Repo *repo, Offset olddeps, Id id, Id marker, int size)
324 /* maintain hash and lastmarkerpos */
325 if (repo->lastidhash_idarraysize != repo->idarraysize || size * 2 > repo->lastidhash_mask || repo->lastmarker != marker)
327 repo->lastmarkerpos = 0;
328 if (size * 2 > repo->lastidhash_mask)
330 repo->lastidhash_mask = mkmask(size < REPO_ADDID_DEP_HASHMIN ? REPO_ADDID_DEP_HASHMIN : size);
331 repo->lastidhash = solv_realloc2(repo->lastidhash, repo->lastidhash_mask + 1, sizeof(Id));
333 memset(repo->lastidhash, 0, (repo->lastidhash_mask + 1) * sizeof(Id));
334 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
336 h = oid & repo->lastidhash_mask;
337 hh = HASHCHAIN_START;
338 while (repo->lastidhash[h] != 0)
339 h = HASHCHAIN_NEXT(h, hh, repo->lastidhash_mask);
340 repo->lastidhash[h] = oid;
341 if (marker && oid == marker)
342 repo->lastmarkerpos = oidp - repo->idarraydata;
344 repo->lastmarker = marker;
345 repo->lastidhash_idarraysize = repo->idarraysize;
348 /* check the hash! */
349 h = id & repo->lastidhash_mask;
350 hh = HASHCHAIN_START;
351 while ((hid = repo->lastidhash[h]) != 0 && hid != id)
352 h = HASHCHAIN_NEXT(h, hh, repo->lastidhash_mask);
353 /* put new element in hash */
355 repo->lastidhash[h] = id;
356 else if (marker == SOLVABLE_FILEMARKER && (!before || !repo->lastmarkerpos))
358 if (marker && !before && !repo->lastmarkerpos)
360 /* we have to add the marker first */
361 repo->lastmarkerpos = repo->idarraysize - 1;
362 olddeps = repo_addid(repo, olddeps, marker);
363 /* now put marker in hash */
364 h = marker & repo->lastidhash_mask;
365 hh = HASHCHAIN_START;
366 while (repo->lastidhash[h] != 0)
367 h = HASHCHAIN_NEXT(h, hh, repo->lastidhash_mask);
368 repo->lastidhash[h] = marker;
369 repo->lastidhash_idarraysize = repo->idarraysize;
373 /* new entry, insert in correct position */
374 if (marker && before && repo->lastmarkerpos)
376 /* need to add it before the marker */
377 olddeps = repo_addid(repo, olddeps, id); /* dummy to make room */
378 memmove(repo->idarraydata + repo->lastmarkerpos + 1, repo->idarraydata + repo->lastmarkerpos, (repo->idarraysize - repo->lastmarkerpos - 2) * sizeof(Id));
379 repo->idarraydata[repo->lastmarkerpos++] = id;
383 /* just append it to the end */
384 olddeps = repo_addid(repo, olddeps, id);
386 repo->lastidhash_idarraysize = repo->idarraysize;
389 /* we already have it in the hash */
392 if (marker == SOLVABLE_FILEMARKER)
394 /* check if it is in the wrong half */
395 /* (we already made sure that "before" and "lastmarkerpos" are set, see above) */
396 for (oidp = repo->idarraydata + repo->lastmarkerpos + 1; (oid = *oidp) != 0; oidp++)
401 /* yes, wrong half. copy it over */
402 memmove(repo->idarraydata + repo->lastmarkerpos + 1, repo->idarraydata + repo->lastmarkerpos, (oidp - (repo->idarraydata + repo->lastmarkerpos)) * sizeof(Id));
403 repo->idarraydata[repo->lastmarkerpos++] = id;
408 /* check if it is in the correct half */
409 for (oidp = repo->idarraydata + repo->lastmarkerpos + 1; (oid = *oidp) != 0; oidp++)
412 /* nope, copy it over */
413 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
417 return olddeps; /* should not happen */
418 memmove(oidp, oidp + 1, (repo->idarraydata + repo->idarraysize - oidp - 2) * sizeof(Id));
419 repo->idarraydata[repo->idarraysize - 2] = id;
420 repo->lastmarkerpos--; /* marker has been moved */
425 * add dependency (as Id) to repo, also unifies dependencies
426 * olddeps = offset into idarraydata
427 * marker= 0 for normal dep
428 * marker > 0 add dep after marker
429 * marker < 0 add dep before -marker
430 * returns new start of dependency array
433 repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker)
435 Id oid, *oidp, *markerp;
441 olddeps = repo_addid(repo, olddeps, marker);
442 return repo_addid(repo, olddeps, id);
445 /* check if we should use the hash optimization */
446 if (olddeps == repo->lastoff)
448 int size = repo->idarraysize - 1 - repo->lastoff;
449 if (size >= REPO_ADDID_DEP_HASHTHRES)
450 return repo_addid_dep_hash(repo, olddeps, id, marker, size);
467 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
470 return repo_addid(repo, olddeps, id);
474 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
484 if (marker == SOLVABLE_FILEMARKER)
486 if (!markerp || !before)
488 /* we found it, but in the second half */
489 memmove(markerp + 1, markerp, (oidp - markerp) * sizeof(Id));
493 if (markerp || before)
495 /* we found it, but in the first half */
497 for (; (oid = *oidp) != 0; oidp++)
502 /* no marker in array yet */
505 memmove(markerp, markerp + 1, (oidp - markerp) * sizeof(Id));
507 return repo_addid(repo, olddeps, id);
511 memmove(markerp, markerp + 1, (oidp - markerp) * sizeof(Id));
515 /* id not yet in array */
516 if (!before && !markerp)
517 olddeps = repo_addid(repo, olddeps, marker);
518 else if (before && markerp)
523 memmove(markerp + 1, markerp, (oidp - markerp) * sizeof(Id));
526 return repo_addid(repo, olddeps, id);
532 * make space for 'num' more dependencies
533 * returns new start of dependency array
535 * reserved ids will always begin at offset idarraysize
539 repo_reserve_ids(Repo *repo, Offset olddeps, int num)
541 num++; /* room for trailing ID_NULL */
543 if (!repo->idarraysize) /* ensure buffer space */
545 repo->idarraysize = 1;
546 repo->idarraydata = solv_extend_resize(0, 1 + num, sizeof(Id), IDARRAY_BLOCK);
547 repo->idarraydata[0] = 0;
552 if (olddeps && olddeps != repo->lastoff) /* if not appending */
554 /* can't insert into idarray, this would invalidate all 'larger' offsets
555 * so create new space at end and move existing deps there.
556 * Leaving 'hole' at old position.
562 for (idstart = idend = repo->idarraydata + olddeps; *idend++; ) /* find end */
564 count = idend - idstart - 1 + num; /* new size */
566 repo->idarraydata = solv_extend(repo->idarraydata, repo->idarraysize, count, sizeof(Id), IDARRAY_BLOCK);
567 /* move old deps to end */
568 olddeps = repo->lastoff = repo->idarraysize;
569 memcpy(repo->idarraydata + olddeps, idstart, count - num);
570 repo->idarraysize = olddeps + count - num;
575 if (olddeps) /* appending */
579 repo->idarraydata = solv_extend(repo->idarraydata, repo->idarraysize, num, sizeof(Id), IDARRAY_BLOCK);
581 /* appending or new */
582 repo->lastoff = olddeps ? olddeps : repo->idarraysize;
584 return repo->lastoff;
588 /***********************************************************************/
591 * some SUSE specific fixups, should go into a separate file
595 repo_fix_supplements(Repo *repo, Offset provides, Offset supplements, Offset freshens)
597 Pool *pool = repo->pool;
599 char buf[1024], *p, *dep;
604 for (i = provides; repo->idarraydata[i]; i++)
606 id = repo->idarraydata[i];
609 dep = (char *)pool_id2str(pool, id);
610 if (!strncmp(dep, "locale(", 7) && strlen(dep) < sizeof(buf) - 2)
613 strcpy(buf + 2, dep);
615 if ((p = strchr(dep, ':')) != 0 && p != dep)
618 idp = pool_str2id(pool, dep, 1);
622 while ((p = strchr(dep, ';')) != 0)
630 idl = pool_str2id(pool, dep, 1);
631 idl = pool_rel2id(pool, NAMESPACE_LANGUAGE, idl, REL_NAMESPACE, 1);
633 id = pool_rel2id(pool, id, idl, REL_OR, 1);
638 if (dep[0] && dep[1])
640 for (p = dep; *p && *p != ')'; p++)
643 idl = pool_str2id(pool, dep, 1);
644 idl = pool_rel2id(pool, NAMESPACE_LANGUAGE, idl, REL_NAMESPACE, 1);
646 id = pool_rel2id(pool, id, idl, REL_OR, 1);
651 id = pool_rel2id(pool, idp, id, REL_AND, 1);
653 supplements = repo_addid_dep(repo, supplements, id, 0);
655 else if ((p = strchr(dep, ':')) != 0 && p != dep && p[1] == '/' && strlen(dep) < sizeof(buf))
660 idp = pool_str2id(pool, buf, 1);
661 /* strip trailing slashes */
663 while (l > 1 && p[l - 1] == '/')
665 id = pool_str2id(pool, p, 1);
666 id = pool_rel2id(pool, idp, id, REL_WITH, 1);
667 id = pool_rel2id(pool, NAMESPACE_SPLITPROVIDES, id, REL_NAMESPACE, 1);
668 supplements = repo_addid_dep(repo, supplements, id, 0);
674 for (i = supplements; repo->idarraydata[i]; i++)
676 id = repo->idarraydata[i];
679 dep = (char *)pool_id2str(pool, id);
680 if (!strncmp(dep, "system:modalias(", 16))
682 if (!strncmp(dep, "modalias(", 9) && dep[9] && dep[10] && strlen(dep) < sizeof(buf))
685 p = strchr(buf + 9, ':');
686 if (p && p != buf + 9 && strchr(p + 1, ':'))
689 idp = pool_str2id(pool, buf + 9, 1);
690 p[strlen(p) - 1] = 0;
691 id = pool_str2id(pool, p, 1);
692 id = pool_rel2id(pool, NAMESPACE_MODALIAS, id, REL_NAMESPACE, 1);
693 id = pool_rel2id(pool, idp, id, REL_AND, 1);
698 p[strlen(p) - 1] = 0;
699 id = pool_str2id(pool, p, 1);
700 id = pool_rel2id(pool, NAMESPACE_MODALIAS, id, REL_NAMESPACE, 1);
703 repo->idarraydata[i] = id;
705 else if (!strncmp(dep, "packageand(", 11) && strlen(dep) < sizeof(buf))
710 while ((p = strchr(dep, ':')) != 0)
717 /* argh, allow pattern: prefix. sigh */
718 if (p - dep == 7 && !strncmp(dep, "pattern", 7))
720 p = strchr(p + 1, ':');
725 idp = pool_str2id(pool, dep, 1);
727 id = pool_rel2id(pool, id, idp, REL_AND, 1);
732 if (dep[0] && dep[1])
734 dep[strlen(dep) - 1] = 0;
735 idp = pool_str2id(pool, dep, 1);
737 id = pool_rel2id(pool, id, idp, REL_AND, 1);
742 repo->idarraydata[i] = id;
744 else if (!strncmp(dep, "filesystem(", 11) && strlen(dep) < sizeof(buf))
746 strcpy(buf, dep + 11);
747 if ((p = strrchr(buf, ')')) != 0)
749 id = pool_str2id(pool, buf, 1);
750 id = pool_rel2id(pool, NAMESPACE_FILESYSTEM, id, REL_NAMESPACE, 1);
751 repo->idarraydata[i] = id;
755 if (freshens && repo->idarraydata[freshens])
757 Id idsupp = 0, idfresh = 0;
758 if (!supplements || !repo->idarraydata[supplements])
760 for (i = supplements; repo->idarraydata[i]; i++)
763 idsupp = repo->idarraydata[i];
765 idsupp = pool_rel2id(pool, idsupp, repo->idarraydata[i], REL_OR, 1);
767 for (i = freshens; repo->idarraydata[i]; i++)
770 idfresh = repo->idarraydata[i];
772 idfresh = pool_rel2id(pool, idfresh, repo->idarraydata[i], REL_OR, 1);
777 idsupp = pool_rel2id(pool, idsupp, idfresh, REL_AND, 1);
778 supplements = repo_addid_dep(repo, 0, idsupp, 0);
784 repo_fix_conflicts(Repo *repo, Offset conflicts)
786 char buf[1024], *p, *dep;
787 Pool *pool = repo->pool;
793 for (i = conflicts; repo->idarraydata[i]; i++)
795 id = repo->idarraydata[i];
798 dep = (char *)pool_id2str(pool, id);
799 if (!strncmp(dep, "otherproviders(", 15) && strlen(dep) < sizeof(buf) - 2)
801 strcpy(buf, dep + 15);
802 if ((p = strchr(buf, ')')) != 0)
804 id = pool_str2id(pool, buf, 1);
805 id = pool_rel2id(pool, NAMESPACE_OTHERPROVIDERS, id, REL_NAMESPACE, 1);
806 repo->idarraydata[i] = id;
812 /***********************************************************************/
820 int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv);
825 repo_matchvalue(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
827 struct matchdata *md = cbdata;
829 if (md->matcher.match)
831 if (!repodata_stringify(md->pool, data, key, kv, md->flags))
833 if (!datamatcher_match(&md->matcher, kv->str))
836 md->stop = md->callback(md->callback_data, s, data, key, kv);
841 /* list of all keys we store in the solvable */
842 /* also used in the dataiterator code in repodata.c */
843 Repokey repo_solvablekeys[RPM_RPMDBID - SOLVABLE_NAME + 1] = {
844 { SOLVABLE_NAME, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
845 { SOLVABLE_ARCH, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
846 { SOLVABLE_EVR, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
847 { SOLVABLE_VENDOR, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
848 { SOLVABLE_PROVIDES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
849 { SOLVABLE_OBSOLETES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
850 { SOLVABLE_CONFLICTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
851 { SOLVABLE_REQUIRES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
852 { SOLVABLE_RECOMMENDS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
853 { SOLVABLE_SUGGESTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
854 { SOLVABLE_SUPPLEMENTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
855 { SOLVABLE_ENHANCES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
856 { RPM_RPMDBID, REPOKEY_TYPE_NUM, 0, KEY_STORAGE_SOLVABLE },
860 domatch_idarray(Solvable *s, Id keyname, struct matchdata *md, Id *ida)
865 for (; *ida && !md->stop; ida++)
868 kv.eof = ida[1] ? 0 : 1;
869 repo_matchvalue(md, s, 0, repo_solvablekeys + (keyname - SOLVABLE_NAME), &kv);
875 repo_search_md(Repo *repo, Id p, Id keyname, struct matchdata *md)
878 Pool *pool = repo->pool;
887 for (p = repo->start, s = repo->pool->solvables + p; p < repo->end; p++, s++)
890 repo_search_md(repo, p, keyname, md);
891 if (md->stop > SEARCH_NEXT_SOLVABLE)
897 /* The callback only supports solvables, so we can't iterate over the
901 if (!(flags & SEARCH_NO_STORAGE_SOLVABLE))
903 s = pool->solvables + p;
911 repo_matchvalue(md, s, 0, repo_solvablekeys + 0, &kv);
913 if (keyname || md->stop > SEARCH_NEXT_KEY)
919 repo_matchvalue(md, s, 0, repo_solvablekeys + 1, &kv);
921 if (keyname || md->stop > SEARCH_NEXT_KEY)
927 repo_matchvalue(md, s, 0, repo_solvablekeys + 2, &kv);
929 if (keyname || md->stop > SEARCH_NEXT_KEY)
931 case SOLVABLE_VENDOR:
935 repo_matchvalue(md, s, 0, repo_solvablekeys + 3, &kv);
937 if (keyname || md->stop > SEARCH_NEXT_KEY)
939 case SOLVABLE_PROVIDES:
941 domatch_idarray(s, SOLVABLE_PROVIDES, md, repo->idarraydata + s->provides);
942 if (keyname || md->stop > SEARCH_NEXT_KEY)
944 case SOLVABLE_OBSOLETES:
946 domatch_idarray(s, SOLVABLE_OBSOLETES, md, repo->idarraydata + s->obsoletes);
947 if (keyname || md->stop > SEARCH_NEXT_KEY)
949 case SOLVABLE_CONFLICTS:
951 domatch_idarray(s, SOLVABLE_CONFLICTS, md, repo->idarraydata + s->conflicts);
952 if (keyname || md->stop > SEARCH_NEXT_KEY)
954 case SOLVABLE_REQUIRES:
956 domatch_idarray(s, SOLVABLE_REQUIRES, md, repo->idarraydata + s->requires);
957 if (keyname || md->stop > SEARCH_NEXT_KEY)
959 case SOLVABLE_RECOMMENDS:
961 domatch_idarray(s, SOLVABLE_RECOMMENDS, md, repo->idarraydata + s->recommends);
962 if (keyname || md->stop > SEARCH_NEXT_KEY)
964 case SOLVABLE_SUPPLEMENTS:
966 domatch_idarray(s, SOLVABLE_SUPPLEMENTS, md, repo->idarraydata + s->supplements);
967 if (keyname || md->stop > SEARCH_NEXT_KEY)
969 case SOLVABLE_SUGGESTS:
971 domatch_idarray(s, SOLVABLE_SUGGESTS, md, repo->idarraydata + s->suggests);
972 if (keyname || md->stop > SEARCH_NEXT_KEY)
974 case SOLVABLE_ENHANCES:
976 domatch_idarray(s, SOLVABLE_ENHANCES, md, repo->idarraydata + s->enhances);
977 if (keyname || md->stop > SEARCH_NEXT_KEY)
982 kv.num = repo->rpmdbid[p - repo->start];
984 repo_matchvalue(md, s, 0, repo_solvablekeys + (RPM_RPMDBID - SOLVABLE_NAME), &kv);
986 if (keyname || md->stop > SEARCH_NEXT_KEY)
994 FOR_REPODATAS(repo, i, data)
996 if (p < data->start || p >= data->end)
998 if (keyname && !repodata_precheck_keyname(data, keyname))
1000 if (keyname == SOLVABLE_FILELIST && !(md->flags & SEARCH_COMPLETE_FILELIST))
1002 /* do not search filelist extensions */
1003 if (data->state != REPODATA_AVAILABLE)
1005 for (j = 1; j < data->nkeys; j++)
1006 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1008 if (j == data->nkeys)
1011 if (data->state == REPODATA_STUB)
1015 for (j = 1; j < data->nkeys; j++)
1016 if (keyname == data->keys[j].name)
1018 if (j == data->nkeys)
1022 if (data->loadcallback)
1023 data->loadcallback(data);
1025 data->state = REPODATA_ERROR;
1027 if (data->state == REPODATA_ERROR)
1029 repodata_search(data, p, keyname, md->flags, repo_matchvalue, md);
1030 if (md->stop > SEARCH_NEXT_KEY)
1036 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)
1038 struct matchdata md;
1040 if (repo->disabled && !(flags & SEARCH_DISABLED_REPOS))
1042 memset(&md, 0, sizeof(md));
1043 md.pool = repo->pool;
1045 md.callback = callback;
1046 md.callback_data = cbdata;
1048 datamatcher_init(&md.matcher, match, flags);
1049 repo_search_md(repo, p, keyname, &md);
1051 datamatcher_free(&md.matcher);
1055 repo_lookup_str(Repo *repo, Id entry, Id keyname)
1057 Pool *pool = repo->pool;
1067 return pool_id2str(pool, pool->solvables[entry].name);
1069 return pool_id2str(pool, pool->solvables[entry].arch);
1071 return pool_id2str(pool, pool->solvables[entry].evr);
1072 case SOLVABLE_VENDOR:
1073 return pool_id2str(pool, pool->solvables[entry].vendor);
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 str = repodata_lookup_str(data, entry, keyname);
1085 if (repodata_lookup_type(data, entry, keyname))
1093 repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned int notfound)
1101 if (keyname == RPM_RPMDBID)
1103 if (repo->rpmdbid && entry >= repo->start && entry < repo->end)
1104 return repo->rpmdbid[entry - repo->start];
1108 FOR_REPODATAS(repo, i, data)
1110 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1112 if (!repodata_precheck_keyname(data, keyname))
1114 if (repodata_lookup_num(data, entry, keyname, &value))
1116 if (repodata_lookup_type(data, entry, keyname))
1123 repo_lookup_id(Repo *repo, Id entry, Id keyname)
1134 return repo->pool->solvables[entry].name;
1136 return repo->pool->solvables[entry].arch;
1138 return repo->pool->solvables[entry].evr;
1139 case SOLVABLE_VENDOR:
1140 return repo->pool->solvables[entry].vendor;
1143 FOR_REPODATAS(repo, i, data)
1145 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1147 if (!repodata_precheck_keyname(data, keyname))
1149 id = repodata_lookup_id(data, entry, keyname);
1151 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1152 if (repodata_lookup_type(data, entry, keyname))
1159 lookup_idarray_solvable(Repo *repo, Offset off, Queue *q)
1165 for (p = repo->idarraydata + off; *p; p++)
1171 repo_lookup_idarray(Repo *repo, Id entry, Id keyname, Queue *q)
1179 case SOLVABLE_PROVIDES:
1180 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].provides, q);
1181 case SOLVABLE_OBSOLETES:
1182 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].obsoletes, q);
1183 case SOLVABLE_CONFLICTS:
1184 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].conflicts, q);
1185 case SOLVABLE_REQUIRES:
1186 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].requires, q);
1187 case SOLVABLE_RECOMMENDS:
1188 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].recommends, q);
1189 case SOLVABLE_SUGGESTS:
1190 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].suggests, q);
1191 case SOLVABLE_SUPPLEMENTS:
1192 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].supplements, q);
1193 case SOLVABLE_ENHANCES:
1194 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].enhances, q);
1197 FOR_REPODATAS(repo, i, data)
1199 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1201 if (!repodata_precheck_keyname(data, keyname))
1203 if (repodata_lookup_idarray(data, entry, keyname, q))
1205 if (data->localpool)
1207 for (i = 0; i < q->count; i++)
1208 q->elements[i] = repodata_globalize_id(data, q->elements[i], 1);
1212 if (repodata_lookup_type(data, entry, keyname))
1220 repo_lookup_deparray(Repo *repo, Id entry, Id keyname, Queue *q, Id marker)
1222 int r = repo_lookup_idarray(repo, entry, keyname, q);
1229 for (i = 0; i < q->count; i++)
1230 if (q->elements[i] == marker)
1232 queue_truncate(q, i);
1238 for (i = 0; i < q->count; i++)
1239 if (q->elements[i] == marker)
1241 queue_deleten(q, 0, i + 1);
1249 const unsigned char *
1250 repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
1254 const unsigned char *chk;
1256 FOR_REPODATAS(repo, i, data)
1258 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1260 if (!repodata_precheck_keyname(data, keyname))
1262 chk = repodata_lookup_bin_checksum(data, entry, keyname, typep);
1265 if (repodata_lookup_type(data, entry, keyname))
1273 repo_lookup_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
1275 const unsigned char *chk = repo_lookup_bin_checksum(repo, entry, keyname, typep);
1276 return chk ? pool_bin2hex(repo->pool, chk, solv_chksum_len(*typep)) : 0;
1280 repo_lookup_void(Repo *repo, Id entry, Id keyname)
1286 FOR_REPODATAS(repo, i, data)
1288 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1290 if (!repodata_precheck_keyname(data, keyname))
1292 type = repodata_lookup_type(data, entry, keyname);
1294 return type == REPOKEY_TYPE_VOID;
1300 repo_lookup_type(Repo *repo, Id entry, Id keyname)
1306 FOR_REPODATAS(repo, i, data)
1308 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1310 if (!repodata_precheck_keyname(data, keyname))
1312 type = repodata_lookup_type(data, entry, keyname);
1314 return type == REPOKEY_TYPE_DELETED ? 0 : type;
1319 /***********************************************************************/
1322 repo_add_repodata(Repo *repo, int flags)
1326 if ((flags & REPO_USE_LOADING) != 0)
1328 for (i = repo->nrepodata - 1; i > 0; i--)
1329 if (repo->repodata[i].state == REPODATA_LOADING)
1331 Repodata *data = repo->repodata + i;
1333 /* hack: we mis-use REPO_REUSE_REPODATA here */
1334 if (!(flags & REPO_REUSE_REPODATA))
1335 repodata_empty(data, (flags & REPO_LOCALPOOL) ? 1 : 0);
1338 return 0; /* must not create a new repodata! */
1340 if ((flags & REPO_REUSE_REPODATA) != 0)
1342 for (i = repo->nrepodata - 1; i > 0; i--)
1343 if (repo->repodata[i].state != REPODATA_STUB)
1344 return repo->repodata + i;
1346 if (!repo->nrepodata)
1348 repo->nrepodata = 2; /* start with id 1 */
1349 repo->repodata = solv_calloc(repo->nrepodata, sizeof(*data));
1354 repo->repodata = solv_realloc2(repo->repodata, repo->nrepodata, sizeof(*data));
1356 data = repo->repodata + repo->nrepodata - 1;
1357 repodata_initdata(data, repo, (flags & REPO_LOCALPOOL) ? 1 : 0);
1362 repo_id2repodata(Repo *repo, Id id)
1364 return id ? repo->repodata + id : 0;
1368 repo_last_repodata(Repo *repo)
1371 for (i = repo->nrepodata - 1; i > 0; i--)
1372 if (repo->repodata[i].state != REPODATA_STUB)
1373 return repo->repodata + i;
1374 return repo_add_repodata(repo, 0);
1378 repo_set_id(Repo *repo, Id p, Id keyname, Id id)
1386 repo->pool->solvables[p].name = id;
1389 repo->pool->solvables[p].arch = id;
1392 repo->pool->solvables[p].evr = id;
1394 case SOLVABLE_VENDOR:
1395 repo->pool->solvables[p].vendor = id;
1399 data = repo_last_repodata(repo);
1400 if (data->localpool)
1401 id = repodata_localize_id(data, id, 1);
1402 repodata_set_id(data, p, keyname, id);
1406 repo_set_num(Repo *repo, Id p, Id keyname, unsigned int num)
1411 if (keyname == RPM_RPMDBID)
1414 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1415 repo->rpmdbid[p] = num;
1419 data = repo_last_repodata(repo);
1420 repodata_set_num(data, p, keyname, num);
1424 repo_set_str(Repo *repo, Id p, Id keyname, const char *str)
1434 case SOLVABLE_VENDOR:
1435 repo_set_id(repo, p, keyname, pool_str2id(repo->pool, str, 1));
1439 data = repo_last_repodata(repo);
1440 repodata_set_str(data, p, keyname, str);
1444 repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str)
1454 case SOLVABLE_VENDOR:
1455 repo_set_id(repo, p, keyname, pool_str2id(repo->pool, str, 1));
1459 data = repo_last_repodata(repo);
1460 repodata_set_poolstr(data, p, keyname, str);
1464 repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str)
1466 Repodata *data = repo_last_repodata(repo);
1467 repodata_add_poolstr_array(data, p, keyname, str);
1471 repo_add_deparray(Repo *repo, Id p, Id keyname, Id dep, Id marker)
1476 Solvable *s = repo->pool->solvables + p;
1479 case SOLVABLE_PROVIDES:
1480 s->provides = repo_addid_dep(repo, s->provides, dep, marker);
1482 case SOLVABLE_OBSOLETES:
1483 s->obsoletes = repo_addid_dep(repo, s->obsoletes, dep, marker);
1485 case SOLVABLE_CONFLICTS:
1486 s->conflicts = repo_addid_dep(repo, s->conflicts, dep, marker);
1488 case SOLVABLE_REQUIRES:
1489 s->requires = repo_addid_dep(repo, s->requires, dep, marker);
1491 case SOLVABLE_RECOMMENDS:
1492 s->recommends = repo_addid_dep(repo, s->recommends, dep, marker);
1494 case SOLVABLE_SUGGESTS:
1495 s->suggests = repo_addid_dep(repo, s->suggests, dep, marker);
1497 case SOLVABLE_SUPPLEMENTS:
1498 s->supplements = repo_addid_dep(repo, s->supplements, dep, marker);
1500 case SOLVABLE_ENHANCES:
1501 s->enhances = repo_addid_dep(repo, s->enhances, dep, marker);
1505 data = repo_last_repodata(repo);
1506 repodata_add_idarray(data, p, keyname, dep);
1510 repo_add_idarray(Repo *repo, Id p, Id keyname, Id id)
1512 repo_add_deparray(repo, p, keyname, id, 0);
1516 repo_set_idarray_solvable(Repo *repo, Queue *q)
1520 for (i = 0; i < q->count; i++)
1521 repo_addid_dep(repo, o, q->elements[i], 0);
1526 repo_set_deparray(Repo *repo, Id p, Id keyname, Queue *q, Id marker)
1531 /* complex case, splice old and new arrays */
1535 repo_lookup_deparray(repo, p, keyname, &q2, -marker);
1540 queue_push(&q2, marker);
1541 for (i = 0; i < q->count; i++)
1542 queue_push(&q2, q->elements[i]);
1548 queue_insert(&q2, 0, -marker);
1549 queue_insertn(&q2, 0, q->count);
1550 for (i = 0; i < q->count; i++)
1551 q2.elements[i] = q->elements[i];
1553 repo_set_deparray(repo, p, keyname, &q2, 0);
1559 Solvable *s = repo->pool->solvables + p;
1562 case SOLVABLE_PROVIDES:
1563 s->provides = repo_set_idarray_solvable(repo, q);
1565 case SOLVABLE_OBSOLETES:
1566 s->obsoletes = repo_set_idarray_solvable(repo, q);
1568 case SOLVABLE_CONFLICTS:
1569 s->conflicts = repo_set_idarray_solvable(repo, q);
1571 case SOLVABLE_REQUIRES:
1572 s->requires = repo_set_idarray_solvable(repo, q);
1574 case SOLVABLE_RECOMMENDS:
1575 s->recommends = repo_set_idarray_solvable(repo, q);
1577 case SOLVABLE_SUGGESTS:
1578 s->suggests = repo_set_idarray_solvable(repo, q);
1580 case SOLVABLE_SUPPLEMENTS:
1581 s->supplements = repo_set_idarray_solvable(repo, q);
1583 case SOLVABLE_ENHANCES:
1584 s->enhances = repo_set_idarray_solvable(repo, q);
1588 data = repo_last_repodata(repo);
1589 repodata_set_idarray(data, p, keyname, q);
1593 repo_set_idarray(Repo *repo, Id p, Id keyname, Queue *q)
1595 repo_set_deparray(repo, p, keyname, q, 0);
1599 repo_internalize(Repo *repo)
1604 FOR_REPODATAS(repo, i, data)
1605 if (data->attrs || data->xattrs)
1606 repodata_internalize(data);
1610 repo_disable_paging(Repo *repo)
1615 FOR_REPODATAS(repo, i, data)
1616 repodata_disable_paging(data);
1620 vim:cinoptions={.5s,g0,p5,t0,(0,^-0.5s,n-0.5s:tw=78:cindent:sw=4: