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));
221 /* specialized version of repo_add_solvable_block that inserts the new solvable
222 * block before the indicated repo, which gets relocated.
223 * used in repo_add_rpmdb
226 repo_add_solvable_block_before(Repo *repo, int count, Repo *beforerepo)
228 Pool *pool = repo->pool;
234 if (!count || !beforerepo || beforerepo->end != pool->nsolvables || beforerepo->start == beforerepo->end)
235 return repo_add_solvable_block(repo, count);
236 p = beforerepo->start;
237 /* make sure all solvables belong to beforerepo */
238 for (i = p, s = pool->solvables + i; i < beforerepo->end; i++, s++)
239 if (s->repo && s->repo != beforerepo)
240 return repo_add_solvable_block(repo, count);
241 /* now move beforerepo to back */
242 pool_add_solvable_block(pool, count); /* must return beforerepo->end! */
243 memmove(pool->solvables + p + count, pool->solvables + p, (beforerepo->end - p) * sizeof(Solvable));
244 memset(pool->solvables + p, 0, sizeof(Solvable) * count);
246 FOR_REPODATAS(beforerepo, i, data)
250 data->start += count;
253 beforerepo->start += count;
254 beforerepo->end += count;
255 /* we now have count free solvables at id p */
256 /* warning: sidedata must be extended before adapting start/end */
258 repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, count);
261 if (p + count > repo->end)
262 repo->end = p + count;
263 repo->nsolvables += count;
264 for (s = pool->solvables + p; count--; s++)
270 /* repository sidedata is solvable data allocated on demand.
271 * It is used for data that is normally not present
272 * in the solvable like the rpmdbid.
273 * The solvable allocation funcions need to make sure that
274 * the sidedata gets extended if new solvables get added.
277 #define REPO_SIDEDATA_BLOCK 63
280 repo_sidedata_create(Repo *repo, size_t size)
282 return solv_calloc_block(repo->end - repo->start, size, REPO_SIDEDATA_BLOCK);
286 repo_sidedata_extend(Repo *repo, void *b, size_t size, Id p, int count)
288 int n = repo->end - repo->start;
291 int d = repo->start - p;
292 b = solv_extend(b, n, d, size, REPO_SIDEDATA_BLOCK);
293 memmove((char *)b + d * size, b, n * size);
294 memset(b, 0, d * size);
297 if (p + count > repo->end)
299 int d = p + count - repo->end;
300 b = solv_extend(b, n, d, size, REPO_SIDEDATA_BLOCK);
301 memset((char *)b + n * size, 0, d * size);
307 * add Id to idarraydata used to store dependencies
308 * olddeps: old array offset to extend
309 * returns new array offset
313 repo_addid(Repo *repo, Offset olddeps, Id id)
319 idarray = repo->idarraydata;
320 idarraysize = repo->idarraysize;
322 if (!idarray) /* alloc idarray if not done yet */
325 idarray = solv_extend_resize(0, 1, sizeof(Id), IDARRAY_BLOCK);
330 if (!olddeps) /* no deps yet */
332 olddeps = idarraysize;
333 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
335 else if (olddeps == repo->lastoff) /* extend at end */
337 else /* can't extend, copy old */
340 olddeps = idarraysize;
341 for (; idarray[i]; i++)
343 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
344 idarray[idarraysize++] = idarray[i];
346 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
349 idarray[idarraysize++] = id; /* insert Id into array */
350 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK);
351 idarray[idarraysize++] = 0; /* ensure NULL termination */
353 repo->idarraydata = idarray;
354 repo->idarraysize = idarraysize;
355 repo->lastoff = olddeps;
360 #define REPO_ADDID_DEP_HASHTHRES 64
361 #define REPO_ADDID_DEP_HASHMIN 128
364 * Optimization for packages with an excessive amount of provides/requires:
365 * if the number of deps exceed a threshold, we build a hash of the already
369 repo_addid_dep_hash(Repo *repo, Offset olddeps, Id id, Id marker, int size)
388 /* maintain hash and lastmarkerpos */
389 if (repo->lastidhash_idarraysize != repo->idarraysize || size * 2 > repo->lastidhash_mask || repo->lastmarker != marker)
391 repo->lastmarkerpos = 0;
392 if (size * 2 > repo->lastidhash_mask)
394 repo->lastidhash_mask = mkmask(size < REPO_ADDID_DEP_HASHMIN ? REPO_ADDID_DEP_HASHMIN : size);
395 repo->lastidhash = solv_realloc2(repo->lastidhash, repo->lastidhash_mask + 1, sizeof(Id));
397 memset(repo->lastidhash, 0, (repo->lastidhash_mask + 1) * sizeof(Id));
398 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
400 h = oid & repo->lastidhash_mask;
401 hh = HASHCHAIN_START;
402 while (repo->lastidhash[h] != 0)
403 h = HASHCHAIN_NEXT(h, hh, repo->lastidhash_mask);
404 repo->lastidhash[h] = oid;
405 if (marker && oid == marker)
406 repo->lastmarkerpos = oidp - repo->idarraydata;
408 repo->lastmarker = marker;
409 repo->lastidhash_idarraysize = repo->idarraysize;
412 /* check the hash! */
413 h = id & repo->lastidhash_mask;
414 hh = HASHCHAIN_START;
415 while ((hid = repo->lastidhash[h]) != 0 && hid != id)
416 h = HASHCHAIN_NEXT(h, hh, repo->lastidhash_mask);
417 /* put new element in hash */
419 repo->lastidhash[h] = id;
420 else if (marker == SOLVABLE_FILEMARKER && (!before || !repo->lastmarkerpos))
422 if (marker && !before && !repo->lastmarkerpos)
424 /* we have to add the marker first */
425 repo->lastmarkerpos = repo->idarraysize - 1;
426 olddeps = repo_addid(repo, olddeps, marker);
427 /* now put marker in hash */
428 h = marker & repo->lastidhash_mask;
429 hh = HASHCHAIN_START;
430 while (repo->lastidhash[h] != 0)
431 h = HASHCHAIN_NEXT(h, hh, repo->lastidhash_mask);
432 repo->lastidhash[h] = marker;
433 repo->lastidhash_idarraysize = repo->idarraysize;
437 /* new entry, insert in correct position */
438 if (marker && before && repo->lastmarkerpos)
440 /* need to add it before the marker */
441 olddeps = repo_addid(repo, olddeps, id); /* dummy to make room */
442 memmove(repo->idarraydata + repo->lastmarkerpos + 1, repo->idarraydata + repo->lastmarkerpos, (repo->idarraysize - repo->lastmarkerpos - 2) * sizeof(Id));
443 repo->idarraydata[repo->lastmarkerpos++] = id;
447 /* just append it to the end */
448 olddeps = repo_addid(repo, olddeps, id);
450 repo->lastidhash_idarraysize = repo->idarraysize;
453 /* we already have it in the hash */
456 if (marker == SOLVABLE_FILEMARKER)
458 /* check if it is in the wrong half */
459 /* (we already made sure that "before" and "lastmarkerpos" are set, see above) */
460 for (oidp = repo->idarraydata + repo->lastmarkerpos + 1; (oid = *oidp) != 0; oidp++)
465 /* yes, wrong half. copy it over */
466 memmove(repo->idarraydata + repo->lastmarkerpos + 1, repo->idarraydata + repo->lastmarkerpos, (oidp - (repo->idarraydata + repo->lastmarkerpos)) * sizeof(Id));
467 repo->idarraydata[repo->lastmarkerpos++] = id;
472 /* check if it is in the correct half */
473 for (oidp = repo->idarraydata + repo->lastmarkerpos + 1; (oid = *oidp) != 0; oidp++)
476 /* nope, copy it over */
477 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
481 return olddeps; /* should not happen */
482 memmove(oidp, oidp + 1, (repo->idarraydata + repo->idarraysize - oidp - 2) * sizeof(Id));
483 repo->idarraydata[repo->idarraysize - 2] = id;
484 repo->lastmarkerpos--; /* marker has been moved */
489 * add dependency (as Id) to repo, also unifies dependencies
490 * olddeps = offset into idarraydata
491 * marker= 0 for normal dep
492 * marker > 0 add dep after marker
493 * marker < 0 add dep before -marker
494 * returns new start of dependency array
497 repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker)
499 Id oid, *oidp, *markerp;
505 olddeps = repo_addid(repo, olddeps, marker);
506 return repo_addid(repo, olddeps, id);
509 /* check if we should use the hash optimization */
510 if (olddeps == repo->lastoff)
512 int size = repo->idarraysize - 1 - repo->lastoff;
513 if (size >= REPO_ADDID_DEP_HASHTHRES)
514 return repo_addid_dep_hash(repo, olddeps, id, marker, size);
531 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
534 return repo_addid(repo, olddeps, id);
538 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
548 if (marker == SOLVABLE_FILEMARKER)
550 if (!markerp || !before)
552 /* we found it, but in the second half */
553 memmove(markerp + 1, markerp, (oidp - markerp) * sizeof(Id));
557 if (markerp || before)
559 /* we found it, but in the first half */
561 for (; (oid = *oidp) != 0; oidp++)
566 /* no marker in array yet */
569 memmove(markerp, markerp + 1, (oidp - markerp) * sizeof(Id));
571 return repo_addid(repo, olddeps, id);
575 memmove(markerp, markerp + 1, (oidp - markerp) * sizeof(Id));
579 /* id not yet in array */
580 if (!before && !markerp)
581 olddeps = repo_addid(repo, olddeps, marker);
582 else if (before && markerp)
587 memmove(markerp + 1, markerp, (oidp - markerp) * sizeof(Id));
590 return repo_addid(repo, olddeps, id);
596 * make space for 'num' more dependencies
597 * returns new start of dependency array
599 * reserved ids will always begin at offset idarraysize
603 repo_reserve_ids(Repo *repo, Offset olddeps, int num)
605 num++; /* room for trailing ID_NULL */
607 if (!repo->idarraysize) /* ensure buffer space */
609 repo->idarraysize = 1;
610 repo->idarraydata = solv_extend_resize(0, 1 + num, sizeof(Id), IDARRAY_BLOCK);
611 repo->idarraydata[0] = 0;
616 if (olddeps && olddeps != repo->lastoff) /* if not appending */
618 /* can't insert into idarray, this would invalidate all 'larger' offsets
619 * so create new space at end and move existing deps there.
620 * Leaving 'hole' at old position.
626 for (idstart = idend = repo->idarraydata + olddeps; *idend++; ) /* find end */
628 count = idend - idstart - 1 + num; /* new size */
630 repo->idarraydata = solv_extend(repo->idarraydata, repo->idarraysize, count, sizeof(Id), IDARRAY_BLOCK);
631 /* move old deps to end */
632 olddeps = repo->lastoff = repo->idarraysize;
633 memcpy(repo->idarraydata + olddeps, idstart, count - num);
634 repo->idarraysize = olddeps + count - num;
639 if (olddeps) /* appending */
643 repo->idarraydata = solv_extend(repo->idarraydata, repo->idarraysize, num, sizeof(Id), IDARRAY_BLOCK);
645 /* appending or new */
646 repo->lastoff = olddeps ? olddeps : repo->idarraysize;
648 return repo->lastoff;
652 /***********************************************************************/
655 * some SUSE specific fixups, should go into a separate file
659 repo_fix_supplements(Repo *repo, Offset provides, Offset supplements, Offset freshens)
661 Pool *pool = repo->pool;
663 char buf[1024], *p, *dep;
668 for (i = provides; repo->idarraydata[i]; i++)
670 id = repo->idarraydata[i];
673 dep = (char *)pool_id2str(pool, id);
674 if (!strncmp(dep, "locale(", 7) && strlen(dep) < sizeof(buf) - 2)
677 strcpy(buf + 2, dep);
679 if ((p = strchr(dep, ':')) != 0 && p != dep)
682 idp = pool_str2id(pool, dep, 1);
686 while ((p = strchr(dep, ';')) != 0)
694 idl = pool_str2id(pool, dep, 1);
695 idl = pool_rel2id(pool, NAMESPACE_LANGUAGE, idl, REL_NAMESPACE, 1);
697 id = pool_rel2id(pool, id, idl, REL_OR, 1);
702 if (dep[0] && dep[1])
704 for (p = dep; *p && *p != ')'; p++)
707 idl = pool_str2id(pool, dep, 1);
708 idl = pool_rel2id(pool, NAMESPACE_LANGUAGE, idl, REL_NAMESPACE, 1);
710 id = pool_rel2id(pool, id, idl, REL_OR, 1);
715 id = pool_rel2id(pool, idp, id, REL_AND, 1);
717 supplements = repo_addid_dep(repo, supplements, id, 0);
719 else if ((p = strchr(dep, ':')) != 0 && p != dep && p[1] == '/' && strlen(dep) < sizeof(buf))
724 idp = pool_str2id(pool, buf, 1);
725 /* strip trailing slashes */
727 while (l > 1 && p[l - 1] == '/')
729 id = pool_str2id(pool, p, 1);
730 id = pool_rel2id(pool, idp, id, REL_WITH, 1);
731 id = pool_rel2id(pool, NAMESPACE_SPLITPROVIDES, id, REL_NAMESPACE, 1);
732 supplements = repo_addid_dep(repo, supplements, id, 0);
738 for (i = supplements; repo->idarraydata[i]; i++)
740 id = repo->idarraydata[i];
743 dep = (char *)pool_id2str(pool, id);
744 if (!strncmp(dep, "system:modalias(", 16))
746 if (!strncmp(dep, "modalias(", 9) && dep[9] && dep[10] && strlen(dep) < sizeof(buf))
749 p = strchr(buf + 9, ':');
750 if (p && p != buf + 9 && strchr(p + 1, ':'))
753 idp = pool_str2id(pool, buf + 9, 1);
754 p[strlen(p) - 1] = 0;
755 id = pool_str2id(pool, p, 1);
756 id = pool_rel2id(pool, NAMESPACE_MODALIAS, id, REL_NAMESPACE, 1);
757 id = pool_rel2id(pool, idp, id, REL_AND, 1);
762 p[strlen(p) - 1] = 0;
763 id = pool_str2id(pool, p, 1);
764 id = pool_rel2id(pool, NAMESPACE_MODALIAS, id, REL_NAMESPACE, 1);
767 repo->idarraydata[i] = id;
769 else if (!strncmp(dep, "packageand(", 11) && strlen(dep) < sizeof(buf))
774 while ((p = strchr(dep, ':')) != 0)
781 /* argh, allow pattern: prefix. sigh */
782 if (p - dep == 7 && !strncmp(dep, "pattern", 7))
784 p = strchr(p + 1, ':');
789 idp = pool_str2id(pool, dep, 1);
791 id = pool_rel2id(pool, id, idp, REL_AND, 1);
796 if (dep[0] && dep[1])
798 dep[strlen(dep) - 1] = 0;
799 idp = pool_str2id(pool, dep, 1);
801 id = pool_rel2id(pool, id, idp, REL_AND, 1);
806 repo->idarraydata[i] = id;
808 else if (!strncmp(dep, "filesystem(", 11) && strlen(dep) < sizeof(buf))
810 strcpy(buf, dep + 11);
811 if ((p = strrchr(buf, ')')) != 0)
813 id = pool_str2id(pool, buf, 1);
814 id = pool_rel2id(pool, NAMESPACE_FILESYSTEM, id, REL_NAMESPACE, 1);
815 repo->idarraydata[i] = id;
819 if (freshens && repo->idarraydata[freshens])
821 Id idsupp = 0, idfresh = 0;
822 if (!supplements || !repo->idarraydata[supplements])
824 for (i = supplements; repo->idarraydata[i]; i++)
827 idsupp = repo->idarraydata[i];
829 idsupp = pool_rel2id(pool, idsupp, repo->idarraydata[i], REL_OR, 1);
831 for (i = freshens; repo->idarraydata[i]; i++)
834 idfresh = repo->idarraydata[i];
836 idfresh = pool_rel2id(pool, idfresh, repo->idarraydata[i], REL_OR, 1);
841 idsupp = pool_rel2id(pool, idsupp, idfresh, REL_AND, 1);
842 supplements = repo_addid_dep(repo, 0, idsupp, 0);
848 repo_fix_conflicts(Repo *repo, Offset conflicts)
850 char buf[1024], *p, *dep;
851 Pool *pool = repo->pool;
857 for (i = conflicts; repo->idarraydata[i]; i++)
859 id = repo->idarraydata[i];
862 dep = (char *)pool_id2str(pool, id);
863 if (!strncmp(dep, "otherproviders(", 15) && strlen(dep) < sizeof(buf) - 2)
865 strcpy(buf, dep + 15);
866 if ((p = strchr(buf, ')')) != 0)
868 id = pool_str2id(pool, buf, 1);
869 id = pool_rel2id(pool, NAMESPACE_OTHERPROVIDERS, id, REL_NAMESPACE, 1);
870 repo->idarraydata[i] = id;
876 /***********************************************************************/
884 int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv);
889 repo_matchvalue(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
891 struct matchdata *md = cbdata;
893 if (md->matcher.match)
895 if (key->name == SOLVABLE_FILELIST && key->type == REPOKEY_TYPE_DIRSTRARRAY && (md->matcher.flags & SEARCH_FILES) != 0)
896 if (!datamatcher_checkbasename(&md->matcher, kv->str))
898 if (!repodata_stringify(md->pool, data, key, kv, md->flags))
900 if (!datamatcher_match(&md->matcher, kv->str))
903 md->stop = md->callback(md->callback_data, s, data, key, kv);
908 /* list of all keys we store in the solvable */
909 /* also used in the dataiterator code in repodata.c */
910 Repokey repo_solvablekeys[RPM_RPMDBID - SOLVABLE_NAME + 1] = {
911 { SOLVABLE_NAME, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
912 { SOLVABLE_ARCH, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
913 { SOLVABLE_EVR, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
914 { SOLVABLE_VENDOR, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE },
915 { SOLVABLE_PROVIDES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
916 { SOLVABLE_OBSOLETES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
917 { SOLVABLE_CONFLICTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
918 { SOLVABLE_REQUIRES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
919 { SOLVABLE_RECOMMENDS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
920 { SOLVABLE_SUGGESTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
921 { SOLVABLE_SUPPLEMENTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
922 { SOLVABLE_ENHANCES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE },
923 { RPM_RPMDBID, REPOKEY_TYPE_NUM, 0, KEY_STORAGE_SOLVABLE },
927 domatch_idarray(Solvable *s, Id keyname, struct matchdata *md, Id *ida)
932 for (; *ida && !md->stop; ida++)
935 kv.eof = ida[1] ? 0 : 1;
936 repo_matchvalue(md, s, 0, repo_solvablekeys + (keyname - SOLVABLE_NAME), &kv);
942 repo_search_md(Repo *repo, Id p, Id keyname, struct matchdata *md)
945 Pool *pool = repo->pool;
954 for (p = repo->start, s = repo->pool->solvables + p; p < repo->end; p++, s++)
957 repo_search_md(repo, p, keyname, md);
958 if (md->stop > SEARCH_NEXT_SOLVABLE)
964 /* The callback only supports solvables, so we can't iterate over the
968 if (!(flags & SEARCH_NO_STORAGE_SOLVABLE))
970 s = pool->solvables + p;
978 repo_matchvalue(md, s, 0, repo_solvablekeys + 0, &kv);
980 if (keyname || md->stop > SEARCH_NEXT_KEY)
986 repo_matchvalue(md, s, 0, repo_solvablekeys + 1, &kv);
988 if (keyname || md->stop > SEARCH_NEXT_KEY)
994 repo_matchvalue(md, s, 0, repo_solvablekeys + 2, &kv);
996 if (keyname || md->stop > SEARCH_NEXT_KEY)
998 case SOLVABLE_VENDOR:
1002 repo_matchvalue(md, s, 0, repo_solvablekeys + 3, &kv);
1004 if (keyname || md->stop > SEARCH_NEXT_KEY)
1006 case SOLVABLE_PROVIDES:
1008 domatch_idarray(s, SOLVABLE_PROVIDES, md, repo->idarraydata + s->provides);
1009 if (keyname || md->stop > SEARCH_NEXT_KEY)
1011 case SOLVABLE_OBSOLETES:
1013 domatch_idarray(s, SOLVABLE_OBSOLETES, md, repo->idarraydata + s->obsoletes);
1014 if (keyname || md->stop > SEARCH_NEXT_KEY)
1016 case SOLVABLE_CONFLICTS:
1018 domatch_idarray(s, SOLVABLE_CONFLICTS, md, repo->idarraydata + s->conflicts);
1019 if (keyname || md->stop > SEARCH_NEXT_KEY)
1021 case SOLVABLE_REQUIRES:
1023 domatch_idarray(s, SOLVABLE_REQUIRES, md, repo->idarraydata + s->requires);
1024 if (keyname || md->stop > SEARCH_NEXT_KEY)
1026 case SOLVABLE_RECOMMENDS:
1028 domatch_idarray(s, SOLVABLE_RECOMMENDS, md, repo->idarraydata + s->recommends);
1029 if (keyname || md->stop > SEARCH_NEXT_KEY)
1031 case SOLVABLE_SUPPLEMENTS:
1033 domatch_idarray(s, SOLVABLE_SUPPLEMENTS, md, repo->idarraydata + s->supplements);
1034 if (keyname || md->stop > SEARCH_NEXT_KEY)
1036 case SOLVABLE_SUGGESTS:
1038 domatch_idarray(s, SOLVABLE_SUGGESTS, md, repo->idarraydata + s->suggests);
1039 if (keyname || md->stop > SEARCH_NEXT_KEY)
1041 case SOLVABLE_ENHANCES:
1043 domatch_idarray(s, SOLVABLE_ENHANCES, md, repo->idarraydata + s->enhances);
1044 if (keyname || md->stop > SEARCH_NEXT_KEY)
1049 kv.num = repo->rpmdbid[p - repo->start];
1051 repo_matchvalue(md, s, 0, repo_solvablekeys + (RPM_RPMDBID - SOLVABLE_NAME), &kv);
1053 if (keyname || md->stop > SEARCH_NEXT_KEY)
1061 FOR_REPODATAS(repo, i, data)
1063 if (p < data->start || p >= data->end)
1065 if (keyname && !repodata_precheck_keyname(data, keyname))
1067 if (keyname == SOLVABLE_FILELIST && !(md->flags & SEARCH_COMPLETE_FILELIST))
1069 /* do not search filelist extensions */
1070 if (data->state != REPODATA_AVAILABLE)
1072 for (j = 1; j < data->nkeys; j++)
1073 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1075 if (j == data->nkeys)
1078 if (data->state == REPODATA_STUB)
1082 for (j = 1; j < data->nkeys; j++)
1083 if (keyname == data->keys[j].name)
1085 if (j == data->nkeys)
1089 if (data->loadcallback)
1090 data->loadcallback(data);
1092 data->state = REPODATA_ERROR;
1094 if (data->state == REPODATA_ERROR)
1096 repodata_search(data, p, keyname, md->flags, repo_matchvalue, md);
1097 if (md->stop > SEARCH_NEXT_KEY)
1103 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)
1105 struct matchdata md;
1107 if (repo->disabled && !(flags & SEARCH_DISABLED_REPOS))
1109 memset(&md, 0, sizeof(md));
1110 md.pool = repo->pool;
1112 md.callback = callback;
1113 md.callback_data = cbdata;
1115 datamatcher_init(&md.matcher, match, flags);
1116 repo_search_md(repo, p, keyname, &md);
1118 datamatcher_free(&md.matcher);
1122 repo_lookup_str(Repo *repo, Id entry, Id keyname)
1124 Pool *pool = repo->pool;
1134 return pool_id2str(pool, pool->solvables[entry].name);
1136 return pool_id2str(pool, pool->solvables[entry].arch);
1138 return pool_id2str(pool, pool->solvables[entry].evr);
1139 case SOLVABLE_VENDOR:
1140 return pool_id2str(pool, pool->solvables[entry].vendor);
1143 else if (entry == SOLVID_POS && pool->pos.repo == repo && pool->pos.repodataid)
1144 return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname);
1145 FOR_REPODATAS(repo, i, data)
1147 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1149 if (!repodata_precheck_keyname(data, keyname))
1151 str = repodata_lookup_str(data, entry, keyname);
1154 if (repodata_lookup_type(data, entry, keyname))
1162 repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned long long notfound)
1164 Pool *pool = repo->pool;
1167 unsigned long long value;
1171 if (keyname == RPM_RPMDBID)
1173 if (repo->rpmdbid && entry >= repo->start && entry < repo->end)
1174 return repo->rpmdbid[entry - repo->start];
1178 else if (entry == SOLVID_POS && pool->pos.repo == repo && pool->pos.repodataid)
1179 return repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname, &value) ? value : notfound;
1180 FOR_REPODATAS(repo, i, data)
1182 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1184 if (!repodata_precheck_keyname(data, keyname))
1186 if (repodata_lookup_num(data, entry, keyname, &value))
1188 if (repodata_lookup_type(data, entry, keyname))
1195 repo_lookup_id(Repo *repo, Id entry, Id keyname)
1197 Pool *pool = repo->pool;
1207 return repo->pool->solvables[entry].name;
1209 return repo->pool->solvables[entry].arch;
1211 return repo->pool->solvables[entry].evr;
1212 case SOLVABLE_VENDOR:
1213 return repo->pool->solvables[entry].vendor;
1216 else if (entry == SOLVID_POS && pool->pos.repo == repo && pool->pos.repodataid)
1218 Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
1219 Id id = repodata_lookup_id(data, entry, keyname);
1220 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1222 FOR_REPODATAS(repo, i, data)
1224 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1226 if (!repodata_precheck_keyname(data, keyname))
1228 id = repodata_lookup_id(data, entry, keyname);
1230 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1231 if (repodata_lookup_type(data, entry, keyname))
1238 lookup_idarray_solvable(Repo *repo, Offset off, Queue *q)
1244 for (p = repo->idarraydata + off; *p; p++)
1250 repo_lookup_idarray(Repo *repo, Id entry, Id keyname, Queue *q)
1252 Pool *pool = repo->pool;
1259 case SOLVABLE_PROVIDES:
1260 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].provides, q);
1261 case SOLVABLE_OBSOLETES:
1262 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].obsoletes, q);
1263 case SOLVABLE_CONFLICTS:
1264 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].conflicts, q);
1265 case SOLVABLE_REQUIRES:
1266 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].requires, q);
1267 case SOLVABLE_RECOMMENDS:
1268 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].recommends, q);
1269 case SOLVABLE_SUGGESTS:
1270 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].suggests, q);
1271 case SOLVABLE_SUPPLEMENTS:
1272 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].supplements, q);
1273 case SOLVABLE_ENHANCES:
1274 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].enhances, q);
1277 else if (entry == SOLVID_POS && pool->pos.repo == repo && pool->pos.repodataid)
1279 Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
1280 if (repodata_lookup_idarray(data, entry, keyname, q))
1282 if (data->localpool)
1284 for (i = 0; i < q->count; i++)
1285 q->elements[i] = repodata_globalize_id(data, q->elements[i], 1);
1290 FOR_REPODATAS(repo, i, data)
1292 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1294 if (!repodata_precheck_keyname(data, keyname))
1296 if (repodata_lookup_idarray(data, entry, keyname, q))
1298 if (data->localpool)
1300 for (i = 0; i < q->count; i++)
1301 q->elements[i] = repodata_globalize_id(data, q->elements[i], 1);
1305 if (repodata_lookup_type(data, entry, keyname))
1313 repo_lookup_deparray(Repo *repo, Id entry, Id keyname, Queue *q, Id marker)
1315 int r = repo_lookup_idarray(repo, entry, keyname, q);
1316 if (r && marker && q->count)
1322 for (i = 0; i < q->count; i++)
1323 if (q->elements[i] == marker)
1325 queue_truncate(q, i);
1331 for (i = 0; i < q->count; i++)
1332 if (q->elements[i] == marker)
1334 queue_deleten(q, 0, i + 1);
1343 const unsigned char *
1344 repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
1346 Pool *pool = repo->pool;
1349 const unsigned char *chk;
1351 if (entry == SOLVID_POS && pool->pos.repo == repo && pool->pos.repodataid)
1352 return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname, typep);
1353 FOR_REPODATAS(repo, i, data)
1355 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1357 if (!repodata_precheck_keyname(data, keyname))
1359 chk = repodata_lookup_bin_checksum(data, entry, keyname, typep);
1362 if (repodata_lookup_type(data, entry, keyname))
1370 repo_lookup_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
1372 const unsigned char *chk = repo_lookup_bin_checksum(repo, entry, keyname, typep);
1373 return chk ? pool_bin2hex(repo->pool, chk, solv_chksum_len(*typep)) : 0;
1377 repo_lookup_void(Repo *repo, Id entry, Id keyname)
1379 Pool *pool = repo->pool;
1384 if (entry == SOLVID_POS && pool->pos.repo == repo && pool->pos.repodataid)
1385 return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname);
1386 FOR_REPODATAS(repo, i, data)
1388 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1390 if (!repodata_precheck_keyname(data, keyname))
1392 type = repodata_lookup_type(data, entry, keyname);
1394 return type == REPOKEY_TYPE_VOID;
1400 repo_lookup_type(Repo *repo, Id entry, Id keyname)
1402 Pool *pool = repo->pool;
1407 if (entry == SOLVID_POS && pool->pos.repo == repo && pool->pos.repodataid)
1408 return repodata_lookup_type(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname);
1409 FOR_REPODATAS(repo, i, data)
1411 if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
1413 if (!repodata_precheck_keyname(data, keyname))
1415 type = repodata_lookup_type(data, entry, keyname);
1417 return type == REPOKEY_TYPE_DELETED ? 0 : type;
1422 /***********************************************************************/
1425 repo_add_repodata(Repo *repo, int flags)
1429 if ((flags & REPO_USE_LOADING) != 0)
1431 for (i = repo->nrepodata - 1; i > 0; i--)
1432 if (repo->repodata[i].state == REPODATA_LOADING)
1434 Repodata *data = repo->repodata + i;
1436 /* hack: we mis-use REPO_REUSE_REPODATA here */
1437 if (!(flags & REPO_REUSE_REPODATA))
1438 repodata_empty(data, (flags & REPO_LOCALPOOL) ? 1 : 0);
1441 return 0; /* must not create a new repodata! */
1443 if ((flags & REPO_REUSE_REPODATA) != 0)
1445 for (i = repo->nrepodata - 1; i > 0; i--)
1446 if (repo->repodata[i].state != REPODATA_STUB)
1447 return repo->repodata + i;
1449 if (!repo->nrepodata)
1451 repo->nrepodata = 2; /* start with id 1 */
1452 repo->repodata = solv_calloc(repo->nrepodata, sizeof(*data));
1457 repo->repodata = solv_realloc2(repo->repodata, repo->nrepodata, sizeof(*data));
1459 data = repo->repodata + repo->nrepodata - 1;
1460 repodata_initdata(data, repo, (flags & REPO_LOCALPOOL) ? 1 : 0);
1465 repo_id2repodata(Repo *repo, Id id)
1467 return id ? repo->repodata + id : 0;
1471 repo_last_repodata(Repo *repo)
1474 for (i = repo->nrepodata - 1; i > 0; i--)
1475 if (repo->repodata[i].state != REPODATA_STUB)
1476 return repo->repodata + i;
1477 return repo_add_repodata(repo, 0);
1481 repo_set_id(Repo *repo, Id p, Id keyname, Id id)
1489 repo->pool->solvables[p].name = id;
1492 repo->pool->solvables[p].arch = id;
1495 repo->pool->solvables[p].evr = id;
1497 case SOLVABLE_VENDOR:
1498 repo->pool->solvables[p].vendor = id;
1502 data = repo_last_repodata(repo);
1503 if (data->localpool)
1504 id = repodata_localize_id(data, id, 1);
1505 repodata_set_id(data, p, keyname, id);
1509 repo_set_num(Repo *repo, Id p, Id keyname, unsigned long long num)
1514 if (keyname == RPM_RPMDBID)
1517 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1518 repo->rpmdbid[p - repo->start] = num;
1522 data = repo_last_repodata(repo);
1523 repodata_set_num(data, p, keyname, num);
1527 repo_set_str(Repo *repo, Id p, Id keyname, const char *str)
1537 case SOLVABLE_VENDOR:
1538 repo_set_id(repo, p, keyname, pool_str2id(repo->pool, str, 1));
1542 data = repo_last_repodata(repo);
1543 repodata_set_str(data, p, keyname, str);
1547 repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str)
1557 case SOLVABLE_VENDOR:
1558 repo_set_id(repo, p, keyname, pool_str2id(repo->pool, str, 1));
1562 data = repo_last_repodata(repo);
1563 repodata_set_poolstr(data, p, keyname, str);
1567 repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str)
1569 Repodata *data = repo_last_repodata(repo);
1570 repodata_add_poolstr_array(data, p, keyname, str);
1574 repo_add_deparray(Repo *repo, Id p, Id keyname, Id dep, Id marker)
1579 Solvable *s = repo->pool->solvables + p;
1582 case SOLVABLE_PROVIDES:
1583 s->provides = repo_addid_dep(repo, s->provides, dep, marker);
1585 case SOLVABLE_OBSOLETES:
1586 s->obsoletes = repo_addid_dep(repo, s->obsoletes, dep, marker);
1588 case SOLVABLE_CONFLICTS:
1589 s->conflicts = repo_addid_dep(repo, s->conflicts, dep, marker);
1591 case SOLVABLE_REQUIRES:
1592 s->requires = repo_addid_dep(repo, s->requires, dep, marker);
1594 case SOLVABLE_RECOMMENDS:
1595 s->recommends = repo_addid_dep(repo, s->recommends, dep, marker);
1597 case SOLVABLE_SUGGESTS:
1598 s->suggests = repo_addid_dep(repo, s->suggests, dep, marker);
1600 case SOLVABLE_SUPPLEMENTS:
1601 s->supplements = repo_addid_dep(repo, s->supplements, dep, marker);
1603 case SOLVABLE_ENHANCES:
1604 s->enhances = repo_addid_dep(repo, s->enhances, dep, marker);
1608 data = repo_last_repodata(repo);
1609 repodata_add_idarray(data, p, keyname, dep);
1613 repo_add_idarray(Repo *repo, Id p, Id keyname, Id id)
1615 repo_add_deparray(repo, p, keyname, id, 0);
1619 repo_set_idarray_solvable(Repo *repo, Queue *q)
1623 for (i = 0; i < q->count; i++)
1624 repo_addid_dep(repo, o, q->elements[i], 0);
1629 repo_set_deparray(Repo *repo, Id p, Id keyname, Queue *q, Id marker)
1634 /* complex case, splice old and new arrays */
1638 repo_lookup_deparray(repo, p, keyname, &q2, -marker);
1643 queue_push(&q2, marker);
1644 for (i = 0; i < q->count; i++)
1645 queue_push(&q2, q->elements[i]);
1651 queue_insert(&q2, 0, -marker);
1652 queue_insertn(&q2, 0, q->count, q->elements);
1654 repo_set_deparray(repo, p, keyname, &q2, 0);
1660 Solvable *s = repo->pool->solvables + p;
1663 case SOLVABLE_PROVIDES:
1664 s->provides = repo_set_idarray_solvable(repo, q);
1666 case SOLVABLE_OBSOLETES:
1667 s->obsoletes = repo_set_idarray_solvable(repo, q);
1669 case SOLVABLE_CONFLICTS:
1670 s->conflicts = repo_set_idarray_solvable(repo, q);
1672 case SOLVABLE_REQUIRES:
1673 s->requires = repo_set_idarray_solvable(repo, q);
1675 case SOLVABLE_RECOMMENDS:
1676 s->recommends = repo_set_idarray_solvable(repo, q);
1678 case SOLVABLE_SUGGESTS:
1679 s->suggests = repo_set_idarray_solvable(repo, q);
1681 case SOLVABLE_SUPPLEMENTS:
1682 s->supplements = repo_set_idarray_solvable(repo, q);
1684 case SOLVABLE_ENHANCES:
1685 s->enhances = repo_set_idarray_solvable(repo, q);
1689 data = repo_last_repodata(repo);
1690 repodata_set_idarray(data, p, keyname, q);
1694 repo_set_idarray(Repo *repo, Id p, Id keyname, Queue *q)
1696 repo_set_deparray(repo, p, keyname, q, 0);
1700 repo_unset(Repo *repo, Id p, Id keyname)
1705 Solvable *s = repo->pool->solvables + p;
1717 case SOLVABLE_VENDOR:
1722 repo->rpmdbid[p - repo->start] = 0;
1724 case SOLVABLE_PROVIDES:
1727 case SOLVABLE_OBSOLETES:
1730 case SOLVABLE_CONFLICTS:
1733 case SOLVABLE_REQUIRES:
1736 case SOLVABLE_RECOMMENDS:
1739 case SOLVABLE_SUGGESTS:
1742 case SOLVABLE_SUPPLEMENTS:
1744 case SOLVABLE_ENHANCES:
1751 data = repo_last_repodata(repo);
1752 repodata_unset(data, p, keyname);
1756 repo_internalize(Repo *repo)
1761 FOR_REPODATAS(repo, i, data)
1762 if (data->attrs || data->xattrs)
1763 repodata_internalize(data);
1767 repo_disable_paging(Repo *repo)
1772 FOR_REPODATAS(repo, i, data)
1773 repodata_disable_paging(data);
1777 vim:cinoptions={.5s,g0,p5,t0,(0,^-0.5s,n-0.5s:tw=78:cindent:sw=4: