Bug Summary

File:src/repo.c
Warning:line 688, column 7
Function call argument is an uninitialized value

Annotated Source Code

1/*
2 * Copyright (c) 2007, Novell Inc.
3 *
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
6 */
7
8/*
9 * repo.c
10 *
11 * Manage metadata coming from one repository
12 *
13 */
14
15#define _GNU_SOURCE
16#include <string.h>
17#include <fnmatch.h>
18
19#include <stdio.h>
20#include <stdlib.h>
21
22
23
24#include "repo.h"
25#include "pool.h"
26#include "poolid_private.h"
27#include "util.h"
28#include "chksum.h"
29
30#define IDARRAY_BLOCK4095 4095
31
32
33/*
34 * create empty repo
35 * and add to pool
36 */
37
38Repo *
39repo_create(Pool *pool, const char *name)
40{
41 Repo *repo;
42
43 pool_freewhatprovides(pool);
44 repo = (Repo *)solv_calloc(1, sizeof(*repo));
45 if (!pool->nrepos)
46 {
47 pool->nrepos = 1; /* start with repoid 1 */
48 pool->repos = (Repo **)solv_calloc(2, sizeof(Repo *));
49 }
50 else
51 pool->repos = (Repo **)solv_realloc2(pool->repos, pool->nrepos + 1, sizeof(Repo *));
52 pool->repos[pool->nrepos] = repo;
53 pool->urepos++;
54 repo->repoid = pool->nrepos++;
55 repo->name = name ? solv_strdup(name) : 0;
56 repo->pool = pool;
57 repo->start = pool->nsolvables;
58 repo->end = pool->nsolvables;
59 repo->nsolvables = 0;
60 return repo;
61}
62
63void
64repo_freedata(Repo *repo)
65{
66 int i;
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);
74 solv_free(repo);
75}
76
77/* delete all solvables and repodata blocks from this repo */
78
79void
80repo_empty(Repo *repo, int reuseids)
81{
82 Pool *pool = repo->pool;
83 Solvable *s;
84 int i;
85
86 pool_freewhatprovides(pool);
87 if (reuseids && repo->end == pool->nsolvables)
88 {
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--)
92 if (s->repo != repo)
93 break;
94 pool_free_solvable_block(pool, i + 1, repo->end - (i + 1), reuseids);
95 repo->end = i + 1;
96 }
97 /* zero out (i.e. free) solvables belonging to this repo */
98 for (i = repo->start, s = pool->solvables + i; i < repo->end; i++, s++)
99 if (s->repo == repo)
100 memset(s, 0, sizeof(*s));
101 repo->end = repo->start;
102 repo->nsolvables = 0;
103
104 /* free all data belonging to this repo */
105 repo->idarraydata = solv_free(repo->idarraydata);
106 repo->idarraysize = 0;
107 repo->lastoff = 0;
108 repo->rpmdbid = solv_free(repo->rpmdbid);
109 for (i = 1; i < repo->nrepodata; i++)
110 repodata_freedata(repo->repodata + i);
111 solv_free(repo->repodata);
112 repo->repodata = 0;
113 repo->nrepodata = 0;
114}
115
116/*
117 * remove repo from pool, delete solvables
118 *
119 */
120
121void
122repo_free(Repo *repo, int reuseids)
123{
124 Pool *pool = repo->pool;
125 int i;
126
127 if (repo == pool->installed)
128 pool->installed = 0;
129 repo_empty(repo, reuseids);
130 for (i = 1; i < pool->nrepos; i++) /* find repo in pool */
131 if (pool->repos[i] == repo)
132 break;
133 if (i == pool->nrepos) /* repo not in pool, return */
134 return;
135 if (i == pool->nrepos - 1 && reuseids)
136 pool->nrepos--;
137 else
138 pool->repos[i] = 0;
139 pool->urepos--;
140 repo_freedata(repo);
141}
142
143Id
144repo_add_solvable(Repo *repo)
145{
146 Id p = pool_add_solvable(repo->pool);
147 if (!repo->start || repo->start == repo->end)
148 repo->start = repo->end = p;
149 /* warning: sidedata must be extended before adapting start/end */
150 if (repo->rpmdbid)
151 repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, 1);
152 if (p < repo->start)
153 repo->start = p;
154 if (p + 1 > repo->end)
155 repo->end = p + 1;
156 repo->nsolvables++;
157 repo->pool->solvables[p].repo = repo;
158 return p;
159}
160
161Id
162repo_add_solvable_block(Repo *repo, int count)
163{
164 Id p;
165 Solvable *s;
166 if (!count)
167 return 0;
168 p = pool_add_solvable_block(repo->pool, count);
169 if (!repo->start || repo->start == repo->end)
170 repo->start = repo->end = p;
171 /* warning: sidedata must be extended before adapting start/end */
172 if (repo->rpmdbid)
173 repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, count);
174 if (p < repo->start)
175 repo->start = p;
176 if (p + count > repo->end)
177 repo->end = p + count;
178 repo->nsolvables += count;
179 for (s = repo->pool->solvables + p; count--; s++)
180 s->repo = repo;
181 return p;
182}
183
184void
185repo_free_solvable(Repo *repo, Id p, int reuseids)
186{
187 repo_free_solvable_block(repo, p, 1, reuseids);
188}
189
190void
191repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids)
192{
193 Solvable *s;
194 Repodata *data;
195 int i;
196 if (start + count == repo->end)
197 repo->end -= count;
198 repo->nsolvables -= count;
199 for (s = repo->pool->solvables + start, i = count; i--; s++)
200 s->repo = 0;
201 pool_free_solvable_block(repo->pool, start, count, reuseids);
202 FOR_REPODATAS(repo, i, data)for (i = 1, data = repo->repodata + i; i < repo->nrepodata
; i++, data++)
203 {
204 int dstart, dend;
205 if (data->end > repo->end)
206 repodata_shrink(data, repo->end);
207 dstart = data->start > start ? data->start : start;
208 dend = data->end < start + count ? data->end : start + count;
209 if (dstart < dend)
210 {
211 if (data->attrs)
212 {
213 int j;
214 for (j = dstart; j < dend; j++)
215 data->attrs[j - data->start] = solv_free(data->attrs[j - data->start]);
216 }
217 if (data->incoreoffset)
218 memset(data->incoreoffset + (dstart - data->start), 0, (dend - dstart) * sizeof(Id));
219 }
220 }
221}
222
223/* specialized version of repo_add_solvable_block that inserts the new solvable
224 * block before the indicated repo, which gets relocated.
225 * used in repo_add_rpmdb
226 */
227Id
228repo_add_solvable_block_before(Repo *repo, int count, Repo *beforerepo)
229{
230 Pool *pool = repo->pool;
231 Id p;
232 Solvable *s;
233 Repodata *data;
234 int i;
235
236 if (!count || !beforerepo || beforerepo->end != pool->nsolvables || beforerepo->start == beforerepo->end)
237 return repo_add_solvable_block(repo, count);
238 p = beforerepo->start;
239 /* make sure all solvables belong to beforerepo */
240 for (i = p, s = pool->solvables + i; i < beforerepo->end; i++, s++)
241 if (s->repo && s->repo != beforerepo)
242 return repo_add_solvable_block(repo, count);
243 /* now move beforerepo to back */
244 pool_add_solvable_block(pool, count); /* must return beforerepo->end! */
245 memmove(pool->solvables + p + count, pool->solvables + p, (beforerepo->end - p) * sizeof(Solvable));
246 memset(pool->solvables + p, 0, sizeof(Solvable) * count);
247 /* adapt repodata */
248 FOR_REPODATAS(beforerepo, i, data)for (i = 1, data = beforerepo->repodata + i; i < beforerepo
->nrepodata; i++, data++)
249 {
250 if (data->start < p)
251 continue;
252 data->start += count;
253 data->end += count;
254 }
255 beforerepo->start += count;
256 beforerepo->end += count;
257 /* we now have count free solvables at id p */
258 /* warning: sidedata must be extended before adapting start/end */
259 if (repo->rpmdbid)
260 repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, count);
261 if (p < repo->start)
262 repo->start = p;
263 if (p + count > repo->end)
264 repo->end = p + count;
265 repo->nsolvables += count;
266 for (s = pool->solvables + p; count--; s++)
267 s->repo = repo;
268 return p;
269}
270
271
272/* repository sidedata is solvable data allocated on demand.
273 * It is used for data that is normally not present
274 * in the solvable like the rpmdbid.
275 * The solvable allocation funcions need to make sure that
276 * the sidedata gets extended if new solvables get added.
277 */
278
279#define REPO_SIDEDATA_BLOCK63 63
280
281void *
282repo_sidedata_create(Repo *repo, size_t size)
283{
284 return solv_calloc_block(repo->end - repo->start, size, REPO_SIDEDATA_BLOCK63);
285}
286
287void *
288repo_sidedata_extend(Repo *repo, void *b, size_t size, Id p, int count)
289{
290 int n = repo->end - repo->start;
291 if (p < repo->start)
292 {
293 int d = repo->start - p;
294 b = solv_extend(b, n, d, size, REPO_SIDEDATA_BLOCK63);
295 memmove((char *)b + d * size, b, n * size);
296 memset(b, 0, d * size);
297 n += d;
298 }
299 if (p + count > repo->end)
300 {
301 int d = p + count - repo->end;
302 b = solv_extend(b, n, d, size, REPO_SIDEDATA_BLOCK63);
303 memset((char *)b + n * size, 0, d * size);
304 }
305 return b;
306}
307
308/*
309 * add Id to idarraydata used to store dependencies
310 * olddeps: old array offset to extend
311 * returns new array offset
312 */
313
314Offset
315repo_addid(Repo *repo, Offset olddeps, Id id)
316{
317 Id *idarray;
318 int idarraysize;
319 int i;
320
321 idarray = repo->idarraydata;
322 idarraysize = repo->idarraysize;
323
324 if (!idarray) /* alloc idarray if not done yet */
325 {
326 idarraysize = 1;
327 idarray = solv_extend_resize(0, 1, sizeof(Id), IDARRAY_BLOCK4095);
328 idarray[0] = 0;
329 repo->lastoff = 0;
330 }
331
332 if (!olddeps) /* no deps yet */
333 {
334 olddeps = idarraysize;
335 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK4095);
336 }
337 else if (olddeps == repo->lastoff) /* extend at end */
338 idarraysize--;
339 else /* can't extend, copy old */
340 {
341 i = olddeps;
342 olddeps = idarraysize;
343 for (; idarray[i]; i++)
344 {
345 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK4095);
346 idarray[idarraysize++] = idarray[i];
347 }
348 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK4095);
349 }
350
351 idarray[idarraysize++] = id; /* insert Id into array */
352 idarray = solv_extend(idarray, idarraysize, 1, sizeof(Id), IDARRAY_BLOCK4095);
353 idarray[idarraysize++] = 0; /* ensure NULL termination */
354
355 repo->idarraydata = idarray;
356 repo->idarraysize = idarraysize;
357 repo->lastoff = olddeps;
358
359 return olddeps;
360}
361
362#define REPO_ADDID_DEP_HASHTHRES64 64
363#define REPO_ADDID_DEP_HASHMIN128 128
364
365/*
366 * Optimization for packages with an excessive amount of provides/requires:
367 * if the number of deps exceed a threshold, we build a hash of the already
368 * seen ids.
369 */
370static Offset
371repo_addid_dep_hash(Repo *repo, Offset olddeps, Id id, Id marker, int size)
372{
373 Id oid, *oidp;
374 int before;
375 Hashval h, hh;
376 Id hid;
377
378 before = 0;
379 if (marker)
380 {
381 if (marker < 0)
382 {
383 marker = -marker;
384 before = 1;
385 }
386 if (marker == id)
387 marker = 0;
388 }
389
390 /* maintain hash and lastmarkerpos */
391 if (repo->lastidhash_idarraysize != repo->idarraysize || (Hashval)size * 2 > repo->lastidhash_mask || repo->lastmarker != marker)
392 {
393 repo->lastmarkerpos = 0;
394 if (size * 2 > (Hashval)repo->lastidhash_mask)
395 {
396 repo->lastidhash_mask = mkmask(size < REPO_ADDID_DEP_HASHMIN128 ? REPO_ADDID_DEP_HASHMIN128 : size);
397 repo->lastidhash = solv_realloc2(repo->lastidhash, repo->lastidhash_mask + 1, sizeof(Id));
398 }
399 memset(repo->lastidhash, 0, (repo->lastidhash_mask + 1) * sizeof(Id));
400 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
401 {
402 h = oid & repo->lastidhash_mask;
403 hh = HASHCHAIN_START7;
404 while (repo->lastidhash[h] != 0)
405 h = HASHCHAIN_NEXT(h, hh, repo->lastidhash_mask)(((h) + (hh)++) & (repo->lastidhash_mask));
406 repo->lastidhash[h] = oid;
407 if (marker && oid == marker)
408 repo->lastmarkerpos = oidp - repo->idarraydata;
409 }
410 repo->lastmarker = marker;
411 repo->lastidhash_idarraysize = repo->idarraysize;
412 }
413
414 /* check the hash! */
415 h = id & repo->lastidhash_mask;
416 hh = HASHCHAIN_START7;
417 while ((hid = repo->lastidhash[h]) != 0 && hid != id)
418 h = HASHCHAIN_NEXT(h, hh, repo->lastidhash_mask)(((h) + (hh)++) & (repo->lastidhash_mask));
419 /* put new element in hash */
420 if (!hid)
421 repo->lastidhash[h] = id;
422 else if (marker == SOLVABLE_FILEMARKER && (!before || !repo->lastmarkerpos))
423 return olddeps;
424 if (marker && !before && !repo->lastmarkerpos)
425 {
426 /* we have to add the marker first */
427 repo->lastmarkerpos = repo->idarraysize - 1;
428 olddeps = repo_addid(repo, olddeps, marker);
429 /* now put marker in hash */
430 h = marker & repo->lastidhash_mask;
431 hh = HASHCHAIN_START7;
432 while (repo->lastidhash[h] != 0)
433 h = HASHCHAIN_NEXT(h, hh, repo->lastidhash_mask)(((h) + (hh)++) & (repo->lastidhash_mask));
434 repo->lastidhash[h] = marker;
435 repo->lastidhash_idarraysize = repo->idarraysize;
436 }
437 if (!hid)
438 {
439 /* new entry, insert in correct position */
440 if (marker && before && repo->lastmarkerpos)
441 {
442 /* need to add it before the marker */
443 olddeps = repo_addid(repo, olddeps, id); /* dummy to make room */
444 memmove(repo->idarraydata + repo->lastmarkerpos + 1, repo->idarraydata + repo->lastmarkerpos, (repo->idarraysize - repo->lastmarkerpos - 2) * sizeof(Id));
445 repo->idarraydata[repo->lastmarkerpos++] = id;
446 }
447 else
448 {
449 /* just append it to the end */
450 olddeps = repo_addid(repo, olddeps, id);
451 }
452 repo->lastidhash_idarraysize = repo->idarraysize;
453 return olddeps;
454 }
455 /* we already have it in the hash */
456 if (!marker)
457 return olddeps;
458 if (marker == SOLVABLE_FILEMARKER)
459 {
460 /* check if it is in the wrong half */
461 /* (we already made sure that "before" and "lastmarkerpos" are set, see above) */
462 for (oidp = repo->idarraydata + repo->lastmarkerpos + 1; (oid = *oidp) != 0; oidp++)
463 if (oid == id)
464 break;
465 if (!oid)
466 return olddeps;
467 /* yes, wrong half. copy it over */
468 memmove(repo->idarraydata + repo->lastmarkerpos + 1, repo->idarraydata + repo->lastmarkerpos, (oidp - (repo->idarraydata + repo->lastmarkerpos)) * sizeof(Id));
469 repo->idarraydata[repo->lastmarkerpos++] = id;
470 return olddeps;
471 }
472 if (before)
473 return olddeps;
474 /* check if it is in the correct half */
475 for (oidp = repo->idarraydata + repo->lastmarkerpos + 1; (oid = *oidp) != 0; oidp++)
476 if (oid == id)
477 return olddeps;
478 /* nope, copy it over */
479 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
480 if (oid == id)
481 break;
482 if (!oid)
483 return olddeps; /* should not happen */
484 memmove(oidp, oidp + 1, (repo->idarraydata + repo->idarraysize - oidp - 2) * sizeof(Id));
485 repo->idarraydata[repo->idarraysize - 2] = id;
486 repo->lastmarkerpos--; /* marker has been moved */
487 return olddeps;
488}
489
490/*
491 * add dependency (as Id) to repo, also unifies dependencies
492 * olddeps = offset into idarraydata
493 * marker= 0 for normal dep
494 * marker > 0 add dep after marker
495 * marker < 0 add dep before -marker
496 * returns new start of dependency array
497 */
498Offset
499repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker)
500{
501 Id oid, *oidp, *markerp;
502 int before;
503
504 if (!olddeps)
505 {
506 if (marker > 0)
507 olddeps = repo_addid(repo, olddeps, marker);
508 return repo_addid(repo, olddeps, id);
509 }
510
511 /* check if we should use the hash optimization */
512 if (olddeps == repo->lastoff)
513 {
514 int size = repo->idarraysize - 1 - repo->lastoff;
515 if (size >= REPO_ADDID_DEP_HASHTHRES64)
516 return repo_addid_dep_hash(repo, olddeps, id, marker, size);
517 }
518
519 before = 0;
520 if (marker)
521 {
522 if (marker < 0)
523 {
524 marker = -marker;
525 before = 1;
526 }
527 if (marker == id)
528 marker = 0;
529 }
530
531 if (!marker)
532 {
533 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
534 if (oid == id)
535 return olddeps;
536 return repo_addid(repo, olddeps, id);
537 }
538
539 markerp = 0;
540 for (oidp = repo->idarraydata + olddeps; (oid = *oidp) != 0; oidp++)
541 {
542 if (oid == marker)
543 markerp = oidp;
544 else if (oid == id)
545 break;
546 }
547
548 if (oid)
549 {
550 if (marker == SOLVABLE_FILEMARKER)
551 {
552 if (!markerp || !before)
553 return olddeps;
554 /* we found it, but in the second half */
555 memmove(markerp + 1, markerp, (oidp - markerp) * sizeof(Id));
556 *markerp = id;
557 return olddeps;
558 }
559 if (markerp || before)
560 return olddeps;
561 /* we found it, but in the first half */
562 markerp = oidp++;
563 for (; (oid = *oidp) != 0; oidp++)
564 if (oid == marker)
565 break;
566 if (!oid)
567 {
568 /* no marker in array yet */
569 oidp--;
570 if (markerp < oidp)
571 memmove(markerp, markerp + 1, (oidp - markerp) * sizeof(Id));
572 *oidp = marker;
573 return repo_addid(repo, olddeps, id);
574 }
575 while (oidp[1])
576 oidp++;
577 memmove(markerp, markerp + 1, (oidp - markerp) * sizeof(Id));
578 *oidp = id;
579 return olddeps;
580 }
581 /* id not yet in array */
582 if (!before && !markerp)
583 olddeps = repo_addid(repo, olddeps, marker);
584 else if (before && markerp)
585 {
586 *markerp++ = id;
587 id = *--oidp;
588 if (markerp < oidp)
589 memmove(markerp + 1, markerp, (oidp - markerp) * sizeof(Id));
590 *markerp = marker;
591 }
592 return repo_addid(repo, olddeps, id);
593}
594
595/* return standard marker for the keyname dependency.
596 * 1: return positive marker, -1: return negative marker
597 */
598Id
599solv_depmarker(Id keyname, Id marker)
600{
601 if (marker != 1 && marker != -1)
602 return marker;
603 if (keyname == SOLVABLE_PROVIDES)
604 return marker < 0 ? -SOLVABLE_FILEMARKER : SOLVABLE_FILEMARKER;
605 if (keyname == SOLVABLE_REQUIRES)
606 return marker < 0 ? -SOLVABLE_PREREQMARKER : SOLVABLE_PREREQMARKER;
607 return 0;
608}
609
610/*
611 * reserve Ids
612 * make space for 'num' more dependencies
613 * returns new start of dependency array
614 *
615 * reserved ids will always begin at offset idarraysize
616 */
617Offset
618repo_reserve_ids(Repo *repo, Offset olddeps, int num)
619{
620 num++; /* room for trailing ID_NULL */
621
622 if (!repo->idarraysize) /* ensure buffer space */
623 {
624 repo->idarraysize = 1;
625 repo->idarraydata = solv_extend_resize(0, 1 + num, sizeof(Id), IDARRAY_BLOCK4095);
626 repo->idarraydata[0] = 0;
627 repo->lastoff = 1;
628 return 1;
629 }
630
631 if (olddeps && olddeps != repo->lastoff) /* if not appending */
632 {
633 /* can't insert into idarray, this would invalidate all 'larger' offsets
634 * so create new space at end and move existing deps there.
635 * Leaving 'hole' at old position.
636 */
637
638 Id *idstart, *idend;
639 int count;
640
641 for (idstart = idend = repo->idarraydata + olddeps; *idend++; ) /* find end */
642 ;
643 count = idend - idstart - 1 + num; /* new size */
644
645 repo->idarraydata = solv_extend(repo->idarraydata, repo->idarraysize, count, sizeof(Id), IDARRAY_BLOCK4095);
646 /* move old deps to end */
647 olddeps = repo->lastoff = repo->idarraysize;
648 memcpy(repo->idarraydata + olddeps, idstart, count - num);
649 repo->idarraysize = olddeps + count - num;
650
651 return olddeps;
652 }
653
654 if (olddeps) /* appending */
655 repo->idarraysize--;
656
657 /* make room*/
658 repo->idarraydata = solv_extend(repo->idarraydata, repo->idarraysize, num, sizeof(Id), IDARRAY_BLOCK4095);
659
660 /* appending or new */
661 repo->lastoff = olddeps ? olddeps : repo->idarraysize;
662
663 return repo->lastoff;
664}
665
666
667/***********************************************************************/
668
669struct matchdata
670{
671 Pool *pool;
672 int flags;
673 Datamatcher matcher;
674 int stop;
675 int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv);
676 void *callback_data;
677};
678
679int
680repo_matchvalue(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
681{
682 struct matchdata *md = cbdata;
683
684 if (md->matcher.match)
11
Assuming the condition is true
12
Taking true branch
685 {
686 const char *str;
687 if (key->name == SOLVABLE_FILELIST && key->type == REPOKEY_TYPE_DIRSTRARRAY && (md->matcher.flags & SEARCH_FILES(1<<17)) != 0)
13
Assuming the condition is true
14
Assuming the condition is true
15
Assuming the condition is true
16
Taking true branch
688 if (!datamatcher_checkbasename(&md->matcher, kv->str))
17
Function call argument is an uninitialized value
689 return 0;
690 if (!(str = repodata_stringify(md->pool, data, key, kv, md->flags)))
691 return 0;
692 if (!datamatcher_match(&md->matcher, str))
693 return 0;
694 }
695 md->stop = md->callback(md->callback_data, s, data, key, kv);
696 return md->stop;
697}
698
699
700/* list of all keys we store in the solvable */
701/* also used in the dataiterator code in repodata.c */
702Repokey repo_solvablekeys[RPM_RPMDBID - SOLVABLE_NAME + 1] = {
703 { SOLVABLE_NAME, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE1 },
704 { SOLVABLE_ARCH, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE1 },
705 { SOLVABLE_EVR, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE1 },
706 { SOLVABLE_VENDOR, REPOKEY_TYPE_ID, 0, KEY_STORAGE_SOLVABLE1 },
707 { SOLVABLE_PROVIDES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE1 },
708 { SOLVABLE_OBSOLETES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE1 },
709 { SOLVABLE_CONFLICTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE1 },
710 { SOLVABLE_REQUIRES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE1 },
711 { SOLVABLE_RECOMMENDS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE1 },
712 { SOLVABLE_SUGGESTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE1 },
713 { SOLVABLE_SUPPLEMENTS, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE1 },
714 { SOLVABLE_ENHANCES, REPOKEY_TYPE_IDARRAY, 0, KEY_STORAGE_SOLVABLE1 },
715 { RPM_RPMDBID, REPOKEY_TYPE_NUM, 0, KEY_STORAGE_SOLVABLE1 },
716};
717
718static void
719domatch_idarray(Solvable *s, Id keyname, struct matchdata *md, Id *ida)
720{
721 KeyValue kv;
722 kv.entry = 0;
723 kv.parent = 0;
724 for (; *ida && !md->stop; ida++)
725 {
726 kv.id = *ida;
727 kv.eof = ida[1] ? 0 : 1;
728 repo_matchvalue(md, s, 0, repo_solvablekeys + (keyname - SOLVABLE_NAME), &kv);
729 kv.entry++;
730 }
731}
732
733static void
734repo_search_md(Repo *repo, Id p, Id keyname, struct matchdata *md)
735{
736 KeyValue kv;
737 Pool *pool = repo->pool;
738 Repodata *data;
739 int i, j, flags;
740 Solvable *s;
741
742 kv.parent = 0;
743 md->stop = 0;
744 if (!p)
1
Assuming 'p' is not equal to 0
2
Taking false branch
745 {
746 for (p = repo->start, s = repo->pool->solvables + p; p < repo->end; p++, s++)
747 {
748 if (s->repo == repo)
749 repo_search_md(repo, p, keyname, md);
750 if (md->stop > SEARCH_NEXT_SOLVABLE2)
751 break;
752 }
753 return;
754 }
755 else if (p < 0)
3
Assuming 'p' is >= 0
4
Taking false branch
756 /* The callback only supports solvables, so we can't iterate over the
757 extra things. */
758 return;
759 flags = md->flags;
760 if (!(flags & SEARCH_NO_STORAGE_SOLVABLE(1<<8)))
5
Assuming the condition is true
6
Taking true branch
761 {
762 s = pool->solvables + p;
763 switch(keyname)
7
Control jumps to 'case RPM_RPMDBID:' at line 838
764 {
765 case 0:
766 case SOLVABLE_NAME:
767 if (s->name)
768 {
769 kv.id = s->name;
770 repo_matchvalue(md, s, 0, repo_solvablekeys + 0, &kv);
771 }
772 if (keyname || md->stop > SEARCH_NEXT_KEY1)
773 return;
774 case SOLVABLE_ARCH:
775 if (s->arch)
776 {
777 kv.id = s->arch;
778 repo_matchvalue(md, s, 0, repo_solvablekeys + 1, &kv);
779 }
780 if (keyname || md->stop > SEARCH_NEXT_KEY1)
781 return;
782 case SOLVABLE_EVR:
783 if (s->evr)
784 {
785 kv.id = s->evr;
786 repo_matchvalue(md, s, 0, repo_solvablekeys + 2, &kv);
787 }
788 if (keyname || md->stop > SEARCH_NEXT_KEY1)
789 return;
790 case SOLVABLE_VENDOR:
791 if (s->vendor)
792 {
793 kv.id = s->vendor;
794 repo_matchvalue(md, s, 0, repo_solvablekeys + 3, &kv);
795 }
796 if (keyname || md->stop > SEARCH_NEXT_KEY1)
797 return;
798 case SOLVABLE_PROVIDES:
799 if (s->provides)
800 domatch_idarray(s, SOLVABLE_PROVIDES, md, repo->idarraydata + s->provides);
801 if (keyname || md->stop > SEARCH_NEXT_KEY1)
802 return;
803 case SOLVABLE_OBSOLETES:
804 if (s->obsoletes)
805 domatch_idarray(s, SOLVABLE_OBSOLETES, md, repo->idarraydata + s->obsoletes);
806 if (keyname || md->stop > SEARCH_NEXT_KEY1)
807 return;
808 case SOLVABLE_CONFLICTS:
809 if (s->conflicts)
810 domatch_idarray(s, SOLVABLE_CONFLICTS, md, repo->idarraydata + s->conflicts);
811 if (keyname || md->stop > SEARCH_NEXT_KEY1)
812 return;
813 case SOLVABLE_REQUIRES:
814 if (s->requires)
815 domatch_idarray(s, SOLVABLE_REQUIRES, md, repo->idarraydata + s->requires);
816 if (keyname || md->stop > SEARCH_NEXT_KEY1)
817 return;
818 case SOLVABLE_RECOMMENDS:
819 if (s->recommends)
820 domatch_idarray(s, SOLVABLE_RECOMMENDS, md, repo->idarraydata + s->recommends);
821 if (keyname || md->stop > SEARCH_NEXT_KEY1)
822 return;
823 case SOLVABLE_SUPPLEMENTS:
824 if (s->supplements)
825 domatch_idarray(s, SOLVABLE_SUPPLEMENTS, md, repo->idarraydata + s->supplements);
826 if (keyname || md->stop > SEARCH_NEXT_KEY1)
827 return;
828 case SOLVABLE_SUGGESTS:
829 if (s->suggests)
830 domatch_idarray(s, SOLVABLE_SUGGESTS, md, repo->idarraydata + s->suggests);
831 if (keyname || md->stop > SEARCH_NEXT_KEY1)
832 return;
833 case SOLVABLE_ENHANCES:
834 if (s->enhances)
835 domatch_idarray(s, SOLVABLE_ENHANCES, md, repo->idarraydata + s->enhances);
836 if (keyname || md->stop > SEARCH_NEXT_KEY1)
837 return;
838 case RPM_RPMDBID:
839 if (repo->rpmdbid)
8
Assuming the condition is true
9
Taking true branch
840 {
841 kv.num = repo->rpmdbid[p - repo->start];
842 kv.num2 = 0;
843 repo_matchvalue(md, s, 0, repo_solvablekeys + (RPM_RPMDBID - SOLVABLE_NAME), &kv);
10
Calling 'repo_matchvalue'
844 }
845 if (keyname || md->stop > SEARCH_NEXT_KEY1)
846 return;
847 break;
848 default:
849 break;
850 }
851 }
852
853 FOR_REPODATAS(repo, i, data)for (i = 1, data = repo->repodata + i; i < repo->nrepodata
; i++, data++)
854 {
855 if (p < data->start || p >= data->end)
856 continue;
857 if (keyname && !repodata_precheck_keyname(data, keyname))
858 continue;
859 if (keyname == SOLVABLE_FILELIST && !(md->flags & SEARCH_COMPLETE_FILELIST(1<<12)))
860 {
861 /* do not search filelist extensions */
862 if (data->state != REPODATA_AVAILABLE0)
863 continue;
864 for (j = 1; j < data->nkeys; j++)
865 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
866 break;
867 if (j == data->nkeys)
868 continue;
869 }
870 if (data->state == REPODATA_STUB1)
871 {
872 if (keyname)
873 {
874 for (j = 1; j < data->nkeys; j++)
875 if (keyname == data->keys[j].name)
876 break;
877 if (j == data->nkeys)
878 continue;
879 }
880 /* load it */
881 if (data->loadcallback)
882 data->loadcallback(data);
883 else
884 data->state = REPODATA_ERROR2;
885 }
886 if (data->state == REPODATA_ERROR2)
887 continue;
888 repodata_search(data, p, keyname, md->flags, repo_matchvalue, md);
889 if (md->stop > SEARCH_NEXT_KEY1)
890 break;
891 }
892}
893
894void
895repo_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)
896{
897 struct matchdata md;
898
899 if (repo->disabled && !(flags & SEARCH_DISABLED_REPOS(1<<11)))
900 return;
901 memset(&md, 0, sizeof(md));
902 md.pool = repo->pool;
903 md.flags = flags;
904 md.callback = callback;
905 md.callback_data = cbdata;
906 if (match)
907 datamatcher_init(&md.matcher, match, flags);
908 repo_search_md(repo, p, keyname, &md);
909 if (match)
910 datamatcher_free(&md.matcher);
911}
912
913const char *
914repo_lookup_str(Repo *repo, Id entry, Id keyname)
915{
916 Pool *pool = repo->pool;
917 Repodata *data;
918 int i;
919 const char *str;
920
921 if (entry >= 0)
922 {
923 switch (keyname)
924 {
925 case SOLVABLE_NAME:
926 return pool_id2str(pool, pool->solvables[entry].name);
927 case SOLVABLE_ARCH:
928 return pool_id2str(pool, pool->solvables[entry].arch);
929 case SOLVABLE_EVR:
930 return pool_id2str(pool, pool->solvables[entry].evr);
931 case SOLVABLE_VENDOR:
932 return pool_id2str(pool, pool->solvables[entry].vendor);
933 }
934 }
935 else if (entry == SOLVID_POS-2 && pool->pos.repo == repo && pool->pos.repodataid)
936 return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname);
937 FOR_REPODATAS(repo, i, data)for (i = 1, data = repo->repodata + i; i < repo->nrepodata
; i++, data++)
938 {
939 if (entry != SOLVID_META-1 && (entry < data->start || entry >= data->end))
940 continue;
941 if (!repodata_precheck_keyname(data, keyname))
942 continue;
943 str = repodata_lookup_str(data, entry, keyname);
944 if (str)
945 return str;
946 if (repodata_lookup_type(data, entry, keyname))
947 return 0;
948 }
949 return 0;
950}
951
952
953unsigned long long
954repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned long long notfound)
955{
956 Pool *pool = repo->pool;
957 Repodata *data;
958 int i;
959 unsigned long long value;
960
961 if (entry >= 0)
962 {
963 if (keyname == RPM_RPMDBID)
964 {
965 if (repo->rpmdbid && entry >= repo->start && entry < repo->end)
966 return repo->rpmdbid[entry - repo->start];
967 return notfound;
968 }
969 }
970 else if (entry == SOLVID_POS-2 && pool->pos.repo == repo && pool->pos.repodataid)
971 return repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname, &value) ? value : notfound;
972 FOR_REPODATAS(repo, i, data)for (i = 1, data = repo->repodata + i; i < repo->nrepodata
; i++, data++)
973 {
974 if (entry != SOLVID_META-1 && (entry < data->start || entry >= data->end))
975 continue;
976 if (!repodata_precheck_keyname(data, keyname))
977 continue;
978 if (repodata_lookup_num(data, entry, keyname, &value))
979 return value;
980 if (repodata_lookup_type(data, entry, keyname))
981 return notfound;
982 }
983 return notfound;
984}
985
986Id
987repo_lookup_id(Repo *repo, Id entry, Id keyname)
988{
989 Pool *pool = repo->pool;
990 Repodata *data;
991 int i;
992 Id id;
993
994 if (entry >= 0)
995 {
996 switch (keyname)
997 {
998 case SOLVABLE_NAME:
999 return repo->pool->solvables[entry].name;
1000 case SOLVABLE_ARCH:
1001 return repo->pool->solvables[entry].arch;
1002 case SOLVABLE_EVR:
1003 return repo->pool->solvables[entry].evr;
1004 case SOLVABLE_VENDOR:
1005 return repo->pool->solvables[entry].vendor;
1006 }
1007 }
1008 else if (entry == SOLVID_POS-2 && pool->pos.repo == repo && pool->pos.repodataid)
1009 {
1010 Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
1011 Id id = repodata_lookup_id(data, entry, keyname);
1012 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1013 }
1014 FOR_REPODATAS(repo, i, data)for (i = 1, data = repo->repodata + i; i < repo->nrepodata
; i++, data++)
1015 {
1016 if (entry != SOLVID_META-1 && (entry < data->start || entry >= data->end))
1017 continue;
1018 if (!repodata_precheck_keyname(data, keyname))
1019 continue;
1020 id = repodata_lookup_id(data, entry, keyname);
1021 if (id)
1022 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1023 if (repodata_lookup_type(data, entry, keyname))
1024 return 0;
1025 }
1026 return 0;
1027}
1028
1029static int
1030lookup_idarray_solvable(Repo *repo, Offset off, Queue *q)
1031{
1032 Id *p;
1033
1034 queue_empty(q);
1035 if (off)
1036 for (p = repo->idarraydata + off; *p; p++)
1037 queue_push(q, *p);
1038 return 1;
1039}
1040
1041int
1042repo_lookup_idarray(Repo *repo, Id entry, Id keyname, Queue *q)
1043{
1044 Pool *pool = repo->pool;
1045 Repodata *data;
1046 int i;
1047 if (entry >= 0)
1048 {
1049 switch (keyname)
1050 {
1051 case SOLVABLE_PROVIDES:
1052 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].provides, q);
1053 case SOLVABLE_OBSOLETES:
1054 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].obsoletes, q);
1055 case SOLVABLE_CONFLICTS:
1056 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].conflicts, q);
1057 case SOLVABLE_REQUIRES:
1058 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].requires, q);
1059 case SOLVABLE_RECOMMENDS:
1060 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].recommends, q);
1061 case SOLVABLE_SUGGESTS:
1062 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].suggests, q);
1063 case SOLVABLE_SUPPLEMENTS:
1064 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].supplements, q);
1065 case SOLVABLE_ENHANCES:
1066 return lookup_idarray_solvable(repo, repo->pool->solvables[entry].enhances, q);
1067 }
1068 }
1069 else if (entry == SOLVID_POS-2 && pool->pos.repo == repo && pool->pos.repodataid)
1070 {
1071 Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
1072 if (repodata_lookup_idarray(data, entry, keyname, q))
1073 {
1074 if (data->localpool)
1075 {
1076 for (i = 0; i < q->count; i++)
1077 q->elements[i] = repodata_globalize_id(data, q->elements[i], 1);
1078 }
1079 return 1;
1080 }
1081 }
1082 FOR_REPODATAS(repo, i, data)for (i = 1, data = repo->repodata + i; i < repo->nrepodata
; i++, data++)
1083 {
1084 if (entry != SOLVID_META-1 && (entry < data->start || entry >= data->end))
1085 continue;
1086 if (!repodata_precheck_keyname(data, keyname))
1087 continue;
1088 if (repodata_lookup_idarray(data, entry, keyname, q))
1089 {
1090 if (data->localpool)
1091 {
1092 for (i = 0; i < q->count; i++)
1093 q->elements[i] = repodata_globalize_id(data, q->elements[i], 1);
1094 }
1095 return 1;
1096 }
1097 if (repodata_lookup_type(data, entry, keyname))
1098 break;
1099 }
1100 queue_empty(q);
1101 return 0;
1102}
1103
1104int
1105repo_lookup_deparray(Repo *repo, Id entry, Id keyname, Queue *q, Id marker)
1106{
1107 int r = repo_lookup_idarray(repo, entry, keyname, q);
1108 if (!r)
1109 return 0;
1110 if (marker == -1 || marker == 1)
1111 marker = solv_depmarker(keyname, marker);
1112 if (marker && q->count)
1113 {
1114 int i;
1115 if (marker < 0)
1116 {
1117 marker = -marker;
1118 for (i = 0; i < q->count; i++)
1119 if (q->elements[i] == marker)
1120 {
1121 queue_truncate(q, i);
1122 return r;
1123 }
1124 }
1125 else
1126 {
1127 for (i = 0; i < q->count; i++)
1128 if (q->elements[i] == marker)
1129 {
1130 queue_deleten(q, 0, i + 1);
1131 return r;
1132 }
1133 queue_empty(q);
1134 }
1135 }
1136 return r;
1137}
1138
1139const unsigned char *
1140repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
1141{
1142 Pool *pool = repo->pool;
1143 Repodata *data;
1144 int i;
1145 const unsigned char *chk;
1146
1147 if (entry == SOLVID_POS-2 && pool->pos.repo == repo && pool->pos.repodataid)
1148 return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname, typep);
1149 FOR_REPODATAS(repo, i, data)for (i = 1, data = repo->repodata + i; i < repo->nrepodata
; i++, data++)
1150 {
1151 if (entry != SOLVID_META-1 && (entry < data->start || entry >= data->end))
1152 continue;
1153 if (!repodata_precheck_keyname(data, keyname))
1154 continue;
1155 chk = repodata_lookup_bin_checksum(data, entry, keyname, typep);
1156 if (chk)
1157 return chk;
1158 if (repodata_lookup_type(data, entry, keyname))
1159 return 0;
1160 }
1161 *typep = 0;
1162 return 0;
1163}
1164
1165const char *
1166repo_lookup_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
1167{
1168 const unsigned char *chk = repo_lookup_bin_checksum(repo, entry, keyname, typep);
1169 return chk ? pool_bin2hex(repo->pool, chk, solv_chksum_len(*typep)) : 0;
1170}
1171
1172int
1173repo_lookup_void(Repo *repo, Id entry, Id keyname)
1174{
1175 Pool *pool = repo->pool;
1176 Repodata *data;
1177 int i;
1178 Id type;
1179
1180 if (entry == SOLVID_POS-2 && pool->pos.repo == repo && pool->pos.repodataid)
1181 return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname);
1182 FOR_REPODATAS(repo, i, data)for (i = 1, data = repo->repodata + i; i < repo->nrepodata
; i++, data++)
1183 {
1184 if (entry != SOLVID_META-1 && (entry < data->start || entry >= data->end))
1185 continue;
1186 if (!repodata_precheck_keyname(data, keyname))
1187 continue;
1188 type = repodata_lookup_type(data, entry, keyname);
1189 if (type)
1190 return type == REPOKEY_TYPE_VOID;
1191 }
1192 return 0;
1193}
1194
1195Id
1196repo_lookup_type(Repo *repo, Id entry, Id keyname)
1197{
1198 Pool *pool = repo->pool;
1199 Repodata *data;
1200 int i;
1201 Id type;
1202
1203 if (entry == SOLVID_POS-2 && pool->pos.repo == repo && pool->pos.repodataid)
1204 return repodata_lookup_type(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname);
1205 FOR_REPODATAS(repo, i, data)for (i = 1, data = repo->repodata + i; i < repo->nrepodata
; i++, data++)
1206 {
1207 if (entry != SOLVID_META-1 && (entry < data->start || entry >= data->end))
1208 continue;
1209 if (!repodata_precheck_keyname(data, keyname))
1210 continue;
1211 type = repodata_lookup_type(data, entry, keyname);
1212 if (type)
1213 return type == REPOKEY_TYPE_DELETED ? 0 : type;
1214 }
1215 return 0;
1216}
1217
1218const void *
1219repo_lookup_binary(Repo *repo, Id entry, Id keyname, int *lenp)
1220{
1221 Pool *pool = repo->pool;
1222 Repodata *data;
1223 int i;
1224 const void *bin;
1225
1226 if (entry == SOLVID_POS-2 && pool->pos.repo == repo && pool->pos.repodataid)
1227 return repodata_lookup_binary(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname, lenp);
1228 FOR_REPODATAS(repo, i, data)for (i = 1, data = repo->repodata + i; i < repo->nrepodata
; i++, data++)
1229 {
1230 if (entry != SOLVID_META-1 && (entry < data->start || entry >= data->end))
1231 continue;
1232 if (!repodata_precheck_keyname(data, keyname))
1233 continue;
1234 bin = repodata_lookup_binary(data, entry, keyname, lenp);
1235 if (bin)
1236 return bin;
1237 }
1238 *lenp = 0;
1239 return 0;
1240}
1241
1242/***********************************************************************/
1243
1244Repodata *
1245repo_add_repodata(Repo *repo, int flags)
1246{
1247 Repodata *data;
1248 int i;
1249 if ((flags & REPO_USE_LOADING(1 << 3)) != 0)
1250 {
1251 for (i = repo->nrepodata - 1; i > 0; i--)
1252 if (repo->repodata[i].state == REPODATA_LOADING4)
1253 {
1254 Repodata *data = repo->repodata + i;
1255 /* re-init */
1256 /* hack: we mis-use REPO_REUSE_REPODATA here */
1257 if (!(flags & REPO_REUSE_REPODATA(1 << 0)))
1258 repodata_empty(data, (flags & REPO_LOCALPOOL(1 << 2)) ? 1 : 0);
1259 return data;
1260 }
1261 return 0; /* must not create a new repodata! */
1262 }
1263 if ((flags & REPO_REUSE_REPODATA(1 << 0)) != 0)
1264 {
1265 for (i = repo->nrepodata - 1; i > 0; i--)
1266 if (repo->repodata[i].state != REPODATA_STUB1)
1267 return repo->repodata + i;
1268 }
1269 if (!repo->nrepodata)
1270 {
1271 repo->nrepodata = 2; /* start with id 1 */
1272 repo->repodata = solv_calloc(repo->nrepodata, sizeof(*data));
1273 }
1274 else
1275 {
1276 repo->nrepodata++;
1277 repo->repodata = solv_realloc2(repo->repodata, repo->nrepodata, sizeof(*data));
1278 }
1279 data = repo->repodata + repo->nrepodata - 1;
1280 repodata_initdata(data, repo, (flags & REPO_LOCALPOOL(1 << 2)) ? 1 : 0);
1281 return data;
1282}
1283
1284Repodata *
1285repo_id2repodata(Repo *repo, Id id)
1286{
1287 return id ? repo->repodata + id : 0;
1288}
1289
1290Repodata *
1291repo_last_repodata(Repo *repo)
1292{
1293 int i;
1294 for (i = repo->nrepodata - 1; i > 0; i--)
1295 if (repo->repodata[i].state != REPODATA_STUB1)
1296 return repo->repodata + i;
1297 return repo_add_repodata(repo, 0);
1298}
1299
1300void
1301repo_set_id(Repo *repo, Id p, Id keyname, Id id)
1302{
1303 Repodata *data;
1304 if (p >= 0)
1305 {
1306 switch (keyname)
1307 {
1308 case SOLVABLE_NAME:
1309 repo->pool->solvables[p].name = id;
1310 return;
1311 case SOLVABLE_ARCH:
1312 repo->pool->solvables[p].arch = id;
1313 return;
1314 case SOLVABLE_EVR:
1315 repo->pool->solvables[p].evr = id;
1316 return;
1317 case SOLVABLE_VENDOR:
1318 repo->pool->solvables[p].vendor = id;
1319 return;
1320 }
1321 }
1322 data = repo_last_repodata(repo);
1323 if (data->localpool)
1324 id = repodata_localize_id(data, id, 1);
1325 repodata_set_id(data, p, keyname, id);
1326}
1327
1328void
1329repo_set_num(Repo *repo, Id p, Id keyname, unsigned long long num)
1330{
1331 Repodata *data;
1332 if (p >= 0)
1333 {
1334 if (keyname == RPM_RPMDBID)
1335 {
1336 if (!repo->rpmdbid)
1337 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1338 repo->rpmdbid[p - repo->start] = num;
1339 return;
1340 }
1341 }
1342 data = repo_last_repodata(repo);
1343 repodata_set_num(data, p, keyname, num);
1344}
1345
1346void
1347repo_set_str(Repo *repo, Id p, Id keyname, const char *str)
1348{
1349 Repodata *data;
1350 if (p >= 0)
1351 {
1352 switch (keyname)
1353 {
1354 case SOLVABLE_NAME:
1355 case SOLVABLE_ARCH:
1356 case SOLVABLE_EVR:
1357 case SOLVABLE_VENDOR:
1358 repo_set_id(repo, p, keyname, pool_str2id(repo->pool, str, 1));
1359 return;
1360 }
1361 }
1362 data = repo_last_repodata(repo);
1363 repodata_set_str(data, p, keyname, str);
1364}
1365
1366void
1367repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str)
1368{
1369 Repodata *data;
1370 if (p >= 0)
1371 {
1372 switch (keyname)
1373 {
1374 case SOLVABLE_NAME:
1375 case SOLVABLE_ARCH:
1376 case SOLVABLE_EVR:
1377 case SOLVABLE_VENDOR:
1378 repo_set_id(repo, p, keyname, pool_str2id(repo->pool, str, 1));
1379 return;
1380 }
1381 }
1382 data = repo_last_repodata(repo);
1383 repodata_set_poolstr(data, p, keyname, str);
1384}
1385
1386void
1387repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str)
1388{
1389 Repodata *data = repo_last_repodata(repo);
1390 repodata_add_poolstr_array(data, p, keyname, str);
1391}
1392
1393void
1394repo_add_deparray(Repo *repo, Id p, Id keyname, Id dep, Id marker)
1395{
1396 Repodata *data;
1397 if (marker == -1 || marker == 1)
1398 marker = solv_depmarker(keyname, marker);
1399 if (p >= 0)
1400 {
1401 Solvable *s = repo->pool->solvables + p;
1402 switch (keyname)
1403 {
1404 case SOLVABLE_PROVIDES:
1405 s->provides = repo_addid_dep(repo, s->provides, dep, marker);
1406 return;
1407 case SOLVABLE_OBSOLETES:
1408 s->obsoletes = repo_addid_dep(repo, s->obsoletes, dep, marker);
1409 return;
1410 case SOLVABLE_CONFLICTS:
1411 s->conflicts = repo_addid_dep(repo, s->conflicts, dep, marker);
1412 return;
1413 case SOLVABLE_REQUIRES:
1414 s->requires = repo_addid_dep(repo, s->requires, dep, marker);
1415 return;
1416 case SOLVABLE_RECOMMENDS:
1417 s->recommends = repo_addid_dep(repo, s->recommends, dep, marker);
1418 return;
1419 case SOLVABLE_SUGGESTS:
1420 s->suggests = repo_addid_dep(repo, s->suggests, dep, marker);
1421 return;
1422 case SOLVABLE_SUPPLEMENTS:
1423 s->supplements = repo_addid_dep(repo, s->supplements, dep, marker);
1424 return;
1425 case SOLVABLE_ENHANCES:
1426 s->enhances = repo_addid_dep(repo, s->enhances, dep, marker);
1427 return;
1428 }
1429 }
1430 data = repo_last_repodata(repo);
1431 repodata_add_idarray(data, p, keyname, dep);
1432}
1433
1434void
1435repo_add_idarray(Repo *repo, Id p, Id keyname, Id id)
1436{
1437 repo_add_deparray(repo, p, keyname, id, 0);
1438}
1439
1440static Offset
1441repo_set_idarray_solvable(Repo *repo, Queue *q)
1442{
1443 Offset o = 0;
1444 int i;
1445 for (i = 0; i < q->count; i++)
1446 repo_addid_dep(repo, o, q->elements[i], 0);
1447 return o;
1448}
1449
1450void
1451repo_set_deparray(Repo *repo, Id p, Id keyname, Queue *q, Id marker)
1452{
1453 Repodata *data;
1454 if (marker == -1 || marker == 1)
1455 marker = solv_depmarker(keyname, marker);
1456 if (marker)
1457 {
1458 /* complex case, splice old and new arrays */
1459 int i;
1460 Queue q2;
1461 queue_init(&q2);
1462 repo_lookup_deparray(repo, p, keyname, &q2, -marker);
1463 if (marker > 0)
1464 {
1465 if (q->count)
1466 {
1467 queue_push(&q2, marker);
1468 for (i = 0; i < q->count; i++)
1469 queue_push(&q2, q->elements[i]);
1470 }
1471 }
1472 else
1473 {
1474 if (q2.count)
1475 queue_insert(&q2, 0, -marker);
1476 queue_insertn(&q2, 0, q->count, q->elements);
1477 }
1478 repo_set_deparray(repo, p, keyname, &q2, 0);
1479 queue_free(&q2);
1480 return;
1481 }
1482 if (p >= 0)
1483 {
1484 Solvable *s = repo->pool->solvables + p;
1485 switch (keyname)
1486 {
1487 case SOLVABLE_PROVIDES:
1488 s->provides = repo_set_idarray_solvable(repo, q);
1489 return;
1490 case SOLVABLE_OBSOLETES:
1491 s->obsoletes = repo_set_idarray_solvable(repo, q);
1492 return;
1493 case SOLVABLE_CONFLICTS:
1494 s->conflicts = repo_set_idarray_solvable(repo, q);
1495 return;
1496 case SOLVABLE_REQUIRES:
1497 s->requires = repo_set_idarray_solvable(repo, q);
1498 return;
1499 case SOLVABLE_RECOMMENDS:
1500 s->recommends = repo_set_idarray_solvable(repo, q);
1501 return;
1502 case SOLVABLE_SUGGESTS:
1503 s->suggests = repo_set_idarray_solvable(repo, q);
1504 return;
1505 case SOLVABLE_SUPPLEMENTS:
1506 s->supplements = repo_set_idarray_solvable(repo, q);
1507 return;
1508 case SOLVABLE_ENHANCES:
1509 s->enhances = repo_set_idarray_solvable(repo, q);
1510 return;
1511 }
1512 }
1513 data = repo_last_repodata(repo);
1514 repodata_set_idarray(data, p, keyname, q);
1515}
1516
1517void
1518repo_set_idarray(Repo *repo, Id p, Id keyname, Queue *q)
1519{
1520 repo_set_deparray(repo, p, keyname, q, 0);
1521}
1522
1523void
1524repo_unset(Repo *repo, Id p, Id keyname)
1525{
1526 Repodata *data;
1527 if (p >= 0)
1528 {
1529 Solvable *s = repo->pool->solvables + p;
1530 switch (keyname)
1531 {
1532 case SOLVABLE_NAME:
1533 s->name = 0;
1534 return;
1535 case SOLVABLE_ARCH:
1536 s->arch = 0;
1537 return;
1538 case SOLVABLE_EVR:
1539 s->evr = 0;
1540 return;
1541 case SOLVABLE_VENDOR:
1542 s->vendor = 0;
1543 return;
1544 case RPM_RPMDBID:
1545 if (repo->rpmdbid)
1546 repo->rpmdbid[p - repo->start] = 0;
1547 return;
1548 case SOLVABLE_PROVIDES:
1549 s->provides = 0;
1550 return;
1551 case SOLVABLE_OBSOLETES:
1552 s->obsoletes = 0;
1553 return;
1554 case SOLVABLE_CONFLICTS:
1555 s->conflicts = 0;
1556 return;
1557 case SOLVABLE_REQUIRES:
1558 s->requires = 0;
1559 return;
1560 case SOLVABLE_RECOMMENDS:
1561 s->recommends = 0;
1562 return;
1563 case SOLVABLE_SUGGESTS:
1564 s->suggests = 0;
1565 return;
1566 case SOLVABLE_SUPPLEMENTS:
1567 s->supplements = 0;
1568 case SOLVABLE_ENHANCES:
1569 s->enhances = 0;
1570 return;
1571 default:
1572 break;
1573 }
1574 }
1575 data = repo_last_repodata(repo);
1576 repodata_unset(data, p, keyname);
1577}
1578
1579void
1580repo_internalize(Repo *repo)
1581{
1582 int i;
1583 Repodata *data;
1584
1585 FOR_REPODATAS(repo, i, data)for (i = 1, data = repo->repodata + i; i < repo->nrepodata
; i++, data++)
1586 if (data->attrs || data->xattrs)
1587 repodata_internalize(data);
1588}
1589
1590void
1591repo_disable_paging(Repo *repo)
1592{
1593 int i;
1594 Repodata *data;
1595
1596 FOR_REPODATAS(repo, i, data)for (i = 1, data = repo->repodata + i; i < repo->nrepodata
; i++, data++)
1597 repodata_disable_paging(data);
1598}
1599