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_U32, 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];
983 repo_matchvalue(md, s, 0, repo_solvablekeys + (RPM_RPMDBID - SOLVABLE_NAME), &kv);
985 if (keyname || md->stop > SEARCH_NEXT_KEY)
993 FOR_REPODATAS(repo, i, data)
995 if (p < data->start || p >= data->end)
997 if (keyname && !repodata_precheck_keyname(data, keyname))
999 if (keyname == SOLVABLE_FILELIST && !(md->flags & SEARCH_COMPLETE_FILELIST))
1001 /* do not search filelist extensions */
1002 if (data->state != REPODATA_AVAILABLE)
1004 for (j = 1; j < data->nkeys; j++)
1005 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1007 if (j == data->nkeys)
1010 if (data->state == REPODATA_STUB)
1014 for (j = 1; j < data->nkeys; j++)
1015 if (keyname == data->keys[j].name)
1017 if (j == data->nkeys)
1021 if (data->loadcallback)
1022 data->loadcallback(data);
1024 data->state = REPODATA_ERROR;
1026 if (data->state == REPODATA_ERROR)
1028 repodata_search(data, p, keyname, md->flags, repo_matchvalue, md);
1029 if (md->stop > SEARCH_NEXT_KEY)
1035 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)
1037 struct matchdata md;
1039 if (repo->disabled && !(flags & SEARCH_DISABLED_REPOS))
1041 memset(&md, 0, sizeof(md));
1042 md.pool = repo->pool;
1044 md.callback = callback;
1045 md.callback_data = cbdata;
1047 datamatcher_init(&md.matcher, match, flags);
1048 repo_search_md(repo, p, keyname, &md);
1050 datamatcher_free(&md.matcher);
1054 repo_lookup_str(Repo *repo, Id entry, Id keyname)
1056 Pool *pool = repo->pool;
1066 return pool_id2str(pool, pool->solvables[entry].name);
1068 return pool_id2str(pool, pool->solvables[entry].arch);
1070 return pool_id2str(pool, pool->solvables[entry].evr);
1071 case SOLVABLE_VENDOR:
1072 return pool_id2str(pool, pool->solvables[entry].vendor);
1075 FOR_REPODATAS(repo, i, data)
1077 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1079 if (!repodata_precheck_keyname(data, keyname))
1081 str = repodata_lookup_str(data, entry, keyname);
1084 if (repodata_lookup_type(data, entry, keyname))
1092 repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned int notfound)
1100 if (keyname == RPM_RPMDBID)
1102 if (repo->rpmdbid && entry >= repo->start && entry < repo->end)
1103 return repo->rpmdbid[entry - repo->start];
1107 FOR_REPODATAS(repo, i, data)
1109 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1111 if (!repodata_precheck_keyname(data, keyname))
1113 if (repodata_lookup_num(data, entry, keyname, &value))
1115 if (repodata_lookup_type(data, entry, keyname))
1122 repo_lookup_id(Repo *repo, Id entry, Id keyname)
1133 return repo->pool->solvables[entry].name;
1135 return repo->pool->solvables[entry].arch;
1137 return repo->pool->solvables[entry].evr;
1138 case SOLVABLE_VENDOR:
1139 return repo->pool->solvables[entry].vendor;
1142 FOR_REPODATAS(repo, i, data)
1144 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1146 if (!repodata_precheck_keyname(data, keyname))
1148 id = repodata_lookup_id(data, entry, keyname);
1150 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1151 if (repodata_lookup_type(data, entry, keyname))
1158 lookup_idarray_solvable(Repo *repo, Offset off, Queue *q)
1164 for (p = repo->idarraydata + off; *p; p++)
1170 repo_lookup_idarray(Repo *repo, Id entry, Id keyname, Queue *q)
1178 case SOLVABLE_PROVIDES:
1179 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].provides, q);
1180 case SOLVABLE_OBSOLETES:
1181 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].obsoletes, q);
1182 case SOLVABLE_CONFLICTS:
1183 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].conflicts, q);
1184 case SOLVABLE_REQUIRES:
1185 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].requires, q);
1186 case SOLVABLE_RECOMMENDS:
1187 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].recommends, q);
1188 case SOLVABLE_SUGGESTS:
1189 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].suggests, q);
1190 case SOLVABLE_SUPPLEMENTS:
1191 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].supplements, q);
1192 case SOLVABLE_ENHANCES:
1193 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].enhances, q);
1196 FOR_REPODATAS(repo, i, data)
1198 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1200 if (!repodata_precheck_keyname(data, keyname))
1202 if (repodata_lookup_idarray(data, entry, keyname, q))
1204 if (data->localpool)
1206 for (i = 0; i < q->count; i++)
1207 q->elements[i] = repodata_globalize_id(data, q->elements[i], 1);
1211 if (repodata_lookup_type(data, entry, keyname))
1219 repo_lookup_deparray(Repo *repo, Id entry, Id keyname, Queue *q, Id marker)
1221 int r = repo_lookup_idarray(repo, entry, keyname, q);
1228 for (i = 0; i < q->count; i++)
1229 if (q->elements[i] == marker)
1231 queue_truncate(q, i);
1237 for (i = 0; i < q->count; i++)
1238 if (q->elements[i] == marker)
1240 queue_deleten(q, 0, i + 1);
1248 const unsigned char *
1249 repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
1253 const unsigned char *chk;
1255 FOR_REPODATAS(repo, i, data)
1257 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1259 if (!repodata_precheck_keyname(data, keyname))
1261 chk = repodata_lookup_bin_checksum(data, entry, keyname, typep);
1264 if (repodata_lookup_type(data, entry, keyname))
1272 repo_lookup_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
1274 const unsigned char *chk = repo_lookup_bin_checksum(repo, entry, keyname, typep);
1275 return chk ? pool_bin2hex(repo->pool, chk, solv_chksum_len(*typep)) : 0;
1279 repo_lookup_void(Repo *repo, Id entry, Id keyname)
1285 FOR_REPODATAS(repo, i, data)
1287 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1289 if (!repodata_precheck_keyname(data, keyname))
1291 type = repodata_lookup_type(data, entry, keyname);
1293 return type == REPOKEY_TYPE_VOID;
1299 repo_lookup_type(Repo *repo, Id entry, Id keyname)
1305 FOR_REPODATAS(repo, i, data)
1307 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1309 if (!repodata_precheck_keyname(data, keyname))
1311 type = repodata_lookup_type(data, entry, keyname);
1313 return type == REPOKEY_TYPE_DELETED ? 0 : type;
1318 /***********************************************************************/
1321 repo_add_repodata(Repo *repo, int flags)
1325 if ((flags & REPO_USE_LOADING) != 0)
1327 for (i = repo->nrepodata - 1; i > 0; i--)
1328 if (repo->repodata[i].state == REPODATA_LOADING)
1330 Repodata *data = repo->repodata + i;
1332 /* hack: we mis-use REPO_REUSE_REPODATA here */
1333 if (!(flags & REPO_REUSE_REPODATA))
1334 repodata_empty(data, (flags & REPO_LOCALPOOL) ? 1 : 0);
1337 return 0; /* must not create a new repodata! */
1339 if ((flags & REPO_REUSE_REPODATA) != 0)
1341 for (i = repo->nrepodata - 1; i > 0; i--)
1342 if (repo->repodata[i].state != REPODATA_STUB)
1343 return repo->repodata + i;
1345 if (!repo->nrepodata)
1347 repo->nrepodata = 2; /* start with id 1 */
1348 repo->repodata = solv_calloc(repo->nrepodata, sizeof(*data));
1353 repo->repodata = solv_realloc2(repo->repodata, repo->nrepodata, sizeof(*data));
1355 data = repo->repodata + repo->nrepodata - 1;
1356 repodata_initdata(data, repo, (flags & REPO_LOCALPOOL) ? 1 : 0);
1361 repo_id2repodata(Repo *repo, Id id)
1363 return id ? repo->repodata + id : 0;
1367 repo_last_repodata(Repo *repo)
1370 for (i = repo->nrepodata - 1; i > 0; i--)
1371 if (repo->repodata[i].state != REPODATA_STUB)
1372 return repo->repodata + i;
1373 return repo_add_repodata(repo, 0);
1377 repo_set_id(Repo *repo, Id p, Id keyname, Id id)
1385 repo->pool->solvables[p].name = id;
1388 repo->pool->solvables[p].arch = id;
1391 repo->pool->solvables[p].evr = id;
1393 case SOLVABLE_VENDOR:
1394 repo->pool->solvables[p].vendor = id;
1398 data = repo_last_repodata(repo);
1399 if (data->localpool)
1400 id = repodata_localize_id(data, id, 1);
1401 repodata_set_id(data, p, keyname, id);
1405 repo_set_num(Repo *repo, Id p, Id keyname, unsigned int num)
1410 if (keyname == RPM_RPMDBID)
1413 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1414 repo->rpmdbid[p] = num;
1418 data = repo_last_repodata(repo);
1419 repodata_set_num(data, p, keyname, num);
1423 repo_set_str(Repo *repo, Id p, Id keyname, const char *str)
1433 case SOLVABLE_VENDOR:
1434 repo_set_id(repo, p, keyname, pool_str2id(repo->pool, str, 1));
1438 data = repo_last_repodata(repo);
1439 repodata_set_str(data, p, keyname, str);
1443 repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str)
1453 case SOLVABLE_VENDOR:
1454 repo_set_id(repo, p, keyname, pool_str2id(repo->pool, str, 1));
1458 data = repo_last_repodata(repo);
1459 repodata_set_poolstr(data, p, keyname, str);
1463 repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str)
1465 Repodata *data = repo_last_repodata(repo);
1466 repodata_add_poolstr_array(data, p, keyname, str);
1470 repo_add_deparray(Repo *repo, Id p, Id keyname, Id dep, Id marker)
1475 Solvable *s = repo->pool->solvables + p;
1478 case SOLVABLE_PROVIDES:
1479 s->provides = repo_addid_dep(repo, s->provides, dep, marker);
1481 case SOLVABLE_OBSOLETES:
1482 s->obsoletes = repo_addid_dep(repo, s->obsoletes, dep, marker);
1484 case SOLVABLE_CONFLICTS:
1485 s->conflicts = repo_addid_dep(repo, s->conflicts, dep, marker);
1487 case SOLVABLE_REQUIRES:
1488 s->requires = repo_addid_dep(repo, s->requires, dep, marker);
1490 case SOLVABLE_RECOMMENDS:
1491 s->recommends = repo_addid_dep(repo, s->recommends, dep, marker);
1493 case SOLVABLE_SUGGESTS:
1494 s->suggests = repo_addid_dep(repo, s->suggests, dep, marker);
1496 case SOLVABLE_SUPPLEMENTS:
1497 s->supplements = repo_addid_dep(repo, s->supplements, dep, marker);
1499 case SOLVABLE_ENHANCES:
1500 s->enhances = repo_addid_dep(repo, s->enhances, dep, marker);
1504 data = repo_last_repodata(repo);
1505 repodata_add_idarray(data, p, keyname, dep);
1509 repo_add_idarray(Repo *repo, Id p, Id keyname, Id id)
1511 repo_add_deparray(repo, p, keyname, id, 0);
1515 repo_set_idarray_solvable(Repo *repo, Queue *q)
1519 for (i = 0; i < q->count; i++)
1520 repo_addid_dep(repo, o, q->elements[i], 0);
1525 repo_set_deparray(Repo *repo, Id p, Id keyname, Queue *q, Id marker)
1530 /* complex case, splice old and new arrays */
1534 repo_lookup_deparray(repo, p, keyname, &q2, -marker);
1539 queue_push(&q2, marker);
1540 for (i = 0; i < q->count; i++)
1541 queue_push(&q2, q->elements[i]);
1547 queue_insert(&q2, 0, -marker);
1548 queue_insertn(&q2, 0, q->count);
1549 for (i = 0; i < q->count; i++)
1550 q2.elements[i] = q->elements[i];
1552 repo_set_deparray(repo, p, keyname, &q2, 0);
1558 Solvable *s = repo->pool->solvables + p;
1561 case SOLVABLE_PROVIDES:
1562 s->provides = repo_set_idarray_solvable(repo, q);
1564 case SOLVABLE_OBSOLETES:
1565 s->obsoletes = repo_set_idarray_solvable(repo, q);
1567 case SOLVABLE_CONFLICTS:
1568 s->conflicts = repo_set_idarray_solvable(repo, q);
1570 case SOLVABLE_REQUIRES:
1571 s->requires = repo_set_idarray_solvable(repo, q);
1573 case SOLVABLE_RECOMMENDS:
1574 s->recommends = repo_set_idarray_solvable(repo, q);
1576 case SOLVABLE_SUGGESTS:
1577 s->suggests = repo_set_idarray_solvable(repo, q);
1579 case SOLVABLE_SUPPLEMENTS:
1580 s->supplements = repo_set_idarray_solvable(repo, q);
1582 case SOLVABLE_ENHANCES:
1583 s->enhances = repo_set_idarray_solvable(repo, q);
1587 data = repo_last_repodata(repo);
1588 repodata_set_idarray(data, p, keyname, q);
1592 repo_set_idarray(Repo *repo, Id p, Id keyname, Queue *q)
1594 repo_set_deparray(repo, p, keyname, q, 0);
1598 repo_internalize(Repo *repo)
1603 FOR_REPODATAS(repo, i, data)
1604 if (data->attrs || data->xattrs)
1605 repodata_internalize(data);
1609 repo_disable_paging(Repo *repo)
1614 FOR_REPODATAS(repo, i, data)
1615 repodata_disable_paging(data);
1619 vim:cinoptions={.5s,g0,p5,t0,(0,^-0.5s,n-0.5s:tw=78:cindent:sw=4: