2 * Copyright (c) 2007-2009, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * The pool contains information about solvables
12 * stored optimized for memory consumption and fast retrieval.
22 #include "poolvendor.h"
25 #include "poolid_private.h"
31 #define SOLVABLE_BLOCK 255
33 #undef LIBSOLV_KNOWNID_H
34 #define KNOWNID_INITIALIZE
36 #undef KNOWNID_INITIALIZE
45 pool = (Pool *)solv_calloc(1, sizeof(*pool));
47 stringpool_init (&pool->ss, initpool_data);
49 /* alloc space for RelDep 0 */
50 pool->rels = solv_extend_resize(0, 1, sizeof(Reldep), REL_BLOCK);
52 memset(pool->rels, 0, sizeof(Reldep));
54 /* alloc space for Solvable 0 and system solvable */
55 pool->solvables = solv_extend_resize(0, 2, sizeof(Solvable), SOLVABLE_BLOCK);
57 memset(pool->solvables, 0, 2 * sizeof(Solvable));
59 queue_init(&pool->vendormap);
60 queue_init(&pool->pooljobs);
61 queue_init(&pool->lazywhatprovidesq);
64 pool->disttype = DISTTYPE_DEB;
65 pool->noarchid = ARCH_ALL;
66 #elif defined(ARCHLINUX)
67 pool->disttype = DISTTYPE_ARCH;
68 pool->noarchid = ARCH_ANY;
70 pool->disttype = DISTTYPE_HAIKU;
71 pool->noarchid = ARCH_ANY;
72 pool->obsoleteusesprovides = 1;
74 pool->disttype = DISTTYPE_RPM;
75 pool->noarchid = ARCH_NOARCH;
78 /* initialize the system solvable */
79 s = pool->solvables + SYSTEMSOLVABLE;
80 s->name = SYSTEM_SYSTEM;
81 s->arch = pool->noarchid;
84 pool->debugmask = SOLV_DEBUG_RESULT; /* FIXME */
86 pool->implicitobsoleteusescolors = 1;
89 pool->noobsoletesmultiversion = 1;
90 pool->forbidselfconflicts = 1;
91 pool->obsoleteusesprovides = 1;
92 pool->implicitobsoleteusesprovides = 1;
93 pool->havedistepoch = 1;
99 /* free all the resources of our pool */
101 pool_free(Pool *pool)
105 pool_freewhatprovides(pool);
106 pool_freeidhashes(pool);
107 pool_freeallrepos(pool, 1);
108 solv_free(pool->id2arch);
109 solv_free(pool->id2color);
110 solv_free(pool->solvables);
111 stringpool_free(&pool->ss);
112 solv_free(pool->rels);
113 pool_setvendorclasses(pool, 0);
114 queue_free(&pool->vendormap);
115 queue_free(&pool->pooljobs);
116 queue_free(&pool->lazywhatprovidesq);
117 for (i = 0; i < POOL_TMPSPACEBUF; i++)
118 solv_free(pool->tmpspace.buf[i]);
119 for (i = 0; i < pool->nlanguages; i++)
120 free((char *)pool->languages[i]);
121 solv_free(pool->languages);
122 solv_free(pool->languagecache);
123 solv_free(pool->errstr);
124 solv_free(pool->rootdir);
129 pool_freeallrepos(Pool *pool, int reuseids)
133 pool_freewhatprovides(pool);
134 for (i = 1; i < pool->nrepos; i++)
136 repo_freedata(pool->repos[i]);
137 pool->repos = solv_free(pool->repos);
140 /* the first two solvables don't belong to a repo */
141 pool_free_solvable_block(pool, 2, pool->nsolvables - 2, reuseids);
144 #ifdef MULTI_SEMANTICS
146 pool_setdisttype(Pool *pool, int disttype)
148 pool->disttype = disttype;
149 if (disttype == DISTTYPE_RPM)
150 pool->noarchid = ARCH_NOARCH;
151 if (disttype == DISTTYPE_DEB)
152 pool->noarchid = ARCH_ALL;
153 if (disttype == DISTTYPE_ARCH)
154 pool->noarchid = ARCH_ANY;
155 if (disttype == DISTTYPE_HAIKU)
156 pool->noarchid = ARCH_ANY;
157 pool->solvables[SYSTEMSOLVABLE].arch = pool->noarchid;
162 pool_get_flag(Pool *pool, int flag)
166 case POOL_FLAG_PROMOTEEPOCH:
167 return pool->promoteepoch;
168 case POOL_FLAG_FORBIDSELFCONFLICTS:
169 return pool->forbidselfconflicts;
170 case POOL_FLAG_OBSOLETEUSESPROVIDES:
171 return pool->obsoleteusesprovides;
172 case POOL_FLAG_IMPLICITOBSOLETEUSESPROVIDES:
173 return pool->implicitobsoleteusesprovides;
174 case POOL_FLAG_OBSOLETEUSESCOLORS:
175 return pool->obsoleteusescolors;
176 case POOL_FLAG_IMPLICITOBSOLETEUSESCOLORS:
177 return pool->implicitobsoleteusescolors;
178 case POOL_FLAG_NOINSTALLEDOBSOLETES:
179 return pool->noinstalledobsoletes;
180 case POOL_FLAG_HAVEDISTEPOCH:
181 return pool->havedistepoch;
182 case POOL_FLAG_NOOBSOLETESMULTIVERSION:
183 return pool->noobsoletesmultiversion;
184 case POOL_FLAG_ADDFILEPROVIDESFILTERED:
185 return pool->addfileprovidesfiltered;
193 pool_set_flag(Pool *pool, int flag, int value)
195 int old = pool_get_flag(pool, flag);
198 case POOL_FLAG_PROMOTEEPOCH:
199 pool->promoteepoch = value;
201 case POOL_FLAG_FORBIDSELFCONFLICTS:
202 pool->forbidselfconflicts = value;
204 case POOL_FLAG_OBSOLETEUSESPROVIDES:
205 pool->obsoleteusesprovides = value;
207 case POOL_FLAG_IMPLICITOBSOLETEUSESPROVIDES:
208 pool->implicitobsoleteusesprovides = value;
210 case POOL_FLAG_OBSOLETEUSESCOLORS:
211 pool->obsoleteusescolors = value;
213 case POOL_FLAG_IMPLICITOBSOLETEUSESCOLORS:
214 pool->implicitobsoleteusescolors = value;
216 case POOL_FLAG_NOINSTALLEDOBSOLETES:
217 pool->noinstalledobsoletes = value;
219 case POOL_FLAG_HAVEDISTEPOCH:
220 pool->havedistepoch = value;
222 case POOL_FLAG_NOOBSOLETESMULTIVERSION:
223 pool->noobsoletesmultiversion = value;
225 case POOL_FLAG_ADDFILEPROVIDESFILTERED:
226 pool->addfileprovidesfiltered = value;
236 pool_add_solvable(Pool *pool)
238 pool->solvables = solv_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
239 memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
240 return pool->nsolvables++;
244 pool_add_solvable_block(Pool *pool, int count)
246 Id nsolvables = pool->nsolvables;
249 pool->solvables = solv_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
250 memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
251 pool->nsolvables += count;
256 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
260 if (reuseids && start + count == pool->nsolvables)
262 /* might want to shrink solvable array */
263 pool->nsolvables = start;
266 memset(pool->solvables + start, 0, sizeof(Solvable) * count);
271 pool_set_installed(Pool *pool, Repo *installed)
273 if (pool->installed == installed)
275 pool->installed = installed;
276 pool_freewhatprovides(pool);
280 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp, void *dp)
285 oa = pool->whatprovides[*(Id *)ap];
286 ob = pool->whatprovides[*(Id *)bp];
288 return *(Id *)ap - *(Id *)bp;
289 da = pool->whatprovidesdata + oa;
290 db = pool->whatprovidesdata + ob;
292 if ((r = (*da++ - *db++)) != 0)
296 return *(Id *)ap - *(Id *)bp;
300 * pool_shrink_whatprovides - unify whatprovides data
302 * whatprovides_rel must be empty for this to work!
306 pool_shrink_whatprovides(Pool *pool)
310 Id lastid, *last, *dp, *lp;
314 if (pool->ss.nstrings < 3)
316 sorted = solv_malloc2(pool->ss.nstrings, sizeof(Id));
317 for (i = id = 0; id < pool->ss.nstrings; id++)
318 if (pool->whatprovides[id] >= 4)
321 solv_sort(sorted, n, sizeof(Id), pool_shrink_whatprovides_sortcmp, pool);
324 for (i = 0; i < n; i++)
327 o = pool->whatprovides[id];
328 dp = pool->whatprovidesdata + o;
342 pool->whatprovides[id] = -lastid;
346 last = pool->whatprovidesdata + o;
350 dp = pool->whatprovidesdata + 4;
351 for (id = 1; id < pool->ss.nstrings; id++)
353 o = pool->whatprovides[id];
361 pool->whatprovides[id] = pool->whatprovides[i];
366 lp = pool->whatprovidesdata + o;
369 pool->whatprovides[id] = dp - pool->whatprovidesdata;
370 while ((*dp++ = *lp++) != 0)
373 o = dp - pool->whatprovidesdata;
374 POOL_DEBUG(SOLV_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
375 if (pool->whatprovidesdataoff == o)
377 r = pool->whatprovidesdataoff - o;
378 pool->whatprovidesdataoff = o;
379 pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
380 if (r > pool->whatprovidesdataleft)
381 r = pool->whatprovidesdataleft;
382 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
387 * pool_createwhatprovides()
389 * create hashes over pool of solvables to ease provide lookups
393 pool_createwhatprovides(Pool *pool)
395 int i, num, np, extra;
400 Offset *whatprovides;
401 Id *whatprovidesdata, *d;
402 Repo *installed = pool->installed;
405 now = solv_timems(0);
406 POOL_DEBUG(SOLV_DEBUG_STATS, "number of solvables: %d, memory used: %d K\n", pool->nsolvables, pool->nsolvables * (int)sizeof(Solvable) / 1024);
407 POOL_DEBUG(SOLV_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
408 POOL_DEBUG(SOLV_DEBUG_STATS, "string memory used: %d K array + %d K data, rel memory used: %d K array\n", pool->ss.nstrings / (1024 / (int)sizeof(Id)), pool->ss.sstrings / 1024, pool->nrels * (int)sizeof(Reldep) / 1024);
409 if (pool->ss.stringhashmask || pool->relhashmask)
410 POOL_DEBUG(SOLV_DEBUG_STATS, "string hash memory: %d K, rel hash memory : %d K\n", (pool->ss.stringhashmask + 1) / (int)(1024/sizeof(Id)), (pool->relhashmask + 1) / (int)(1024/sizeof(Id)));
412 pool_freeidhashes(pool); /* XXX: should not be here! */
413 pool_freewhatprovides(pool);
414 num = pool->ss.nstrings;
415 pool->whatprovides = whatprovides = solv_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
416 pool->whatprovides_rel = solv_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
418 /* count providers for each name */
419 for (i = pool->nsolvables - 1; i > 0; i--)
422 s = pool->solvables + i;
423 if (!s->provides || !s->repo || s->repo->disabled)
425 /* we always need the installed solvable in the whatprovides data,
426 otherwise obsoletes/conflicts on them won't work */
427 if (s->repo != installed && !pool_installable(pool, s))
429 pp = s->repo->idarraydata + s->provides;
430 while ((id = *pp++) != 0)
434 Reldep *rd = GETRELDEP(pool, id);
437 whatprovides[id]++; /* inc count of providers */
441 off = 4; /* first entry is undef, second is empty list, third is system solvable */
442 np = 0; /* number of names provided */
443 for (i = 0, idp = whatprovides; i < num; i++, idp++)
446 if (!n) /* no providers */
448 *idp = 1; /* offset for empty list */
451 off += n; /* make space for all providers */
452 *idp = off++; /* now idp points to terminating zero */
453 np++; /* inc # of provider 'slots' for stats */
456 POOL_DEBUG(SOLV_DEBUG_STATS, "provide ids: %d\n", np);
458 /* reserve some space for relation data */
459 extra = 2 * pool->nrels;
463 POOL_DEBUG(SOLV_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
465 /* alloc space for all providers + extra */
466 whatprovidesdata = solv_calloc(off + extra, sizeof(Id));
467 whatprovidesdata[2] = SYSTEMSOLVABLE;
469 /* now fill data for all provides */
470 for (i = pool->nsolvables - 1; i > 0; i--)
473 s = pool->solvables + i;
474 if (!s->provides || !s->repo || s->repo->disabled)
476 if (s->repo != installed && !pool_installable(pool, s))
479 /* for all provides of this solvable */
480 pp = s->repo->idarraydata + s->provides;
481 while ((id = *pp++) != 0)
485 Reldep *rd = GETRELDEP(pool, id);
488 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
489 if (*d != i) /* don't add same solvable twice */
496 pool->whatprovidesdata = whatprovidesdata;
497 pool->whatprovidesdataoff = off;
498 pool->whatprovidesdataleft = extra;
499 pool_shrink_whatprovides(pool);
500 POOL_DEBUG(SOLV_DEBUG_STATS, "whatprovides memory used: %d K id array, %d K data\n", (pool->ss.nstrings + pool->nrels + WHATPROVIDES_BLOCK) / (int)(1024/sizeof(Id)), (pool->whatprovidesdataoff + pool->whatprovidesdataleft) / (int)(1024/sizeof(Id)));
502 queue_empty(&pool->lazywhatprovidesq);
503 if ((!pool->addedfileprovides && pool->disttype == DISTTYPE_RPM) || pool->addedfileprovides == 1)
505 if (!pool->addedfileprovides)
506 POOL_DEBUG(SOLV_DEBUG_STATS, "WARNING: pool_addfileprovides was not called, this may result in slow operation\n");
507 /* lazyly add file provides */
508 for (i = 1; i < num; i++)
510 const char *str = pool->ss.stringspace + pool->ss.strings[i];
513 if (pool->addedfileprovides == 1 && repodata_filelistfilter_matches(0, str))
515 /* setup lazy adding, but remember old value */
516 if (pool->whatprovides[i] > 1)
517 queue_push2(&pool->lazywhatprovidesq, i, pool->whatprovides[i]);
518 pool->whatprovides[i] = 0;
520 POOL_DEBUG(SOLV_DEBUG_STATS, "lazywhatprovidesq size: %d entries\n", pool->lazywhatprovidesq.count / 2);
523 POOL_DEBUG(SOLV_DEBUG_STATS, "createwhatprovides took %d ms\n", solv_timems(now));
527 * free all of our whatprovides data
528 * be careful, everything internalized with pool_queuetowhatprovides is
532 pool_freewhatprovides(Pool *pool)
534 pool->whatprovides = solv_free(pool->whatprovides);
535 pool->whatprovides_rel = solv_free(pool->whatprovides_rel);
536 pool->whatprovidesdata = solv_free(pool->whatprovidesdata);
537 pool->whatprovidesdataoff = 0;
538 pool->whatprovidesdataleft = 0;
542 /******************************************************************************/
545 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
547 * used for whatprovides, jobs, learnt rules, selections
548 * input: q: queue of Ids
549 * returns: Offset into whatprovidesdata
553 pool_queuetowhatprovides(Pool *pool, Queue *q)
556 int count = q->count;
558 if (count == 0) /* queue empty -> 1 */
560 if (count == 1 && q->elements[0] == SYSTEMSOLVABLE)
563 /* extend whatprovidesdata if needed, +1 for 0-termination */
564 if (pool->whatprovidesdataleft < count + 1)
566 POOL_DEBUG(SOLV_DEBUG_STATS, "growing provides hash data...\n");
567 pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
568 pool->whatprovidesdataleft = count + 4096;
571 /* copy queue to next free slot */
572 off = pool->whatprovidesdataoff;
573 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
575 /* adapt count and 0-terminate */
576 pool->whatprovidesdataoff += count;
577 pool->whatprovidesdata[pool->whatprovidesdataoff++] = 0;
578 pool->whatprovidesdataleft -= count + 1;
584 /*************************************************************************/
586 #if defined(MULTI_SEMANTICS)
587 # define EVRCMP_DEPCMP (pool->disttype == DISTTYPE_DEB ? EVRCMP_COMPARE : EVRCMP_MATCH_RELEASE)
588 #elif defined(DEBIAN)
589 # define EVRCMP_DEPCMP EVRCMP_COMPARE
591 # define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
594 /* check if a package's nevr matches a dependency */
595 /* semi-private, called from public pool_match_nevr */
598 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
600 Reldep *rd = GETRELDEP(pool, d);
603 int flags = rd->flags;
612 if (evr != ARCH_SRC || s->arch != ARCH_NOSRC)
615 return pool_match_nevr(pool, s, name);
617 if (pool_match_nevr(pool, s, name))
619 return pool_match_nevr(pool, s, evr);
622 if (!pool_match_nevr(pool, s, name))
624 return pool_match_nevr(pool, s, evr);
628 /* XXX : need to check for Multi-Arch: allowed! */
629 return pool_match_nevr(pool, s, name);
634 if (!pool_match_nevr(pool, s, name))
637 return (flags & REL_EQ) ? 1 : 0;
642 switch (pool_evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP))
647 return (flags & REL_LT) ? 1 : 0;
649 return (flags & REL_EQ) ? 1 : 0;
651 return (flags & REL_GT) ? 1 : 0;
653 return (flags & REL_EQ) ? 1 : 0;
660 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
661 /* forward declaration */
662 static int pool_match_flags_evr_rel_compat(Pool *pool, Reldep *range, int flags, int evr);
665 /* match (flags, evr) against provider (pflags, pevr) */
667 pool_match_flags_evr(Pool *pool, int pflags, Id pevr, int flags, int evr)
669 if (!pflags || !flags || pflags >= 8 || flags >= 8)
671 if (flags == 7 || pflags == 7)
672 return 1; /* rel provides every version */
673 if ((pflags & flags & (REL_LT | REL_GT)) != 0)
674 return 1; /* both rels show in the same direction */
676 return (flags & pflags & REL_EQ) ? 1 : 0;
677 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
680 Reldep *rd = GETRELDEP(pool, pevr);
681 if (rd->flags == REL_COMPAT)
682 return pool_match_flags_evr_rel_compat(pool, rd, flags, evr);
685 switch (pool_evrcmp(pool, pevr, evr, EVRCMP_DEPCMP))
688 return (pflags & REL_EQ) ? 1 : 0;
690 return (flags & REL_LT) || (pflags & REL_GT) ? 1 : 0;
692 return (flags & pflags & REL_EQ) ? 1 : 0;
694 return (flags & REL_GT) || (pflags & REL_LT) ? 1 : 0;
696 return (flags & REL_EQ) ? 1 : 0;
703 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
705 pool_match_flags_evr_rel_compat(Pool *pool, Reldep *range, int flags, int evr)
707 /* range->name is the actual version, range->evr the backwards compatibility
708 version. If flags are '>=' or '>', we match the compatibility version
709 as well, otherwise only the actual version. */
710 if (!(flags & REL_GT) || (flags & REL_LT))
711 return pool_match_flags_evr(pool, REL_EQ, range->name, flags, evr);
712 return pool_match_flags_evr(pool, REL_LT | REL_EQ, range->name, flags, evr) &&
713 pool_match_flags_evr(pool, REL_GT | REL_EQ, range->evr, REL_EQ, evr);
717 /* public (i.e. not inlined) version of pool_match_flags_evr */
719 pool_intersect_evrs(Pool *pool, int pflags, Id pevr, int flags, int evr)
721 return pool_match_flags_evr(pool, pflags, pevr, flags, evr);
724 /* match two dependencies (d1 = provider) */
727 pool_match_dep(Pool *pool, Id d1, Id d2)
737 rd2 = GETRELDEP(pool, d2);
738 return pool_match_dep(pool, d1, rd2->name);
740 rd1 = GETRELDEP(pool, d1);
743 return pool_match_dep(pool, rd1->name, d2);
745 rd2 = GETRELDEP(pool, d2);
746 /* first match name */
747 if (!pool_match_dep(pool, rd1->name, rd2->name))
749 /* name matches, check flags and evr */
750 return pool_intersect_evrs(pool, rd1->flags, rd1->evr, rd2->flags, rd2->evr);
754 pool_searchlazywhatprovidesq(Pool *pool, Id d)
757 int end = pool->lazywhatprovidesq.count;
761 elements = pool->lazywhatprovidesq.elements;
762 while (end - start > 16)
764 int mid = (start + end) / 2 & ~1;
765 if (elements[mid] == d)
766 return elements[mid + 1];
767 if (elements[mid] < d)
772 for (; start < end; start += 2)
773 if (elements[start] == d)
774 return elements[start + 1];
781 * lazy populating of the whatprovides array, non relation case
784 pool_addstdproviders(Pool *pool, Id d)
792 if (pool->addedfileprovides == 2)
794 pool->whatprovides[d] = 1;
797 str = pool->ss.stringspace + pool->ss.strings[d];
800 pool->whatprovides[d] = 1;
803 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
804 dataiterator_init(&di, pool, 0, 0, SOLVABLE_FILELIST, str, SEARCH_STRING|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
805 for (; dataiterator_step(&di); dataiterator_skip_solvable(&di))
807 Solvable *s = pool->solvables + di.solvid;
808 /* XXX: maybe should add a provides dependency to the solvables
809 * OTOH this is only needed for rel deps that filter the provides,
810 * and those should not use filelist entries */
811 if (s->repo->disabled)
813 if (s->repo != pool->installed && !pool_installable(pool, s))
815 queue_push(&q, di.solvid);
817 dataiterator_free(&di);
818 oldoffset = pool_searchlazywhatprovidesq(pool, d);
820 pool->whatprovides[d] = oldoffset ? oldoffset : 1;
825 Id *oo = pool->whatprovidesdata + oldoffset;
827 /* unify both queues. easy, as we know both are sorted */
828 for (i = 0; i < q.count; i++)
830 if (*oo > q.elements[i])
832 if (*oo < q.elements[i])
833 queue_insert(&q, i, *oo);
839 queue_push(&q, *oo++);
840 if (q.count == oo - (pool->whatprovidesdata + oldoffset))
842 /* end result has same size as oldoffset -> no new entries */
844 pool->whatprovides[d] = oldoffset;
848 pool->whatprovides[d] = pool_queuetowhatprovides(pool, &q);
851 return pool->whatprovides[d];
856 pool_is_kind(Pool *pool, Id name, Id kind)
861 n = pool_id2str(pool, name);
864 const char *kn = pool_id2str(pool, kind);
865 int knl = strlen(kn);
866 return !strncmp(n, kn, knl) && n[knl] == ':' ? 1 : 0;
872 while(*n >= 'a' && *n <= 'z')
874 return *n == ':' ? 0 : 1;
881 * add packages fulfilling the relation to whatprovides array
883 * some words about REL_AND and REL_IF: we assume the best case
884 * here, so that you get a "potential" result if you ask for a match.
885 * E.g. if you ask for "whatrequires A" and package X contains
886 * "Requires: A & B", you'll get "X" as an answer.
889 pool_addrelproviders(Pool *pool, Id d)
900 return pool_addstdproviders(pool, d);
901 rd = GETRELDEP(pool, d);
906 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
910 /* special relation */
917 wp = pool_whatprovides(pool, name);
918 pp2 = pool_whatprovides_ptr(pool, evr);
919 pp = pool->whatprovidesdata + wp;
920 while ((p = *pp++) != 0)
922 for (pp3 = pp2; *pp3; pp3++)
926 queue_push(&plist, p); /* found it */
934 wp = pool_whatprovides(pool, name);
935 if (!pool->whatprovidesdata[wp])
936 wp = pool_whatprovides(pool, evr);
940 pp2 = pool_whatprovides_ptr(pool, evr);
941 pp = pool->whatprovidesdata + wp;
945 queue_push(&plist, *pp++);
950 queue_push(&plist, *pp2++);
954 queue_push(&plist, *pp++);
956 queue_push(&plist, *pp2++);
957 /* if the number of elements did not change, we can reuse wp */
958 if (pp - (pool->whatprovidesdata + wp) != plist.count)
964 /* assume the condition is true */
965 wp = pool_whatprovides(pool, name);
969 if (name == NAMESPACE_OTHERPROVIDERS)
971 wp = pool_whatprovides(pool, evr);
974 if (pool->nscallback)
976 /* ask callback which packages provide the dependency
978 * 1: the system (aka SYSTEMSOLVABLE)
979 * >1: set of packages, stored as offset on whatprovidesdata
981 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
985 queue_push(&plist, SYSTEMSOLVABLE);
989 /* small hack: make it possible to match <pkg>.src
990 * we have to iterate over the solvables as src packages do not
991 * provide anything, thus they are not indexed in our
992 * whatprovides hash */
993 if (evr == ARCH_SRC || evr == ARCH_NOSRC)
996 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
1000 if (s->arch != evr && s->arch != ARCH_NOSRC)
1002 if (pool_disabled_solvable(pool, s))
1004 if (!name || pool_match_nevr(pool, s, name))
1005 queue_push(&plist, p);
1011 FOR_POOL_SOLVABLES(p)
1013 Solvable *s = pool->solvables + p;
1014 if (s->repo != pool->installed && !pool_installable(pool, s))
1017 queue_push(&plist, p);
1021 wp = pool_whatprovides(pool, name);
1022 pp = pool->whatprovidesdata + wp;
1023 while ((p = *pp++) != 0)
1025 Solvable *s = pool->solvables + p;
1027 queue_push(&plist, p);
1033 if (evr != ARCH_ANY)
1035 /* XXX : need to check for Multi-Arch: allowed! */
1036 wp = pool_whatprovides(pool, name);
1039 /* package kind filtering */
1042 FOR_POOL_SOLVABLES(p)
1044 Solvable *s = pool->solvables + p;
1045 if (s->repo != pool->installed && !pool_installable(pool, s))
1047 if (pool_is_kind(pool, s->name, evr))
1048 queue_push(&plist, p);
1052 wp = pool_whatprovides(pool, name);
1053 pp = pool->whatprovidesdata + wp;
1054 while ((p = *pp++) != 0)
1056 Solvable *s = pool->solvables + p;
1057 if (pool_is_kind(pool, s->name, evr))
1058 queue_push(&plist, p);
1063 case REL_FILECONFLICT:
1064 pp = pool_whatprovides_ptr(pool, name);
1065 while ((p = *pp++) != 0)
1067 Id origd = MAKERELDEP(d);
1068 Solvable *s = pool->solvables + p;
1071 pidp = s->repo->idarraydata + s->provides;
1072 while ((pid = *pidp++) != 0)
1076 queue_push(&plist, p);
1084 /* we can reuse an existing entry */
1086 pool->whatprovides_rel[d] = wp;
1092 /* simple version comparison relation */
1094 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: what provides %s?\n", pool_dep2str(pool, name));
1096 pp = pool_whatprovides_ptr(pool, name);
1097 while (ISRELDEP(name))
1099 rd = GETRELDEP(pool, name);
1102 while ((p = *pp++) != 0)
1104 Solvable *s = pool->solvables + p;
1107 /* no provides - check nevr */
1108 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
1109 queue_push(&plist, p);
1112 /* solvable p provides name in some rels */
1113 pidp = s->repo->idarraydata + s->provides;
1114 while ((pid = *pidp++) != 0)
1119 continue; /* wrong provides name */
1120 if (pool->disttype == DISTTYPE_DEB)
1121 continue; /* unversioned provides can never match versioned deps */
1124 prd = GETRELDEP(pool, pid);
1125 if (prd->name != name)
1126 continue; /* wrong provides name */
1127 /* right package, both deps are rels. check flags/evr */
1128 if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
1129 break; /* matches */
1132 continue; /* none of the providers matched */
1133 queue_push(&plist, p);
1135 /* make our system solvable provide all unknown rpmlib() stuff */
1136 if (plist.count == 0 && !strncmp(pool_id2str(pool, name), "rpmlib(", 7))
1137 queue_push(&plist, SYSTEMSOLVABLE);
1139 /* add providers to whatprovides */
1141 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
1143 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
1146 return pool->whatprovides_rel[d];
1150 pool_flush_namespaceproviders(Pool *pool, Id ns, Id evr)
1152 int nrels = pool->nrels;
1156 if (!pool->whatprovides_rel)
1158 for (d = 1, rd = pool->rels + d; d < nrels; d++, rd++)
1160 if (rd->flags != REL_NAMESPACE || rd->name == NAMESPACE_OTHERPROVIDERS)
1162 if (ns && rd->name != ns)
1164 if (evr && rd->evr != evr)
1166 pool->whatprovides_rel[d] = 0;
1170 /* intersect dependencies in keyname with dep, return list of matching packages */
1172 pool_whatmatchesdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker)
1177 FOR_POOL_SOLVABLES(p)
1179 Solvable *s = pool->solvables + p;
1180 if (s->repo->disabled)
1182 if (s->repo != pool->installed && !pool_installable(pool, s))
1184 if (solvable_matchesdep(s, keyname, dep, marker))
1189 /*************************************************************************/
1192 pool_debug(Pool *pool, int type, const char *format, ...)
1197 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0)
1199 if ((pool->debugmask & type) == 0)
1202 va_start(args, format);
1203 if (!pool->debugcallback)
1205 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0 && !(pool->debugmask & SOLV_DEBUG_TO_STDERR))
1206 vprintf(format, args);
1208 vfprintf(stderr, format, args);
1211 vsnprintf(buf, sizeof(buf), format, args);
1213 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
1217 pool_error(Pool *pool, int ret, const char *format, ...)
1221 va_start(args, format);
1224 pool->errstra = 1024;
1225 pool->errstr = solv_malloc(pool->errstra);
1233 l = vsnprintf(pool->errstr, pool->errstra, format, args);
1235 if (l >= 0 && l + 1 > pool->errstra)
1237 pool->errstra = l + 256;
1238 pool->errstr = solv_realloc(pool->errstr, pool->errstra);
1239 va_start(args, format);
1240 l = vsnprintf(pool->errstr, pool->errstra, format, args);
1244 strcpy(pool->errstr, "unknown error");
1245 if (pool->debugmask & SOLV_ERROR)
1246 pool_debug(pool, SOLV_ERROR, "%s\n", pool->errstr);
1251 pool_errstr(Pool *pool)
1253 return pool->errstr ? pool->errstr : "no error";
1257 pool_setdebuglevel(Pool *pool, int level)
1259 int mask = SOLV_DEBUG_RESULT;
1261 mask |= SOLV_DEBUG_STATS|SOLV_DEBUG_ANALYZE|SOLV_DEBUG_UNSOLVABLE|SOLV_DEBUG_SOLVER|SOLV_DEBUG_TRANSACTION|SOLV_ERROR;
1263 mask |= SOLV_DEBUG_JOB|SOLV_DEBUG_SOLUTIONS|SOLV_DEBUG_POLICY;
1265 mask |= SOLV_DEBUG_PROPAGATE;
1267 mask |= SOLV_DEBUG_RULE_CREATION;
1268 mask |= pool->debugmask & SOLV_DEBUG_TO_STDERR; /* keep bit */
1269 pool->debugmask = mask;
1272 void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
1274 pool->debugcallback = debugcallback;
1275 pool->debugcallbackdata = debugcallbackdata;
1278 void pool_setdebugmask(Pool *pool, int mask)
1280 pool->debugmask = mask;
1283 void pool_setloadcallback(Pool *pool, int (*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata)
1285 pool->loadcallback = cb;
1286 pool->loadcallbackdata = loadcbdata;
1289 void pool_setnamespacecallback(Pool *pool, Id (*cb)(struct _Pool *, void *, Id, Id), void *nscbdata)
1291 pool->nscallback = cb;
1292 pool->nscallbackdata = nscbdata;
1295 /*************************************************************************/
1297 struct searchfiles {
1303 #define SEARCHFILES_BLOCK 127
1306 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
1310 struct searchfiles *csf;
1312 while ((dep = *ida++) != 0)
1315 while (ISRELDEP(dep))
1318 sid = pool->ss.nstrings + GETRELID(dep);
1319 if (MAPTST(&csf->seen, sid))
1324 MAPSET(&csf->seen, sid);
1325 rd = GETRELDEP(pool, dep);
1328 else if (rd->flags == REL_NAMESPACE)
1330 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
1333 if (!csf || MAPTST(&csf->seen, sid))
1338 MAPSET(&csf->seen, sid);
1342 else if (rd->flags == REL_FILECONFLICT)
1352 pool_addfileprovides_dep(pool, ids, csf, isf);
1358 if (MAPTST(&csf->seen, dep))
1360 MAPSET(&csf->seen, dep);
1361 s = pool_id2str(pool, dep);
1364 if (csf != isf && pool->addedfileprovides == 1 && !repodata_filelistfilter_matches(0, s))
1365 continue; /* skip non-standard locations csf == isf: installed case */
1366 csf->ids = solv_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
1367 csf->ids[csf->nfiles++] = dep;
1371 struct addfileprovides_cbdata {
1385 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1387 struct addfileprovides_cbdata *cbd = cbdata;
1390 if (!cbd->useddirs.size)
1392 map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
1395 cbd->dirs = solv_malloc2(cbd->nfiles, sizeof(char *));
1396 cbd->names = solv_malloc2(cbd->nfiles, sizeof(char *));
1397 for (i = 0; i < cbd->nfiles; i++)
1399 char *s = solv_strdup(pool_id2str(data->repo->pool, cbd->ids[i]));
1401 s = strrchr(s, '/');
1403 cbd->names[i] = s + 1;
1406 for (i = 0; i < cbd->nfiles; i++)
1409 if (MAPTST(&cbd->providedids, cbd->ids[i]))
1414 did = repodata_str2dir(data, cbd->dirs[i], 0);
1417 MAPSET(&cbd->useddirs, did);
1419 repodata_free_dircache(data);
1421 if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
1423 for (i = 0; i < cbd->nfiles; i++)
1424 if (cbd->dids[i] == value->id && !strcmp(cbd->names[i], value->str))
1425 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
1430 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
1435 Queue fileprovidesq;
1436 int i, j, repoid, repodataid;
1437 int provstart, provend;
1439 int ndone, incomplete;
1444 cbd->nfiles = sf->nfiles;
1448 cbd->dids = solv_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
1449 map_init(&cbd->providedids, pool->ss.nstrings);
1452 repo = repoonly ? repoonly : pool->repos[repoid];
1453 map_init(&donemap, pool->nsolvables);
1454 queue_init(&fileprovidesq);
1455 provstart = provend = 0;
1458 if (!repo || repo->disabled)
1460 if (repoonly || ++repoid == pool->nrepos)
1462 repo = pool->repos[repoid];
1466 FOR_REPODATAS(repo, repodataid, data)
1468 if (ndone >= repo->nsolvables)
1471 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
1473 map_empty(&cbd->providedids);
1474 for (i = 0; i < fileprovidesq.count; i++)
1475 MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
1476 provstart = data->start;
1477 provend = data->end;
1478 for (i = 0; i < cbd->nfiles; i++)
1479 if (!MAPTST(&cbd->providedids, cbd->ids[i]))
1481 if (i == cbd->nfiles)
1483 /* great! no need to search files */
1484 for (p = data->start; p < data->end; p++)
1485 if (pool->solvables[p].repo == repo)
1487 if (MAPTST(&donemap, p))
1489 MAPSET(&donemap, p);
1496 if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
1499 if (data->start < provstart || data->end > provend)
1501 map_empty(&cbd->providedids);
1502 provstart = provend = 0;
1505 /* check if the data is incomplete */
1507 if (data->state == REPODATA_AVAILABLE)
1509 for (j = 1; j < data->nkeys; j++)
1510 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1512 if (j < data->nkeys)
1515 for (i = 0; i < cbd->nfiles; i++)
1516 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1517 printf("need complete filelist because of %s\n", pool_id2str(pool, cbd->ids[i]));
1519 for (i = 0; i < cbd->nfiles; i++)
1520 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1522 if (i < cbd->nfiles)
1528 map_init(&cbd->useddirs, 0);
1529 for (p = data->start; p < data->end; p++)
1530 if (pool->solvables[p].repo == repo)
1532 if (MAPTST(&donemap, p))
1534 repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
1537 MAPSET(&donemap, p);
1541 map_free(&cbd->useddirs);
1544 if (repoonly || ++repoid == pool->nrepos)
1546 repo = pool->repos[repoid];
1549 queue_free(&fileprovidesq);
1550 map_free(&cbd->providedids);
1553 for (i = 0; i < cbd->nfiles; i++)
1554 solv_free(cbd->dirs[i]);
1555 cbd->dirs = solv_free(cbd->dirs);
1556 cbd->names = solv_free(cbd->names);
1561 pool_addfileprovides_queue(Pool *pool, Queue *idq, Queue *idqinst)
1564 Repo *installed, *repo;
1565 struct searchfiles sf, isf, *isfp;
1566 struct addfileprovides_cbdata cbd;
1570 installed = pool->installed;
1571 now = solv_timems(0);
1572 memset(&sf, 0, sizeof(sf));
1573 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
1574 memset(&isf, 0, sizeof(isf));
1575 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
1576 pool->addedfileprovides = pool->addfileprovidesfiltered ? 1 : 2;
1581 queue_empty(idqinst);
1582 isfp = installed ? &isf : 0;
1583 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1589 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1591 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1593 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1595 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1597 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1599 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1601 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1604 map_free(&isf.seen);
1605 POOL_DEBUG(SOLV_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
1610 for (i = 0; i < sf.nfiles; i++)
1611 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in filelist\n", pool_id2str(pool, sf.ids[i]));
1613 pool_addfileprovides_search(pool, &cbd, &sf, 0);
1615 for (i = 0; i < sf.nfiles; i++)
1616 queue_push(idq, sf.ids[i]);
1618 for (i = 0; i < sf.nfiles; i++)
1619 queue_push(idqinst, sf.ids[i]);
1625 for (i = 0; i < isf.nfiles; i++)
1626 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in installed filelist\n", pool_id2str(pool, isf.ids[i]));
1629 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1630 if (installed && idqinst)
1631 for (i = 0; i < isf.nfiles; i++)
1632 queue_pushunique(idqinst, isf.ids[i]);
1635 solv_free(cbd.dids);
1636 pool_freewhatprovides(pool); /* as we have added provides */
1637 POOL_DEBUG(SOLV_DEBUG_STATS, "addfileprovides took %d ms\n", solv_timems(now));
1641 pool_addfileprovides(Pool *pool)
1643 pool_addfileprovides_queue(pool, 0, 0);
1647 pool_search(Pool *pool, Id p, Id key, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, struct _Repodata *data, struct _Repokey *key, struct _KeyValue *kv), void *cbdata)
1651 if (pool->solvables[p].repo)
1652 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1655 /* FIXME: obey callback return value! */
1656 for (p = 1; p < pool->nsolvables; p++)
1657 if (pool->solvables[p].repo)
1658 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1662 pool_clear_pos(Pool *pool)
1664 memset(&pool->pos, 0, sizeof(pool->pos));
1669 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1673 pool->languagecache = solv_free(pool->languagecache);
1674 pool->languagecacheother = 0;
1675 for (i = 0; i < pool->nlanguages; i++)
1676 free((char *)pool->languages[i]);
1677 pool->languages = solv_free(pool->languages);
1678 pool->nlanguages = nlanguages;
1681 pool->languages = solv_calloc(nlanguages, sizeof(const char **));
1682 for (i = 0; i < pool->nlanguages; i++)
1683 pool->languages[i] = solv_strdup(languages[i]);
1687 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1693 if (!lang || !*lang)
1695 n = pool_id2str(pool, id);
1696 l = strlen(n) + strlen(lang) + 2;
1697 if (l > sizeof(buf))
1698 p = solv_malloc(strlen(n) + strlen(lang) + 2);
1701 sprintf(p, "%s:%s", n, lang);
1702 id = pool_str2id(pool, p, create);
1709 pool_alloctmpspace(Pool *pool, int len)
1711 int n = pool->tmpspace.n;
1714 if (len > pool->tmpspace.len[n])
1716 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1717 pool->tmpspace.len[n] = len + 32;
1719 pool->tmpspace.n = (n + 1) % POOL_TMPSPACEBUF;
1720 return pool->tmpspace.buf[n];
1724 pool_alloctmpspace_free(Pool *pool, const char *space, int len)
1729 n = oldn = pool->tmpspace.n;
1733 n = POOL_TMPSPACEBUF - 1;
1736 if (pool->tmpspace.buf[n] != space)
1738 if (len > pool->tmpspace.len[n])
1740 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1741 pool->tmpspace.len[n] = len + 32;
1743 return pool->tmpspace.buf[n];
1750 pool_freetmpspace(Pool *pool, const char *space)
1752 int n = pool->tmpspace.n;
1755 n = (n + (POOL_TMPSPACEBUF - 1)) % POOL_TMPSPACEBUF;
1756 if (pool->tmpspace.buf[n] == space)
1757 pool->tmpspace.n = n;
1761 pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
1765 l1 = str1 ? strlen(str1) : 0;
1766 l2 = str2 ? strlen(str2) : 0;
1767 l3 = str3 ? strlen(str3) : 0;
1768 s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1789 pool_tmpappend(Pool *pool, const char *str1, const char *str2, const char *str3)
1794 l1 = str1 ? strlen(str1) : 0;
1795 l2 = str2 ? strlen(str2) : 0;
1796 l3 = str3 ? strlen(str3) : 0;
1797 str = pool_alloctmpspace_free(pool, str1, l1 + l2 + l3 + 1);
1801 str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1824 pool_bin2hex(Pool *pool, const unsigned char *buf, int len)
1829 s = pool_alloctmpspace(pool, 2 * len + 1);
1830 solv_bin2hex(buf, len, s);
1834 /*******************************************************************/
1846 struct mptree *mptree;
1857 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1859 struct ducbdata *cbd = cbdata;
1862 if (data != cbd->olddata)
1864 Id dn, mp, comp, *dirmap, *dirs;
1866 const char *compstr;
1867 struct mptree *mptree;
1869 /* create map from dir to mptree */
1870 cbd->dirmap = solv_free(cbd->dirmap);
1872 dirmap = solv_calloc(data->dirpool.ndirs, sizeof(Id));
1873 mptree = cbd->mptree;
1875 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1889 if (!mptree[mp].child)
1894 if (data->localpool)
1895 compstr = stringpool_id2str(&data->spool, comp);
1897 compstr = pool_id2str(data->repo->pool, comp);
1898 compl = strlen(compstr);
1899 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1900 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1902 dirmap[dn] = i ? i : -mp;
1904 /* change dirmap to point to mountpoint instead of mptree */
1905 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1908 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1910 cbd->dirmap = dirmap;
1911 cbd->nmap = data->dirpool.ndirs;
1912 cbd->olddata = data;
1915 if (value->id < 0 || value->id >= cbd->nmap)
1917 mp = cbd->dirmap[value->id];
1920 if (cbd->addsub > 0)
1922 cbd->mps[mp].kbytes += value->num;
1923 cbd->mps[mp].files += value->num2;
1927 cbd->mps[mp].kbytes -= value->num;
1928 cbd->mps[mp].files -= value->num2;
1934 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1937 if (mptree[pos].mountpoint == -1)
1938 mptree[pos].mountpoint = mountpoint;
1940 mountpoint = mptree[pos].mountpoint;
1941 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1942 propagate_mountpoints(mptree, i, mountpoint);
1945 #define MPTREE_BLOCK 15
1947 static struct mptree *
1948 create_mptree(DUChanges *mps, int nmps)
1951 struct mptree *mptree;
1954 const char *p, *path, *compstr;
1956 mptree = solv_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1959 mptree[0].sibling = 0;
1960 mptree[0].child = 0;
1962 mptree[0].compl = 0;
1963 mptree[0].mountpoint = -1;
1966 /* create component tree */
1967 for (mp = 0; mp < nmps; mp++)
1972 path = mps[mp].path;
1977 if ((p = strchr(path, '/')) == 0)
1980 compl = strlen(compstr);
1991 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1992 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1996 /* create new node */
1997 mptree = solv_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1999 mptree[i].sibling = mptree[pos].child;
2000 mptree[i].child = 0;
2001 mptree[i].comp = compstr;
2002 mptree[i].compl = compl;
2003 mptree[i].mountpoint = -1;
2004 mptree[pos].child = i;
2008 mptree[pos].mountpoint = mp;
2011 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
2014 for (i = 0; i < nmptree; i++)
2016 printf("#%d sibling: %d\n", i, mptree[i].sibling);
2017 printf("#%d child: %d\n", i, mptree[i].child);
2018 printf("#%d comp: %s\n", i, mptree[i].comp);
2019 printf("#%d compl: %d\n", i, mptree[i].compl);
2020 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
2028 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
2030 struct mptree *mptree;
2031 struct ducbdata cbd;
2035 Repo *oldinstalled = pool->installed;
2037 map_init(&ignoredu, 0);
2038 mptree = create_mptree(mps, nmps);
2044 cbd.mptree = mptree;
2046 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
2048 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
2050 if (!MAPTST(installedmap, sp))
2053 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
2054 if (!cbd.hasdu && oldinstalled)
2057 /* no du data available, ignore data of all installed solvables we obsolete */
2059 map_grow(&ignoredu, oldinstalled->end - oldinstalled->start);
2062 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
2063 while ((obs = *obsp++) != 0)
2064 FOR_PROVIDES(op, opp, obs)
2065 if (op >= oldinstalled->start && op < oldinstalled->end)
2066 MAPSET(&ignoredu, op - oldinstalled->start);
2068 FOR_PROVIDES(op, opp, s->name)
2069 if (pool->solvables[op].name == s->name)
2070 if (op >= oldinstalled->start && op < oldinstalled->end)
2071 MAPSET(&ignoredu, op - oldinstalled->start);
2077 /* assumes we allways have du data for installed solvables */
2078 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
2080 if (MAPTST(installedmap, sp))
2082 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
2084 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
2087 map_free(&ignoredu);
2088 solv_free(cbd.dirmap);
2093 pool_calc_installsizechange(Pool *pool, Map *installedmap)
2098 Repo *oldinstalled = pool->installed;
2100 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
2102 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
2104 if (!MAPTST(installedmap, sp))
2106 change += solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
2110 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
2112 if (MAPTST(installedmap, sp))
2114 change -= solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
2122 * 2: conflicts with installed
2123 * 8: interesting (only true if installed)
2127 static inline Id dep2name(Pool *pool, Id dep)
2129 while (ISRELDEP(dep))
2131 Reldep *rd = GETRELDEP(pool, dep);
2137 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con)
2140 Solvable *sn = pool->solvables + n;
2142 FOR_PROVIDES(p, pp, sn->name)
2144 Solvable *s = pool->solvables + p;
2145 if (s->name != sn->name || s->arch != sn->arch)
2147 if ((map[p] & 9) != 9)
2149 if (pool_match_nevr(pool, pool->solvables + p, con))
2151 return 1; /* found installed package that doesn't conflict */
2156 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *multiversionmap)
2160 FOR_PROVIDES(p, pp, dep)
2162 if (p == SYSTEMSOLVABLE)
2163 return 1; /* always boring, as never constraining */
2164 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
2166 if (ispatch && multiversionmap && multiversionmap->size && MAPTST(multiversionmap, p) && ISRELDEP(dep))
2167 if (providedbyinstalled_multiversion(pool, map, p, dep))
2169 if ((map[p] & 9) == 9)
2177 * pool_trivial_installable - calculate if a set of solvables is
2178 * trivial installable without any other installs/deinstalls of
2179 * packages not belonging to the set.
2181 * the state is returned in the result queue:
2182 * 1: solvable is installable without any other package changes
2183 * 0: solvable is not installable
2184 * -1: solvable is installable, but doesn't constrain any installed packages
2188 pool_trivial_installable_multiversionmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *multiversionmap)
2191 Id p, *dp, con, *conp, req, *reqp;
2195 map = solv_calloc(pool->nsolvables, 1);
2196 for (p = 1; p < pool->nsolvables; p++)
2198 if (!MAPTST(installedmap, p))
2201 s = pool->solvables + p;
2204 conp = s->repo->idarraydata + s->conflicts;
2205 while ((con = *conp++) != 0)
2207 dp = pool_whatprovides_ptr(pool, con);
2209 map[p] |= 2; /* XXX: self conflict ? */
2212 for (i = 0; i < pkgs->count; i++)
2213 map[pkgs->elements[i]] = 16;
2215 for (i = 0, did = 0; did < pkgs->count; i++, did++)
2217 if (i == pkgs->count)
2219 p = pkgs->elements[i];
2220 if ((map[p] & 16) == 0)
2222 if ((map[p] & 2) != 0)
2227 s = pool->solvables + p;
2231 reqp = s->repo->idarraydata + s->requires;
2232 while ((req = *reqp++) != 0)
2234 if (req == SOLVABLE_PREREQMARKER)
2236 r = providedbyinstalled(pool, map, req, 0, 0);
2239 /* decided and miss */
2245 break; /* undecided */
2246 m |= r; /* 1 | 9 | 17 */
2255 int ispatch = 0; /* see solver.c patch handling */
2257 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
2259 conp = s->repo->idarraydata + s->conflicts;
2260 while ((con = *conp++) != 0)
2262 if ((providedbyinstalled(pool, map, con, ispatch, multiversionmap) & 1) != 0)
2268 if ((m == 1 || m == 17) && ISRELDEP(con))
2270 con = dep2name(pool, con);
2271 if ((providedbyinstalled(pool, map, con, ispatch, multiversionmap) & 1) != 0)
2276 continue; /* found a conflict */
2279 if (s->repo && s->repo != oldinstalled)
2281 Id p2, obs, *obsp, *pp;
2285 obsp = s->repo->idarraydata + s->obsoletes;
2286 while ((obs = *obsp++) != 0)
2288 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
2297 FOR_PROVIDES(p2, pp, s->name)
2299 s2 = pool->solvables + p2;
2300 if (s2->name == s->name && (map[p2] & 1) != 0)
2317 queue_init_clone(res, pkgs);
2318 for (i = 0; i < pkgs->count; i++)
2320 m = map[pkgs->elements[i]];
2327 res->elements[i] = r;
2333 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
2335 pool_trivial_installable_multiversionmap(pool, installedmap, pkgs, res, 0);
2339 pool_lookup_str(Pool *pool, Id entry, Id keyname)
2341 if (entry == SOLVID_POS && pool->pos.repo)
2342 return repo_lookup_str(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
2345 return solvable_lookup_str(pool->solvables + entry, keyname);
2349 pool_lookup_id(Pool *pool, Id entry, Id keyname)
2351 if (entry == SOLVID_POS && pool->pos.repo)
2352 return repo_lookup_id(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
2355 return solvable_lookup_id(pool->solvables + entry, keyname);
2359 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned long long notfound)
2361 if (entry == SOLVID_POS && pool->pos.repo)
2362 return repo_lookup_num(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, notfound);
2365 return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
2369 pool_lookup_void(Pool *pool, Id entry, Id keyname)
2371 if (entry == SOLVID_POS && pool->pos.repo)
2372 return repo_lookup_void(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
2375 return solvable_lookup_void(pool->solvables + entry, keyname);
2378 const unsigned char *
2379 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
2381 if (entry == SOLVID_POS && pool->pos.repo)
2382 return repo_lookup_bin_checksum(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, typep);
2385 return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
2389 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
2391 if (entry == SOLVID_POS && pool->pos.repo)
2392 return repo_lookup_checksum(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, typep);
2395 return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
2399 pool_lookup_idarray(Pool *pool, Id entry, Id keyname, Queue *q)
2401 if (entry == SOLVID_POS && pool->pos.repo)
2402 return repo_lookup_idarray(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, q);
2405 return solvable_lookup_idarray(pool->solvables + entry, keyname, q);
2409 pool_lookup_deltalocation(Pool *pool, Id entry, unsigned int *medianrp)
2414 if (entry != SOLVID_POS)
2416 loc = pool_lookup_str(pool, entry, DELTA_LOCATION_DIR);
2417 loc = pool_tmpjoin(pool, loc, loc ? "/" : 0, pool_lookup_str(pool, entry, DELTA_LOCATION_NAME));
2418 loc = pool_tmpappend(pool, loc, "-", pool_lookup_str(pool, entry, DELTA_LOCATION_EVR));
2419 loc = pool_tmpappend(pool, loc, ".", pool_lookup_str(pool, entry, DELTA_LOCATION_SUFFIX));
2424 add_new_provider(Pool *pool, Id id, Id p)
2429 while (ISRELDEP(id))
2431 Reldep *rd = GETRELDEP(pool, id);
2436 for (pp = pool->whatprovidesdata + pool->whatprovides[id]; *pp; pp++)
2448 queue_push(&q, *pp);
2452 pool->whatprovides[id] = pool_queuetowhatprovides(pool, &q);
2457 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
2459 int hadhashes = pool->relhashtbl ? 1 : 0;
2465 if (!conflicts->count)
2467 for (i = 0; i < conflicts->count; i += 6)
2469 fn = conflicts->elements[i];
2470 p = conflicts->elements[i + 1];
2471 md5 = conflicts->elements[i + 2];
2472 q = conflicts->elements[i + 4];
2473 id = pool_rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
2474 s = pool->solvables + p;
2477 s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
2478 if (pool->whatprovides)
2479 add_new_provider(pool, fn, p);
2480 if (pool->whatprovides_rel)
2481 pool->whatprovides_rel[GETRELID(id)] = 0; /* clear cache */
2482 s = pool->solvables + q;
2485 s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
2488 pool_freeidhashes(pool);
2492 pool_prepend_rootdir(Pool *pool, const char *path)
2497 return solv_strdup(path);
2498 return solv_dupjoin(pool->rootdir, "/", *path == '/' ? path + 1 : path);
2502 pool_prepend_rootdir_tmp(Pool *pool, const char *path)
2508 return pool_tmpjoin(pool, pool->rootdir, "/", *path == '/' ? path + 1 : path);
2512 pool_set_rootdir(Pool *pool, const char *rootdir)
2514 solv_free(pool->rootdir);
2515 pool->rootdir = solv_strdup(rootdir);
2519 pool_get_rootdir(Pool *pool)
2521 return pool->rootdir;
2524 /* only used in libzypp */
2526 pool_set_custom_vendorcheck(Pool *pool, int (*vendorcheck)(Pool *, Solvable *, Solvable *))
2528 pool->custom_vendorcheck = vendorcheck;