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.
24 #include "poolid_private.h"
30 #define SOLVABLE_BLOCK 255
32 #define KNOWNID_INITIALIZE
34 #undef KNOWNID_INITIALIZE
43 pool = (Pool *)solv_calloc(1, sizeof(*pool));
45 stringpool_init (&pool->ss, initpool_data);
47 /* alloc space for RelDep 0 */
48 pool->rels = solv_extend_resize(0, 1, sizeof(Reldep), REL_BLOCK);
50 memset(pool->rels, 0, sizeof(Reldep));
52 /* alloc space for Solvable 0 and system solvable */
53 pool->solvables = solv_extend_resize(0, 2, sizeof(Solvable), SOLVABLE_BLOCK);
55 memset(pool->solvables, 0, 2 * sizeof(Solvable));
57 queue_init(&pool->vendormap);
60 pool->disttype = DISTTYPE_DEB;
61 pool->noarchid = ARCH_ALL;
62 #elif defined(ARCHLINUX)
63 pool->disttype = DISTTYPE_ARCH;
64 pool->noarchid = ARCH_ANY;
66 pool->disttype = DISTTYPE_HAIKU;
67 pool->noarchid = ARCH_ANY;
68 pool->obsoleteusesprovides = 1;
70 pool->disttype = DISTTYPE_RPM;
71 pool->noarchid = ARCH_NOARCH;
74 /* initialize the system solvable */
75 s = pool->solvables + SYSTEMSOLVABLE;
76 s->name = SYSTEM_SYSTEM;
77 s->arch = pool->noarchid;
80 pool->debugmask = SOLV_DEBUG_RESULT; /* FIXME */
82 pool->obsoleteusescolors = 1;
85 pool->noobsoletesmultiversion = 1;
86 pool->forbidselfconflicts = 1;
87 pool->obsoleteusesprovides = 1;
88 pool->implicitobsoleteusesprovides = 1;
89 pool->havedistepoch = 1;
95 /* free all the resources of our pool */
101 pool_freewhatprovides(pool);
102 pool_freeidhashes(pool);
103 pool_freeallrepos(pool, 1);
104 solv_free(pool->id2arch);
105 solv_free(pool->id2color);
106 solv_free(pool->solvables);
107 stringpool_free(&pool->ss);
108 solv_free(pool->rels);
109 pool_setvendorclasses(pool, 0);
110 queue_free(&pool->vendormap);
111 queue_free(&pool->pooljobs);
112 for (i = 0; i < POOL_TMPSPACEBUF; i++)
113 solv_free(pool->tmpspace.buf[i]);
114 for (i = 0; i < pool->nlanguages; i++)
115 free((char *)pool->languages[i]);
116 solv_free(pool->languages);
117 solv_free(pool->languagecache);
118 solv_free(pool->errstr);
119 solv_free(pool->rootdir);
124 pool_freeallrepos(Pool *pool, int reuseids)
128 pool_freewhatprovides(pool);
129 for (i = 1; i < pool->nrepos; i++)
131 repo_freedata(pool->repos[i]);
132 pool->repos = solv_free(pool->repos);
135 /* the first two solvables don't belong to a repo */
136 pool_free_solvable_block(pool, 2, pool->nsolvables - 2, reuseids);
139 #ifdef MULTI_SEMANTICS
141 pool_setdisttype(Pool *pool, int disttype)
143 pool->disttype = disttype;
144 if (disttype == DISTTYPE_RPM)
145 pool->noarchid = ARCH_NOARCH;
146 if (disttype == DISTTYPE_DEB)
147 pool->noarchid = ARCH_ALL;
148 if (disttype == DISTTYPE_ARCH)
149 pool->noarchid = ARCH_ANY;
150 if (disttype == DISTTYPE_HAIKU)
151 pool->noarchid = ARCH_ANY;
152 pool->solvables[SYSTEMSOLVABLE].arch = pool->noarchid;
157 pool_get_flag(Pool *pool, int flag)
161 case POOL_FLAG_PROMOTEEPOCH:
162 return pool->promoteepoch;
163 case POOL_FLAG_FORBIDSELFCONFLICTS:
164 return pool->forbidselfconflicts;
165 case POOL_FLAG_OBSOLETEUSESPROVIDES:
166 return pool->obsoleteusesprovides;
167 case POOL_FLAG_IMPLICITOBSOLETEUSESPROVIDES:
168 return pool->implicitobsoleteusesprovides;
169 case POOL_FLAG_OBSOLETEUSESCOLORS:
170 return pool->obsoleteusescolors;
171 case POOL_FLAG_NOINSTALLEDOBSOLETES:
172 return pool->noinstalledobsoletes;
173 case POOL_FLAG_HAVEDISTEPOCH:
174 return pool->havedistepoch;
175 case POOL_FLAG_NOOBSOLETESMULTIVERSION:
176 return pool->noobsoletesmultiversion;
184 pool_set_flag(Pool *pool, int flag, int value)
186 int old = pool_get_flag(pool, flag);
189 case POOL_FLAG_PROMOTEEPOCH:
190 pool->promoteepoch = value;
192 case POOL_FLAG_FORBIDSELFCONFLICTS:
193 pool->forbidselfconflicts = value;
195 case POOL_FLAG_OBSOLETEUSESPROVIDES:
196 pool->obsoleteusesprovides = value;
198 case POOL_FLAG_IMPLICITOBSOLETEUSESPROVIDES:
199 pool->implicitobsoleteusesprovides = value;
201 case POOL_FLAG_OBSOLETEUSESCOLORS:
202 pool->obsoleteusescolors = value;
204 case POOL_FLAG_NOINSTALLEDOBSOLETES:
205 pool->noinstalledobsoletes = value;
207 case POOL_FLAG_HAVEDISTEPOCH:
208 pool->havedistepoch = value;
210 case POOL_FLAG_NOOBSOLETESMULTIVERSION:
211 pool->noobsoletesmultiversion = value;
221 pool_add_solvable(Pool *pool)
223 pool->solvables = solv_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
224 memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
225 return pool->nsolvables++;
229 pool_add_solvable_block(Pool *pool, int count)
231 Id nsolvables = pool->nsolvables;
234 pool->solvables = solv_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
235 memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
236 pool->nsolvables += count;
241 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
245 if (reuseids && start + count == pool->nsolvables)
247 /* might want to shrink solvable array */
248 pool->nsolvables = start;
251 memset(pool->solvables + start, 0, sizeof(Solvable) * count);
256 pool_set_installed(Pool *pool, Repo *installed)
258 if (pool->installed == installed)
260 pool->installed = installed;
261 pool_freewhatprovides(pool);
265 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp, void *dp)
270 oa = pool->whatprovides[*(Id *)ap];
271 ob = pool->whatprovides[*(Id *)bp];
273 return *(Id *)ap - *(Id *)bp;
274 da = pool->whatprovidesdata + oa;
275 db = pool->whatprovidesdata + ob;
277 if ((r = (*da++ - *db++)) != 0)
281 return *(Id *)ap - *(Id *)bp;
285 * pool_shrink_whatprovides - unify whatprovides data
287 * whatprovides_rel must be empty for this to work!
291 pool_shrink_whatprovides(Pool *pool)
295 Id lastid, *last, *dp, *lp;
299 if (pool->ss.nstrings < 3)
301 sorted = solv_malloc2(pool->ss.nstrings, sizeof(Id));
302 for (i = id = 0; id < pool->ss.nstrings; id++)
303 if (pool->whatprovides[id] >= 4)
306 solv_sort(sorted, n, sizeof(Id), pool_shrink_whatprovides_sortcmp, pool);
309 for (i = 0; i < n; i++)
312 o = pool->whatprovides[id];
313 dp = pool->whatprovidesdata + o;
327 pool->whatprovides[id] = -lastid;
331 last = pool->whatprovidesdata + o;
335 dp = pool->whatprovidesdata + 4;
336 for (id = 1; id < pool->ss.nstrings; id++)
338 o = pool->whatprovides[id];
346 pool->whatprovides[id] = pool->whatprovides[i];
351 lp = pool->whatprovidesdata + o;
354 pool->whatprovides[id] = dp - pool->whatprovidesdata;
355 while ((*dp++ = *lp++) != 0)
358 o = dp - pool->whatprovidesdata;
359 POOL_DEBUG(SOLV_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
360 if (pool->whatprovidesdataoff == o)
362 r = pool->whatprovidesdataoff - o;
363 pool->whatprovidesdataoff = o;
364 pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
365 if (r > pool->whatprovidesdataleft)
366 r = pool->whatprovidesdataleft;
367 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
372 * pool_createwhatprovides()
374 * create hashes over pool of solvables to ease provide lookups
378 pool_createwhatprovides(Pool *pool)
380 int i, num, np, extra;
385 Offset *whatprovides;
386 Id *whatprovidesdata, *d;
387 Repo *installed = pool->installed;
390 now = solv_timems(0);
391 POOL_DEBUG(SOLV_DEBUG_STATS, "number of solvables: %d, memory used: %d K\n", pool->nsolvables, pool->nsolvables * (int)sizeof(Solvable) / 1024);
392 POOL_DEBUG(SOLV_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
393 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);
394 if (pool->ss.stringhashmask || pool->relhashmask)
395 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)));
397 pool_freeidhashes(pool); /* XXX: should not be here! */
398 pool_freewhatprovides(pool);
399 num = pool->ss.nstrings;
400 pool->whatprovides = whatprovides = solv_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
401 pool->whatprovides_rel = solv_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
403 /* count providers for each name */
404 for (i = pool->nsolvables - 1; i > 0; i--)
407 s = pool->solvables + i;
408 if (!s->provides || !s->repo || s->repo->disabled)
410 /* we always need the installed solvable in the whatprovides data,
411 otherwise obsoletes/conflicts on them won't work */
412 if (s->repo != installed && !pool_installable(pool, s))
414 pp = s->repo->idarraydata + s->provides;
415 while ((id = *pp++) != 0)
419 Reldep *rd = GETRELDEP(pool, id);
422 whatprovides[id]++; /* inc count of providers */
426 off = 4; /* first entry is undef, second is empty list, third is system solvable */
427 np = 0; /* number of names provided */
428 for (i = 0, idp = whatprovides; i < num; i++, idp++)
431 if (!n) /* no providers */
433 off += n; /* make space for all providers */
434 *idp = off++; /* now idp points to terminating zero */
435 np++; /* inc # of provider 'slots' for stats */
438 POOL_DEBUG(SOLV_DEBUG_STATS, "provide ids: %d\n", np);
440 /* reserve some space for relation data */
441 extra = 2 * pool->nrels;
445 POOL_DEBUG(SOLV_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
447 /* alloc space for all providers + extra */
448 whatprovidesdata = solv_calloc(off + extra, sizeof(Id));
449 whatprovidesdata[2] = SYSTEMSOLVABLE;
451 /* now fill data for all provides */
452 for (i = pool->nsolvables - 1; i > 0; i--)
455 s = pool->solvables + i;
456 if (!s->provides || !s->repo || s->repo->disabled)
458 if (s->repo != installed && !pool_installable(pool, s))
461 /* for all provides of this solvable */
462 pp = s->repo->idarraydata + s->provides;
463 while ((id = *pp++) != 0)
467 Reldep *rd = GETRELDEP(pool, id);
470 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
471 if (*d != i) /* don't add same solvable twice */
478 pool->whatprovidesdata = whatprovidesdata;
479 pool->whatprovidesdataoff = off;
480 pool->whatprovidesdataleft = extra;
481 pool_shrink_whatprovides(pool);
482 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)));
483 POOL_DEBUG(SOLV_DEBUG_STATS, "createwhatprovides took %d ms\n", solv_timems(now));
487 * free all of our whatprovides data
488 * be careful, everything internalized with pool_queuetowhatprovides is
492 pool_freewhatprovides(Pool *pool)
494 pool->whatprovides = solv_free(pool->whatprovides);
495 pool->whatprovides_rel = solv_free(pool->whatprovides_rel);
496 pool->whatprovidesdata = solv_free(pool->whatprovidesdata);
497 pool->whatprovidesdataoff = 0;
498 pool->whatprovidesdataleft = 0;
502 /******************************************************************************/
505 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
507 * used for whatprovides, jobs, learnt rules, selections
508 * input: q: queue of Ids
509 * returns: Offset into whatprovidesdata
513 pool_queuetowhatprovides(Pool *pool, Queue *q)
516 int count = q->count;
518 if (count == 0) /* queue empty -> 1 */
520 if (count == 1 && q->elements[0] == SYSTEMSOLVABLE)
523 /* extend whatprovidesdata if needed, +1 for 0-termination */
524 if (pool->whatprovidesdataleft < count + 1)
526 POOL_DEBUG(SOLV_DEBUG_STATS, "growing provides hash data...\n");
527 pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
528 pool->whatprovidesdataleft = count + 4096;
531 /* copy queue to next free slot */
532 off = pool->whatprovidesdataoff;
533 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
535 /* adapt count and 0-terminate */
536 pool->whatprovidesdataoff += count;
537 pool->whatprovidesdata[pool->whatprovidesdataoff++] = 0;
538 pool->whatprovidesdataleft -= count + 1;
544 /*************************************************************************/
546 #if defined(MULTI_SEMANTICS)
547 # define EVRCMP_DEPCMP (pool->disttype == DISTTYPE_DEB ? EVRCMP_COMPARE : EVRCMP_MATCH_RELEASE)
548 #elif defined(DEBIAN)
549 # define EVRCMP_DEPCMP EVRCMP_COMPARE
551 # define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
554 /* check if a package's nevr matches a dependency */
557 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
559 Reldep *rd = GETRELDEP(pool, d);
562 int flags = rd->flags;
571 if (evr != ARCH_SRC || s->arch != ARCH_NOSRC)
574 return pool_match_nevr(pool, s, name);
576 if (pool_match_nevr(pool, s, name))
578 return pool_match_nevr(pool, s, evr);
581 if (!pool_match_nevr(pool, s, name))
583 return pool_match_nevr(pool, s, evr);
588 if (!pool_match_nevr(pool, s, name))
591 return (flags & REL_EQ) ? 1 : 0;
596 switch (pool_evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP))
601 return (flags & REL_LT) ? 1 : 0;
603 return (flags & REL_EQ) ? 1 : 0;
605 return (flags & REL_GT) ? 1 : 0;
607 return (flags & REL_EQ) ? 1 : 0;
614 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
615 /* forward declaration */
616 static int pool_match_flags_evr_rel_compat(Pool *pool, Reldep *range, int flags, int evr);
619 /* match (flags, evr) against provider (pflags, pevr) */
621 pool_match_flags_evr(Pool *pool, int pflags, Id pevr, int flags, int evr)
623 if (!pflags || !flags || pflags >= 8 || flags >= 8)
625 if (flags == 7 || pflags == 7)
626 return 1; /* rel provides every version */
627 if ((pflags & flags & (REL_LT | REL_GT)) != 0)
628 return 1; /* both rels show in the same direction */
630 return (flags & pflags & REL_EQ) ? 1 : 0;
631 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
634 Reldep *rd = GETRELDEP(pool, pevr);
635 if (rd->flags == REL_COMPAT)
636 return pool_match_flags_evr_rel_compat(pool, rd, flags, evr);
639 switch (pool_evrcmp(pool, pevr, evr, EVRCMP_DEPCMP))
642 return (pflags & REL_EQ) ? 1 : 0;
644 return (flags & REL_LT) || (pflags & REL_GT) ? 1 : 0;
646 return (flags & pflags & REL_EQ) ? 1 : 0;
648 return (flags & REL_GT) || (pflags & REL_LT) ? 1 : 0;
650 return (flags & REL_EQ) ? 1 : 0;
657 #if defined(HAIKU) || defined(MULTI_SEMANTICS)
659 pool_match_flags_evr_rel_compat(Pool *pool, Reldep *range, int flags, int evr)
661 /* range->name is the actual version, range->evr the backwards compatibility
662 version. If flags are '>=' or '>', we match the compatibility version
663 as well, otherwise only the actual version. */
664 if (!(flags & REL_GT) || (flags & REL_LT))
665 return pool_match_flags_evr(pool, REL_EQ, range->name, flags, evr);
666 return pool_match_flags_evr(pool, REL_LT | REL_EQ, range->name, flags, evr) &&
667 pool_match_flags_evr(pool, REL_GT | REL_EQ, range->evr, REL_EQ, evr);
671 /* match two dependencies (d1 = provider) */
674 pool_match_dep(Pool *pool, Id d1, Id d2)
684 rd2 = GETRELDEP(pool, d2);
685 return pool_match_dep(pool, d1, rd2->name);
687 rd1 = GETRELDEP(pool, d1);
690 return pool_match_dep(pool, rd1->name, d2);
692 rd2 = GETRELDEP(pool, d2);
693 /* first match name */
694 if (!pool_match_dep(pool, rd1->name, rd2->name))
696 /* name matches, check flags and evr */
697 return pool_match_flags_evr(pool, rd1->flags, rd1->evr, rd2->flags, rd2->evr);
703 * add packages fulfilling the relation to whatprovides array
704 * no exact providers, do range match
709 pool_addrelproviders(Pool *pool, Id d)
711 Reldep *rd = GETRELDEP(pool, d);
717 int flags = rd->flags;
722 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
726 /* special relation */
734 wp = pool_whatprovides(pool, name);
735 pp2 = pool_whatprovides_ptr(pool, evr);
736 pp = pool->whatprovidesdata + wp;
737 while ((p = *pp++) != 0)
739 for (pp3 = pp2; *pp3; pp3++)
743 queue_push(&plist, p); /* found it */
749 wp = pool_whatprovides(pool, name);
750 pp = pool->whatprovidesdata + wp;
752 wp = pool_whatprovides(pool, evr);
756 while ((p = *pp++) != 0)
757 queue_push(&plist, p);
759 pp = pool_whatprovides_ptr(pool, evr);
760 while ((p = *pp++) != 0)
761 queue_pushunique(&plist, p);
762 if (plist.count != cnt)
767 if (name == NAMESPACE_OTHERPROVIDERS)
769 wp = pool_whatprovides(pool, evr);
772 if (pool->nscallback)
774 /* ask callback which packages provide the dependency
776 * 1: the system (aka SYSTEMSOLVABLE)
777 * >1: set of packages, stored as offset on whatprovidesdata
779 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
783 queue_push(&plist, SYSTEMSOLVABLE);
787 /* small hack: make it possible to match <pkg>.src
788 * we have to iterate over the solvables as src packages do not
789 * provide anything, thus they are not indexed in our
790 * whatprovides hash */
791 if (evr == ARCH_SRC || evr == ARCH_NOSRC)
794 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
798 if (s->arch != evr && s->arch != ARCH_NOSRC)
800 if (pool_disabled_solvable(pool, s))
802 if (pool_match_nevr(pool, s, name))
803 queue_push(&plist, p);
807 wp = pool_whatprovides(pool, name);
808 pp = pool->whatprovidesdata + wp;
809 while ((p = *pp++) != 0)
811 Solvable *s = pool->solvables + p;
813 queue_push(&plist, p);
818 case REL_FILECONFLICT:
819 pp = pool_whatprovides_ptr(pool, name);
820 while ((p = *pp++) != 0)
822 Id origd = MAKERELDEP(d);
823 Solvable *s = pool->solvables + p;
826 pidp = s->repo->idarraydata + s->provides;
827 while ((pid = *pidp++) != 0)
831 queue_push(&plist, p);
839 /* we can reuse an existing entry */
841 pool->whatprovides_rel[d] = wp;
847 /* simple version comparison relation */
849 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: what provides %s?\n", pool_dep2str(pool, name));
851 pp = pool_whatprovides_ptr(pool, name);
852 while (ISRELDEP(name))
854 rd = GETRELDEP(pool, name);
857 while ((p = *pp++) != 0)
859 Solvable *s = pool->solvables + p;
862 /* no provides - check nevr */
863 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
864 queue_push(&plist, p);
867 /* solvable p provides name in some rels */
868 pidp = s->repo->idarraydata + s->provides;
869 while ((pid = *pidp++) != 0)
874 continue; /* wrong provides name */
875 if (pool->disttype == DISTTYPE_DEB)
876 continue; /* unversioned provides can never match versioned deps */
879 prd = GETRELDEP(pool, pid);
880 if (prd->name != name)
881 continue; /* wrong provides name */
882 /* right package, both deps are rels. check flags/evr */
883 if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
887 continue; /* none of the providers matched */
888 queue_push(&plist, p);
890 /* make our system solvable provide all unknown rpmlib() stuff */
891 if (plist.count == 0 && !strncmp(pool_id2str(pool, name), "rpmlib(", 7))
892 queue_push(&plist, SYSTEMSOLVABLE);
894 /* add providers to whatprovides */
896 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
898 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
901 return pool->whatprovides_rel[d];
905 pool_flush_namespaceproviders(Pool *pool, Id ns, Id evr)
907 int nrels = pool->nrels;
911 if (!pool->whatprovides_rel)
913 for (d = 1, rd = pool->rels + d; d < nrels; d++, rd++)
915 if (rd->flags != REL_NAMESPACE || rd->name == NAMESPACE_OTHERPROVIDERS)
917 if (ns && rd->name != ns)
919 if (evr && rd->evr != evr)
921 pool->whatprovides_rel[d] = 0;
925 /*************************************************************************/
928 pool_debug(Pool *pool, int type, const char *format, ...)
933 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0)
935 if ((pool->debugmask & type) == 0)
938 va_start(args, format);
939 if (!pool->debugcallback)
941 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0 && !(pool->debugmask & SOLV_DEBUG_TO_STDERR))
942 vprintf(format, args);
944 vfprintf(stderr, format, args);
947 vsnprintf(buf, sizeof(buf), format, args);
949 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
953 pool_error(Pool *pool, int ret, const char *format, ...)
957 va_start(args, format);
960 pool->errstra = 1024;
961 pool->errstr = solv_malloc(pool->errstra);
969 l = vsnprintf(pool->errstr, pool->errstra, format, args);
971 if (l >= 0 && l + 1 > pool->errstra)
973 pool->errstra = l + 256;
974 pool->errstr = solv_realloc(pool->errstr, pool->errstra);
975 va_start(args, format);
976 l = vsnprintf(pool->errstr, pool->errstra, format, args);
980 strcpy(pool->errstr, "unknown error");
981 if (pool->debugmask & SOLV_ERROR)
982 pool_debug(pool, SOLV_ERROR, "%s\n", pool->errstr);
987 pool_errstr(Pool *pool)
989 return pool->errstr ? pool->errstr : "no error";
993 pool_setdebuglevel(Pool *pool, int level)
995 int mask = SOLV_DEBUG_RESULT;
997 mask |= SOLV_DEBUG_STATS|SOLV_DEBUG_ANALYZE|SOLV_DEBUG_UNSOLVABLE|SOLV_DEBUG_SOLVER|SOLV_DEBUG_TRANSACTION|SOLV_ERROR;
999 mask |= SOLV_DEBUG_JOB|SOLV_DEBUG_SOLUTIONS|SOLV_DEBUG_POLICY;
1001 mask |= SOLV_DEBUG_PROPAGATE;
1003 mask |= SOLV_DEBUG_RULE_CREATION;
1004 mask |= pool->debugmask & SOLV_DEBUG_TO_STDERR; /* keep bit */
1005 pool->debugmask = mask;
1008 void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
1010 pool->debugcallback = debugcallback;
1011 pool->debugcallbackdata = debugcallbackdata;
1014 void pool_setdebugmask(Pool *pool, int mask)
1016 pool->debugmask = mask;
1019 void pool_setloadcallback(Pool *pool, int (*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata)
1021 pool->loadcallback = cb;
1022 pool->loadcallbackdata = loadcbdata;
1025 void pool_setnamespacecallback(Pool *pool, Id (*cb)(struct _Pool *, void *, Id, Id), void *nscbdata)
1027 pool->nscallback = cb;
1028 pool->nscallbackdata = nscbdata;
1031 /*************************************************************************/
1033 struct searchfiles {
1041 #define SEARCHFILES_BLOCK 127
1044 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
1048 struct searchfiles *csf;
1050 while ((dep = *ida++) != 0)
1053 while (ISRELDEP(dep))
1056 sid = pool->ss.nstrings + GETRELID(dep);
1057 if (MAPTST(&csf->seen, sid))
1062 MAPSET(&csf->seen, sid);
1063 rd = GETRELDEP(pool, dep);
1066 else if (rd->flags == REL_NAMESPACE)
1068 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
1071 if (!csf || MAPTST(&csf->seen, sid))
1076 MAPSET(&csf->seen, sid);
1080 else if (rd->flags == REL_FILECONFLICT)
1090 pool_addfileprovides_dep(pool, ids, csf, isf);
1096 if (MAPTST(&csf->seen, dep))
1098 MAPSET(&csf->seen, dep);
1099 s = pool_id2str(pool, dep);
1102 csf->ids = solv_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
1103 csf->dirs = solv_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
1104 csf->names = solv_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
1105 csf->ids[csf->nfiles] = dep;
1106 sr = strrchr(s, '/');
1107 csf->names[csf->nfiles] = solv_strdup(sr + 1);
1108 csf->dirs[csf->nfiles] = solv_malloc(sr - s + 1);
1110 strncpy(csf->dirs[csf->nfiles], s, sr - s);
1111 csf->dirs[csf->nfiles][sr - s] = 0;
1116 struct addfileprovides_cbdata {
1130 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1132 struct addfileprovides_cbdata *cbd = cbdata;
1135 if (!cbd->useddirs.size)
1137 map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
1138 for (i = 0; i < cbd->nfiles; i++)
1141 if (MAPTST(&cbd->providedids, cbd->ids[i]))
1146 did = repodata_str2dir(data, cbd->dirs[i], 0);
1149 MAPSET(&cbd->useddirs, did);
1151 repodata_free_dircache(data);
1153 if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
1155 for (i = 0; i < cbd->nfiles; i++)
1157 if (cbd->dids[i] != value->id)
1159 if (!strcmp(cbd->names[i], value->str))
1162 if (i == cbd->nfiles)
1164 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
1169 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
1174 Queue fileprovidesq;
1175 int i, j, repoid, repodataid;
1176 int provstart, provend;
1178 int ndone, incomplete;
1183 cbd->nfiles = sf->nfiles;
1185 cbd->dirs = sf->dirs;
1186 cbd->names = sf->names;
1187 cbd->dids = solv_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
1188 map_init(&cbd->providedids, pool->ss.nstrings);
1191 repo = repoonly ? repoonly : pool->repos[repoid];
1192 map_init(&donemap, pool->nsolvables);
1193 queue_init(&fileprovidesq);
1194 provstart = provend = 0;
1197 if (!repo || repo->disabled)
1199 if (repoonly || ++repoid == pool->nrepos)
1201 repo = pool->repos[repoid];
1205 FOR_REPODATAS(repo, repodataid, data)
1207 if (ndone >= repo->nsolvables)
1210 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
1212 map_empty(&cbd->providedids);
1213 for (i = 0; i < fileprovidesq.count; i++)
1214 MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
1215 provstart = data->start;
1216 provend = data->end;
1217 for (i = 0; i < cbd->nfiles; i++)
1218 if (!MAPTST(&cbd->providedids, cbd->ids[i]))
1220 if (i == cbd->nfiles)
1222 /* great! no need to search files */
1223 for (p = data->start; p < data->end; p++)
1224 if (pool->solvables[p].repo == repo)
1226 if (MAPTST(&donemap, p))
1228 MAPSET(&donemap, p);
1235 if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
1238 if (data->start < provstart || data->end > provend)
1240 map_empty(&cbd->providedids);
1241 provstart = provend = 0;
1244 /* check if the data is incomplete */
1246 if (data->state == REPODATA_AVAILABLE)
1248 for (j = 1; j < data->nkeys; j++)
1249 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1251 if (j < data->nkeys)
1254 for (i = 0; i < cbd->nfiles; i++)
1255 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1256 printf("need complete filelist because of %s\n", pool_id2str(pool, cbd->ids[i]));
1258 for (i = 0; i < cbd->nfiles; i++)
1259 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1261 if (i < cbd->nfiles)
1267 map_init(&cbd->useddirs, 0);
1268 for (p = data->start; p < data->end; p++)
1269 if (pool->solvables[p].repo == repo)
1271 if (MAPTST(&donemap, p))
1273 repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
1276 MAPSET(&donemap, p);
1280 map_free(&cbd->useddirs);
1283 if (repoonly || ++repoid == pool->nrepos)
1285 repo = pool->repos[repoid];
1288 queue_free(&fileprovidesq);
1289 map_free(&cbd->providedids);
1293 pool_addfileprovides_queue(Pool *pool, Queue *idq, Queue *idqinst)
1296 Repo *installed, *repo;
1297 struct searchfiles sf, isf, *isfp;
1298 struct addfileprovides_cbdata cbd;
1302 installed = pool->installed;
1303 now = solv_timems(0);
1304 memset(&sf, 0, sizeof(sf));
1305 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
1306 memset(&isf, 0, sizeof(isf));
1307 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
1312 queue_empty(idqinst);
1313 isfp = installed ? &isf : 0;
1314 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1320 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1322 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1324 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1326 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1328 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1330 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1332 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1335 map_free(&isf.seen);
1336 POOL_DEBUG(SOLV_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
1341 for (i = 0; i < sf.nfiles; i++)
1342 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in filelist\n", pool_id2str(pool, sf.ids[i]));
1344 pool_addfileprovides_search(pool, &cbd, &sf, 0);
1346 for (i = 0; i < sf.nfiles; i++)
1347 queue_push(idq, sf.ids[i]);
1349 for (i = 0; i < sf.nfiles; i++)
1350 queue_push(idqinst, sf.ids[i]);
1352 for (i = 0; i < sf.nfiles; i++)
1354 solv_free(sf.dirs[i]);
1355 solv_free(sf.names[i]);
1358 solv_free(sf.names);
1363 for (i = 0; i < isf.nfiles; i++)
1364 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in installed filelist\n", pool_id2str(pool, isf.ids[i]));
1367 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1368 if (installed && idqinst)
1369 for (i = 0; i < isf.nfiles; i++)
1370 queue_pushunique(idqinst, isf.ids[i]);
1372 for (i = 0; i < isf.nfiles; i++)
1374 solv_free(isf.dirs[i]);
1375 solv_free(isf.names[i]);
1377 solv_free(isf.dirs);
1378 solv_free(isf.names);
1380 solv_free(cbd.dids);
1381 pool_freewhatprovides(pool); /* as we have added provides */
1382 POOL_DEBUG(SOLV_DEBUG_STATS, "addfileprovides took %d ms\n", solv_timems(now));
1386 pool_addfileprovides(Pool *pool)
1388 pool_addfileprovides_queue(pool, 0, 0);
1392 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)
1396 if (pool->solvables[p].repo)
1397 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1400 /* FIXME: obey callback return value! */
1401 for (p = 1; p < pool->nsolvables; p++)
1402 if (pool->solvables[p].repo)
1403 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1407 pool_clear_pos(Pool *pool)
1409 memset(&pool->pos, 0, sizeof(pool->pos));
1414 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1418 pool->languagecache = solv_free(pool->languagecache);
1419 pool->languagecacheother = 0;
1420 if (pool->nlanguages)
1422 for (i = 0; i < pool->nlanguages; i++)
1423 free((char *)pool->languages[i]);
1424 free(pool->languages);
1426 pool->nlanguages = nlanguages;
1429 pool->languages = solv_calloc(nlanguages, sizeof(const char **));
1430 for (i = 0; i < pool->nlanguages; i++)
1431 pool->languages[i] = solv_strdup(languages[i]);
1435 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1441 if (!lang || !*lang)
1443 n = pool_id2str(pool, id);
1444 l = strlen(n) + strlen(lang) + 2;
1445 if (l > sizeof(buf))
1446 p = solv_malloc(strlen(n) + strlen(lang) + 2);
1449 sprintf(p, "%s:%s", n, lang);
1450 id = pool_str2id(pool, p, create);
1457 pool_alloctmpspace(Pool *pool, int len)
1459 int n = pool->tmpspace.n;
1462 if (len > pool->tmpspace.len[n])
1464 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1465 pool->tmpspace.len[n] = len + 32;
1467 pool->tmpspace.n = (n + 1) % POOL_TMPSPACEBUF;
1468 return pool->tmpspace.buf[n];
1472 pool_alloctmpspace_free(Pool *pool, const char *space, int len)
1477 n = oldn = pool->tmpspace.n;
1481 n = POOL_TMPSPACEBUF - 1;
1484 if (pool->tmpspace.buf[n] != space)
1486 if (len > pool->tmpspace.len[n])
1488 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1489 pool->tmpspace.len[n] = len + 32;
1491 return pool->tmpspace.buf[n];
1498 pool_freetmpspace(Pool *pool, const char *space)
1500 int n = pool->tmpspace.n;
1503 n = (n + (POOL_TMPSPACEBUF - 1)) % POOL_TMPSPACEBUF;
1504 if (pool->tmpspace.buf[n] == space)
1505 pool->tmpspace.n = n;
1509 pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
1513 l1 = str1 ? strlen(str1) : 0;
1514 l2 = str2 ? strlen(str2) : 0;
1515 l3 = str3 ? strlen(str3) : 0;
1516 s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1537 pool_tmpappend(Pool *pool, const char *str1, const char *str2, const char *str3)
1542 l1 = str1 ? strlen(str1) : 0;
1543 l2 = str2 ? strlen(str2) : 0;
1544 l3 = str3 ? strlen(str3) : 0;
1545 str = pool_alloctmpspace_free(pool, str1, l1 + l2 + l3 + 1);
1549 str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1572 pool_bin2hex(Pool *pool, const unsigned char *buf, int len)
1577 s = pool_alloctmpspace(pool, 2 * len + 1);
1578 solv_bin2hex(buf, len, s);
1582 /*******************************************************************/
1594 struct mptree *mptree;
1605 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1607 struct ducbdata *cbd = cbdata;
1610 if (data != cbd->olddata)
1612 Id dn, mp, comp, *dirmap, *dirs;
1614 const char *compstr;
1615 struct mptree *mptree;
1617 /* create map from dir to mptree */
1618 cbd->dirmap = solv_free(cbd->dirmap);
1620 dirmap = solv_calloc(data->dirpool.ndirs, sizeof(Id));
1621 mptree = cbd->mptree;
1623 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1637 if (!mptree[mp].child)
1642 if (data->localpool)
1643 compstr = stringpool_id2str(&data->spool, comp);
1645 compstr = pool_id2str(data->repo->pool, comp);
1646 compl = strlen(compstr);
1647 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1648 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1650 dirmap[dn] = i ? i : -mp;
1652 /* change dirmap to point to mountpoint instead of mptree */
1653 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1656 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1658 cbd->dirmap = dirmap;
1659 cbd->nmap = data->dirpool.ndirs;
1660 cbd->olddata = data;
1663 if (value->id < 0 || value->id >= cbd->nmap)
1665 mp = cbd->dirmap[value->id];
1668 if (cbd->addsub > 0)
1670 cbd->mps[mp].kbytes += value->num;
1671 cbd->mps[mp].files += value->num2;
1675 cbd->mps[mp].kbytes -= value->num;
1676 cbd->mps[mp].files -= value->num2;
1682 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1685 if (mptree[pos].mountpoint == -1)
1686 mptree[pos].mountpoint = mountpoint;
1688 mountpoint = mptree[pos].mountpoint;
1689 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1690 propagate_mountpoints(mptree, i, mountpoint);
1693 #define MPTREE_BLOCK 15
1696 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1699 const char *path, *compstr;
1700 struct mptree *mptree;
1704 struct ducbdata cbd;
1708 Repo *oldinstalled = pool->installed;
1710 memset(&ignoredu, 0, sizeof(ignoredu));
1717 mptree = solv_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1720 mptree[0].sibling = 0;
1721 mptree[0].child = 0;
1723 mptree[0].compl = 0;
1724 mptree[0].mountpoint = -1;
1727 /* create component tree */
1728 for (mp = 0; mp < nmps; mp++)
1733 path = mps[mp].path;
1738 if ((p = strchr(path, '/')) == 0)
1741 compl = strlen(compstr);
1752 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1753 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1757 /* create new node */
1758 mptree = solv_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1760 mptree[i].sibling = mptree[pos].child;
1761 mptree[i].child = 0;
1762 mptree[i].comp = compstr;
1763 mptree[i].compl = compl;
1764 mptree[i].mountpoint = -1;
1765 mptree[pos].child = i;
1769 mptree[pos].mountpoint = mp;
1772 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1775 for (i = 0; i < nmptree; i++)
1777 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1778 printf("#%d child: %d\n", i, mptree[i].child);
1779 printf("#%d comp: %s\n", i, mptree[i].comp);
1780 printf("#%d compl: %d\n", i, mptree[i].compl);
1781 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1785 cbd.mptree = mptree;
1787 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1789 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1791 if (!MAPTST(installedmap, sp))
1794 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1795 if (!cbd.hasdu && oldinstalled)
1798 /* no du data available, ignore data of all installed solvables we obsolete */
1800 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1803 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1804 while ((obs = *obsp++) != 0)
1805 FOR_PROVIDES(op, opp, obs)
1806 if (op >= oldinstalled->start && op < oldinstalled->end)
1807 MAPSET(&ignoredu, op - oldinstalled->start);
1809 FOR_PROVIDES(op, opp, s->name)
1810 if (pool->solvables[op].name == s->name)
1811 if (op >= oldinstalled->start && op < oldinstalled->end)
1812 MAPSET(&ignoredu, op - oldinstalled->start);
1818 /* assumes we allways have du data for installed solvables */
1819 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1821 if (MAPTST(installedmap, sp))
1823 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1825 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1829 map_free(&ignoredu);
1830 solv_free(cbd.dirmap);
1835 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1840 Repo *oldinstalled = pool->installed;
1842 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1844 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1846 if (!MAPTST(installedmap, sp))
1848 change += solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
1852 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1854 if (MAPTST(installedmap, sp))
1856 change -= solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
1864 * 2: conflicts with installed
1865 * 8: interesting (only true if installed)
1869 static inline Id dep2name(Pool *pool, Id dep)
1871 while (ISRELDEP(dep))
1873 Reldep *rd = rd = GETRELDEP(pool, dep);
1879 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con)
1882 Solvable *sn = pool->solvables + n;
1884 FOR_PROVIDES(p, pp, sn->name)
1886 Solvable *s = pool->solvables + p;
1887 if (s->name != sn->name || s->arch != sn->arch)
1889 if ((map[p] & 9) != 9)
1891 if (pool_match_nevr(pool, pool->solvables + p, con))
1893 return 1; /* found installed package that doesn't conflict */
1898 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *multiversionmap)
1902 FOR_PROVIDES(p, pp, dep)
1904 if (p == SYSTEMSOLVABLE)
1905 return 1; /* always boring, as never constraining */
1906 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
1908 if (ispatch && multiversionmap && multiversionmap->size && MAPTST(multiversionmap, p) && ISRELDEP(dep))
1909 if (providedbyinstalled_multiversion(pool, map, p, dep))
1911 if ((map[p] & 9) == 9)
1919 * pool_trivial_installable - calculate if a set of solvables is
1920 * trivial installable without any other installs/deinstalls of
1921 * packages not belonging to the set.
1923 * the state is returned in the result queue:
1924 * 1: solvable is installable without any other package changes
1925 * 0: solvable is not installable
1926 * -1: solvable is installable, but doesn't constrain any installed packages
1930 pool_trivial_installable_multiversionmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *multiversionmap)
1933 Id p, *dp, con, *conp, req, *reqp;
1937 map = solv_calloc(pool->nsolvables, 1);
1938 for (p = 1; p < pool->nsolvables; p++)
1940 if (!MAPTST(installedmap, p))
1943 s = pool->solvables + p;
1946 conp = s->repo->idarraydata + s->conflicts;
1947 while ((con = *conp++) != 0)
1949 dp = pool_whatprovides_ptr(pool, con);
1951 map[p] |= 2; /* XXX: self conflict ? */
1954 for (i = 0; i < pkgs->count; i++)
1955 map[pkgs->elements[i]] = 16;
1957 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1959 if (i == pkgs->count)
1961 p = pkgs->elements[i];
1962 if ((map[p] & 16) == 0)
1964 if ((map[p] & 2) != 0)
1969 s = pool->solvables + p;
1973 reqp = s->repo->idarraydata + s->requires;
1974 while ((req = *reqp++) != 0)
1976 if (req == SOLVABLE_PREREQMARKER)
1978 r = providedbyinstalled(pool, map, req, 0, 0);
1981 /* decided and miss */
1987 break; /* undecided */
1988 m |= r; /* 1 | 9 | 17 */
1997 int ispatch = 0; /* see solver.c patch handling */
1999 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
2001 conp = s->repo->idarraydata + s->conflicts;
2002 while ((con = *conp++) != 0)
2004 if ((providedbyinstalled(pool, map, con, ispatch, multiversionmap) & 1) != 0)
2010 if ((m == 1 || m == 17) && ISRELDEP(con))
2012 con = dep2name(pool, con);
2013 if ((providedbyinstalled(pool, map, con, ispatch, multiversionmap) & 1) != 0)
2018 continue; /* found a conflict */
2021 if (s->repo && s->repo != oldinstalled)
2023 Id p2, obs, *obsp, *pp;
2027 obsp = s->repo->idarraydata + s->obsoletes;
2028 while ((obs = *obsp++) != 0)
2030 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
2039 FOR_PROVIDES(p2, pp, s->name)
2041 s2 = pool->solvables + p2;
2042 if (s2->name == s->name && (map[p2] & 1) != 0)
2059 queue_init_clone(res, pkgs);
2060 for (i = 0; i < pkgs->count; i++)
2062 m = map[pkgs->elements[i]];
2069 res->elements[i] = r;
2075 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
2077 pool_trivial_installable_multiversionmap(pool, installedmap, pkgs, res, 0);
2081 pool_lookup_str(Pool *pool, Id entry, Id keyname)
2083 if (entry == SOLVID_POS && pool->pos.repo)
2084 return repo_lookup_str(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
2087 return solvable_lookup_str(pool->solvables + entry, keyname);
2091 pool_lookup_id(Pool *pool, Id entry, Id keyname)
2093 if (entry == SOLVID_POS && pool->pos.repo)
2094 return repo_lookup_id(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
2097 return solvable_lookup_id(pool->solvables + entry, keyname);
2101 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned long long notfound)
2103 if (entry == SOLVID_POS && pool->pos.repo)
2104 return repo_lookup_num(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, notfound);
2107 return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
2111 pool_lookup_void(Pool *pool, Id entry, Id keyname)
2113 if (entry == SOLVID_POS && pool->pos.repo)
2114 return repo_lookup_void(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
2117 return solvable_lookup_void(pool->solvables + entry, keyname);
2120 const unsigned char *
2121 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
2123 if (entry == SOLVID_POS && pool->pos.repo)
2124 return repo_lookup_bin_checksum(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, typep);
2127 return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
2131 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
2133 if (entry == SOLVID_POS && pool->pos.repo)
2134 return repo_lookup_checksum(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, typep);
2137 return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
2141 pool_lookup_deltalocation(Pool *pool, Id entry, unsigned int *medianrp)
2146 if (entry != SOLVID_POS)
2148 loc = pool_lookup_str(pool, entry, DELTA_LOCATION_DIR);
2149 loc = pool_tmpjoin(pool, loc, loc ? "/" : 0, pool_lookup_str(pool, entry, DELTA_LOCATION_NAME));
2150 loc = pool_tmpappend(pool, loc, "-", pool_lookup_str(pool, entry, DELTA_LOCATION_EVR));
2151 loc = pool_tmpappend(pool, loc, ".", pool_lookup_str(pool, entry, DELTA_LOCATION_SUFFIX));
2156 add_new_provider(Pool *pool, Id id, Id p)
2161 while (ISRELDEP(id))
2163 Reldep *rd = GETRELDEP(pool, id);
2168 for (pp = pool->whatprovidesdata + pool->whatprovides[id]; *pp; pp++)
2180 queue_push(&q, *pp);
2184 pool->whatprovides[id] = pool_queuetowhatprovides(pool, &q);
2189 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
2191 int hadhashes = pool->relhashtbl ? 1 : 0;
2197 if (!conflicts->count)
2199 for (i = 0; i < conflicts->count; i += 6)
2201 fn = conflicts->elements[i];
2202 p = conflicts->elements[i + 1];
2203 md5 = conflicts->elements[i + 2];
2204 q = conflicts->elements[i + 4];
2205 id = pool_rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
2206 s = pool->solvables + p;
2209 s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
2210 if (pool->whatprovides)
2211 add_new_provider(pool, fn, p);
2212 if (pool->whatprovides_rel)
2213 pool->whatprovides_rel[GETRELID(id)] = 0; /* clear cache */
2214 s = pool->solvables + q;
2217 s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
2220 pool_freeidhashes(pool);
2224 pool_prepend_rootdir(Pool *pool, const char *path)
2229 return solv_strdup(path);
2230 return solv_dupjoin(pool->rootdir, "/", *path == '/' ? path + 1 : path);
2234 pool_prepend_rootdir_tmp(Pool *pool, const char *path)
2240 return pool_tmpjoin(pool, pool->rootdir, "/", *path == '/' ? path + 1 : path);
2244 pool_set_rootdir(Pool *pool, const char *rootdir)
2246 solv_free(pool->rootdir);
2247 pool->rootdir = solv_strdup(rootdir);
2251 pool_get_rootdir(Pool *pool)
2253 return pool->rootdir;
2256 /* only used in libzypp */
2258 pool_set_custom_vendorcheck(Pool *pool, int (*vendorcheck)(Pool *, Solvable *, Solvable *))
2260 pool->custom_vendorcheck = vendorcheck;