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 */
594 /* semi-private, called from public pool_match_nevr */
597 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
599 Reldep *rd = GETRELDEP(pool, d);
602 int flags = rd->flags;
611 if (evr != ARCH_SRC || s->arch != ARCH_NOSRC)
614 return pool_match_nevr(pool, s, name);
616 if (pool_match_nevr(pool, s, name))
618 return pool_match_nevr(pool, s, evr);
621 if (!pool_match_nevr(pool, s, name))
623 return pool_match_nevr(pool, s, evr);
627 /* XXX : need to check for Multi-Arch: allowed! */
628 return pool_match_nevr(pool, s, name);
633 if (!pool_match_nevr(pool, s, name))
636 return (flags & REL_EQ) ? 1 : 0;
641 switch (pool_evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP))
646 return (flags & REL_LT) ? 1 : 0;
648 return (flags & REL_EQ) ? 1 : 0;
650 return (flags & REL_GT) ? 1 : 0;
652 return (flags & REL_EQ) ? 1 : 0;
659 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
660 /* forward declaration */
661 static int pool_match_flags_evr_rel_compat(Pool *pool, Reldep *range, int flags, int evr);
664 /* match (flags, evr) against provider (pflags, pevr) */
666 pool_match_flags_evr(Pool *pool, int pflags, Id pevr, int flags, int evr)
668 if (!pflags || !flags || pflags >= 8 || flags >= 8)
670 if (flags == 7 || pflags == 7)
671 return 1; /* rel provides every version */
672 if ((pflags & flags & (REL_LT | REL_GT)) != 0)
673 return 1; /* both rels show in the same direction */
675 return (flags & pflags & REL_EQ) ? 1 : 0;
676 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
679 Reldep *rd = GETRELDEP(pool, pevr);
680 if (rd->flags == REL_COMPAT)
681 return pool_match_flags_evr_rel_compat(pool, rd, flags, evr);
684 switch (pool_evrcmp(pool, pevr, evr, EVRCMP_DEPCMP))
687 return (pflags & REL_EQ) ? 1 : 0;
689 return (flags & REL_LT) || (pflags & REL_GT) ? 1 : 0;
691 return (flags & pflags & REL_EQ) ? 1 : 0;
693 return (flags & REL_GT) || (pflags & REL_LT) ? 1 : 0;
695 return (flags & REL_EQ) ? 1 : 0;
702 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
704 pool_match_flags_evr_rel_compat(Pool *pool, Reldep *range, int flags, int evr)
706 /* range->name is the actual version, range->evr the backwards compatibility
707 version. If flags are '>=' or '>', we match the compatibility version
708 as well, otherwise only the actual version. */
709 if (!(flags & REL_GT) || (flags & REL_LT))
710 return pool_match_flags_evr(pool, REL_EQ, range->name, flags, evr);
711 return pool_match_flags_evr(pool, REL_LT | REL_EQ, range->name, flags, evr) &&
712 pool_match_flags_evr(pool, REL_GT | REL_EQ, range->evr, REL_EQ, evr);
716 /* public (i.e. not inlined) version of pool_match_flags_evr */
718 pool_intersect_evrs(Pool *pool, int pflags, Id pevr, int flags, int evr)
720 return pool_match_flags_evr(pool, pflags, pevr, flags, evr);
723 /* match two dependencies (d1 = provider) */
726 pool_match_dep(Pool *pool, Id d1, Id d2)
736 rd2 = GETRELDEP(pool, d2);
737 return pool_match_dep(pool, d1, rd2->name);
739 rd1 = GETRELDEP(pool, d1);
742 return pool_match_dep(pool, rd1->name, d2);
744 rd2 = GETRELDEP(pool, d2);
745 /* first match name */
746 if (!pool_match_dep(pool, rd1->name, rd2->name))
748 /* name matches, check flags and evr */
749 return pool_intersect_evrs(pool, rd1->flags, rd1->evr, rd2->flags, rd2->evr);
753 pool_searchlazywhatprovidesq(Pool *pool, Id d)
756 int end = pool->lazywhatprovidesq.count;
760 elements = pool->lazywhatprovidesq.elements;
761 while (end - start > 16)
763 int mid = (start + end) / 2 & ~1;
764 if (elements[mid] == d)
765 return elements[mid + 1];
766 if (elements[mid] < d)
771 for (; start < end; start += 2)
772 if (elements[start] == d)
773 return elements[start + 1];
780 * lazy populating of the whatprovides array, non relation case
783 pool_addstdproviders(Pool *pool, Id d)
791 if (pool->addedfileprovides == 2)
793 pool->whatprovides[d] = 1;
796 str = pool->ss.stringspace + pool->ss.strings[d];
799 pool->whatprovides[d] = 1;
802 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
803 dataiterator_init(&di, pool, 0, 0, SOLVABLE_FILELIST, str, SEARCH_STRING|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
804 for (; dataiterator_step(&di); dataiterator_skip_solvable(&di))
806 Solvable *s = pool->solvables + di.solvid;
807 /* XXX: maybe should add a provides dependency to the solvables
808 * OTOH this is only needed for rel deps that filter the provides,
809 * and those should not use filelist entries */
810 if (s->repo->disabled)
812 if (s->repo != pool->installed && !pool_installable(pool, s))
814 queue_push(&q, di.solvid);
816 dataiterator_free(&di);
817 oldoffset = pool_searchlazywhatprovidesq(pool, d);
819 pool->whatprovides[d] = oldoffset ? oldoffset : 1;
824 Id *oo = pool->whatprovidesdata + oldoffset;
826 /* unify both queues. easy, as we know both are sorted */
827 for (i = 0; i < q.count; i++)
829 if (*oo > q.elements[i])
831 if (*oo < q.elements[i])
832 queue_insert(&q, i, *oo);
838 queue_push(&q, *oo++);
839 if (q.count == oo - (pool->whatprovidesdata + oldoffset))
841 /* end result has same size as oldoffset -> no new entries */
843 pool->whatprovides[d] = oldoffset;
847 pool->whatprovides[d] = pool_queuetowhatprovides(pool, &q);
850 return pool->whatprovides[d];
855 pool_is_kind(Pool *pool, Id name, Id kind)
860 n = pool_id2str(pool, name);
863 const char *kn = pool_id2str(pool, kind);
864 int knl = strlen(kn);
865 return !strncmp(n, kn, knl) && n[knl] == ':' ? 1 : 0;
871 while(*n >= 'a' && *n <= 'z')
873 return *n == ':' ? 0 : 1;
880 * add packages fulfilling the relation to whatprovides array
884 pool_addrelproviders(Pool *pool, Id d)
895 return pool_addstdproviders(pool, d);
896 rd = GETRELDEP(pool, d);
901 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
905 /* special relation */
913 wp = pool_whatprovides(pool, name);
914 pp2 = pool_whatprovides_ptr(pool, evr);
915 pp = pool->whatprovidesdata + wp;
916 while ((p = *pp++) != 0)
918 for (pp3 = pp2; *pp3; pp3++)
922 queue_push(&plist, p); /* found it */
928 wp = pool_whatprovides(pool, name);
929 pp = pool->whatprovidesdata + wp;
931 wp = pool_whatprovides(pool, evr);
935 while ((p = *pp++) != 0)
936 queue_push(&plist, p);
938 pp = pool_whatprovides_ptr(pool, evr);
939 while ((p = *pp++) != 0)
940 queue_pushunique(&plist, p);
941 if (plist.count != cnt)
946 if (name == NAMESPACE_OTHERPROVIDERS)
948 wp = pool_whatprovides(pool, evr);
951 if (pool->nscallback)
953 /* ask callback which packages provide the dependency
955 * 1: the system (aka SYSTEMSOLVABLE)
956 * >1: set of packages, stored as offset on whatprovidesdata
958 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
962 queue_push(&plist, SYSTEMSOLVABLE);
966 /* small hack: make it possible to match <pkg>.src
967 * we have to iterate over the solvables as src packages do not
968 * provide anything, thus they are not indexed in our
969 * whatprovides hash */
970 if (evr == ARCH_SRC || evr == ARCH_NOSRC)
973 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
977 if (s->arch != evr && s->arch != ARCH_NOSRC)
979 if (pool_disabled_solvable(pool, s))
981 if (!name || pool_match_nevr(pool, s, name))
982 queue_push(&plist, p);
988 FOR_POOL_SOLVABLES(p)
990 Solvable *s = pool->solvables + p;
991 if (s->repo != pool->installed && !pool_installable(pool, s))
994 queue_push(&plist, p);
998 wp = pool_whatprovides(pool, name);
999 pp = pool->whatprovidesdata + wp;
1000 while ((p = *pp++) != 0)
1002 Solvable *s = pool->solvables + p;
1004 queue_push(&plist, p);
1010 if (evr != ARCH_ANY)
1012 /* XXX : need to check for Multi-Arch: allowed! */
1013 wp = pool_whatprovides(pool, name);
1016 /* package kind filtering */
1019 FOR_POOL_SOLVABLES(p)
1021 Solvable *s = pool->solvables + p;
1022 if (s->repo != pool->installed && !pool_installable(pool, s))
1024 if (pool_is_kind(pool, s->name, evr))
1025 queue_push(&plist, p);
1029 wp = pool_whatprovides(pool, name);
1030 pp = pool->whatprovidesdata + wp;
1031 while ((p = *pp++) != 0)
1033 Solvable *s = pool->solvables + p;
1034 if (pool_is_kind(pool, s->name, evr))
1035 queue_push(&plist, p);
1040 case REL_FILECONFLICT:
1041 pp = pool_whatprovides_ptr(pool, name);
1042 while ((p = *pp++) != 0)
1044 Id origd = MAKERELDEP(d);
1045 Solvable *s = pool->solvables + p;
1048 pidp = s->repo->idarraydata + s->provides;
1049 while ((pid = *pidp++) != 0)
1053 queue_push(&plist, p);
1061 /* we can reuse an existing entry */
1063 pool->whatprovides_rel[d] = wp;
1069 /* simple version comparison relation */
1071 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: what provides %s?\n", pool_dep2str(pool, name));
1073 pp = pool_whatprovides_ptr(pool, name);
1074 while (ISRELDEP(name))
1076 rd = GETRELDEP(pool, name);
1079 while ((p = *pp++) != 0)
1081 Solvable *s = pool->solvables + p;
1084 /* no provides - check nevr */
1085 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
1086 queue_push(&plist, p);
1089 /* solvable p provides name in some rels */
1090 pidp = s->repo->idarraydata + s->provides;
1091 while ((pid = *pidp++) != 0)
1096 continue; /* wrong provides name */
1097 if (pool->disttype == DISTTYPE_DEB)
1098 continue; /* unversioned provides can never match versioned deps */
1101 prd = GETRELDEP(pool, pid);
1102 if (prd->name != name)
1103 continue; /* wrong provides name */
1104 /* right package, both deps are rels. check flags/evr */
1105 if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
1106 break; /* matches */
1109 continue; /* none of the providers matched */
1110 queue_push(&plist, p);
1112 /* make our system solvable provide all unknown rpmlib() stuff */
1113 if (plist.count == 0 && !strncmp(pool_id2str(pool, name), "rpmlib(", 7))
1114 queue_push(&plist, SYSTEMSOLVABLE);
1116 /* add providers to whatprovides */
1118 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
1120 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
1123 return pool->whatprovides_rel[d];
1127 pool_flush_namespaceproviders(Pool *pool, Id ns, Id evr)
1129 int nrels = pool->nrels;
1133 if (!pool->whatprovides_rel)
1135 for (d = 1, rd = pool->rels + d; d < nrels; d++, rd++)
1137 if (rd->flags != REL_NAMESPACE || rd->name == NAMESPACE_OTHERPROVIDERS)
1139 if (ns && rd->name != ns)
1141 if (evr && rd->evr != evr)
1143 pool->whatprovides_rel[d] = 0;
1147 /* intersect dependencies in keyname with dep, return list of matching packages */
1149 pool_whatmatchesdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker)
1154 FOR_POOL_SOLVABLES(p)
1156 Solvable *s = pool->solvables + p;
1157 if (s->repo->disabled)
1159 if (s->repo != pool->installed && !pool_installable(pool, s))
1161 if (solvable_matchesdep(s, keyname, dep, marker))
1166 /*************************************************************************/
1169 pool_debug(Pool *pool, int type, const char *format, ...)
1174 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0)
1176 if ((pool->debugmask & type) == 0)
1179 va_start(args, format);
1180 if (!pool->debugcallback)
1182 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0 && !(pool->debugmask & SOLV_DEBUG_TO_STDERR))
1183 vprintf(format, args);
1185 vfprintf(stderr, format, args);
1188 vsnprintf(buf, sizeof(buf), format, args);
1190 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
1194 pool_error(Pool *pool, int ret, const char *format, ...)
1198 va_start(args, format);
1201 pool->errstra = 1024;
1202 pool->errstr = solv_malloc(pool->errstra);
1210 l = vsnprintf(pool->errstr, pool->errstra, format, args);
1212 if (l >= 0 && l + 1 > pool->errstra)
1214 pool->errstra = l + 256;
1215 pool->errstr = solv_realloc(pool->errstr, pool->errstra);
1216 va_start(args, format);
1217 l = vsnprintf(pool->errstr, pool->errstra, format, args);
1221 strcpy(pool->errstr, "unknown error");
1222 if (pool->debugmask & SOLV_ERROR)
1223 pool_debug(pool, SOLV_ERROR, "%s\n", pool->errstr);
1228 pool_errstr(Pool *pool)
1230 return pool->errstr ? pool->errstr : "no error";
1234 pool_setdebuglevel(Pool *pool, int level)
1236 int mask = SOLV_DEBUG_RESULT;
1238 mask |= SOLV_DEBUG_STATS|SOLV_DEBUG_ANALYZE|SOLV_DEBUG_UNSOLVABLE|SOLV_DEBUG_SOLVER|SOLV_DEBUG_TRANSACTION|SOLV_ERROR;
1240 mask |= SOLV_DEBUG_JOB|SOLV_DEBUG_SOLUTIONS|SOLV_DEBUG_POLICY;
1242 mask |= SOLV_DEBUG_PROPAGATE;
1244 mask |= SOLV_DEBUG_RULE_CREATION;
1245 mask |= pool->debugmask & SOLV_DEBUG_TO_STDERR; /* keep bit */
1246 pool->debugmask = mask;
1249 void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
1251 pool->debugcallback = debugcallback;
1252 pool->debugcallbackdata = debugcallbackdata;
1255 void pool_setdebugmask(Pool *pool, int mask)
1257 pool->debugmask = mask;
1260 void pool_setloadcallback(Pool *pool, int (*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata)
1262 pool->loadcallback = cb;
1263 pool->loadcallbackdata = loadcbdata;
1266 void pool_setnamespacecallback(Pool *pool, Id (*cb)(struct _Pool *, void *, Id, Id), void *nscbdata)
1268 pool->nscallback = cb;
1269 pool->nscallbackdata = nscbdata;
1272 /*************************************************************************/
1274 struct searchfiles {
1282 #define SEARCHFILES_BLOCK 127
1285 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
1289 struct searchfiles *csf;
1291 while ((dep = *ida++) != 0)
1294 while (ISRELDEP(dep))
1297 sid = pool->ss.nstrings + GETRELID(dep);
1298 if (MAPTST(&csf->seen, sid))
1303 MAPSET(&csf->seen, sid);
1304 rd = GETRELDEP(pool, dep);
1307 else if (rd->flags == REL_NAMESPACE)
1309 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
1312 if (!csf || MAPTST(&csf->seen, sid))
1317 MAPSET(&csf->seen, sid);
1321 else if (rd->flags == REL_FILECONFLICT)
1331 pool_addfileprovides_dep(pool, ids, csf, isf);
1337 if (MAPTST(&csf->seen, dep))
1339 MAPSET(&csf->seen, dep);
1340 s = pool_id2str(pool, dep);
1343 if (csf != isf && pool->addedfileprovides == 1 && !repodata_filelistfilter_matches(0, s))
1344 continue; /* skip non-standard locations csf == isf: installed case */
1345 csf->ids = solv_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
1346 csf->dirs = solv_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
1347 csf->names = solv_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
1348 csf->ids[csf->nfiles] = dep;
1349 sr = strrchr(s, '/');
1350 csf->names[csf->nfiles] = solv_strdup(sr + 1);
1351 csf->dirs[csf->nfiles] = solv_malloc(sr - s + 1);
1353 strncpy(csf->dirs[csf->nfiles], s, sr - s);
1354 csf->dirs[csf->nfiles][sr - s] = 0;
1359 struct addfileprovides_cbdata {
1373 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1375 struct addfileprovides_cbdata *cbd = cbdata;
1378 if (!cbd->useddirs.size)
1380 map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
1381 for (i = 0; i < cbd->nfiles; i++)
1384 if (MAPTST(&cbd->providedids, cbd->ids[i]))
1389 did = repodata_str2dir(data, cbd->dirs[i], 0);
1392 MAPSET(&cbd->useddirs, did);
1394 repodata_free_dircache(data);
1396 if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
1398 for (i = 0; i < cbd->nfiles; i++)
1400 if (cbd->dids[i] != value->id)
1402 if (!strcmp(cbd->names[i], value->str))
1405 if (i == cbd->nfiles)
1407 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
1412 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
1417 Queue fileprovidesq;
1418 int i, j, repoid, repodataid;
1419 int provstart, provend;
1421 int ndone, incomplete;
1426 cbd->nfiles = sf->nfiles;
1428 cbd->dirs = sf->dirs;
1429 cbd->names = sf->names;
1430 cbd->dids = solv_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
1431 map_init(&cbd->providedids, pool->ss.nstrings);
1434 repo = repoonly ? repoonly : pool->repos[repoid];
1435 map_init(&donemap, pool->nsolvables);
1436 queue_init(&fileprovidesq);
1437 provstart = provend = 0;
1440 if (!repo || repo->disabled)
1442 if (repoonly || ++repoid == pool->nrepos)
1444 repo = pool->repos[repoid];
1448 FOR_REPODATAS(repo, repodataid, data)
1450 if (ndone >= repo->nsolvables)
1453 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
1455 map_empty(&cbd->providedids);
1456 for (i = 0; i < fileprovidesq.count; i++)
1457 MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
1458 provstart = data->start;
1459 provend = data->end;
1460 for (i = 0; i < cbd->nfiles; i++)
1461 if (!MAPTST(&cbd->providedids, cbd->ids[i]))
1463 if (i == cbd->nfiles)
1465 /* great! no need to search files */
1466 for (p = data->start; p < data->end; p++)
1467 if (pool->solvables[p].repo == repo)
1469 if (MAPTST(&donemap, p))
1471 MAPSET(&donemap, p);
1478 if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
1481 if (data->start < provstart || data->end > provend)
1483 map_empty(&cbd->providedids);
1484 provstart = provend = 0;
1487 /* check if the data is incomplete */
1489 if (data->state == REPODATA_AVAILABLE)
1491 for (j = 1; j < data->nkeys; j++)
1492 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1494 if (j < data->nkeys)
1497 for (i = 0; i < cbd->nfiles; i++)
1498 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1499 printf("need complete filelist because of %s\n", pool_id2str(pool, cbd->ids[i]));
1501 for (i = 0; i < cbd->nfiles; i++)
1502 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1504 if (i < cbd->nfiles)
1510 map_init(&cbd->useddirs, 0);
1511 for (p = data->start; p < data->end; p++)
1512 if (pool->solvables[p].repo == repo)
1514 if (MAPTST(&donemap, p))
1516 repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
1519 MAPSET(&donemap, p);
1523 map_free(&cbd->useddirs);
1526 if (repoonly || ++repoid == pool->nrepos)
1528 repo = pool->repos[repoid];
1531 queue_free(&fileprovidesq);
1532 map_free(&cbd->providedids);
1536 pool_addfileprovides_queue(Pool *pool, Queue *idq, Queue *idqinst)
1539 Repo *installed, *repo;
1540 struct searchfiles sf, isf, *isfp;
1541 struct addfileprovides_cbdata cbd;
1545 installed = pool->installed;
1546 now = solv_timems(0);
1547 memset(&sf, 0, sizeof(sf));
1548 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
1549 memset(&isf, 0, sizeof(isf));
1550 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
1551 pool->addedfileprovides = pool->addfileprovidesfiltered ? 1 : 2;
1556 queue_empty(idqinst);
1557 isfp = installed ? &isf : 0;
1558 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1564 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1566 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1568 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1570 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1572 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1574 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1576 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1579 map_free(&isf.seen);
1580 POOL_DEBUG(SOLV_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
1585 for (i = 0; i < sf.nfiles; i++)
1586 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in filelist\n", pool_id2str(pool, sf.ids[i]));
1588 pool_addfileprovides_search(pool, &cbd, &sf, 0);
1590 for (i = 0; i < sf.nfiles; i++)
1591 queue_push(idq, sf.ids[i]);
1593 for (i = 0; i < sf.nfiles; i++)
1594 queue_push(idqinst, sf.ids[i]);
1596 for (i = 0; i < sf.nfiles; i++)
1598 solv_free(sf.dirs[i]);
1599 solv_free(sf.names[i]);
1602 solv_free(sf.names);
1607 for (i = 0; i < isf.nfiles; i++)
1608 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in installed filelist\n", pool_id2str(pool, isf.ids[i]));
1611 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1612 if (installed && idqinst)
1613 for (i = 0; i < isf.nfiles; i++)
1614 queue_pushunique(idqinst, isf.ids[i]);
1616 for (i = 0; i < isf.nfiles; i++)
1618 solv_free(isf.dirs[i]);
1619 solv_free(isf.names[i]);
1621 solv_free(isf.dirs);
1622 solv_free(isf.names);
1624 solv_free(cbd.dids);
1625 pool_freewhatprovides(pool); /* as we have added provides */
1626 POOL_DEBUG(SOLV_DEBUG_STATS, "addfileprovides took %d ms\n", solv_timems(now));
1630 pool_addfileprovides(Pool *pool)
1632 pool_addfileprovides_queue(pool, 0, 0);
1636 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)
1640 if (pool->solvables[p].repo)
1641 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1644 /* FIXME: obey callback return value! */
1645 for (p = 1; p < pool->nsolvables; p++)
1646 if (pool->solvables[p].repo)
1647 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1651 pool_clear_pos(Pool *pool)
1653 memset(&pool->pos, 0, sizeof(pool->pos));
1658 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1662 pool->languagecache = solv_free(pool->languagecache);
1663 pool->languagecacheother = 0;
1664 if (pool->nlanguages)
1666 for (i = 0; i < pool->nlanguages; i++)
1667 free((char *)pool->languages[i]);
1668 free(pool->languages);
1670 pool->nlanguages = nlanguages;
1673 pool->languages = solv_calloc(nlanguages, sizeof(const char **));
1674 for (i = 0; i < pool->nlanguages; i++)
1675 pool->languages[i] = solv_strdup(languages[i]);
1679 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1685 if (!lang || !*lang)
1687 n = pool_id2str(pool, id);
1688 l = strlen(n) + strlen(lang) + 2;
1689 if (l > sizeof(buf))
1690 p = solv_malloc(strlen(n) + strlen(lang) + 2);
1693 sprintf(p, "%s:%s", n, lang);
1694 id = pool_str2id(pool, p, create);
1701 pool_alloctmpspace(Pool *pool, int len)
1703 int n = pool->tmpspace.n;
1706 if (len > pool->tmpspace.len[n])
1708 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1709 pool->tmpspace.len[n] = len + 32;
1711 pool->tmpspace.n = (n + 1) % POOL_TMPSPACEBUF;
1712 return pool->tmpspace.buf[n];
1716 pool_alloctmpspace_free(Pool *pool, const char *space, int len)
1721 n = oldn = pool->tmpspace.n;
1725 n = POOL_TMPSPACEBUF - 1;
1728 if (pool->tmpspace.buf[n] != space)
1730 if (len > pool->tmpspace.len[n])
1732 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1733 pool->tmpspace.len[n] = len + 32;
1735 return pool->tmpspace.buf[n];
1742 pool_freetmpspace(Pool *pool, const char *space)
1744 int n = pool->tmpspace.n;
1747 n = (n + (POOL_TMPSPACEBUF - 1)) % POOL_TMPSPACEBUF;
1748 if (pool->tmpspace.buf[n] == space)
1749 pool->tmpspace.n = n;
1753 pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
1757 l1 = str1 ? strlen(str1) : 0;
1758 l2 = str2 ? strlen(str2) : 0;
1759 l3 = str3 ? strlen(str3) : 0;
1760 s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1781 pool_tmpappend(Pool *pool, const char *str1, const char *str2, const char *str3)
1786 l1 = str1 ? strlen(str1) : 0;
1787 l2 = str2 ? strlen(str2) : 0;
1788 l3 = str3 ? strlen(str3) : 0;
1789 str = pool_alloctmpspace_free(pool, str1, l1 + l2 + l3 + 1);
1793 str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1816 pool_bin2hex(Pool *pool, const unsigned char *buf, int len)
1821 s = pool_alloctmpspace(pool, 2 * len + 1);
1822 solv_bin2hex(buf, len, s);
1826 /*******************************************************************/
1838 struct mptree *mptree;
1849 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1851 struct ducbdata *cbd = cbdata;
1854 if (data != cbd->olddata)
1856 Id dn, mp, comp, *dirmap, *dirs;
1858 const char *compstr;
1859 struct mptree *mptree;
1861 /* create map from dir to mptree */
1862 cbd->dirmap = solv_free(cbd->dirmap);
1864 dirmap = solv_calloc(data->dirpool.ndirs, sizeof(Id));
1865 mptree = cbd->mptree;
1867 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1881 if (!mptree[mp].child)
1886 if (data->localpool)
1887 compstr = stringpool_id2str(&data->spool, comp);
1889 compstr = pool_id2str(data->repo->pool, comp);
1890 compl = strlen(compstr);
1891 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1892 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1894 dirmap[dn] = i ? i : -mp;
1896 /* change dirmap to point to mountpoint instead of mptree */
1897 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1900 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1902 cbd->dirmap = dirmap;
1903 cbd->nmap = data->dirpool.ndirs;
1904 cbd->olddata = data;
1907 if (value->id < 0 || value->id >= cbd->nmap)
1909 mp = cbd->dirmap[value->id];
1912 if (cbd->addsub > 0)
1914 cbd->mps[mp].kbytes += value->num;
1915 cbd->mps[mp].files += value->num2;
1919 cbd->mps[mp].kbytes -= value->num;
1920 cbd->mps[mp].files -= value->num2;
1926 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1929 if (mptree[pos].mountpoint == -1)
1930 mptree[pos].mountpoint = mountpoint;
1932 mountpoint = mptree[pos].mountpoint;
1933 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1934 propagate_mountpoints(mptree, i, mountpoint);
1937 #define MPTREE_BLOCK 15
1940 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1943 const char *path, *compstr;
1944 struct mptree *mptree;
1948 struct ducbdata cbd;
1952 Repo *oldinstalled = pool->installed;
1954 memset(&ignoredu, 0, sizeof(ignoredu));
1961 mptree = solv_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1964 mptree[0].sibling = 0;
1965 mptree[0].child = 0;
1967 mptree[0].compl = 0;
1968 mptree[0].mountpoint = -1;
1971 /* create component tree */
1972 for (mp = 0; mp < nmps; mp++)
1977 path = mps[mp].path;
1982 if ((p = strchr(path, '/')) == 0)
1985 compl = strlen(compstr);
1996 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1997 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
2001 /* create new node */
2002 mptree = solv_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
2004 mptree[i].sibling = mptree[pos].child;
2005 mptree[i].child = 0;
2006 mptree[i].comp = compstr;
2007 mptree[i].compl = compl;
2008 mptree[i].mountpoint = -1;
2009 mptree[pos].child = i;
2013 mptree[pos].mountpoint = mp;
2016 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
2019 for (i = 0; i < nmptree; i++)
2021 printf("#%d sibling: %d\n", i, mptree[i].sibling);
2022 printf("#%d child: %d\n", i, mptree[i].child);
2023 printf("#%d comp: %s\n", i, mptree[i].comp);
2024 printf("#%d compl: %d\n", i, mptree[i].compl);
2025 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
2029 cbd.mptree = mptree;
2031 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
2033 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
2035 if (!MAPTST(installedmap, sp))
2038 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
2039 if (!cbd.hasdu && oldinstalled)
2042 /* no du data available, ignore data of all installed solvables we obsolete */
2044 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
2047 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
2048 while ((obs = *obsp++) != 0)
2049 FOR_PROVIDES(op, opp, obs)
2050 if (op >= oldinstalled->start && op < oldinstalled->end)
2051 MAPSET(&ignoredu, op - oldinstalled->start);
2053 FOR_PROVIDES(op, opp, s->name)
2054 if (pool->solvables[op].name == s->name)
2055 if (op >= oldinstalled->start && op < oldinstalled->end)
2056 MAPSET(&ignoredu, op - oldinstalled->start);
2062 /* assumes we allways have du data for installed solvables */
2063 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
2065 if (MAPTST(installedmap, sp))
2067 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
2069 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
2073 map_free(&ignoredu);
2074 solv_free(cbd.dirmap);
2079 pool_calc_installsizechange(Pool *pool, Map *installedmap)
2084 Repo *oldinstalled = pool->installed;
2086 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
2088 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
2090 if (!MAPTST(installedmap, sp))
2092 change += solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
2096 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
2098 if (MAPTST(installedmap, sp))
2100 change -= solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
2108 * 2: conflicts with installed
2109 * 8: interesting (only true if installed)
2113 static inline Id dep2name(Pool *pool, Id dep)
2115 while (ISRELDEP(dep))
2117 Reldep *rd = rd = GETRELDEP(pool, dep);
2123 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con)
2126 Solvable *sn = pool->solvables + n;
2128 FOR_PROVIDES(p, pp, sn->name)
2130 Solvable *s = pool->solvables + p;
2131 if (s->name != sn->name || s->arch != sn->arch)
2133 if ((map[p] & 9) != 9)
2135 if (pool_match_nevr(pool, pool->solvables + p, con))
2137 return 1; /* found installed package that doesn't conflict */
2142 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *multiversionmap)
2146 FOR_PROVIDES(p, pp, dep)
2148 if (p == SYSTEMSOLVABLE)
2149 return 1; /* always boring, as never constraining */
2150 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
2152 if (ispatch && multiversionmap && multiversionmap->size && MAPTST(multiversionmap, p) && ISRELDEP(dep))
2153 if (providedbyinstalled_multiversion(pool, map, p, dep))
2155 if ((map[p] & 9) == 9)
2163 * pool_trivial_installable - calculate if a set of solvables is
2164 * trivial installable without any other installs/deinstalls of
2165 * packages not belonging to the set.
2167 * the state is returned in the result queue:
2168 * 1: solvable is installable without any other package changes
2169 * 0: solvable is not installable
2170 * -1: solvable is installable, but doesn't constrain any installed packages
2174 pool_trivial_installable_multiversionmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *multiversionmap)
2177 Id p, *dp, con, *conp, req, *reqp;
2181 map = solv_calloc(pool->nsolvables, 1);
2182 for (p = 1; p < pool->nsolvables; p++)
2184 if (!MAPTST(installedmap, p))
2187 s = pool->solvables + p;
2190 conp = s->repo->idarraydata + s->conflicts;
2191 while ((con = *conp++) != 0)
2193 dp = pool_whatprovides_ptr(pool, con);
2195 map[p] |= 2; /* XXX: self conflict ? */
2198 for (i = 0; i < pkgs->count; i++)
2199 map[pkgs->elements[i]] = 16;
2201 for (i = 0, did = 0; did < pkgs->count; i++, did++)
2203 if (i == pkgs->count)
2205 p = pkgs->elements[i];
2206 if ((map[p] & 16) == 0)
2208 if ((map[p] & 2) != 0)
2213 s = pool->solvables + p;
2217 reqp = s->repo->idarraydata + s->requires;
2218 while ((req = *reqp++) != 0)
2220 if (req == SOLVABLE_PREREQMARKER)
2222 r = providedbyinstalled(pool, map, req, 0, 0);
2225 /* decided and miss */
2231 break; /* undecided */
2232 m |= r; /* 1 | 9 | 17 */
2241 int ispatch = 0; /* see solver.c patch handling */
2243 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
2245 conp = s->repo->idarraydata + s->conflicts;
2246 while ((con = *conp++) != 0)
2248 if ((providedbyinstalled(pool, map, con, ispatch, multiversionmap) & 1) != 0)
2254 if ((m == 1 || m == 17) && ISRELDEP(con))
2256 con = dep2name(pool, con);
2257 if ((providedbyinstalled(pool, map, con, ispatch, multiversionmap) & 1) != 0)
2262 continue; /* found a conflict */
2265 if (s->repo && s->repo != oldinstalled)
2267 Id p2, obs, *obsp, *pp;
2271 obsp = s->repo->idarraydata + s->obsoletes;
2272 while ((obs = *obsp++) != 0)
2274 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
2283 FOR_PROVIDES(p2, pp, s->name)
2285 s2 = pool->solvables + p2;
2286 if (s2->name == s->name && (map[p2] & 1) != 0)
2303 queue_init_clone(res, pkgs);
2304 for (i = 0; i < pkgs->count; i++)
2306 m = map[pkgs->elements[i]];
2313 res->elements[i] = r;
2319 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
2321 pool_trivial_installable_multiversionmap(pool, installedmap, pkgs, res, 0);
2325 pool_lookup_str(Pool *pool, Id entry, Id keyname)
2327 if (entry == SOLVID_POS && pool->pos.repo)
2328 return repo_lookup_str(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
2331 return solvable_lookup_str(pool->solvables + entry, keyname);
2335 pool_lookup_id(Pool *pool, Id entry, Id keyname)
2337 if (entry == SOLVID_POS && pool->pos.repo)
2338 return repo_lookup_id(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
2341 return solvable_lookup_id(pool->solvables + entry, keyname);
2345 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned long long notfound)
2347 if (entry == SOLVID_POS && pool->pos.repo)
2348 return repo_lookup_num(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, notfound);
2351 return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
2355 pool_lookup_void(Pool *pool, Id entry, Id keyname)
2357 if (entry == SOLVID_POS && pool->pos.repo)
2358 return repo_lookup_void(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
2361 return solvable_lookup_void(pool->solvables + entry, keyname);
2364 const unsigned char *
2365 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
2367 if (entry == SOLVID_POS && pool->pos.repo)
2368 return repo_lookup_bin_checksum(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, typep);
2371 return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
2375 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
2377 if (entry == SOLVID_POS && pool->pos.repo)
2378 return repo_lookup_checksum(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, typep);
2381 return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
2385 pool_lookup_idarray(Pool *pool, Id entry, Id keyname, Queue *q)
2387 if (entry == SOLVID_POS && pool->pos.repo)
2388 return repo_lookup_idarray(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, q);
2391 return solvable_lookup_idarray(pool->solvables + entry, keyname, q);
2395 pool_lookup_deltalocation(Pool *pool, Id entry, unsigned int *medianrp)
2400 if (entry != SOLVID_POS)
2402 loc = pool_lookup_str(pool, entry, DELTA_LOCATION_DIR);
2403 loc = pool_tmpjoin(pool, loc, loc ? "/" : 0, pool_lookup_str(pool, entry, DELTA_LOCATION_NAME));
2404 loc = pool_tmpappend(pool, loc, "-", pool_lookup_str(pool, entry, DELTA_LOCATION_EVR));
2405 loc = pool_tmpappend(pool, loc, ".", pool_lookup_str(pool, entry, DELTA_LOCATION_SUFFIX));
2410 add_new_provider(Pool *pool, Id id, Id p)
2415 while (ISRELDEP(id))
2417 Reldep *rd = GETRELDEP(pool, id);
2422 for (pp = pool->whatprovidesdata + pool->whatprovides[id]; *pp; pp++)
2434 queue_push(&q, *pp);
2438 pool->whatprovides[id] = pool_queuetowhatprovides(pool, &q);
2443 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
2445 int hadhashes = pool->relhashtbl ? 1 : 0;
2451 if (!conflicts->count)
2453 for (i = 0; i < conflicts->count; i += 6)
2455 fn = conflicts->elements[i];
2456 p = conflicts->elements[i + 1];
2457 md5 = conflicts->elements[i + 2];
2458 q = conflicts->elements[i + 4];
2459 id = pool_rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
2460 s = pool->solvables + p;
2463 s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
2464 if (pool->whatprovides)
2465 add_new_provider(pool, fn, p);
2466 if (pool->whatprovides_rel)
2467 pool->whatprovides_rel[GETRELID(id)] = 0; /* clear cache */
2468 s = pool->solvables + q;
2471 s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
2474 pool_freeidhashes(pool);
2478 pool_prepend_rootdir(Pool *pool, const char *path)
2483 return solv_strdup(path);
2484 return solv_dupjoin(pool->rootdir, "/", *path == '/' ? path + 1 : path);
2488 pool_prepend_rootdir_tmp(Pool *pool, const char *path)
2494 return pool_tmpjoin(pool, pool->rootdir, "/", *path == '/' ? path + 1 : path);
2498 pool_set_rootdir(Pool *pool, const char *rootdir)
2500 solv_free(pool->rootdir);
2501 pool->rootdir = solv_strdup(rootdir);
2505 pool_get_rootdir(Pool *pool)
2507 return pool->rootdir;
2510 /* only used in libzypp */
2512 pool_set_custom_vendorcheck(Pool *pool, int (*vendorcheck)(Pool *, Solvable *, Solvable *))
2514 pool->custom_vendorcheck = vendorcheck;