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)
203 if (data->end > repo->end)
204 repodata_shrink(data, repo->end);
205 dstart = data->start > start ? data->start : start;
206 dend = data->end < start + count ? data->end : start + count;
212 for (j = dstart; j < dend; j++)
213 data->attrs[j - data->start] = solv_free(data->attrs[j - data->start]);
215 if (data->incoreoffset)
216 memset(data->incoreoffset + (dstart - data->start), 0, (dend - dstart) * sizeof(Id));
222 /* repository sidedata is solvable data allocated on demand.
223 * It is used for data that is normally not present
224 * in the solvable like the rpmdbid.
225 * The solvable allocation funcions need to make sure that
226 * the sidedata gets extended if new solvables get added.
229 #define REPO_SIDEDATA_BLOCK 63
232 repo_sidedata_create(Repo *repo, size_t size)
234 return solv_calloc_block(repo->end - repo->start, size, REPO_SIDEDATA_BLOCK);
238 repo_sidedata_extend(Repo *repo, void *b, size_t size, Id p, int count)
240 int n = repo->end - repo->start;
243 int d = repo->start - p;
244 b = solv_extend(b, n, d, size, REPO_SIDEDATA_BLOCK);
245 memmove((char *)b + d * size, b, n * size);
246 memset(b, 0, d * size);
249 if (p + count > repo->end)
251 int d = p + count - repo->end;
252 b = solv_extend(b, n, d, size, REPO_SIDEDATA_BLOCK);
253 memset((char *)b + n * size, 0, d * size);
259 * add Id to idarraydata used to store dependencies
260 * olddeps: old array offset to extend
261 * returns new array offset
265 repo_addid(Repo *repo, Offset olddeps, Id id)
271 idarray = repo->idarraydata;
272 idarraysize = repo->idarraysize;
274 if (!idarray) /* alloc idarray if not done yet */
277 idarray = solv_extend_resize(0, 1, sizeof(Id), IDARRAY_BLOCK);
282 if (!olddeps) /* no deps yet */
284 olddeps = idarraysize;
285 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
287 else if (olddeps == repo->lastoff) /* extend at end */
289 else /* can't extend, copy old */
292 olddeps = idarraysize;
293 for (; idarray[i]; i++)
295 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
296 idarray[idarraysize++] = idarray[i];
298 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
301 idarray[idarraysize++] = id; /* insert Id into array */
302 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
303 idarray[idarraysize++] = 0; /* ensure NULL termination */
305 repo->idarraydata = idarray;
306 repo->idarraysize = idarraysize;
307 repo->lastoff = olddeps;
312 #define REPO_ADDID_DEP_HASHTHRES 64
313 #define REPO_ADDID_DEP_HASHMIN 128
316 * Optimization for packages with an excessive amount of provides/requires:
317 * if the number of deps exceed a threshold, we build a hash of the already
321 repo_addid_dep_hash(Repo *repo, Offset olddeps, Id id, Id marker, int size)
340 /* maintain hash and lastmarkerpos */
341 if (repo->lastidhash_idarraysize != repo->idarraysize || size * 2 > repo->lastidhash_mask || repo->lastmarker != marker)
343 repo->lastmarkerpos = 0;
344 if (size * 2 > repo->lastidhash_mask)
346 repo->lastidhash_mask = mkmask(size < REPO_ADDID_DEP_HASHMIN ? REPO_ADDID_DEP_HASHMIN : size);
347 repo->lastidhash = solv_realloc2(repo->lastidhash, repo->lastidhash_mask + 1, sizeof(Id));
349 memset(repo->lastidhash, 0, (repo->lastidhash_mask + 1) * sizeof(Id));
350 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
352 h = oid & repo->lastidhash_mask;
353 hh = HASHCHAIN_START;
354 while (repo->lastidhash[h] != 0)
355 h = HASHCHAIN_NEXT(h, hh, repo->lastidhash_mask);
356 repo->lastidhash[h] = oid;
357 if (marker && oid == marker)
358 repo->lastmarkerpos = oidp - repo->idarraydata;
360 repo->lastmarker = marker;
361 repo->lastidhash_idarraysize = repo->idarraysize;
364 /* check the hash! */
365 h = id & repo->lastidhash_mask;
366 hh = HASHCHAIN_START;
367 while ((hid = repo->lastidhash[h]) != 0 && hid != id)
368 h = HASHCHAIN_NEXT(h, hh, repo->lastidhash_mask);
369 /* put new element in hash */
371 repo->lastidhash[h] = id;
372 else if (marker == SOLVABLE_FILEMARKER && (!before || !repo->lastmarkerpos))
374 if (marker && !before && !repo->lastmarkerpos)
376 /* we have to add the marker first */
377 repo->lastmarkerpos = repo->idarraysize - 1;
378 olddeps = repo_addid(repo, olddeps, marker);
379 /* now put marker in hash */
380 h = marker & repo->lastidhash_mask;
381 hh = HASHCHAIN_START;
382 while (repo->lastidhash[h] != 0)
383 h = HASHCHAIN_NEXT(h, hh, repo->lastidhash_mask);
384 repo->lastidhash[h] = marker;
385 repo->lastidhash_idarraysize = repo->idarraysize;
389 /* new entry, insert in correct position */
390 if (marker && before && repo->lastmarkerpos)
392 /* need to add it before the marker */
393 olddeps = repo_addid(repo, olddeps, id); /* dummy to make room */
394 memmove(repo->idarraydata + repo->lastmarkerpos + 1, repo->idarraydata + repo->lastmarkerpos, (repo->idarraysize - repo->lastmarkerpos - 2) * sizeof(Id));
395 repo->idarraydata[repo->lastmarkerpos++] = id;
399 /* just append it to the end */
400 olddeps = repo_addid(repo, olddeps, id);
402 repo->lastidhash_idarraysize = repo->idarraysize;
405 /* we already have it in the hash */
408 if (marker == SOLVABLE_FILEMARKER)
410 /* check if it is in the wrong half */
411 /* (we already made sure that "before" and "lastmarkerpos" are set, see above) */
412 for (oidp = repo->idarraydata + repo->lastmarkerpos + 1; (oid = *oidp) != 0; oidp++)
417 /* yes, wrong half. copy it over */
418 memmove(repo->idarraydata + repo->lastmarkerpos + 1, repo->idarraydata + repo->lastmarkerpos, (oidp - (repo->idarraydata + repo->lastmarkerpos)) * sizeof(Id));
419 repo->idarraydata[repo->lastmarkerpos++] = id;
424 /* check if it is in the correct half */
425 for (oidp = repo->idarraydata + repo->lastmarkerpos + 1; (oid = *oidp) != 0; oidp++)
428 /* nope, copy it over */
429 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
433 return olddeps; /* should not happen */
434 memmove(oidp, oidp + 1, (repo->idarraydata + repo->idarraysize - oidp - 2) * sizeof(Id));
435 repo->idarraydata[repo->idarraysize - 2] = id;
436 repo->lastmarkerpos--; /* marker has been moved */
441 * add dependency (as Id) to repo, also unifies dependencies
442 * olddeps = offset into idarraydata
443 * marker= 0 for normal dep
444 * marker > 0 add dep after marker
445 * marker < 0 add dep before -marker
446 * returns new start of dependency array
449 repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker)
451 Id oid, *oidp, *markerp;
457 olddeps = repo_addid(repo, olddeps, marker);
458 return repo_addid(repo, olddeps, id);
461 /* check if we should use the hash optimization */
462 if (olddeps == repo->lastoff)
464 int size = repo->idarraysize - 1 - repo->lastoff;
465 if (size >= REPO_ADDID_DEP_HASHTHRES)
466 return repo_addid_dep_hash(repo, olddeps, id, marker, size);
483 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
486 return repo_addid(repo, olddeps, id);
490 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
500 if (marker == SOLVABLE_FILEMARKER)
502 if (!markerp || !before)
504 /* we found it, but in the second half */
505 memmove(markerp + 1, markerp, (oidp - markerp) * sizeof(Id));
509 if (markerp || before)
511 /* we found it, but in the first half */
513 for (; (oid = *oidp) != 0; oidp++)
518 /* no marker in array yet */
521 memmove(markerp, markerp + 1, (oidp - markerp) * sizeof(Id));
523 return repo_addid(repo, olddeps, id);
527 memmove(markerp, markerp + 1, (oidp - markerp) * sizeof(Id));
531 /* id not yet in array */
532 if (!before && !markerp)
533 olddeps = repo_addid(repo, olddeps, marker);
534 else if (before && markerp)
539 memmove(markerp + 1, markerp, (oidp - markerp) * sizeof(Id));
542 return repo_addid(repo, olddeps, id);
548 * make space for 'num' more dependencies
549 * returns new start of dependency array
551 * reserved ids will always begin at offset idarraysize
555 repo_reserve_ids(Repo *repo, Offset olddeps, int num)
557 num++; /* room for trailing ID_NULL */
559 if (!repo->idarraysize) /* ensure buffer space */
561 repo->idarraysize = 1;
562 repo->idarraydata = solv_extend_resize(0, 1 + num, sizeof(Id), IDARRAY_BLOCK);
563 repo->idarraydata[0] = 0;
568 if (olddeps && olddeps != repo->lastoff) /* if not appending */
570 /* can't insert into idarray, this would invalidate all 'larger' offsets
571 * so create new space at end and move existing deps there.
572 * Leaving 'hole' at old position.
578 for (idstart = idend = repo->idarraydata + olddeps; *idend++; ) /* find end */
580 count = idend - idstart - 1 + num; /* new size */
582 repo->idarraydata = solv_extend(repo->idarraydata, repo->idarraysize, count, sizeof(Id), IDARRAY_BLOCK);
583 /* move old deps to end */
584 olddeps = repo->lastoff = repo->idarraysize;
585 memcpy(repo->idarraydata + olddeps, idstart, count - num);
586 repo->idarraysize = olddeps + count - num;
591 if (olddeps) /* appending */
595 repo->idarraydata = solv_extend(repo->idarraydata, repo->idarraysize, num, sizeof(Id), IDARRAY_BLOCK);
597 /* appending or new */
598 repo->lastoff = olddeps ? olddeps : repo->idarraysize;
600 return repo->lastoff;
604 /***********************************************************************/
607 * some SUSE specific fixups, should go into a separate file
611 repo_fix_supplements(Repo *repo, Offset provides, Offset supplements, Offset freshens)
613 Pool *pool = repo->pool;
615 char buf[1024], *p, *dep;
620 for (i = provides; repo->idarraydata[i]; i++)
622 id = repo->idarraydata[i];
625 dep = (char *)pool_id2str(pool, id);
626 if (!strncmp(dep, "locale(", 7) && strlen(dep) < sizeof(buf) - 2)
629 strcpy(buf + 2, dep);
631 if ((p = strchr(dep, ':')) != 0 && p != dep)
634 idp = pool_str2id(pool, dep, 1);
638 while ((p = strchr(dep, ';')) != 0)
646 idl = pool_str2id(pool, dep, 1);
647 idl = pool_rel2id(pool, NAMESPACE_LANGUAGE, idl, REL_NAMESPACE, 1);
649 id = pool_rel2id(pool, id, idl, REL_OR, 1);
654 if (dep[0] && dep[1])
656 for (p = dep; *p && *p != ')'; p++)
659 idl = pool_str2id(pool, dep, 1);
660 idl = pool_rel2id(pool, NAMESPACE_LANGUAGE, idl, REL_NAMESPACE, 1);
662 id = pool_rel2id(pool, id, idl, REL_OR, 1);
667 id = pool_rel2id(pool, idp, id, REL_AND, 1);
669 supplements = repo_addid_dep(repo, supplements, id, 0);
671 else if ((p = strchr(dep, ':')) != 0 && p != dep && p[1] == '/' && strlen(dep) < sizeof(buf))
676 idp = pool_str2id(pool, buf, 1);
677 /* strip trailing slashes */
679 while (l > 1 && p[l - 1] == '/')
681 id = pool_str2id(pool, p, 1);
682 id = pool_rel2id(pool, idp, id, REL_WITH, 1);
683 id = pool_rel2id(pool, NAMESPACE_SPLITPROVIDES, id, REL_NAMESPACE, 1);
684 supplements = repo_addid_dep(repo, supplements, id, 0);
690 for (i = supplements; repo->idarraydata[i]; i++)
692 id = repo->idarraydata[i];
695 dep = (char *)pool_id2str(pool, id);
696 if (!strncmp(dep, "system:modalias(", 16))
698 if (!strncmp(dep, "modalias(", 9) && dep[9] && dep[10] && strlen(dep) < sizeof(buf))
701 p = strchr(buf + 9, ':');
702 if (p && p != buf + 9 && strchr(p + 1, ':'))
705 idp = pool_str2id(pool, buf + 9, 1);
706 p[strlen(p) - 1] = 0;
707 id = pool_str2id(pool, p, 1);
708 id = pool_rel2id(pool, NAMESPACE_MODALIAS, id, REL_NAMESPACE, 1);
709 id = pool_rel2id(pool, idp, id, REL_AND, 1);
714 p[strlen(p) - 1] = 0;
715 id = pool_str2id(pool, p, 1);
716 id = pool_rel2id(pool, NAMESPACE_MODALIAS, id, REL_NAMESPACE, 1);
719 repo->idarraydata[i] = id;
721 else if (!strncmp(dep, "packageand(", 11) && strlen(dep) < sizeof(buf))
726 while ((p = strchr(dep, ':')) != 0)
733 /* argh, allow pattern: prefix. sigh */
734 if (p - dep == 7 && !strncmp(dep, "pattern", 7))
736 p = strchr(p + 1, ':');
741 idp = pool_str2id(pool, dep, 1);
743 id = pool_rel2id(pool, id, idp, REL_AND, 1);
748 if (dep[0] && dep[1])
750 dep[strlen(dep) - 1] = 0;
751 idp = pool_str2id(pool, dep, 1);
753 id = pool_rel2id(pool, id, idp, REL_AND, 1);
758 repo->idarraydata[i] = id;
760 else if (!strncmp(dep, "filesystem(", 11) && strlen(dep) < sizeof(buf))
762 strcpy(buf, dep + 11);
763 if ((p = strrchr(buf, ')')) != 0)
765 id = pool_str2id(pool, buf, 1);
766 id = pool_rel2id(pool, NAMESPACE_FILESYSTEM, id, REL_NAMESPACE, 1);
767 repo->idarraydata[i] = id;
771 if (freshens && repo->idarraydata[freshens])
773 Id idsupp = 0, idfresh = 0;
774 if (!supplements || !repo->idarraydata[supplements])
776 for (i = supplements; repo->idarraydata[i]; i++)
779 idsupp = repo->idarraydata[i];
781 idsupp = pool_rel2id(pool, idsupp, repo->idarraydata[i], REL_OR, 1);
783 for (i = freshens; repo->idarraydata[i]; i++)
786 idfresh = repo->idarraydata[i];
788 idfresh = pool_rel2id(pool, idfresh, repo->idarraydata[i], REL_OR, 1);
793 idsupp = pool_rel2id(pool, idsupp, idfresh, REL_AND, 1);
794 supplements = repo_addid_dep(repo, 0, idsupp, 0);
800 repo_fix_conflicts(Repo *repo, Offset conflicts)
802 char buf[1024], *p, *dep;
803 Pool *pool = repo->pool;
809 for (i = conflicts; repo->idarraydata[i]; i++)
811 id = repo->idarraydata[i];
814 dep = (char *)pool_id2str(pool, id);
815 if (!strncmp(dep, "otherproviders(", 15) && strlen(dep) < sizeof(buf) - 2)
817 strcpy(buf, dep + 15);
818 if ((p = strchr(buf, ')')) != 0)
820 id = pool_str2id(pool, buf, 1);
821 id = pool_rel2id(pool, NAMESPACE_OTHERPROVIDERS, id, REL_NAMESPACE, 1);
822 repo->idarraydata[i] = id;
828 /***********************************************************************/
836 int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv);
841 repo_matchvalue(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
843 struct matchdata *md = cbdata;
845 if (md->matcher.match)
847 if (!repodata_stringify(md->pool, data, key, kv, md->flags))
849 if (!datamatcher_match(&md->matcher, kv->str))
852 md->stop = md->callback(md->callback_data, s, data, key, kv);
857 /* list of all keys we store in the solvable */
858 /* also used in the dataiterator code in repodata.c */
859 Repokey repo_solvablekeys[RPM_RPMDBID - SOLVABLE_NAME + 1] = {
860 { SOLVABLE_NAME, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
861 { SOLVABLE_ARCH, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
862 { SOLVABLE_EVR, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
863 { SOLVABLE_VENDOR, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
864 { SOLVABLE_PROVIDES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
865 { SOLVABLE_OBSOLETES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
866 { SOLVABLE_CONFLICTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
867 { SOLVABLE_REQUIRES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
868 { SOLVABLE_RECOMMENDS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
869 { SOLVABLE_SUGGESTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
870 { SOLVABLE_SUPPLEMENTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
871 { SOLVABLE_ENHANCES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
872 { RPM_RPMDBID, REPOKEY_TYPE_NUM, 0, KEY_STORAGE_SOLVABLE },
876 domatch_idarray(Solvable *s, Id keyname, struct matchdata *md, Id *ida)
881 for (; *ida && !md->stop; ida++)
884 kv.eof = ida[1] ? 0 : 1;
885 repo_matchvalue(md, s, 0, repo_solvablekeys + (keyname - SOLVABLE_NAME), &kv);
891 repo_search_md(Repo *repo, Id p, Id keyname, struct matchdata *md)
894 Pool *pool = repo->pool;
903 for (p = repo->start, s = repo->pool->solvables + p; p < repo->end; p++, s++)
906 repo_search_md(repo, p, keyname, md);
907 if (md->stop > SEARCH_NEXT_SOLVABLE)
913 /* The callback only supports solvables, so we can't iterate over the
917 if (!(flags & SEARCH_NO_STORAGE_SOLVABLE))
919 s = pool->solvables + p;
927 repo_matchvalue(md, s, 0, repo_solvablekeys + 0, &kv);
929 if (keyname || md->stop > SEARCH_NEXT_KEY)
935 repo_matchvalue(md, s, 0, repo_solvablekeys + 1, &kv);
937 if (keyname || md->stop > SEARCH_NEXT_KEY)
943 repo_matchvalue(md, s, 0, repo_solvablekeys + 2, &kv);
945 if (keyname || md->stop > SEARCH_NEXT_KEY)
947 case SOLVABLE_VENDOR:
951 repo_matchvalue(md, s, 0, repo_solvablekeys + 3, &kv);
953 if (keyname || md->stop > SEARCH_NEXT_KEY)
955 case SOLVABLE_PROVIDES:
957 domatch_idarray(s, SOLVABLE_PROVIDES, md, repo->idarraydata + s->provides);
958 if (keyname || md->stop > SEARCH_NEXT_KEY)
960 case SOLVABLE_OBSOLETES:
962 domatch_idarray(s, SOLVABLE_OBSOLETES, md, repo->idarraydata + s->obsoletes);
963 if (keyname || md->stop > SEARCH_NEXT_KEY)
965 case SOLVABLE_CONFLICTS:
967 domatch_idarray(s, SOLVABLE_CONFLICTS, md, repo->idarraydata + s->conflicts);
968 if (keyname || md->stop > SEARCH_NEXT_KEY)
970 case SOLVABLE_REQUIRES:
972 domatch_idarray(s, SOLVABLE_REQUIRES, md, repo->idarraydata + s->requires);
973 if (keyname || md->stop > SEARCH_NEXT_KEY)
975 case SOLVABLE_RECOMMENDS:
977 domatch_idarray(s, SOLVABLE_RECOMMENDS, md, repo->idarraydata + s->recommends);
978 if (keyname || md->stop > SEARCH_NEXT_KEY)
980 case SOLVABLE_SUPPLEMENTS:
982 domatch_idarray(s, SOLVABLE_SUPPLEMENTS, md, repo->idarraydata + s->supplements);
983 if (keyname || md->stop > SEARCH_NEXT_KEY)
985 case SOLVABLE_SUGGESTS:
987 domatch_idarray(s, SOLVABLE_SUGGESTS, md, repo->idarraydata + s->suggests);
988 if (keyname || md->stop > SEARCH_NEXT_KEY)
990 case SOLVABLE_ENHANCES:
992 domatch_idarray(s, SOLVABLE_ENHANCES, md, repo->idarraydata + s->enhances);
993 if (keyname || md->stop > SEARCH_NEXT_KEY)
998 kv.num = repo->rpmdbid[p - repo->start];
1000 repo_matchvalue(md, s, 0, repo_solvablekeys + (RPM_RPMDBID - SOLVABLE_NAME), &kv);
1002 if (keyname || md->stop > SEARCH_NEXT_KEY)
1010 FOR_REPODATAS(repo, i, data)
1012 if (p < data->start || p >= data->end)
1014 if (keyname && !repodata_precheck_keyname(data, keyname))
1016 if (keyname == SOLVABLE_FILELIST && !(md->flags & SEARCH_COMPLETE_FILELIST))
1018 /* do not search filelist extensions */
1019 if (data->state != REPODATA_AVAILABLE)
1021 for (j = 1; j < data->nkeys; j++)
1022 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1024 if (j == data->nkeys)
1027 if (data->state == REPODATA_STUB)
1031 for (j = 1; j < data->nkeys; j++)
1032 if (keyname == data->keys[j].name)
1034 if (j == data->nkeys)
1038 if (data->loadcallback)
1039 data->loadcallback(data);
1041 data->state = REPODATA_ERROR;
1043 if (data->state == REPODATA_ERROR)
1045 repodata_search(data, p, keyname, md->flags, repo_matchvalue, md);
1046 if (md->stop > SEARCH_NEXT_KEY)
1052 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)
1054 struct matchdata md;
1056 if (repo->disabled && !(flags & SEARCH_DISABLED_REPOS))
1058 memset(&md, 0, sizeof(md));
1059 md.pool = repo->pool;
1061 md.callback = callback;
1062 md.callback_data = cbdata;
1064 datamatcher_init(&md.matcher, match, flags);
1065 repo_search_md(repo, p, keyname, &md);
1067 datamatcher_free(&md.matcher);
1071 repo_lookup_str(Repo *repo, Id entry, Id keyname)
1073 Pool *pool = repo->pool;
1083 return pool_id2str(pool, pool->solvables[entry].name);
1085 return pool_id2str(pool, pool->solvables[entry].arch);
1087 return pool_id2str(pool, pool->solvables[entry].evr);
1088 case SOLVABLE_VENDOR:
1089 return pool_id2str(pool, pool->solvables[entry].vendor);
1092 FOR_REPODATAS(repo, i, data)
1094 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1096 if (!repodata_precheck_keyname(data, keyname))
1098 str = repodata_lookup_str(data, entry, keyname);
1101 if (repodata_lookup_type(data, entry, keyname))
1109 repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned long long notfound)
1113 unsigned long long value;
1117 if (keyname == RPM_RPMDBID)
1119 if (repo->rpmdbid && entry >= repo->start && entry < repo->end)
1120 return repo->rpmdbid[entry - repo->start];
1124 FOR_REPODATAS(repo, i, data)
1126 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1128 if (!repodata_precheck_keyname(data, keyname))
1130 if (repodata_lookup_num(data, entry, keyname, &value))
1132 if (repodata_lookup_type(data, entry, keyname))
1139 repo_lookup_id(Repo *repo, Id entry, Id keyname)
1150 return repo->pool->solvables[entry].name;
1152 return repo->pool->solvables[entry].arch;
1154 return repo->pool->solvables[entry].evr;
1155 case SOLVABLE_VENDOR:
1156 return repo->pool->solvables[entry].vendor;
1159 FOR_REPODATAS(repo, i, data)
1161 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1163 if (!repodata_precheck_keyname(data, keyname))
1165 id = repodata_lookup_id(data, entry, keyname);
1167 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1168 if (repodata_lookup_type(data, entry, keyname))
1175 lookup_idarray_solvable(Repo *repo, Offset off, Queue *q)
1181 for (p = repo->idarraydata + off; *p; p++)
1187 repo_lookup_idarray(Repo *repo, Id entry, Id keyname, Queue *q)
1195 case SOLVABLE_PROVIDES:
1196 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].provides, q);
1197 case SOLVABLE_OBSOLETES:
1198 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].obsoletes, q);
1199 case SOLVABLE_CONFLICTS:
1200 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].conflicts, q);
1201 case SOLVABLE_REQUIRES:
1202 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].requires, q);
1203 case SOLVABLE_RECOMMENDS:
1204 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].recommends, q);
1205 case SOLVABLE_SUGGESTS:
1206 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].suggests, q);
1207 case SOLVABLE_SUPPLEMENTS:
1208 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].supplements, q);
1209 case SOLVABLE_ENHANCES:
1210 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].enhances, q);
1213 FOR_REPODATAS(repo, i, data)
1215 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1217 if (!repodata_precheck_keyname(data, keyname))
1219 if (repodata_lookup_idarray(data, entry, keyname, q))
1221 if (data->localpool)
1223 for (i = 0; i < q->count; i++)
1224 q->elements[i] = repodata_globalize_id(data, q->elements[i], 1);
1228 if (repodata_lookup_type(data, entry, keyname))
1236 repo_lookup_deparray(Repo *repo, Id entry, Id keyname, Queue *q, Id marker)
1238 int r = repo_lookup_idarray(repo, entry, keyname, q);
1239 if (r && marker && q->count)
1245 for (i = 0; i < q->count; i++)
1246 if (q->elements[i] == marker)
1248 queue_truncate(q, i);
1254 for (i = 0; i < q->count; i++)
1255 if (q->elements[i] == marker)
1257 queue_deleten(q, 0, i + 1);
1266 const unsigned char *
1267 repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
1271 const unsigned char *chk;
1273 FOR_REPODATAS(repo, i, data)
1275 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1277 if (!repodata_precheck_keyname(data, keyname))
1279 chk = repodata_lookup_bin_checksum(data, entry, keyname, typep);
1282 if (repodata_lookup_type(data, entry, keyname))
1290 repo_lookup_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
1292 const unsigned char *chk = repo_lookup_bin_checksum(repo, entry, keyname, typep);
1293 return chk ? pool_bin2hex(repo->pool, chk, solv_chksum_len(*typep)) : 0;
1297 repo_lookup_void(Repo *repo, Id entry, Id keyname)
1303 FOR_REPODATAS(repo, i, data)
1305 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1307 if (!repodata_precheck_keyname(data, keyname))
1309 type = repodata_lookup_type(data, entry, keyname);
1311 return type == REPOKEY_TYPE_VOID;
1317 repo_lookup_type(Repo *repo, Id entry, Id keyname)
1323 FOR_REPODATAS(repo, i, data)
1325 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1327 if (!repodata_precheck_keyname(data, keyname))
1329 type = repodata_lookup_type(data, entry, keyname);
1331 return type == REPOKEY_TYPE_DELETED ? 0 : type;
1336 /***********************************************************************/
1339 repo_add_repodata(Repo *repo, int flags)
1343 if ((flags & REPO_USE_LOADING) != 0)
1345 for (i = repo->nrepodata - 1; i > 0; i--)
1346 if (repo->repodata[i].state == REPODATA_LOADING)
1348 Repodata *data = repo->repodata + i;
1350 /* hack: we mis-use REPO_REUSE_REPODATA here */
1351 if (!(flags & REPO_REUSE_REPODATA))
1352 repodata_empty(data, (flags & REPO_LOCALPOOL) ? 1 : 0);
1355 return 0; /* must not create a new repodata! */
1357 if ((flags & REPO_REUSE_REPODATA) != 0)
1359 for (i = repo->nrepodata - 1; i > 0; i--)
1360 if (repo->repodata[i].state != REPODATA_STUB)
1361 return repo->repodata + i;
1363 if (!repo->nrepodata)
1365 repo->nrepodata = 2; /* start with id 1 */
1366 repo->repodata = solv_calloc(repo->nrepodata, sizeof(*data));
1371 repo->repodata = solv_realloc2(repo->repodata, repo->nrepodata, sizeof(*data));
1373 data = repo->repodata + repo->nrepodata - 1;
1374 repodata_initdata(data, repo, (flags & REPO_LOCALPOOL) ? 1 : 0);
1379 repo_id2repodata(Repo *repo, Id id)
1381 return id ? repo->repodata + id : 0;
1385 repo_last_repodata(Repo *repo)
1388 for (i = repo->nrepodata - 1; i > 0; i--)
1389 if (repo->repodata[i].state != REPODATA_STUB)
1390 return repo->repodata + i;
1391 return repo_add_repodata(repo, 0);
1395 repo_set_id(Repo *repo, Id p, Id keyname, Id id)
1403 repo->pool->solvables[p].name = id;
1406 repo->pool->solvables[p].arch = id;
1409 repo->pool->solvables[p].evr = id;
1411 case SOLVABLE_VENDOR:
1412 repo->pool->solvables[p].vendor = id;
1416 data = repo_last_repodata(repo);
1417 if (data->localpool)
1418 id = repodata_localize_id(data, id, 1);
1419 repodata_set_id(data, p, keyname, id);
1423 repo_set_num(Repo *repo, Id p, Id keyname, unsigned long long num)
1428 if (keyname == RPM_RPMDBID)
1431 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1432 repo->rpmdbid[p] = num;
1436 data = repo_last_repodata(repo);
1437 repodata_set_num(data, p, keyname, num);
1441 repo_set_str(Repo *repo, Id p, Id keyname, const char *str)
1451 case SOLVABLE_VENDOR:
1452 repo_set_id(repo, p, keyname, pool_str2id(repo->pool, str, 1));
1456 data = repo_last_repodata(repo);
1457 repodata_set_str(data, p, keyname, str);
1461 repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str)
1471 case SOLVABLE_VENDOR:
1472 repo_set_id(repo, p, keyname, pool_str2id(repo->pool, str, 1));
1476 data = repo_last_repodata(repo);
1477 repodata_set_poolstr(data, p, keyname, str);
1481 repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str)
1483 Repodata *data = repo_last_repodata(repo);
1484 repodata_add_poolstr_array(data, p, keyname, str);
1488 repo_add_deparray(Repo *repo, Id p, Id keyname, Id dep, Id marker)
1493 Solvable *s = repo->pool->solvables + p;
1496 case SOLVABLE_PROVIDES:
1497 s->provides = repo_addid_dep(repo, s->provides, dep, marker);
1499 case SOLVABLE_OBSOLETES:
1500 s->obsoletes = repo_addid_dep(repo, s->obsoletes, dep, marker);
1502 case SOLVABLE_CONFLICTS:
1503 s->conflicts = repo_addid_dep(repo, s->conflicts, dep, marker);
1505 case SOLVABLE_REQUIRES:
1506 s->requires = repo_addid_dep(repo, s->requires, dep, marker);
1508 case SOLVABLE_RECOMMENDS:
1509 s->recommends = repo_addid_dep(repo, s->recommends, dep, marker);
1511 case SOLVABLE_SUGGESTS:
1512 s->suggests = repo_addid_dep(repo, s->suggests, dep, marker);
1514 case SOLVABLE_SUPPLEMENTS:
1515 s->supplements = repo_addid_dep(repo, s->supplements, dep, marker);
1517 case SOLVABLE_ENHANCES:
1518 s->enhances = repo_addid_dep(repo, s->enhances, dep, marker);
1522 data = repo_last_repodata(repo);
1523 repodata_add_idarray(data, p, keyname, dep);
1527 repo_add_idarray(Repo *repo, Id p, Id keyname, Id id)
1529 repo_add_deparray(repo, p, keyname, id, 0);
1533 repo_set_idarray_solvable(Repo *repo, Queue *q)
1537 for (i = 0; i < q->count; i++)
1538 repo_addid_dep(repo, o, q->elements[i], 0);
1543 repo_set_deparray(Repo *repo, Id p, Id keyname, Queue *q, Id marker)
1548 /* complex case, splice old and new arrays */
1552 repo_lookup_deparray(repo, p, keyname, &q2, -marker);
1557 queue_push(&q2, marker);
1558 for (i = 0; i < q->count; i++)
1559 queue_push(&q2, q->elements[i]);
1565 queue_insert(&q2, 0, -marker);
1566 queue_insertn(&q2, 0, q->count);
1567 for (i = 0; i < q->count; i++)
1568 q2.elements[i] = q->elements[i];
1570 repo_set_deparray(repo, p, keyname, &q2, 0);
1576 Solvable *s = repo->pool->solvables + p;
1579 case SOLVABLE_PROVIDES:
1580 s->provides = repo_set_idarray_solvable(repo, q);
1582 case SOLVABLE_OBSOLETES:
1583 s->obsoletes = repo_set_idarray_solvable(repo, q);
1585 case SOLVABLE_CONFLICTS:
1586 s->conflicts = repo_set_idarray_solvable(repo, q);
1588 case SOLVABLE_REQUIRES:
1589 s->requires = repo_set_idarray_solvable(repo, q);
1591 case SOLVABLE_RECOMMENDS:
1592 s->recommends = repo_set_idarray_solvable(repo, q);
1594 case SOLVABLE_SUGGESTS:
1595 s->suggests = repo_set_idarray_solvable(repo, q);
1597 case SOLVABLE_SUPPLEMENTS:
1598 s->supplements = repo_set_idarray_solvable(repo, q);
1600 case SOLVABLE_ENHANCES:
1601 s->enhances = repo_set_idarray_solvable(repo, q);
1605 data = repo_last_repodata(repo);
1606 repodata_set_idarray(data, p, keyname, q);
1610 repo_set_idarray(Repo *repo, Id p, Id keyname, Queue *q)
1612 repo_set_deparray(repo, p, keyname, q, 0);
1616 repo_internalize(Repo *repo)
1621 FOR_REPODATAS(repo, i, data)
1622 if (data->attrs || data->xattrs)
1623 repodata_internalize(data);
1627 repo_disable_paging(Repo *repo)
1632 FOR_REPODATAS(repo, i, data)
1633 repodata_disable_paging(data);
1637 vim:cinoptions={.5s,g0,p5,t0,(0,^-0.5s,n-0.5s:tw=78:cindent:sw=4: