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);
628 if (!pool_match_nevr(pool, s, name))
631 return (flags & REL_EQ) ? 1 : 0;
636 switch (pool_evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP))
641 return (flags & REL_LT) ? 1 : 0;
643 return (flags & REL_EQ) ? 1 : 0;
645 return (flags & REL_GT) ? 1 : 0;
647 return (flags & REL_EQ) ? 1 : 0;
654 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
655 /* forward declaration */
656 static int pool_match_flags_evr_rel_compat(Pool *pool, Reldep *range, int flags, int evr);
659 /* match (flags, evr) against provider (pflags, pevr) */
661 pool_match_flags_evr(Pool *pool, int pflags, Id pevr, int flags, int evr)
663 if (!pflags || !flags || pflags >= 8 || flags >= 8)
665 if (flags == 7 || pflags == 7)
666 return 1; /* rel provides every version */
667 if ((pflags & flags & (REL_LT | REL_GT)) != 0)
668 return 1; /* both rels show in the same direction */
670 return (flags & pflags & REL_EQ) ? 1 : 0;
671 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
674 Reldep *rd = GETRELDEP(pool, pevr);
675 if (rd->flags == REL_COMPAT)
676 return pool_match_flags_evr_rel_compat(pool, rd, flags, evr);
679 switch (pool_evrcmp(pool, pevr, evr, EVRCMP_DEPCMP))
682 return (pflags & REL_EQ) ? 1 : 0;
684 return (flags & REL_LT) || (pflags & REL_GT) ? 1 : 0;
686 return (flags & pflags & REL_EQ) ? 1 : 0;
688 return (flags & REL_GT) || (pflags & REL_LT) ? 1 : 0;
690 return (flags & REL_EQ) ? 1 : 0;
697 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
699 pool_match_flags_evr_rel_compat(Pool *pool, Reldep *range, int flags, int evr)
701 /* range->name is the actual version, range->evr the backwards compatibility
702 version. If flags are '>=' or '>', we match the compatibility version
703 as well, otherwise only the actual version. */
704 if (!(flags & REL_GT) || (flags & REL_LT))
705 return pool_match_flags_evr(pool, REL_EQ, range->name, flags, evr);
706 return pool_match_flags_evr(pool, REL_LT | REL_EQ, range->name, flags, evr) &&
707 pool_match_flags_evr(pool, REL_GT | REL_EQ, range->evr, REL_EQ, evr);
711 /* public (i.e. not inlined) version of pool_match_flags_evr */
713 pool_intersect_evrs(Pool *pool, int pflags, Id pevr, int flags, int evr)
715 return pool_match_flags_evr(pool, pflags, pevr, flags, evr);
718 /* match two dependencies (d1 = provider) */
721 pool_match_dep(Pool *pool, Id d1, Id d2)
731 rd2 = GETRELDEP(pool, d2);
732 return pool_match_dep(pool, d1, rd2->name);
734 rd1 = GETRELDEP(pool, d1);
737 return pool_match_dep(pool, rd1->name, d2);
739 rd2 = GETRELDEP(pool, d2);
740 /* first match name */
741 if (!pool_match_dep(pool, rd1->name, rd2->name))
743 /* name matches, check flags and evr */
744 return pool_intersect_evrs(pool, rd1->flags, rd1->evr, rd2->flags, rd2->evr);
748 pool_searchlazywhatprovidesq(Pool *pool, Id d)
751 int end = pool->lazywhatprovidesq.count;
755 elements = pool->lazywhatprovidesq.elements;
756 while (end - start > 16)
758 int mid = (start + end) / 2 & ~1;
759 if (elements[mid] == d)
760 return elements[mid + 1];
761 if (elements[mid] < d)
766 for (; start < end; start += 2)
767 if (elements[start] == d)
768 return elements[start + 1];
775 * lazy populating of the whatprovides array, non relation case
778 pool_addstdproviders(Pool *pool, Id d)
786 if (pool->addedfileprovides == 2)
788 pool->whatprovides[d] = 1;
791 str = pool->ss.stringspace + pool->ss.strings[d];
794 pool->whatprovides[d] = 1;
797 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
798 dataiterator_init(&di, pool, 0, 0, SOLVABLE_FILELIST, str, SEARCH_STRING|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
799 for (; dataiterator_step(&di); dataiterator_skip_solvable(&di))
801 Solvable *s = pool->solvables + di.solvid;
802 /* XXX: maybe should add a provides dependency to the solvables
803 * OTOH this is only needed for rel deps that filter the provides,
804 * and those should not use filelist entries */
805 if (s->repo->disabled)
807 if (s->repo != pool->installed && !pool_installable(pool, s))
809 queue_push(&q, di.solvid);
811 dataiterator_free(&di);
812 oldoffset = pool_searchlazywhatprovidesq(pool, d);
814 pool->whatprovides[d] = oldoffset ? oldoffset : 1;
819 Id *oo = pool->whatprovidesdata + oldoffset;
821 /* unify both queues. easy, as we know both are sorted */
822 for (i = 0; i < q.count; i++)
824 if (*oo > q.elements[i])
826 if (*oo < q.elements[i])
827 queue_insert(&q, i, *oo);
833 queue_push(&q, *oo++);
834 if (q.count == oo - (pool->whatprovidesdata + oldoffset))
836 /* end result has same size as oldoffset -> no new entries */
838 pool->whatprovides[d] = oldoffset;
842 pool->whatprovides[d] = pool_queuetowhatprovides(pool, &q);
845 return pool->whatprovides[d];
850 pool_is_kind(Pool *pool, Id name, Id kind)
855 n = pool_id2str(pool, name);
858 const char *kn = pool_id2str(pool, kind);
859 int knl = strlen(kn);
860 return !strncmp(n, kn, knl) && n[knl] == ':' ? 1 : 0;
866 while(*n >= 'a' && *n <= 'z')
868 return *n == ':' ? 0 : 1;
875 * add packages fulfilling the relation to whatprovides array
879 pool_addrelproviders(Pool *pool, Id d)
890 return pool_addstdproviders(pool, d);
891 rd = GETRELDEP(pool, d);
896 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
900 /* special relation */
908 wp = pool_whatprovides(pool, name);
909 pp2 = pool_whatprovides_ptr(pool, evr);
910 pp = pool->whatprovidesdata + wp;
911 while ((p = *pp++) != 0)
913 for (pp3 = pp2; *pp3; pp3++)
917 queue_push(&plist, p); /* found it */
923 wp = pool_whatprovides(pool, name);
924 pp = pool->whatprovidesdata + wp;
926 wp = pool_whatprovides(pool, evr);
930 while ((p = *pp++) != 0)
931 queue_push(&plist, p);
933 pp = pool_whatprovides_ptr(pool, evr);
934 while ((p = *pp++) != 0)
935 queue_pushunique(&plist, p);
936 if (plist.count != cnt)
941 if (name == NAMESPACE_OTHERPROVIDERS)
943 wp = pool_whatprovides(pool, evr);
946 if (pool->nscallback)
948 /* ask callback which packages provide the dependency
950 * 1: the system (aka SYSTEMSOLVABLE)
951 * >1: set of packages, stored as offset on whatprovidesdata
953 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
957 queue_push(&plist, SYSTEMSOLVABLE);
961 /* small hack: make it possible to match <pkg>.src
962 * we have to iterate over the solvables as src packages do not
963 * provide anything, thus they are not indexed in our
964 * whatprovides hash */
965 if (evr == ARCH_SRC || evr == ARCH_NOSRC)
968 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
972 if (s->arch != evr && s->arch != ARCH_NOSRC)
974 if (pool_disabled_solvable(pool, s))
976 if (!name || pool_match_nevr(pool, s, name))
977 queue_push(&plist, p);
983 FOR_POOL_SOLVABLES(p)
985 Solvable *s = pool->solvables + p;
986 if (s->repo != pool->installed && !pool_installable(pool, s))
989 queue_push(&plist, p);
993 wp = pool_whatprovides(pool, name);
994 pp = pool->whatprovidesdata + wp;
995 while ((p = *pp++) != 0)
997 Solvable *s = pool->solvables + p;
999 queue_push(&plist, p);
1005 /* package kind filtering */
1008 FOR_POOL_SOLVABLES(p)
1010 Solvable *s = pool->solvables + p;
1011 if (s->repo != pool->installed && !pool_installable(pool, s))
1013 if (pool_is_kind(pool, s->name, evr))
1014 queue_push(&plist, p);
1018 wp = pool_whatprovides(pool, name);
1019 pp = pool->whatprovidesdata + wp;
1020 while ((p = *pp++) != 0)
1022 Solvable *s = pool->solvables + p;
1023 if (pool_is_kind(pool, s->name, evr))
1024 queue_push(&plist, p);
1029 case REL_FILECONFLICT:
1030 pp = pool_whatprovides_ptr(pool, name);
1031 while ((p = *pp++) != 0)
1033 Id origd = MAKERELDEP(d);
1034 Solvable *s = pool->solvables + p;
1037 pidp = s->repo->idarraydata + s->provides;
1038 while ((pid = *pidp++) != 0)
1042 queue_push(&plist, p);
1050 /* we can reuse an existing entry */
1052 pool->whatprovides_rel[d] = wp;
1058 /* simple version comparison relation */
1060 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: what provides %s?\n", pool_dep2str(pool, name));
1062 pp = pool_whatprovides_ptr(pool, name);
1063 while (ISRELDEP(name))
1065 rd = GETRELDEP(pool, name);
1068 while ((p = *pp++) != 0)
1070 Solvable *s = pool->solvables + p;
1073 /* no provides - check nevr */
1074 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
1075 queue_push(&plist, p);
1078 /* solvable p provides name in some rels */
1079 pidp = s->repo->idarraydata + s->provides;
1080 while ((pid = *pidp++) != 0)
1085 continue; /* wrong provides name */
1086 if (pool->disttype == DISTTYPE_DEB)
1087 continue; /* unversioned provides can never match versioned deps */
1090 prd = GETRELDEP(pool, pid);
1091 if (prd->name != name)
1092 continue; /* wrong provides name */
1093 /* right package, both deps are rels. check flags/evr */
1094 if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
1095 break; /* matches */
1098 continue; /* none of the providers matched */
1099 queue_push(&plist, p);
1101 /* make our system solvable provide all unknown rpmlib() stuff */
1102 if (plist.count == 0 && !strncmp(pool_id2str(pool, name), "rpmlib(", 7))
1103 queue_push(&plist, SYSTEMSOLVABLE);
1105 /* add providers to whatprovides */
1107 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
1109 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
1112 return pool->whatprovides_rel[d];
1116 pool_flush_namespaceproviders(Pool *pool, Id ns, Id evr)
1118 int nrels = pool->nrels;
1122 if (!pool->whatprovides_rel)
1124 for (d = 1, rd = pool->rels + d; d < nrels; d++, rd++)
1126 if (rd->flags != REL_NAMESPACE || rd->name == NAMESPACE_OTHERPROVIDERS)
1128 if (ns && rd->name != ns)
1130 if (evr && rd->evr != evr)
1132 pool->whatprovides_rel[d] = 0;
1136 /* intersect dependencies in keyname with dep, return list of matching packages */
1138 pool_whatmatchesdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker)
1143 FOR_POOL_SOLVABLES(p)
1145 Solvable *s = pool->solvables + p;
1146 if (s->repo->disabled)
1148 if (s->repo != pool->installed && !pool_installable(pool, s))
1150 if (solvable_matchesdep(s, keyname, dep, marker))
1155 /*************************************************************************/
1158 pool_debug(Pool *pool, int type, const char *format, ...)
1163 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0)
1165 if ((pool->debugmask & type) == 0)
1168 va_start(args, format);
1169 if (!pool->debugcallback)
1171 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0 && !(pool->debugmask & SOLV_DEBUG_TO_STDERR))
1172 vprintf(format, args);
1174 vfprintf(stderr, format, args);
1177 vsnprintf(buf, sizeof(buf), format, args);
1179 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
1183 pool_error(Pool *pool, int ret, const char *format, ...)
1187 va_start(args, format);
1190 pool->errstra = 1024;
1191 pool->errstr = solv_malloc(pool->errstra);
1199 l = vsnprintf(pool->errstr, pool->errstra, format, args);
1201 if (l >= 0 && l + 1 > pool->errstra)
1203 pool->errstra = l + 256;
1204 pool->errstr = solv_realloc(pool->errstr, pool->errstra);
1205 va_start(args, format);
1206 l = vsnprintf(pool->errstr, pool->errstra, format, args);
1210 strcpy(pool->errstr, "unknown error");
1211 if (pool->debugmask & SOLV_ERROR)
1212 pool_debug(pool, SOLV_ERROR, "%s\n", pool->errstr);
1217 pool_errstr(Pool *pool)
1219 return pool->errstr ? pool->errstr : "no error";
1223 pool_setdebuglevel(Pool *pool, int level)
1225 int mask = SOLV_DEBUG_RESULT;
1227 mask |= SOLV_DEBUG_STATS|SOLV_DEBUG_ANALYZE|SOLV_DEBUG_UNSOLVABLE|SOLV_DEBUG_SOLVER|SOLV_DEBUG_TRANSACTION|SOLV_ERROR;
1229 mask |= SOLV_DEBUG_JOB|SOLV_DEBUG_SOLUTIONS|SOLV_DEBUG_POLICY;
1231 mask |= SOLV_DEBUG_PROPAGATE;
1233 mask |= SOLV_DEBUG_RULE_CREATION;
1234 mask |= pool->debugmask & SOLV_DEBUG_TO_STDERR; /* keep bit */
1235 pool->debugmask = mask;
1238 void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
1240 pool->debugcallback = debugcallback;
1241 pool->debugcallbackdata = debugcallbackdata;
1244 void pool_setdebugmask(Pool *pool, int mask)
1246 pool->debugmask = mask;
1249 void pool_setloadcallback(Pool *pool, int (*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata)
1251 pool->loadcallback = cb;
1252 pool->loadcallbackdata = loadcbdata;
1255 void pool_setnamespacecallback(Pool *pool, Id (*cb)(struct _Pool *, void *, Id, Id), void *nscbdata)
1257 pool->nscallback = cb;
1258 pool->nscallbackdata = nscbdata;
1261 /*************************************************************************/
1263 struct searchfiles {
1271 #define SEARCHFILES_BLOCK 127
1274 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
1278 struct searchfiles *csf;
1280 while ((dep = *ida++) != 0)
1283 while (ISRELDEP(dep))
1286 sid = pool->ss.nstrings + GETRELID(dep);
1287 if (MAPTST(&csf->seen, sid))
1292 MAPSET(&csf->seen, sid);
1293 rd = GETRELDEP(pool, dep);
1296 else if (rd->flags == REL_NAMESPACE)
1298 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
1301 if (!csf || MAPTST(&csf->seen, sid))
1306 MAPSET(&csf->seen, sid);
1310 else if (rd->flags == REL_FILECONFLICT)
1320 pool_addfileprovides_dep(pool, ids, csf, isf);
1326 if (MAPTST(&csf->seen, dep))
1328 MAPSET(&csf->seen, dep);
1329 s = pool_id2str(pool, dep);
1332 if (csf != isf && pool->addedfileprovides == 1 && !repodata_filelistfilter_matches(0, s))
1333 continue; /* skip non-standard locations csf == isf: installed case */
1334 csf->ids = solv_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
1335 csf->dirs = solv_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
1336 csf->names = solv_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
1337 csf->ids[csf->nfiles] = dep;
1338 sr = strrchr(s, '/');
1339 csf->names[csf->nfiles] = solv_strdup(sr + 1);
1340 csf->dirs[csf->nfiles] = solv_malloc(sr - s + 1);
1342 strncpy(csf->dirs[csf->nfiles], s, sr - s);
1343 csf->dirs[csf->nfiles][sr - s] = 0;
1348 struct addfileprovides_cbdata {
1362 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1364 struct addfileprovides_cbdata *cbd = cbdata;
1367 if (!cbd->useddirs.size)
1369 map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
1370 for (i = 0; i < cbd->nfiles; i++)
1373 if (MAPTST(&cbd->providedids, cbd->ids[i]))
1378 did = repodata_str2dir(data, cbd->dirs[i], 0);
1381 MAPSET(&cbd->useddirs, did);
1383 repodata_free_dircache(data);
1385 if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
1387 for (i = 0; i < cbd->nfiles; i++)
1389 if (cbd->dids[i] != value->id)
1391 if (!strcmp(cbd->names[i], value->str))
1394 if (i == cbd->nfiles)
1396 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
1401 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
1406 Queue fileprovidesq;
1407 int i, j, repoid, repodataid;
1408 int provstart, provend;
1410 int ndone, incomplete;
1415 cbd->nfiles = sf->nfiles;
1417 cbd->dirs = sf->dirs;
1418 cbd->names = sf->names;
1419 cbd->dids = solv_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
1420 map_init(&cbd->providedids, pool->ss.nstrings);
1423 repo = repoonly ? repoonly : pool->repos[repoid];
1424 map_init(&donemap, pool->nsolvables);
1425 queue_init(&fileprovidesq);
1426 provstart = provend = 0;
1429 if (!repo || repo->disabled)
1431 if (repoonly || ++repoid == pool->nrepos)
1433 repo = pool->repos[repoid];
1437 FOR_REPODATAS(repo, repodataid, data)
1439 if (ndone >= repo->nsolvables)
1442 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
1444 map_empty(&cbd->providedids);
1445 for (i = 0; i < fileprovidesq.count; i++)
1446 MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
1447 provstart = data->start;
1448 provend = data->end;
1449 for (i = 0; i < cbd->nfiles; i++)
1450 if (!MAPTST(&cbd->providedids, cbd->ids[i]))
1452 if (i == cbd->nfiles)
1454 /* great! no need to search files */
1455 for (p = data->start; p < data->end; p++)
1456 if (pool->solvables[p].repo == repo)
1458 if (MAPTST(&donemap, p))
1460 MAPSET(&donemap, p);
1467 if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
1470 if (data->start < provstart || data->end > provend)
1472 map_empty(&cbd->providedids);
1473 provstart = provend = 0;
1476 /* check if the data is incomplete */
1478 if (data->state == REPODATA_AVAILABLE)
1480 for (j = 1; j < data->nkeys; j++)
1481 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1483 if (j < data->nkeys)
1486 for (i = 0; i < cbd->nfiles; i++)
1487 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1488 printf("need complete filelist because of %s\n", pool_id2str(pool, cbd->ids[i]));
1490 for (i = 0; i < cbd->nfiles; i++)
1491 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1493 if (i < cbd->nfiles)
1499 map_init(&cbd->useddirs, 0);
1500 for (p = data->start; p < data->end; p++)
1501 if (pool->solvables[p].repo == repo)
1503 if (MAPTST(&donemap, p))
1505 repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
1508 MAPSET(&donemap, p);
1512 map_free(&cbd->useddirs);
1515 if (repoonly || ++repoid == pool->nrepos)
1517 repo = pool->repos[repoid];
1520 queue_free(&fileprovidesq);
1521 map_free(&cbd->providedids);
1525 pool_addfileprovides_queue(Pool *pool, Queue *idq, Queue *idqinst)
1528 Repo *installed, *repo;
1529 struct searchfiles sf, isf, *isfp;
1530 struct addfileprovides_cbdata cbd;
1534 installed = pool->installed;
1535 now = solv_timems(0);
1536 memset(&sf, 0, sizeof(sf));
1537 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
1538 memset(&isf, 0, sizeof(isf));
1539 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
1540 pool->addedfileprovides = pool->addfileprovidesfiltered ? 1 : 2;
1545 queue_empty(idqinst);
1546 isfp = installed ? &isf : 0;
1547 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1553 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1555 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1557 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1559 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1561 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1563 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1565 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1568 map_free(&isf.seen);
1569 POOL_DEBUG(SOLV_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
1574 for (i = 0; i < sf.nfiles; i++)
1575 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in filelist\n", pool_id2str(pool, sf.ids[i]));
1577 pool_addfileprovides_search(pool, &cbd, &sf, 0);
1579 for (i = 0; i < sf.nfiles; i++)
1580 queue_push(idq, sf.ids[i]);
1582 for (i = 0; i < sf.nfiles; i++)
1583 queue_push(idqinst, sf.ids[i]);
1585 for (i = 0; i < sf.nfiles; i++)
1587 solv_free(sf.dirs[i]);
1588 solv_free(sf.names[i]);
1591 solv_free(sf.names);
1596 for (i = 0; i < isf.nfiles; i++)
1597 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in installed filelist\n", pool_id2str(pool, isf.ids[i]));
1600 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1601 if (installed && idqinst)
1602 for (i = 0; i < isf.nfiles; i++)
1603 queue_pushunique(idqinst, isf.ids[i]);
1605 for (i = 0; i < isf.nfiles; i++)
1607 solv_free(isf.dirs[i]);
1608 solv_free(isf.names[i]);
1610 solv_free(isf.dirs);
1611 solv_free(isf.names);
1613 solv_free(cbd.dids);
1614 pool_freewhatprovides(pool); /* as we have added provides */
1615 POOL_DEBUG(SOLV_DEBUG_STATS, "addfileprovides took %d ms\n", solv_timems(now));
1619 pool_addfileprovides(Pool *pool)
1621 pool_addfileprovides_queue(pool, 0, 0);
1625 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)
1629 if (pool->solvables[p].repo)
1630 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1633 /* FIXME: obey callback return value! */
1634 for (p = 1; p < pool->nsolvables; p++)
1635 if (pool->solvables[p].repo)
1636 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1640 pool_clear_pos(Pool *pool)
1642 memset(&pool->pos, 0, sizeof(pool->pos));
1647 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1651 pool->languagecache = solv_free(pool->languagecache);
1652 pool->languagecacheother = 0;
1653 if (pool->nlanguages)
1655 for (i = 0; i < pool->nlanguages; i++)
1656 free((char *)pool->languages[i]);
1657 free(pool->languages);
1659 pool->nlanguages = nlanguages;
1662 pool->languages = solv_calloc(nlanguages, sizeof(const char **));
1663 for (i = 0; i < pool->nlanguages; i++)
1664 pool->languages[i] = solv_strdup(languages[i]);
1668 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1674 if (!lang || !*lang)
1676 n = pool_id2str(pool, id);
1677 l = strlen(n) + strlen(lang) + 2;
1678 if (l > sizeof(buf))
1679 p = solv_malloc(strlen(n) + strlen(lang) + 2);
1682 sprintf(p, "%s:%s", n, lang);
1683 id = pool_str2id(pool, p, create);
1690 pool_alloctmpspace(Pool *pool, int len)
1692 int n = pool->tmpspace.n;
1695 if (len > pool->tmpspace.len[n])
1697 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1698 pool->tmpspace.len[n] = len + 32;
1700 pool->tmpspace.n = (n + 1) % POOL_TMPSPACEBUF;
1701 return pool->tmpspace.buf[n];
1705 pool_alloctmpspace_free(Pool *pool, const char *space, int len)
1710 n = oldn = pool->tmpspace.n;
1714 n = POOL_TMPSPACEBUF - 1;
1717 if (pool->tmpspace.buf[n] != space)
1719 if (len > pool->tmpspace.len[n])
1721 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1722 pool->tmpspace.len[n] = len + 32;
1724 return pool->tmpspace.buf[n];
1731 pool_freetmpspace(Pool *pool, const char *space)
1733 int n = pool->tmpspace.n;
1736 n = (n + (POOL_TMPSPACEBUF - 1)) % POOL_TMPSPACEBUF;
1737 if (pool->tmpspace.buf[n] == space)
1738 pool->tmpspace.n = n;
1742 pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
1746 l1 = str1 ? strlen(str1) : 0;
1747 l2 = str2 ? strlen(str2) : 0;
1748 l3 = str3 ? strlen(str3) : 0;
1749 s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1770 pool_tmpappend(Pool *pool, const char *str1, const char *str2, const char *str3)
1775 l1 = str1 ? strlen(str1) : 0;
1776 l2 = str2 ? strlen(str2) : 0;
1777 l3 = str3 ? strlen(str3) : 0;
1778 str = pool_alloctmpspace_free(pool, str1, l1 + l2 + l3 + 1);
1782 str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1805 pool_bin2hex(Pool *pool, const unsigned char *buf, int len)
1810 s = pool_alloctmpspace(pool, 2 * len + 1);
1811 solv_bin2hex(buf, len, s);
1815 /*******************************************************************/
1827 struct mptree *mptree;
1838 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1840 struct ducbdata *cbd = cbdata;
1843 if (data != cbd->olddata)
1845 Id dn, mp, comp, *dirmap, *dirs;
1847 const char *compstr;
1848 struct mptree *mptree;
1850 /* create map from dir to mptree */
1851 cbd->dirmap = solv_free(cbd->dirmap);
1853 dirmap = solv_calloc(data->dirpool.ndirs, sizeof(Id));
1854 mptree = cbd->mptree;
1856 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1870 if (!mptree[mp].child)
1875 if (data->localpool)
1876 compstr = stringpool_id2str(&data->spool, comp);
1878 compstr = pool_id2str(data->repo->pool, comp);
1879 compl = strlen(compstr);
1880 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1881 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1883 dirmap[dn] = i ? i : -mp;
1885 /* change dirmap to point to mountpoint instead of mptree */
1886 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1889 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1891 cbd->dirmap = dirmap;
1892 cbd->nmap = data->dirpool.ndirs;
1893 cbd->olddata = data;
1896 if (value->id < 0 || value->id >= cbd->nmap)
1898 mp = cbd->dirmap[value->id];
1901 if (cbd->addsub > 0)
1903 cbd->mps[mp].kbytes += value->num;
1904 cbd->mps[mp].files += value->num2;
1908 cbd->mps[mp].kbytes -= value->num;
1909 cbd->mps[mp].files -= value->num2;
1915 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1918 if (mptree[pos].mountpoint == -1)
1919 mptree[pos].mountpoint = mountpoint;
1921 mountpoint = mptree[pos].mountpoint;
1922 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1923 propagate_mountpoints(mptree, i, mountpoint);
1926 #define MPTREE_BLOCK 15
1929 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1932 const char *path, *compstr;
1933 struct mptree *mptree;
1937 struct ducbdata cbd;
1941 Repo *oldinstalled = pool->installed;
1943 memset(&ignoredu, 0, sizeof(ignoredu));
1950 mptree = solv_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1953 mptree[0].sibling = 0;
1954 mptree[0].child = 0;
1956 mptree[0].compl = 0;
1957 mptree[0].mountpoint = -1;
1960 /* create component tree */
1961 for (mp = 0; mp < nmps; mp++)
1966 path = mps[mp].path;
1971 if ((p = strchr(path, '/')) == 0)
1974 compl = strlen(compstr);
1985 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1986 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1990 /* create new node */
1991 mptree = solv_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1993 mptree[i].sibling = mptree[pos].child;
1994 mptree[i].child = 0;
1995 mptree[i].comp = compstr;
1996 mptree[i].compl = compl;
1997 mptree[i].mountpoint = -1;
1998 mptree[pos].child = i;
2002 mptree[pos].mountpoint = mp;
2005 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
2008 for (i = 0; i < nmptree; i++)
2010 printf("#%d sibling: %d\n", i, mptree[i].sibling);
2011 printf("#%d child: %d\n", i, mptree[i].child);
2012 printf("#%d comp: %s\n", i, mptree[i].comp);
2013 printf("#%d compl: %d\n", i, mptree[i].compl);
2014 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
2018 cbd.mptree = mptree;
2020 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
2022 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
2024 if (!MAPTST(installedmap, sp))
2027 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
2028 if (!cbd.hasdu && oldinstalled)
2031 /* no du data available, ignore data of all installed solvables we obsolete */
2033 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
2036 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
2037 while ((obs = *obsp++) != 0)
2038 FOR_PROVIDES(op, opp, obs)
2039 if (op >= oldinstalled->start && op < oldinstalled->end)
2040 MAPSET(&ignoredu, op - oldinstalled->start);
2042 FOR_PROVIDES(op, opp, s->name)
2043 if (pool->solvables[op].name == s->name)
2044 if (op >= oldinstalled->start && op < oldinstalled->end)
2045 MAPSET(&ignoredu, op - oldinstalled->start);
2051 /* assumes we allways have du data for installed solvables */
2052 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
2054 if (MAPTST(installedmap, sp))
2056 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
2058 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
2062 map_free(&ignoredu);
2063 solv_free(cbd.dirmap);
2068 pool_calc_installsizechange(Pool *pool, Map *installedmap)
2073 Repo *oldinstalled = pool->installed;
2075 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
2077 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
2079 if (!MAPTST(installedmap, sp))
2081 change += solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
2085 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
2087 if (MAPTST(installedmap, sp))
2089 change -= solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
2097 * 2: conflicts with installed
2098 * 8: interesting (only true if installed)
2102 static inline Id dep2name(Pool *pool, Id dep)
2104 while (ISRELDEP(dep))
2106 Reldep *rd = rd = GETRELDEP(pool, dep);
2112 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con)
2115 Solvable *sn = pool->solvables + n;
2117 FOR_PROVIDES(p, pp, sn->name)
2119 Solvable *s = pool->solvables + p;
2120 if (s->name != sn->name || s->arch != sn->arch)
2122 if ((map[p] & 9) != 9)
2124 if (pool_match_nevr(pool, pool->solvables + p, con))
2126 return 1; /* found installed package that doesn't conflict */
2131 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *multiversionmap)
2135 FOR_PROVIDES(p, pp, dep)
2137 if (p == SYSTEMSOLVABLE)
2138 return 1; /* always boring, as never constraining */
2139 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
2141 if (ispatch && multiversionmap && multiversionmap->size && MAPTST(multiversionmap, p) && ISRELDEP(dep))
2142 if (providedbyinstalled_multiversion(pool, map, p, dep))
2144 if ((map[p] & 9) == 9)
2152 * pool_trivial_installable - calculate if a set of solvables is
2153 * trivial installable without any other installs/deinstalls of
2154 * packages not belonging to the set.
2156 * the state is returned in the result queue:
2157 * 1: solvable is installable without any other package changes
2158 * 0: solvable is not installable
2159 * -1: solvable is installable, but doesn't constrain any installed packages
2163 pool_trivial_installable_multiversionmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *multiversionmap)
2166 Id p, *dp, con, *conp, req, *reqp;
2170 map = solv_calloc(pool->nsolvables, 1);
2171 for (p = 1; p < pool->nsolvables; p++)
2173 if (!MAPTST(installedmap, p))
2176 s = pool->solvables + p;
2179 conp = s->repo->idarraydata + s->conflicts;
2180 while ((con = *conp++) != 0)
2182 dp = pool_whatprovides_ptr(pool, con);
2184 map[p] |= 2; /* XXX: self conflict ? */
2187 for (i = 0; i < pkgs->count; i++)
2188 map[pkgs->elements[i]] = 16;
2190 for (i = 0, did = 0; did < pkgs->count; i++, did++)
2192 if (i == pkgs->count)
2194 p = pkgs->elements[i];
2195 if ((map[p] & 16) == 0)
2197 if ((map[p] & 2) != 0)
2202 s = pool->solvables + p;
2206 reqp = s->repo->idarraydata + s->requires;
2207 while ((req = *reqp++) != 0)
2209 if (req == SOLVABLE_PREREQMARKER)
2211 r = providedbyinstalled(pool, map, req, 0, 0);
2214 /* decided and miss */
2220 break; /* undecided */
2221 m |= r; /* 1 | 9 | 17 */
2230 int ispatch = 0; /* see solver.c patch handling */
2232 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
2234 conp = s->repo->idarraydata + s->conflicts;
2235 while ((con = *conp++) != 0)
2237 if ((providedbyinstalled(pool, map, con, ispatch, multiversionmap) & 1) != 0)
2243 if ((m == 1 || m == 17) && ISRELDEP(con))
2245 con = dep2name(pool, con);
2246 if ((providedbyinstalled(pool, map, con, ispatch, multiversionmap) & 1) != 0)
2251 continue; /* found a conflict */
2254 if (s->repo && s->repo != oldinstalled)
2256 Id p2, obs, *obsp, *pp;
2260 obsp = s->repo->idarraydata + s->obsoletes;
2261 while ((obs = *obsp++) != 0)
2263 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
2272 FOR_PROVIDES(p2, pp, s->name)
2274 s2 = pool->solvables + p2;
2275 if (s2->name == s->name && (map[p2] & 1) != 0)
2292 queue_init_clone(res, pkgs);
2293 for (i = 0; i < pkgs->count; i++)
2295 m = map[pkgs->elements[i]];
2302 res->elements[i] = r;
2308 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
2310 pool_trivial_installable_multiversionmap(pool, installedmap, pkgs, res, 0);
2314 pool_lookup_str(Pool *pool, Id entry, Id keyname)
2316 if (entry == SOLVID_POS && pool->pos.repo)
2317 return repo_lookup_str(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
2320 return solvable_lookup_str(pool->solvables + entry, keyname);
2324 pool_lookup_id(Pool *pool, Id entry, Id keyname)
2326 if (entry == SOLVID_POS && pool->pos.repo)
2327 return repo_lookup_id(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
2330 return solvable_lookup_id(pool->solvables + entry, keyname);
2334 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned long long notfound)
2336 if (entry == SOLVID_POS && pool->pos.repo)
2337 return repo_lookup_num(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, notfound);
2340 return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
2344 pool_lookup_void(Pool *pool, Id entry, Id keyname)
2346 if (entry == SOLVID_POS && pool->pos.repo)
2347 return repo_lookup_void(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
2350 return solvable_lookup_void(pool->solvables + entry, keyname);
2353 const unsigned char *
2354 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
2356 if (entry == SOLVID_POS && pool->pos.repo)
2357 return repo_lookup_bin_checksum(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, typep);
2360 return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
2364 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
2366 if (entry == SOLVID_POS && pool->pos.repo)
2367 return repo_lookup_checksum(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, typep);
2370 return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
2374 pool_lookup_idarray(Pool *pool, Id entry, Id keyname, Queue *q)
2376 if (entry == SOLVID_POS && pool->pos.repo)
2377 return repo_lookup_idarray(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, q);
2380 return solvable_lookup_idarray(pool->solvables + entry, keyname, q);
2384 pool_lookup_deltalocation(Pool *pool, Id entry, unsigned int *medianrp)
2389 if (entry != SOLVID_POS)
2391 loc = pool_lookup_str(pool, entry, DELTA_LOCATION_DIR);
2392 loc = pool_tmpjoin(pool, loc, loc ? "/" : 0, pool_lookup_str(pool, entry, DELTA_LOCATION_NAME));
2393 loc = pool_tmpappend(pool, loc, "-", pool_lookup_str(pool, entry, DELTA_LOCATION_EVR));
2394 loc = pool_tmpappend(pool, loc, ".", pool_lookup_str(pool, entry, DELTA_LOCATION_SUFFIX));
2399 add_new_provider(Pool *pool, Id id, Id p)
2404 while (ISRELDEP(id))
2406 Reldep *rd = GETRELDEP(pool, id);
2411 for (pp = pool->whatprovidesdata + pool->whatprovides[id]; *pp; pp++)
2423 queue_push(&q, *pp);
2427 pool->whatprovides[id] = pool_queuetowhatprovides(pool, &q);
2432 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
2434 int hadhashes = pool->relhashtbl ? 1 : 0;
2440 if (!conflicts->count)
2442 for (i = 0; i < conflicts->count; i += 6)
2444 fn = conflicts->elements[i];
2445 p = conflicts->elements[i + 1];
2446 md5 = conflicts->elements[i + 2];
2447 q = conflicts->elements[i + 4];
2448 id = pool_rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
2449 s = pool->solvables + p;
2452 s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
2453 if (pool->whatprovides)
2454 add_new_provider(pool, fn, p);
2455 if (pool->whatprovides_rel)
2456 pool->whatprovides_rel[GETRELID(id)] = 0; /* clear cache */
2457 s = pool->solvables + q;
2460 s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
2463 pool_freeidhashes(pool);
2467 pool_prepend_rootdir(Pool *pool, const char *path)
2472 return solv_strdup(path);
2473 return solv_dupjoin(pool->rootdir, "/", *path == '/' ? path + 1 : path);
2477 pool_prepend_rootdir_tmp(Pool *pool, const char *path)
2483 return pool_tmpjoin(pool, pool->rootdir, "/", *path == '/' ? path + 1 : path);
2487 pool_set_rootdir(Pool *pool, const char *rootdir)
2489 solv_free(pool->rootdir);
2490 pool->rootdir = solv_strdup(rootdir);
2494 pool_get_rootdir(Pool *pool)
2496 return pool->rootdir;
2499 /* only used in libzypp */
2501 pool_set_custom_vendorcheck(Pool *pool, int (*vendorcheck)(Pool *, Solvable *, Solvable *))
2503 pool->custom_vendorcheck = vendorcheck;