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 #define KNOWNID_INITIALIZE
35 #undef KNOWNID_INITIALIZE
44 pool = (Pool *)solv_calloc(1, sizeof(*pool));
46 stringpool_init (&pool->ss, initpool_data);
48 /* alloc space for RelDep 0 */
49 pool->rels = solv_extend_resize(0, 1, sizeof(Reldep), REL_BLOCK);
51 memset(pool->rels, 0, sizeof(Reldep));
53 /* alloc space for Solvable 0 and system solvable */
54 pool->solvables = solv_extend_resize(0, 2, sizeof(Solvable), SOLVABLE_BLOCK);
56 memset(pool->solvables, 0, 2 * sizeof(Solvable));
58 queue_init(&pool->vendormap);
59 queue_init(&pool->pooljobs);
60 queue_init(&pool->lazywhatprovidesq);
63 pool->disttype = DISTTYPE_DEB;
64 pool->noarchid = ARCH_ALL;
65 #elif defined(ARCHLINUX)
66 pool->disttype = DISTTYPE_ARCH;
67 pool->noarchid = ARCH_ANY;
69 pool->disttype = DISTTYPE_HAIKU;
70 pool->noarchid = ARCH_ANY;
71 pool->obsoleteusesprovides = 1;
73 pool->disttype = DISTTYPE_RPM;
74 pool->noarchid = ARCH_NOARCH;
77 /* initialize the system solvable */
78 s = pool->solvables + SYSTEMSOLVABLE;
79 s->name = SYSTEM_SYSTEM;
80 s->arch = pool->noarchid;
83 pool->debugmask = SOLV_DEBUG_RESULT; /* FIXME */
85 pool->implicitobsoleteusescolors = 1;
88 pool->noobsoletesmultiversion = 1;
89 pool->forbidselfconflicts = 1;
90 pool->obsoleteusesprovides = 1;
91 pool->implicitobsoleteusesprovides = 1;
92 pool->havedistepoch = 1;
98 /* free all the resources of our pool */
100 pool_free(Pool *pool)
104 pool_freewhatprovides(pool);
105 pool_freeidhashes(pool);
106 pool_freeallrepos(pool, 1);
107 solv_free(pool->id2arch);
108 solv_free(pool->id2color);
109 solv_free(pool->solvables);
110 stringpool_free(&pool->ss);
111 solv_free(pool->rels);
112 pool_setvendorclasses(pool, 0);
113 queue_free(&pool->vendormap);
114 queue_free(&pool->pooljobs);
115 queue_free(&pool->lazywhatprovidesq);
116 for (i = 0; i < POOL_TMPSPACEBUF; i++)
117 solv_free(pool->tmpspace.buf[i]);
118 for (i = 0; i < pool->nlanguages; i++)
119 free((char *)pool->languages[i]);
120 solv_free(pool->languages);
121 solv_free(pool->languagecache);
122 solv_free(pool->errstr);
123 solv_free(pool->rootdir);
128 pool_freeallrepos(Pool *pool, int reuseids)
132 pool_freewhatprovides(pool);
133 for (i = 1; i < pool->nrepos; i++)
135 repo_freedata(pool->repos[i]);
136 pool->repos = solv_free(pool->repos);
139 /* the first two solvables don't belong to a repo */
140 pool_free_solvable_block(pool, 2, pool->nsolvables - 2, reuseids);
143 #ifdef MULTI_SEMANTICS
145 pool_setdisttype(Pool *pool, int disttype)
147 pool->disttype = disttype;
148 if (disttype == DISTTYPE_RPM)
149 pool->noarchid = ARCH_NOARCH;
150 if (disttype == DISTTYPE_DEB)
151 pool->noarchid = ARCH_ALL;
152 if (disttype == DISTTYPE_ARCH)
153 pool->noarchid = ARCH_ANY;
154 if (disttype == DISTTYPE_HAIKU)
155 pool->noarchid = ARCH_ANY;
156 pool->solvables[SYSTEMSOLVABLE].arch = pool->noarchid;
161 pool_get_flag(Pool *pool, int flag)
165 case POOL_FLAG_PROMOTEEPOCH:
166 return pool->promoteepoch;
167 case POOL_FLAG_FORBIDSELFCONFLICTS:
168 return pool->forbidselfconflicts;
169 case POOL_FLAG_OBSOLETEUSESPROVIDES:
170 return pool->obsoleteusesprovides;
171 case POOL_FLAG_IMPLICITOBSOLETEUSESPROVIDES:
172 return pool->implicitobsoleteusesprovides;
173 case POOL_FLAG_OBSOLETEUSESCOLORS:
174 return pool->obsoleteusescolors;
175 case POOL_FLAG_IMPLICITOBSOLETEUSESCOLORS:
176 return pool->implicitobsoleteusescolors;
177 case POOL_FLAG_NOINSTALLEDOBSOLETES:
178 return pool->noinstalledobsoletes;
179 case POOL_FLAG_HAVEDISTEPOCH:
180 return pool->havedistepoch;
181 case POOL_FLAG_NOOBSOLETESMULTIVERSION:
182 return pool->noobsoletesmultiversion;
183 case POOL_FLAG_ADDFILEPROVIDESFILTERED:
184 return pool->addfileprovidesfiltered;
192 pool_set_flag(Pool *pool, int flag, int value)
194 int old = pool_get_flag(pool, flag);
197 case POOL_FLAG_PROMOTEEPOCH:
198 pool->promoteepoch = value;
200 case POOL_FLAG_FORBIDSELFCONFLICTS:
201 pool->forbidselfconflicts = value;
203 case POOL_FLAG_OBSOLETEUSESPROVIDES:
204 pool->obsoleteusesprovides = value;
206 case POOL_FLAG_IMPLICITOBSOLETEUSESPROVIDES:
207 pool->implicitobsoleteusesprovides = value;
209 case POOL_FLAG_OBSOLETEUSESCOLORS:
210 pool->obsoleteusescolors = value;
212 case POOL_FLAG_IMPLICITOBSOLETEUSESCOLORS:
213 pool->implicitobsoleteusescolors = value;
215 case POOL_FLAG_NOINSTALLEDOBSOLETES:
216 pool->noinstalledobsoletes = value;
218 case POOL_FLAG_HAVEDISTEPOCH:
219 pool->havedistepoch = value;
221 case POOL_FLAG_NOOBSOLETESMULTIVERSION:
222 pool->noobsoletesmultiversion = value;
224 case POOL_FLAG_ADDFILEPROVIDESFILTERED:
225 pool->addfileprovidesfiltered = value;
235 pool_add_solvable(Pool *pool)
237 pool->solvables = solv_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
238 memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
239 return pool->nsolvables++;
243 pool_add_solvable_block(Pool *pool, int count)
245 Id nsolvables = pool->nsolvables;
248 pool->solvables = solv_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
249 memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
250 pool->nsolvables += count;
255 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
259 if (reuseids && start + count == pool->nsolvables)
261 /* might want to shrink solvable array */
262 pool->nsolvables = start;
265 memset(pool->solvables + start, 0, sizeof(Solvable) * count);
270 pool_set_installed(Pool *pool, Repo *installed)
272 if (pool->installed == installed)
274 pool->installed = installed;
275 pool_freewhatprovides(pool);
279 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp, void *dp)
284 oa = pool->whatprovides[*(Id *)ap];
285 ob = pool->whatprovides[*(Id *)bp];
287 return *(Id *)ap - *(Id *)bp;
288 da = pool->whatprovidesdata + oa;
289 db = pool->whatprovidesdata + ob;
291 if ((r = (*da++ - *db++)) != 0)
295 return *(Id *)ap - *(Id *)bp;
299 * pool_shrink_whatprovides - unify whatprovides data
301 * whatprovides_rel must be empty for this to work!
305 pool_shrink_whatprovides(Pool *pool)
309 Id lastid, *last, *dp, *lp;
313 if (pool->ss.nstrings < 3)
315 sorted = solv_malloc2(pool->ss.nstrings, sizeof(Id));
316 for (i = id = 0; id < pool->ss.nstrings; id++)
317 if (pool->whatprovides[id] >= 4)
320 solv_sort(sorted, n, sizeof(Id), pool_shrink_whatprovides_sortcmp, pool);
323 for (i = 0; i < n; i++)
326 o = pool->whatprovides[id];
327 dp = pool->whatprovidesdata + o;
341 pool->whatprovides[id] = -lastid;
345 last = pool->whatprovidesdata + o;
349 dp = pool->whatprovidesdata + 4;
350 for (id = 1; id < pool->ss.nstrings; id++)
352 o = pool->whatprovides[id];
360 pool->whatprovides[id] = pool->whatprovides[i];
365 lp = pool->whatprovidesdata + o;
368 pool->whatprovides[id] = dp - pool->whatprovidesdata;
369 while ((*dp++ = *lp++) != 0)
372 o = dp - pool->whatprovidesdata;
373 POOL_DEBUG(SOLV_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
374 if (pool->whatprovidesdataoff == o)
376 r = pool->whatprovidesdataoff - o;
377 pool->whatprovidesdataoff = o;
378 pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
379 if (r > pool->whatprovidesdataleft)
380 r = pool->whatprovidesdataleft;
381 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
386 * pool_createwhatprovides()
388 * create hashes over pool of solvables to ease provide lookups
392 pool_createwhatprovides(Pool *pool)
394 int i, num, np, extra;
399 Offset *whatprovides;
400 Id *whatprovidesdata, *d;
401 Repo *installed = pool->installed;
404 now = solv_timems(0);
405 POOL_DEBUG(SOLV_DEBUG_STATS, "number of solvables: %d, memory used: %d K\n", pool->nsolvables, pool->nsolvables * (int)sizeof(Solvable) / 1024);
406 POOL_DEBUG(SOLV_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
407 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);
408 if (pool->ss.stringhashmask || pool->relhashmask)
409 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)));
411 pool_freeidhashes(pool); /* XXX: should not be here! */
412 pool_freewhatprovides(pool);
413 num = pool->ss.nstrings;
414 pool->whatprovides = whatprovides = solv_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
415 pool->whatprovides_rel = solv_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
417 /* count providers for each name */
418 for (i = pool->nsolvables - 1; i > 0; i--)
421 s = pool->solvables + i;
422 if (!s->provides || !s->repo || s->repo->disabled)
424 /* we always need the installed solvable in the whatprovides data,
425 otherwise obsoletes/conflicts on them won't work */
426 if (s->repo != installed && !pool_installable(pool, s))
428 pp = s->repo->idarraydata + s->provides;
429 while ((id = *pp++) != 0)
433 Reldep *rd = GETRELDEP(pool, id);
436 whatprovides[id]++; /* inc count of providers */
440 off = 4; /* first entry is undef, second is empty list, third is system solvable */
441 np = 0; /* number of names provided */
442 for (i = 0, idp = whatprovides; i < num; i++, idp++)
445 if (!n) /* no providers */
447 *idp = 1; /* offset for empty list */
450 off += n; /* make space for all providers */
451 *idp = off++; /* now idp points to terminating zero */
452 np++; /* inc # of provider 'slots' for stats */
455 POOL_DEBUG(SOLV_DEBUG_STATS, "provide ids: %d\n", np);
457 /* reserve some space for relation data */
458 extra = 2 * pool->nrels;
462 POOL_DEBUG(SOLV_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
464 /* alloc space for all providers + extra */
465 whatprovidesdata = solv_calloc(off + extra, sizeof(Id));
466 whatprovidesdata[2] = SYSTEMSOLVABLE;
468 /* now fill data for all provides */
469 for (i = pool->nsolvables - 1; i > 0; i--)
472 s = pool->solvables + i;
473 if (!s->provides || !s->repo || s->repo->disabled)
475 if (s->repo != installed && !pool_installable(pool, s))
478 /* for all provides of this solvable */
479 pp = s->repo->idarraydata + s->provides;
480 while ((id = *pp++) != 0)
484 Reldep *rd = GETRELDEP(pool, id);
487 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
488 if (*d != i) /* don't add same solvable twice */
495 pool->whatprovidesdata = whatprovidesdata;
496 pool->whatprovidesdataoff = off;
497 pool->whatprovidesdataleft = extra;
498 pool_shrink_whatprovides(pool);
499 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)));
501 queue_empty(&pool->lazywhatprovidesq);
502 if ((!pool->addedfileprovides && pool->disttype == DISTTYPE_RPM) || pool->addedfileprovides == 1)
504 if (!pool->addedfileprovides)
505 POOL_DEBUG(SOLV_DEBUG_STATS, "WARNING: pool_addfileprovides was not called, this may result in slow operation\n");
506 /* lazyly add file provides */
507 for (i = 1; i < num; i++)
509 const char *str = pool->ss.stringspace + pool->ss.strings[i];
512 if (pool->addedfileprovides == 1 && repodata_filelistfilter_matches(0, str))
514 /* setup lazy adding, but remember old value */
515 if (pool->whatprovides[i] > 1)
516 queue_push2(&pool->lazywhatprovidesq, i, pool->whatprovides[i]);
517 pool->whatprovides[i] = 0;
519 POOL_DEBUG(SOLV_DEBUG_STATS, "lazywhatprovidesq size: %d entries\n", pool->lazywhatprovidesq.count / 2);
522 POOL_DEBUG(SOLV_DEBUG_STATS, "createwhatprovides took %d ms\n", solv_timems(now));
526 * free all of our whatprovides data
527 * be careful, everything internalized with pool_queuetowhatprovides is
531 pool_freewhatprovides(Pool *pool)
533 pool->whatprovides = solv_free(pool->whatprovides);
534 pool->whatprovides_rel = solv_free(pool->whatprovides_rel);
535 pool->whatprovidesdata = solv_free(pool->whatprovidesdata);
536 pool->whatprovidesdataoff = 0;
537 pool->whatprovidesdataleft = 0;
541 /******************************************************************************/
544 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
546 * used for whatprovides, jobs, learnt rules, selections
547 * input: q: queue of Ids
548 * returns: Offset into whatprovidesdata
552 pool_queuetowhatprovides(Pool *pool, Queue *q)
555 int count = q->count;
557 if (count == 0) /* queue empty -> 1 */
559 if (count == 1 && q->elements[0] == SYSTEMSOLVABLE)
562 /* extend whatprovidesdata if needed, +1 for 0-termination */
563 if (pool->whatprovidesdataleft < count + 1)
565 POOL_DEBUG(SOLV_DEBUG_STATS, "growing provides hash data...\n");
566 pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
567 pool->whatprovidesdataleft = count + 4096;
570 /* copy queue to next free slot */
571 off = pool->whatprovidesdataoff;
572 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
574 /* adapt count and 0-terminate */
575 pool->whatprovidesdataoff += count;
576 pool->whatprovidesdata[pool->whatprovidesdataoff++] = 0;
577 pool->whatprovidesdataleft -= count + 1;
583 /*************************************************************************/
585 #if defined(MULTI_SEMANTICS)
586 # define EVRCMP_DEPCMP (pool->disttype == DISTTYPE_DEB ? EVRCMP_COMPARE : EVRCMP_MATCH_RELEASE)
587 #elif defined(DEBIAN)
588 # define EVRCMP_DEPCMP EVRCMP_COMPARE
590 # define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
593 /* check if a package's nevr matches a dependency */
596 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
598 Reldep *rd = GETRELDEP(pool, d);
601 int flags = rd->flags;
610 if (evr != ARCH_SRC || s->arch != ARCH_NOSRC)
613 return pool_match_nevr(pool, s, name);
615 if (pool_match_nevr(pool, s, name))
617 return pool_match_nevr(pool, s, evr);
620 if (!pool_match_nevr(pool, s, name))
622 return pool_match_nevr(pool, s, evr);
627 if (!pool_match_nevr(pool, s, name))
630 return (flags & REL_EQ) ? 1 : 0;
635 switch (pool_evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP))
640 return (flags & REL_LT) ? 1 : 0;
642 return (flags & REL_EQ) ? 1 : 0;
644 return (flags & REL_GT) ? 1 : 0;
646 return (flags & REL_EQ) ? 1 : 0;
653 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
654 /* forward declaration */
655 static int pool_match_flags_evr_rel_compat(Pool *pool, Reldep *range, int flags, int evr);
658 /* match (flags, evr) against provider (pflags, pevr) */
660 pool_match_flags_evr(Pool *pool, int pflags, Id pevr, int flags, int evr)
662 if (!pflags || !flags || pflags >= 8 || flags >= 8)
664 if (flags == 7 || pflags == 7)
665 return 1; /* rel provides every version */
666 if ((pflags & flags & (REL_LT | REL_GT)) != 0)
667 return 1; /* both rels show in the same direction */
669 return (flags & pflags & REL_EQ) ? 1 : 0;
670 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
673 Reldep *rd = GETRELDEP(pool, pevr);
674 if (rd->flags == REL_COMPAT)
675 return pool_match_flags_evr_rel_compat(pool, rd, flags, evr);
678 switch (pool_evrcmp(pool, pevr, evr, EVRCMP_DEPCMP))
681 return (pflags & REL_EQ) ? 1 : 0;
683 return (flags & REL_LT) || (pflags & REL_GT) ? 1 : 0;
685 return (flags & pflags & REL_EQ) ? 1 : 0;
687 return (flags & REL_GT) || (pflags & REL_LT) ? 1 : 0;
689 return (flags & REL_EQ) ? 1 : 0;
696 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
698 pool_match_flags_evr_rel_compat(Pool *pool, Reldep *range, int flags, int evr)
700 /* range->name is the actual version, range->evr the backwards compatibility
701 version. If flags are '>=' or '>', we match the compatibility version
702 as well, otherwise only the actual version. */
703 if (!(flags & REL_GT) || (flags & REL_LT))
704 return pool_match_flags_evr(pool, REL_EQ, range->name, flags, evr);
705 return pool_match_flags_evr(pool, REL_LT | REL_EQ, range->name, flags, evr) &&
706 pool_match_flags_evr(pool, REL_GT | REL_EQ, range->evr, REL_EQ, evr);
710 /* match two dependencies (d1 = provider) */
713 pool_match_dep(Pool *pool, Id d1, Id d2)
723 rd2 = GETRELDEP(pool, d2);
724 return pool_match_dep(pool, d1, rd2->name);
726 rd1 = GETRELDEP(pool, d1);
729 return pool_match_dep(pool, rd1->name, d2);
731 rd2 = GETRELDEP(pool, d2);
732 /* first match name */
733 if (!pool_match_dep(pool, rd1->name, rd2->name))
735 /* name matches, check flags and evr */
736 return pool_match_flags_evr(pool, rd1->flags, rd1->evr, rd2->flags, rd2->evr);
740 pool_searchlazywhatprovidesq(Pool *pool, Id d)
743 int end = pool->lazywhatprovidesq.count;
747 elements = pool->lazywhatprovidesq.elements;
748 while (end - start > 16)
750 int mid = (start + end) / 2 & ~1;
751 if (elements[mid] == d)
752 return elements[mid + 1];
753 if (elements[mid] < d)
758 for (; start < end; start += 2)
759 if (elements[start] == d)
760 return elements[start + 1];
767 * lazy populating of the whatprovides array, non relation case
770 pool_addstdproviders(Pool *pool, Id d)
778 if (pool->addedfileprovides == 2)
780 pool->whatprovides[d] = 1;
783 str = pool->ss.stringspace + pool->ss.strings[d];
786 pool->whatprovides[d] = 1;
789 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
790 dataiterator_init(&di, pool, 0, 0, SOLVABLE_FILELIST, str, SEARCH_STRING|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
791 for (; dataiterator_step(&di); dataiterator_skip_solvable(&di))
793 Solvable *s = pool->solvables + di.solvid;
794 /* XXX: maybe should add a provides dependency to the solvables
795 * OTOH this is only needed for rel deps that filter the provides,
796 * and those should not use filelist entries */
797 if (s->repo->disabled)
799 if (s->repo != pool->installed && !pool_installable(pool, s))
801 queue_push(&q, di.solvid);
803 dataiterator_free(&di);
804 oldoffset = pool_searchlazywhatprovidesq(pool, d);
806 pool->whatprovides[d] = oldoffset ? oldoffset : 1;
811 Id *oo = pool->whatprovidesdata + oldoffset;
813 /* unify both queues. easy, as we know both are sorted */
814 for (i = 0; i < q.count; i++)
816 if (*oo > q.elements[i])
818 if (*oo < q.elements[i])
819 queue_insert(&q, i, *oo);
825 queue_push(&q, *oo++);
826 if (q.count == oo - (pool->whatprovidesdata + oldoffset))
828 /* end result has same size as oldoffset -> no new entries */
830 pool->whatprovides[d] = oldoffset;
834 pool->whatprovides[d] = pool_queuetowhatprovides(pool, &q);
837 return pool->whatprovides[d];
844 * add packages fulfilling the relation to whatprovides array
848 pool_addrelproviders(Pool *pool, Id d)
859 return pool_addstdproviders(pool, d);
860 rd = GETRELDEP(pool, d);
865 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
869 /* special relation */
877 wp = pool_whatprovides(pool, name);
878 pp2 = pool_whatprovides_ptr(pool, evr);
879 pp = pool->whatprovidesdata + wp;
880 while ((p = *pp++) != 0)
882 for (pp3 = pp2; *pp3; pp3++)
886 queue_push(&plist, p); /* found it */
892 wp = pool_whatprovides(pool, name);
893 pp = pool->whatprovidesdata + wp;
895 wp = pool_whatprovides(pool, evr);
899 while ((p = *pp++) != 0)
900 queue_push(&plist, p);
902 pp = pool_whatprovides_ptr(pool, evr);
903 while ((p = *pp++) != 0)
904 queue_pushunique(&plist, p);
905 if (plist.count != cnt)
910 if (name == NAMESPACE_OTHERPROVIDERS)
912 wp = pool_whatprovides(pool, evr);
915 if (pool->nscallback)
917 /* ask callback which packages provide the dependency
919 * 1: the system (aka SYSTEMSOLVABLE)
920 * >1: set of packages, stored as offset on whatprovidesdata
922 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
926 queue_push(&plist, SYSTEMSOLVABLE);
930 /* small hack: make it possible to match <pkg>.src
931 * we have to iterate over the solvables as src packages do not
932 * provide anything, thus they are not indexed in our
933 * whatprovides hash */
934 if (evr == ARCH_SRC || evr == ARCH_NOSRC)
937 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
941 if (s->arch != evr && s->arch != ARCH_NOSRC)
943 if (pool_disabled_solvable(pool, s))
945 if (pool_match_nevr(pool, s, name))
946 queue_push(&plist, p);
950 wp = pool_whatprovides(pool, name);
951 pp = pool->whatprovidesdata + wp;
952 while ((p = *pp++) != 0)
954 Solvable *s = pool->solvables + p;
956 queue_push(&plist, p);
961 case REL_FILECONFLICT:
962 pp = pool_whatprovides_ptr(pool, name);
963 while ((p = *pp++) != 0)
965 Id origd = MAKERELDEP(d);
966 Solvable *s = pool->solvables + p;
969 pidp = s->repo->idarraydata + s->provides;
970 while ((pid = *pidp++) != 0)
974 queue_push(&plist, p);
982 /* we can reuse an existing entry */
984 pool->whatprovides_rel[d] = wp;
990 /* simple version comparison relation */
992 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: what provides %s?\n", pool_dep2str(pool, name));
994 pp = pool_whatprovides_ptr(pool, name);
995 while (ISRELDEP(name))
997 rd = GETRELDEP(pool, name);
1000 while ((p = *pp++) != 0)
1002 Solvable *s = pool->solvables + p;
1005 /* no provides - check nevr */
1006 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
1007 queue_push(&plist, p);
1010 /* solvable p provides name in some rels */
1011 pidp = s->repo->idarraydata + s->provides;
1012 while ((pid = *pidp++) != 0)
1017 continue; /* wrong provides name */
1018 if (pool->disttype == DISTTYPE_DEB)
1019 continue; /* unversioned provides can never match versioned deps */
1022 prd = GETRELDEP(pool, pid);
1023 if (prd->name != name)
1024 continue; /* wrong provides name */
1025 /* right package, both deps are rels. check flags/evr */
1026 if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
1027 break; /* matches */
1030 continue; /* none of the providers matched */
1031 queue_push(&plist, p);
1033 /* make our system solvable provide all unknown rpmlib() stuff */
1034 if (plist.count == 0 && !strncmp(pool_id2str(pool, name), "rpmlib(", 7))
1035 queue_push(&plist, SYSTEMSOLVABLE);
1037 /* add providers to whatprovides */
1039 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
1041 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
1044 return pool->whatprovides_rel[d];
1048 pool_flush_namespaceproviders(Pool *pool, Id ns, Id evr)
1050 int nrels = pool->nrels;
1054 if (!pool->whatprovides_rel)
1056 for (d = 1, rd = pool->rels + d; d < nrels; d++, rd++)
1058 if (rd->flags != REL_NAMESPACE || rd->name == NAMESPACE_OTHERPROVIDERS)
1060 if (ns && rd->name != ns)
1062 if (evr && rd->evr != evr)
1064 pool->whatprovides_rel[d] = 0;
1068 /* intersect dependencies in keyname with dep, return list of matching packages */
1070 pool_whatmatchesdep(Pool *pool, Id keyname, Id dep, Queue *q)
1075 FOR_POOL_SOLVABLES(p)
1077 Solvable *s = pool->solvables + p;
1078 if (s->repo->disabled)
1080 if (s->repo != pool->installed && !pool_installable(pool, s))
1082 if (solvable_matchesdep(s, keyname, dep))
1087 /*************************************************************************/
1090 pool_debug(Pool *pool, int type, const char *format, ...)
1095 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0)
1097 if ((pool->debugmask & type) == 0)
1100 va_start(args, format);
1101 if (!pool->debugcallback)
1103 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0 && !(pool->debugmask & SOLV_DEBUG_TO_STDERR))
1104 vprintf(format, args);
1106 vfprintf(stderr, format, args);
1109 vsnprintf(buf, sizeof(buf), format, args);
1111 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
1115 pool_error(Pool *pool, int ret, const char *format, ...)
1119 va_start(args, format);
1122 pool->errstra = 1024;
1123 pool->errstr = solv_malloc(pool->errstra);
1131 l = vsnprintf(pool->errstr, pool->errstra, format, args);
1133 if (l >= 0 && l + 1 > pool->errstra)
1135 pool->errstra = l + 256;
1136 pool->errstr = solv_realloc(pool->errstr, pool->errstra);
1137 va_start(args, format);
1138 l = vsnprintf(pool->errstr, pool->errstra, format, args);
1142 strcpy(pool->errstr, "unknown error");
1143 if (pool->debugmask & SOLV_ERROR)
1144 pool_debug(pool, SOLV_ERROR, "%s\n", pool->errstr);
1149 pool_errstr(Pool *pool)
1151 return pool->errstr ? pool->errstr : "no error";
1155 pool_setdebuglevel(Pool *pool, int level)
1157 int mask = SOLV_DEBUG_RESULT;
1159 mask |= SOLV_DEBUG_STATS|SOLV_DEBUG_ANALYZE|SOLV_DEBUG_UNSOLVABLE|SOLV_DEBUG_SOLVER|SOLV_DEBUG_TRANSACTION|SOLV_ERROR;
1161 mask |= SOLV_DEBUG_JOB|SOLV_DEBUG_SOLUTIONS|SOLV_DEBUG_POLICY;
1163 mask |= SOLV_DEBUG_PROPAGATE;
1165 mask |= SOLV_DEBUG_RULE_CREATION;
1166 mask |= pool->debugmask & SOLV_DEBUG_TO_STDERR; /* keep bit */
1167 pool->debugmask = mask;
1170 void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
1172 pool->debugcallback = debugcallback;
1173 pool->debugcallbackdata = debugcallbackdata;
1176 void pool_setdebugmask(Pool *pool, int mask)
1178 pool->debugmask = mask;
1181 void pool_setloadcallback(Pool *pool, int (*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata)
1183 pool->loadcallback = cb;
1184 pool->loadcallbackdata = loadcbdata;
1187 void pool_setnamespacecallback(Pool *pool, Id (*cb)(struct _Pool *, void *, Id, Id), void *nscbdata)
1189 pool->nscallback = cb;
1190 pool->nscallbackdata = nscbdata;
1193 /*************************************************************************/
1195 struct searchfiles {
1203 #define SEARCHFILES_BLOCK 127
1206 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
1210 struct searchfiles *csf;
1212 while ((dep = *ida++) != 0)
1215 while (ISRELDEP(dep))
1218 sid = pool->ss.nstrings + GETRELID(dep);
1219 if (MAPTST(&csf->seen, sid))
1224 MAPSET(&csf->seen, sid);
1225 rd = GETRELDEP(pool, dep);
1228 else if (rd->flags == REL_NAMESPACE)
1230 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
1233 if (!csf || MAPTST(&csf->seen, sid))
1238 MAPSET(&csf->seen, sid);
1242 else if (rd->flags == REL_FILECONFLICT)
1252 pool_addfileprovides_dep(pool, ids, csf, isf);
1258 if (MAPTST(&csf->seen, dep))
1260 MAPSET(&csf->seen, dep);
1261 s = pool_id2str(pool, dep);
1264 if (csf != isf && pool->addedfileprovides == 1 && !repodata_filelistfilter_matches(0, s))
1265 continue; /* skip non-standard locations csf == isf: installed case */
1266 csf->ids = solv_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
1267 csf->dirs = solv_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
1268 csf->names = solv_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
1269 csf->ids[csf->nfiles] = dep;
1270 sr = strrchr(s, '/');
1271 csf->names[csf->nfiles] = solv_strdup(sr + 1);
1272 csf->dirs[csf->nfiles] = solv_malloc(sr - s + 1);
1274 strncpy(csf->dirs[csf->nfiles], s, sr - s);
1275 csf->dirs[csf->nfiles][sr - s] = 0;
1280 struct addfileprovides_cbdata {
1294 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1296 struct addfileprovides_cbdata *cbd = cbdata;
1299 if (!cbd->useddirs.size)
1301 map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
1302 for (i = 0; i < cbd->nfiles; i++)
1305 if (MAPTST(&cbd->providedids, cbd->ids[i]))
1310 did = repodata_str2dir(data, cbd->dirs[i], 0);
1313 MAPSET(&cbd->useddirs, did);
1315 repodata_free_dircache(data);
1317 if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
1319 for (i = 0; i < cbd->nfiles; i++)
1321 if (cbd->dids[i] != value->id)
1323 if (!strcmp(cbd->names[i], value->str))
1326 if (i == cbd->nfiles)
1328 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
1333 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
1338 Queue fileprovidesq;
1339 int i, j, repoid, repodataid;
1340 int provstart, provend;
1342 int ndone, incomplete;
1347 cbd->nfiles = sf->nfiles;
1349 cbd->dirs = sf->dirs;
1350 cbd->names = sf->names;
1351 cbd->dids = solv_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
1352 map_init(&cbd->providedids, pool->ss.nstrings);
1355 repo = repoonly ? repoonly : pool->repos[repoid];
1356 map_init(&donemap, pool->nsolvables);
1357 queue_init(&fileprovidesq);
1358 provstart = provend = 0;
1361 if (!repo || repo->disabled)
1363 if (repoonly || ++repoid == pool->nrepos)
1365 repo = pool->repos[repoid];
1369 FOR_REPODATAS(repo, repodataid, data)
1371 if (ndone >= repo->nsolvables)
1374 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
1376 map_empty(&cbd->providedids);
1377 for (i = 0; i < fileprovidesq.count; i++)
1378 MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
1379 provstart = data->start;
1380 provend = data->end;
1381 for (i = 0; i < cbd->nfiles; i++)
1382 if (!MAPTST(&cbd->providedids, cbd->ids[i]))
1384 if (i == cbd->nfiles)
1386 /* great! no need to search files */
1387 for (p = data->start; p < data->end; p++)
1388 if (pool->solvables[p].repo == repo)
1390 if (MAPTST(&donemap, p))
1392 MAPSET(&donemap, p);
1399 if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
1402 if (data->start < provstart || data->end > provend)
1404 map_empty(&cbd->providedids);
1405 provstart = provend = 0;
1408 /* check if the data is incomplete */
1410 if (data->state == REPODATA_AVAILABLE)
1412 for (j = 1; j < data->nkeys; j++)
1413 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1415 if (j < data->nkeys)
1418 for (i = 0; i < cbd->nfiles; i++)
1419 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1420 printf("need complete filelist because of %s\n", pool_id2str(pool, cbd->ids[i]));
1422 for (i = 0; i < cbd->nfiles; i++)
1423 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1425 if (i < cbd->nfiles)
1431 map_init(&cbd->useddirs, 0);
1432 for (p = data->start; p < data->end; p++)
1433 if (pool->solvables[p].repo == repo)
1435 if (MAPTST(&donemap, p))
1437 repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
1440 MAPSET(&donemap, p);
1444 map_free(&cbd->useddirs);
1447 if (repoonly || ++repoid == pool->nrepos)
1449 repo = pool->repos[repoid];
1452 queue_free(&fileprovidesq);
1453 map_free(&cbd->providedids);
1457 pool_addfileprovides_queue(Pool *pool, Queue *idq, Queue *idqinst)
1460 Repo *installed, *repo;
1461 struct searchfiles sf, isf, *isfp;
1462 struct addfileprovides_cbdata cbd;
1466 installed = pool->installed;
1467 now = solv_timems(0);
1468 memset(&sf, 0, sizeof(sf));
1469 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
1470 memset(&isf, 0, sizeof(isf));
1471 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
1472 pool->addedfileprovides = pool->addfileprovidesfiltered ? 1 : 2;
1477 queue_empty(idqinst);
1478 isfp = installed ? &isf : 0;
1479 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1485 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1487 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1489 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1491 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1493 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1495 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1497 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1500 map_free(&isf.seen);
1501 POOL_DEBUG(SOLV_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
1506 for (i = 0; i < sf.nfiles; i++)
1507 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in filelist\n", pool_id2str(pool, sf.ids[i]));
1509 pool_addfileprovides_search(pool, &cbd, &sf, 0);
1511 for (i = 0; i < sf.nfiles; i++)
1512 queue_push(idq, sf.ids[i]);
1514 for (i = 0; i < sf.nfiles; i++)
1515 queue_push(idqinst, sf.ids[i]);
1517 for (i = 0; i < sf.nfiles; i++)
1519 solv_free(sf.dirs[i]);
1520 solv_free(sf.names[i]);
1523 solv_free(sf.names);
1528 for (i = 0; i < isf.nfiles; i++)
1529 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in installed filelist\n", pool_id2str(pool, isf.ids[i]));
1532 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1533 if (installed && idqinst)
1534 for (i = 0; i < isf.nfiles; i++)
1535 queue_pushunique(idqinst, isf.ids[i]);
1537 for (i = 0; i < isf.nfiles; i++)
1539 solv_free(isf.dirs[i]);
1540 solv_free(isf.names[i]);
1542 solv_free(isf.dirs);
1543 solv_free(isf.names);
1545 solv_free(cbd.dids);
1546 pool_freewhatprovides(pool); /* as we have added provides */
1547 POOL_DEBUG(SOLV_DEBUG_STATS, "addfileprovides took %d ms\n", solv_timems(now));
1551 pool_addfileprovides(Pool *pool)
1553 pool_addfileprovides_queue(pool, 0, 0);
1557 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)
1561 if (pool->solvables[p].repo)
1562 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1565 /* FIXME: obey callback return value! */
1566 for (p = 1; p < pool->nsolvables; p++)
1567 if (pool->solvables[p].repo)
1568 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1572 pool_clear_pos(Pool *pool)
1574 memset(&pool->pos, 0, sizeof(pool->pos));
1579 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1583 pool->languagecache = solv_free(pool->languagecache);
1584 pool->languagecacheother = 0;
1585 if (pool->nlanguages)
1587 for (i = 0; i < pool->nlanguages; i++)
1588 free((char *)pool->languages[i]);
1589 free(pool->languages);
1591 pool->nlanguages = nlanguages;
1594 pool->languages = solv_calloc(nlanguages, sizeof(const char **));
1595 for (i = 0; i < pool->nlanguages; i++)
1596 pool->languages[i] = solv_strdup(languages[i]);
1600 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1606 if (!lang || !*lang)
1608 n = pool_id2str(pool, id);
1609 l = strlen(n) + strlen(lang) + 2;
1610 if (l > sizeof(buf))
1611 p = solv_malloc(strlen(n) + strlen(lang) + 2);
1614 sprintf(p, "%s:%s", n, lang);
1615 id = pool_str2id(pool, p, create);
1622 pool_alloctmpspace(Pool *pool, int len)
1624 int n = pool->tmpspace.n;
1627 if (len > pool->tmpspace.len[n])
1629 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1630 pool->tmpspace.len[n] = len + 32;
1632 pool->tmpspace.n = (n + 1) % POOL_TMPSPACEBUF;
1633 return pool->tmpspace.buf[n];
1637 pool_alloctmpspace_free(Pool *pool, const char *space, int len)
1642 n = oldn = pool->tmpspace.n;
1646 n = POOL_TMPSPACEBUF - 1;
1649 if (pool->tmpspace.buf[n] != space)
1651 if (len > pool->tmpspace.len[n])
1653 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1654 pool->tmpspace.len[n] = len + 32;
1656 return pool->tmpspace.buf[n];
1663 pool_freetmpspace(Pool *pool, const char *space)
1665 int n = pool->tmpspace.n;
1668 n = (n + (POOL_TMPSPACEBUF - 1)) % POOL_TMPSPACEBUF;
1669 if (pool->tmpspace.buf[n] == space)
1670 pool->tmpspace.n = n;
1674 pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
1678 l1 = str1 ? strlen(str1) : 0;
1679 l2 = str2 ? strlen(str2) : 0;
1680 l3 = str3 ? strlen(str3) : 0;
1681 s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1702 pool_tmpappend(Pool *pool, const char *str1, const char *str2, const char *str3)
1707 l1 = str1 ? strlen(str1) : 0;
1708 l2 = str2 ? strlen(str2) : 0;
1709 l3 = str3 ? strlen(str3) : 0;
1710 str = pool_alloctmpspace_free(pool, str1, l1 + l2 + l3 + 1);
1714 str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1737 pool_bin2hex(Pool *pool, const unsigned char *buf, int len)
1742 s = pool_alloctmpspace(pool, 2 * len + 1);
1743 solv_bin2hex(buf, len, s);
1747 /*******************************************************************/
1759 struct mptree *mptree;
1770 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1772 struct ducbdata *cbd = cbdata;
1775 if (data != cbd->olddata)
1777 Id dn, mp, comp, *dirmap, *dirs;
1779 const char *compstr;
1780 struct mptree *mptree;
1782 /* create map from dir to mptree */
1783 cbd->dirmap = solv_free(cbd->dirmap);
1785 dirmap = solv_calloc(data->dirpool.ndirs, sizeof(Id));
1786 mptree = cbd->mptree;
1788 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1802 if (!mptree[mp].child)
1807 if (data->localpool)
1808 compstr = stringpool_id2str(&data->spool, comp);
1810 compstr = pool_id2str(data->repo->pool, comp);
1811 compl = strlen(compstr);
1812 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1813 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1815 dirmap[dn] = i ? i : -mp;
1817 /* change dirmap to point to mountpoint instead of mptree */
1818 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1821 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1823 cbd->dirmap = dirmap;
1824 cbd->nmap = data->dirpool.ndirs;
1825 cbd->olddata = data;
1828 if (value->id < 0 || value->id >= cbd->nmap)
1830 mp = cbd->dirmap[value->id];
1833 if (cbd->addsub > 0)
1835 cbd->mps[mp].kbytes += value->num;
1836 cbd->mps[mp].files += value->num2;
1840 cbd->mps[mp].kbytes -= value->num;
1841 cbd->mps[mp].files -= value->num2;
1847 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1850 if (mptree[pos].mountpoint == -1)
1851 mptree[pos].mountpoint = mountpoint;
1853 mountpoint = mptree[pos].mountpoint;
1854 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1855 propagate_mountpoints(mptree, i, mountpoint);
1858 #define MPTREE_BLOCK 15
1861 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1864 const char *path, *compstr;
1865 struct mptree *mptree;
1869 struct ducbdata cbd;
1873 Repo *oldinstalled = pool->installed;
1875 memset(&ignoredu, 0, sizeof(ignoredu));
1882 mptree = solv_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1885 mptree[0].sibling = 0;
1886 mptree[0].child = 0;
1888 mptree[0].compl = 0;
1889 mptree[0].mountpoint = -1;
1892 /* create component tree */
1893 for (mp = 0; mp < nmps; mp++)
1898 path = mps[mp].path;
1903 if ((p = strchr(path, '/')) == 0)
1906 compl = strlen(compstr);
1917 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1918 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1922 /* create new node */
1923 mptree = solv_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1925 mptree[i].sibling = mptree[pos].child;
1926 mptree[i].child = 0;
1927 mptree[i].comp = compstr;
1928 mptree[i].compl = compl;
1929 mptree[i].mountpoint = -1;
1930 mptree[pos].child = i;
1934 mptree[pos].mountpoint = mp;
1937 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1940 for (i = 0; i < nmptree; i++)
1942 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1943 printf("#%d child: %d\n", i, mptree[i].child);
1944 printf("#%d comp: %s\n", i, mptree[i].comp);
1945 printf("#%d compl: %d\n", i, mptree[i].compl);
1946 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1950 cbd.mptree = mptree;
1952 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1954 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1956 if (!MAPTST(installedmap, sp))
1959 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1960 if (!cbd.hasdu && oldinstalled)
1963 /* no du data available, ignore data of all installed solvables we obsolete */
1965 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1968 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1969 while ((obs = *obsp++) != 0)
1970 FOR_PROVIDES(op, opp, obs)
1971 if (op >= oldinstalled->start && op < oldinstalled->end)
1972 MAPSET(&ignoredu, op - oldinstalled->start);
1974 FOR_PROVIDES(op, opp, s->name)
1975 if (pool->solvables[op].name == s->name)
1976 if (op >= oldinstalled->start && op < oldinstalled->end)
1977 MAPSET(&ignoredu, op - oldinstalled->start);
1983 /* assumes we allways have du data for installed solvables */
1984 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1986 if (MAPTST(installedmap, sp))
1988 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1990 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1994 map_free(&ignoredu);
1995 solv_free(cbd.dirmap);
2000 pool_calc_installsizechange(Pool *pool, Map *installedmap)
2005 Repo *oldinstalled = pool->installed;
2007 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
2009 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
2011 if (!MAPTST(installedmap, sp))
2013 change += solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
2017 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
2019 if (MAPTST(installedmap, sp))
2021 change -= solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
2029 * 2: conflicts with installed
2030 * 8: interesting (only true if installed)
2034 static inline Id dep2name(Pool *pool, Id dep)
2036 while (ISRELDEP(dep))
2038 Reldep *rd = rd = GETRELDEP(pool, dep);
2044 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con)
2047 Solvable *sn = pool->solvables + n;
2049 FOR_PROVIDES(p, pp, sn->name)
2051 Solvable *s = pool->solvables + p;
2052 if (s->name != sn->name || s->arch != sn->arch)
2054 if ((map[p] & 9) != 9)
2056 if (pool_match_nevr(pool, pool->solvables + p, con))
2058 return 1; /* found installed package that doesn't conflict */
2063 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *multiversionmap)
2067 FOR_PROVIDES(p, pp, dep)
2069 if (p == SYSTEMSOLVABLE)
2070 return 1; /* always boring, as never constraining */
2071 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
2073 if (ispatch && multiversionmap && multiversionmap->size && MAPTST(multiversionmap, p) && ISRELDEP(dep))
2074 if (providedbyinstalled_multiversion(pool, map, p, dep))
2076 if ((map[p] & 9) == 9)
2084 * pool_trivial_installable - calculate if a set of solvables is
2085 * trivial installable without any other installs/deinstalls of
2086 * packages not belonging to the set.
2088 * the state is returned in the result queue:
2089 * 1: solvable is installable without any other package changes
2090 * 0: solvable is not installable
2091 * -1: solvable is installable, but doesn't constrain any installed packages
2095 pool_trivial_installable_multiversionmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *multiversionmap)
2098 Id p, *dp, con, *conp, req, *reqp;
2102 map = solv_calloc(pool->nsolvables, 1);
2103 for (p = 1; p < pool->nsolvables; p++)
2105 if (!MAPTST(installedmap, p))
2108 s = pool->solvables + p;
2111 conp = s->repo->idarraydata + s->conflicts;
2112 while ((con = *conp++) != 0)
2114 dp = pool_whatprovides_ptr(pool, con);
2116 map[p] |= 2; /* XXX: self conflict ? */
2119 for (i = 0; i < pkgs->count; i++)
2120 map[pkgs->elements[i]] = 16;
2122 for (i = 0, did = 0; did < pkgs->count; i++, did++)
2124 if (i == pkgs->count)
2126 p = pkgs->elements[i];
2127 if ((map[p] & 16) == 0)
2129 if ((map[p] & 2) != 0)
2134 s = pool->solvables + p;
2138 reqp = s->repo->idarraydata + s->requires;
2139 while ((req = *reqp++) != 0)
2141 if (req == SOLVABLE_PREREQMARKER)
2143 r = providedbyinstalled(pool, map, req, 0, 0);
2146 /* decided and miss */
2152 break; /* undecided */
2153 m |= r; /* 1 | 9 | 17 */
2162 int ispatch = 0; /* see solver.c patch handling */
2164 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
2166 conp = s->repo->idarraydata + s->conflicts;
2167 while ((con = *conp++) != 0)
2169 if ((providedbyinstalled(pool, map, con, ispatch, multiversionmap) & 1) != 0)
2175 if ((m == 1 || m == 17) && ISRELDEP(con))
2177 con = dep2name(pool, con);
2178 if ((providedbyinstalled(pool, map, con, ispatch, multiversionmap) & 1) != 0)
2183 continue; /* found a conflict */
2186 if (s->repo && s->repo != oldinstalled)
2188 Id p2, obs, *obsp, *pp;
2192 obsp = s->repo->idarraydata + s->obsoletes;
2193 while ((obs = *obsp++) != 0)
2195 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
2204 FOR_PROVIDES(p2, pp, s->name)
2206 s2 = pool->solvables + p2;
2207 if (s2->name == s->name && (map[p2] & 1) != 0)
2224 queue_init_clone(res, pkgs);
2225 for (i = 0; i < pkgs->count; i++)
2227 m = map[pkgs->elements[i]];
2234 res->elements[i] = r;
2240 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
2242 pool_trivial_installable_multiversionmap(pool, installedmap, pkgs, res, 0);
2246 pool_lookup_str(Pool *pool, Id entry, Id keyname)
2248 if (entry == SOLVID_POS && pool->pos.repo)
2249 return repo_lookup_str(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
2252 return solvable_lookup_str(pool->solvables + entry, keyname);
2256 pool_lookup_id(Pool *pool, Id entry, Id keyname)
2258 if (entry == SOLVID_POS && pool->pos.repo)
2259 return repo_lookup_id(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
2262 return solvable_lookup_id(pool->solvables + entry, keyname);
2266 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned long long notfound)
2268 if (entry == SOLVID_POS && pool->pos.repo)
2269 return repo_lookup_num(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, notfound);
2272 return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
2276 pool_lookup_void(Pool *pool, Id entry, Id keyname)
2278 if (entry == SOLVID_POS && pool->pos.repo)
2279 return repo_lookup_void(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
2282 return solvable_lookup_void(pool->solvables + entry, keyname);
2285 const unsigned char *
2286 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
2288 if (entry == SOLVID_POS && pool->pos.repo)
2289 return repo_lookup_bin_checksum(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, typep);
2292 return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
2296 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
2298 if (entry == SOLVID_POS && pool->pos.repo)
2299 return repo_lookup_checksum(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, typep);
2302 return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
2306 pool_lookup_idarray(Pool *pool, Id entry, Id keyname, Queue *q)
2308 if (entry == SOLVID_POS && pool->pos.repo)
2309 return repo_lookup_idarray(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, q);
2312 return solvable_lookup_idarray(pool->solvables + entry, keyname, q);
2316 pool_lookup_deltalocation(Pool *pool, Id entry, unsigned int *medianrp)
2321 if (entry != SOLVID_POS)
2323 loc = pool_lookup_str(pool, entry, DELTA_LOCATION_DIR);
2324 loc = pool_tmpjoin(pool, loc, loc ? "/" : 0, pool_lookup_str(pool, entry, DELTA_LOCATION_NAME));
2325 loc = pool_tmpappend(pool, loc, "-", pool_lookup_str(pool, entry, DELTA_LOCATION_EVR));
2326 loc = pool_tmpappend(pool, loc, ".", pool_lookup_str(pool, entry, DELTA_LOCATION_SUFFIX));
2331 add_new_provider(Pool *pool, Id id, Id p)
2336 while (ISRELDEP(id))
2338 Reldep *rd = GETRELDEP(pool, id);
2343 for (pp = pool->whatprovidesdata + pool->whatprovides[id]; *pp; pp++)
2355 queue_push(&q, *pp);
2359 pool->whatprovides[id] = pool_queuetowhatprovides(pool, &q);
2364 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
2366 int hadhashes = pool->relhashtbl ? 1 : 0;
2372 if (!conflicts->count)
2374 for (i = 0; i < conflicts->count; i += 6)
2376 fn = conflicts->elements[i];
2377 p = conflicts->elements[i + 1];
2378 md5 = conflicts->elements[i + 2];
2379 q = conflicts->elements[i + 4];
2380 id = pool_rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
2381 s = pool->solvables + p;
2384 s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
2385 if (pool->whatprovides)
2386 add_new_provider(pool, fn, p);
2387 if (pool->whatprovides_rel)
2388 pool->whatprovides_rel[GETRELID(id)] = 0; /* clear cache */
2389 s = pool->solvables + q;
2392 s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
2395 pool_freeidhashes(pool);
2399 pool_prepend_rootdir(Pool *pool, const char *path)
2404 return solv_strdup(path);
2405 return solv_dupjoin(pool->rootdir, "/", *path == '/' ? path + 1 : path);
2409 pool_prepend_rootdir_tmp(Pool *pool, const char *path)
2415 return pool_tmpjoin(pool, pool->rootdir, "/", *path == '/' ? path + 1 : path);
2419 pool_set_rootdir(Pool *pool, const char *rootdir)
2421 solv_free(pool->rootdir);
2422 pool->rootdir = solv_strdup(rootdir);
2426 pool_get_rootdir(Pool *pool)
2428 return pool->rootdir;
2431 /* only used in libzypp */
2433 pool_set_custom_vendorcheck(Pool *pool, int (*vendorcheck)(Pool *, Solvable *, Solvable *))
2435 pool->custom_vendorcheck = vendorcheck;