2 * Copyright (c) 2007-2009, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * SAT based dependency solver
21 #include "solver_private.h"
28 #include "solverdebug.h"
30 #define RULES_BLOCK 63
32 static void addrpmruleinfo(Solver *solv, Id p, Id d, int type, Id dep);
33 static void solver_createcleandepsmap(Solver *solv, Map *cleandepsmap, int unneeded);
35 /*-------------------------------------------------------------------
36 * Check if dependency is possible
38 * mirrors solver_dep_fulfilled but uses map m instead of the decisionmap.
39 * used in solver_addrpmrulesforweak and solver_createcleandepsmap.
43 dep_possible(Solver *solv, Id dep, Map *m)
45 Pool *pool = solv->pool;
50 Reldep *rd = GETRELDEP(pool, dep);
53 if (rd->flags == REL_AND)
55 if (!dep_possible(solv, rd->name, m))
57 return dep_possible(solv, rd->evr, m);
59 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
60 return solver_splitprovides(solv, rd->evr);
61 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
62 return solver_dep_installed(solv, rd->evr);
65 FOR_PROVIDES(p, pp, dep)
73 /********************************************************************
77 * - unify rules, remove duplicates
80 /*-------------------------------------------------------------------
82 * compare rules for unification sort
87 unifyrules_sortcmp(const void *ap, const void *bp, void *dp)
97 return x; /* p differs */
100 if (a->d == 0 && b->d == 0)
101 return a->w2 - b->w2; /* assertion: return w2 diff */
103 if (a->d == 0) /* a is assertion, b not */
105 x = a->w2 - pool->whatprovidesdata[b->d];
109 if (b->d == 0) /* b is assertion, a not */
111 x = pool->whatprovidesdata[a->d] - b->w2;
115 /* compare whatprovidesdata */
116 ad = pool->whatprovidesdata + a->d;
117 bd = pool->whatprovidesdata + b->d;
119 if ((x = *ad++ - *bd++) != 0)
125 solver_rulecmp(Solver *solv, Rule *r1, Rule *r2)
127 return unifyrules_sortcmp(r1, r2, solv->pool);
131 /*-------------------------------------------------------------------
134 * go over all rules and remove duplicates
138 solver_unifyrules(Solver *solv)
140 Pool *pool = solv->pool;
144 if (solv->nrules <= 2) /* nothing to unify */
147 /* sort rules first */
148 solv_sort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp, solv->pool);
155 for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
157 if (jr && !unifyrules_sortcmp(ir, jr, pool))
158 continue; /* prune! */
159 jr = solv->rules + j++; /* keep! */
164 /* reduced count from nrules to j rules */
165 POOL_DEBUG(SOLV_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
167 /* adapt rule buffer */
169 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
172 * debug: log rule statistics
174 IF_POOLDEBUG (SOLV_DEBUG_STATS)
181 for (i = 1; i < solv->nrules; i++)
188 dp = solv->pool->whatprovidesdata + r->d;
193 POOL_DEBUG(SOLV_DEBUG_STATS, " binary: %d\n", binr);
194 POOL_DEBUG(SOLV_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
205 hashrule(Solver *solv, Id p, Id d, int n)
207 unsigned int x = (unsigned int)p;
211 return (x * 37) ^ (unsigned int)d;
212 dp = solv->pool->whatprovidesdata + d;
214 x = (x * 37) ^ (unsigned int)*dp++;
220 /*-------------------------------------------------------------------
226 * p = direct literal; always < 0 for installed rpm rules
227 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
230 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
232 * p < 0 : pkg id of A
233 * d > 0 : Offset in whatprovidesdata (list of providers of b)
235 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
236 * p < 0 : pkg id of A
237 * d < 0 : Id of solvable (e.g. B1)
239 * d == 0: unary rule, assertion => (A) or (-A)
241 * Install: p > 0, d = 0 (A) user requested install
242 * Remove: p < 0, d = 0 (-A) user requested remove (also: uninstallable)
243 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
244 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
245 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
246 * also used for obsoletes
247 * ?: p > 0, d < 0 (A|-B)
248 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
252 * Direct assertion (no watch needed) --> d = 0, w1 = p, w2 = 0
253 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
254 * every other : w1 = p, w2 = whatprovidesdata[d];
255 * Disabled rule: w1 = 0
257 * always returns a rule for non-rpm rules
261 solver_addrule(Solver *solv, Id p, Id d)
263 Pool *pool = solv->pool;
267 int n = 0; /* number of literals in rule - 1
268 0 = direct assertion (single literal)
273 /* it often happenes that requires lead to adding the same rpm rule
274 * multiple times, so we prune those duplicates right away to make
275 * the work for unifyrules a bit easier */
277 if (!solv->rpmrules_end) /* we add rpm rules */
279 r = solv->rules + solv->nrules - 1; /* get the last added rule */
280 if (r->p == p && r->d == d && (d != 0 || !r->w2))
285 * compute number of literals (n) in rule
290 /* always a binary rule */
292 return 0; /* ignore self conflict */
297 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
299 return 0; /* rule is self-fulfilling */
301 if (n == 1) /* convert to binary rule */
305 if (n == 1 && p > d && !solv->rpmrules_end)
307 /* smallest literal first so we can find dups */
308 n = p; p = d; d = n; /* p <-> d */
309 n = 1; /* re-set n, was used as temp var */
313 * check for duplicate
316 /* check if the last added rule (r) is exactly the same as what we're looking for. */
317 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
318 return r; /* binary rule */
320 /* have n-ary rule with same first literal, check other literals */
321 if (r && n > 1 && r->d && r->p == p)
323 /* Rule where d is an offset in whatprovidesdata */
327 dp2 = pool->whatprovidesdata + r->d;
328 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
339 /* extend rule buffer */
340 solv->rules = solv_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
341 r = solv->rules + solv->nrules++; /* point to rule space */
350 /* direct assertion, no watch needed */
366 r->w2 = pool->whatprovidesdata[d];
371 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
373 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, " Add rule: ");
374 solver_printrule(solv, SOLV_DEBUG_RULE_CREATION, r);
381 solver_shrinkrules(Solver *solv, int nrules)
383 solv->nrules = nrules;
384 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
387 /******************************************************************************
389 *** rpm rule part: create rules representing the package dependencies
394 * special multiversion patch conflict handling:
395 * a patch conflict is also satisfied if some other
396 * version with the same name/arch that doesn't conflict
397 * gets installed. The generated rule is thus:
398 * -patch|-cpack|opack1|opack2|...
401 makemultiversionconflict(Solver *solv, Id n, Id con)
403 Pool *pool = solv->pool;
408 sn = pool->solvables + n;
409 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
411 FOR_PROVIDES(p, pp, sn->name)
413 s = pool->solvables + p;
414 if (s->name != sn->name || s->arch != sn->arch)
416 if (!MAPTST(&solv->multiversion, p))
418 if (pool_match_nevr(pool, pool->solvables + p, con))
420 /* here we have a multiversion solvable that doesn't conflict */
421 /* thus we're not in conflict if it is installed */
425 return -n; /* no other package found, generate normal conflict */
426 return pool_queuetowhatprovides(pool, &q);
430 addrpmrule(Solver *solv, Id p, Id d, int type, Id dep)
432 if (!solv->ruleinfoq)
433 solver_addrule(solv, p, d);
435 addrpmruleinfo(solv, p, d, type, dep);
438 #ifdef ENABLE_LINKED_PKGS
441 addlinks(Solver *solv, Solvable *s, Id req, Queue *qr, Id prv, Queue *qp, Map *m, Queue *workq)
443 Pool *pool = solv->pool;
448 if (m && !MAPTST(m, s - pool->solvables))
450 /* called from solver_addrpmrulesforlinked */
451 for (i = 0; i < qr->count; i++)
452 if (MAPTST(m, qr->elements[i]))
456 queue_push(workq, s - pool->solvables);
461 /* just push required packages on the work queue */
462 for (i = 0; i < qr->count; i++)
463 queue_push(workq, qr->elements[i]);
467 printf("ADDLINKS %s\n -> %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, req));
468 for (i = 0; i < qr->count; i++)
469 printf(" - %s\n", pool_solvid2str(pool, qr->elements[i]));
470 printf(" <- %s\n", pool_dep2str(pool, prv));
471 for (i = 0; i < qp->count; i++)
472 printf(" - %s\n", pool_solvid2str(pool, qp->elements[i]));
476 addrpmrule(solv, qr->elements[0], -(s - pool->solvables), SOLVER_RULE_RPM_PACKAGE_REQUIRES, req);
478 addrpmrule(solv, -(s - pool->solvables), pool_queuetowhatprovides(pool, qr), SOLVER_RULE_RPM_PACKAGE_REQUIRES, req);
481 Id d = pool_queuetowhatprovides(pool, qp);
482 for (i = 0; i < qr->count; i++)
483 addrpmrule(solv, -qr->elements[i], d, SOLVER_RULE_RPM_PACKAGE_REQUIRES, prv);
487 for (i = 0; i < qr->count; i++)
488 addrpmrule(solv, qp->elements[0], -qr->elements[i], SOLVER_RULE_RPM_PACKAGE_REQUIRES, prv);
492 for (i = 0; i < qr->count; i++)
493 if (m && !MAPTST(m, qr->elements[i]))
494 queue_push(workq, qr->elements[i]);
495 for (i = 0; i < qp->count; i++)
496 if (m && !MAPTST(m, qp->elements[i]))
497 queue_push(workq, qp->elements[i]);
498 if (solv->installed && s->repo == solv->installed)
500 Repo *installed = solv->installed;
501 /* record installed buddies */
502 if (!solv->instbuddy)
503 solv->instbuddy = solv_calloc(installed->end - installed->start, sizeof(Id));
505 solv->instbuddy[s - pool->solvables - installed->start] = qr->elements[0];
506 for (i = 0; i < qp->count; i++)
508 Id p = qp->elements[i];
509 if (pool->solvables[p].repo != installed)
511 if (qp->count > 1 || (solv->instbuddy[p - installed->start] != 0 && solv->instbuddy[p - installed->start] != s - pool->solvables))
512 solv->instbuddy[p - installed->start] = 1; /* 1: ambiguous buddy */
514 solv->instbuddy[p - installed->start] = s - pool->solvables;
520 add_application_link(Solver *solv, Solvable *s, Map *m, Queue *workq)
522 Pool *pool = solv->pool;
528 /* find appdata requires */
531 Id *reqp = s->repo->idarraydata + s->requires;
532 while ((req = *reqp++) != 0) /* go through all requires */
536 if (!strncmp("appdata(", pool_id2str(pool, req), 8))
542 /* find application-appdata provides */
545 Id *prvp = s->repo->idarraydata + s->provides;
546 while ((prv = *prvp++) != 0) /* go through all provides */
550 if (strncmp("application-appdata(", pool_id2str(pool, prv), 20))
552 if (!strcmp(pool_id2str(pool, prv) + 12, pool_id2str(pool, req)))
561 FOR_PROVIDES(p, pp, req)
562 if (pool->solvables[p].repo == s->repo)
564 FOR_PROVIDES(p, pp, prv)
565 if (pool->solvables[p].repo == s->repo)
567 addlinks(solv, s, req, &qr, prv, &qp, m, workq);
573 add_product_link(Solver *solv, Solvable *s, Map *m, Queue *workq)
575 Pool *pool = solv->pool;
576 Id n = s - pool->solvables;
581 if (pool->nscallback)
583 Id buddy = pool->nscallback(pool, pool->nscallbackdata, NAMESPACE_PRODUCTBUDDY, n);
584 if (buddy > 0 && buddy != SYSTEMSOLVABLE && buddy != n && buddy < pool->nsolvables)
588 queue_push(&qr, buddy);
590 addlinks(solv, s, solvable_selfprovidedep(pool->solvables + buddy), &qr, solvable_selfprovidedep(s), &qp, m, workq);
593 if (m && !MAPTST(m, buddy))
594 queue_push(workq, buddy);
598 /* search for project requires */
602 Id req, *reqp = s->repo->idarraydata + s->requires;
603 const char *nn = pool_id2str(pool, s->name);
604 int nnl = strlen(nn);
605 while ((req = *reqp++) != 0) /* go through all requires */
609 Reldep *rd = GETRELDEP(pool, req);
610 if (rd->flags != REL_EQ || rd->evr != s->evr)
612 rn = pool_id2str(pool, rd->name);
613 if (!strncmp(rn, "product(", 8) && !strncmp(rn + 8, nn + 8, nnl - 8) && !strcmp( rn + nnl, ")"))
622 /* too bad. construct from scratch */
623 str = pool_tmpjoin(pool, pool_id2str(pool, s->name), ")", 0);
625 namerelid = pool_rel2id(pool, pool_str2id(pool, str, 1), s->evr, REL_EQ, 1);
629 FOR_PROVIDES(p, pp, namerelid)
631 Solvable *ps = pool->solvables + p;
632 if (ps->repo != s->repo || ps->arch != s->arch)
636 if (!qr.count && s->repo == solv->installed)
638 /* oh no! Look up reference file */
640 const char *refbasename = solvable_lookup_str(s, PRODUCT_REFERENCEFILE);
641 dataiterator_init(&di, pool, s->repo, 0, SOLVABLE_FILELIST, refbasename, SEARCH_STRING);
642 while (dataiterator_step(&di))
643 queue_push(&qr, di.solvid);
644 dataiterator_free(&di);
645 dataiterator_init(&di, pool, s->repo, 0, PRODUCT_REFERENCEFILE, refbasename, SEARCH_STRING);
646 while (dataiterator_step(&di))
647 queue_push(&qp, di.solvid);
648 dataiterator_free(&di);
653 FOR_PROVIDES(p, pp, s->name)
655 Solvable *ps = pool->solvables + p;
656 if (s->name != ps->name || ps->repo != s->repo || ps->arch != s->arch || s->evr != ps->evr)
661 addlinks(solv, s, namerelid, &qr, solvable_selfprovidedep(s), &qp, m, workq);
667 add_autopattern_link(Solver *solv, Solvable *s, Map *m, Queue *workq)
669 Pool *pool = solv->pool;
670 Id p, pp, *pr, apevr = 0, aprel = 0;
673 /* check if autopattern */
676 for (pr = s->repo->idarraydata + s->provides; (p = *pr++) != 0; )
679 Reldep *rd = GETRELDEP(pool, p);
680 if (rd->flags == REL_EQ && !strcmp(pool_id2str(pool, rd->name), "autopattern()"))
691 FOR_PROVIDES(p, pp, apevr)
693 Solvable *s2 = pool->solvables + p;
694 if (s2->repo == s->repo && s2->name == apevr && s2->evr == s->evr && s2->vendor == s->vendor)
697 FOR_PROVIDES(p, pp, aprel)
699 Solvable *s2 = pool->solvables + p;
700 if (s2->repo == s->repo && s2->evr == s->evr && s2->vendor == s->vendor)
703 addlinks(solv, s, apevr, &qr, aprel, &qp, m, workq);
709 add_package_link(Solver *solv, Solvable *s, Map *m, Queue *workq)
711 const char *name = pool_id2str(solv->pool, s->name);
712 if (name[0] == 'a' && !strncmp("application:", name, 12))
713 add_application_link(solv, s, m, workq);
714 if (name[0] == 'p' && !strncmp("pattern:", name, 7))
715 add_autopattern_link(solv, s, m, workq);
716 if (name[0] == 'p' && !strncmp("product:", name, 8))
717 add_product_link(solv, s, m, workq);
722 /*-------------------------------------------------------------------
724 * add (install) rules for solvable
726 * s: Solvable for which to add rules
727 * m: m[s] = 1 for solvables which have rules, prevent rule duplication
729 * Algorithm: 'visit all nodes of a graph'. The graph nodes are
730 * solvables, the edges their dependencies.
731 * Starting from an installed solvable, this will create all rules
732 * representing the graph created by the solvables dependencies.
734 * for unfulfilled requirements, conflicts, obsoletes,....
735 * add a negative assertion for solvables that are not installable
737 * It will also create rules for all solvables referenced by 's'
738 * i.e. descend to all providers of requirements of 's'
743 solver_addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
745 Pool *pool = solv->pool;
746 Repo *installed = solv->installed;
748 /* 'work' queue. keeps Ids of solvables we still have to work on.
749 And buffer for it. */
754 /* if to add rules for broken deps ('rpm -V' functionality)
758 /* Id var and pointer for each dependency
759 * (not used in parallel)
766 Id p, pp; /* whatprovides loops */
767 Id *dp; /* ptr to 'whatprovides' */
768 Id n; /* Id for current solvable 's' */
770 queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
771 queue_push(&workq, s - pool->solvables); /* push solvable Id to work queue */
773 /* loop until there's no more work left */
778 * s: Pointer to solvable
781 n = queue_shift(&workq); /* 'pop' next solvable to work on from queue */
784 if (MAPTST(m, n)) /* continue if already visited */
786 MAPSET(m, n); /* mark as visited */
789 s = pool->solvables + n; /* s = Solvable in question */
792 if (installed /* Installed system available */
793 && s->repo == installed /* solvable is installed */
794 && !solv->fixmap_all /* NOT repair errors in rpm dependency graph */
795 && !(solv->fixmap.size && MAPTST(&solv->fixmap, n - installed->start)))
797 dontfix = 1; /* dont care about broken rpm deps */
802 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC
803 ? pool_disabled_solvable(pool, s)
804 : !pool_installable(pool, s))
806 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", pool_solvable2str(pool, s), (Id)(s - pool->solvables));
807 addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOT_INSTALLABLE, 0);
811 #ifdef ENABLE_LINKED_PKGS
812 /* add pseudo-package <-> real-package links */
813 add_package_link(solv, s, m, &workq);
816 /*-----------------------------------------
817 * check requires of s
822 reqp = s->repo->idarraydata + s->requires;
823 while ((req = *reqp++) != 0) /* go through all requires */
825 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
828 /* find list of solvables providing 'req' */
829 dp = pool_whatprovides_ptr(pool, req);
831 if (*dp == SYSTEMSOLVABLE) /* always installed */
836 /* the strategy here is to not insist on dependencies
837 * that are already broken. so if we find one provider
838 * that was already installed, we know that the
839 * dependency was not broken before so we enforce it */
841 /* check if any of the providers for 'req' is installed */
842 for (i = 0; (p = dp[i]) != 0; i++)
844 if (pool->solvables[p].repo == installed)
845 break; /* provider was installed */
847 /* didn't find an installed provider: previously broken dependency */
850 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", pool_dep2str(pool, req), pool_solvable2str(pool, s));
857 /* nothing provides req! */
858 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", pool_solvable2str(pool, s), (Id)(s - pool->solvables), pool_dep2str(pool, req));
859 addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP, req);
863 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
865 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION," %s requires %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, req));
866 for (i = 0; dp[i]; i++)
867 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, " provided by %s\n", pool_solvid2str(pool, dp[i]));
870 /* add 'requires' dependency */
871 /* rule: (-requestor|provider1|provider2|...|providerN) */
872 addrpmrule(solv, -n, dp - pool->whatprovidesdata, SOLVER_RULE_RPM_PACKAGE_REQUIRES, req);
874 /* descend the dependency tree
875 push all non-visited providers on the work queue */
881 queue_push(&workq, *dp);
885 } /* while, requirements of n */
887 } /* if, requirements */
889 /* that's all we check for src packages */
890 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
893 /*-----------------------------------------
894 * check conflicts of s
901 /* we treat conflicts in patches a bit differen:
903 * - multiversion handling
904 * XXX: we should really handle this different, looking
905 * at the name is a bad hack
907 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
909 conp = s->repo->idarraydata + s->conflicts;
910 /* foreach conflicts of 's' */
911 while ((con = *conp++) != 0)
913 /* foreach providers of a conflict of 's' */
914 FOR_PROVIDES(p, pp, con)
916 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, con))
918 /* dontfix: dont care about conflicts with already installed packs */
919 if (dontfix && pool->solvables[p].repo == installed)
921 /* p == n: self conflict */
922 if (p == n && pool->forbidselfconflicts)
926 Reldep *rd = GETRELDEP(pool, con);
927 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
930 p = 0; /* make it a negative assertion, aka 'uninstallable' */
932 if (p && ispatch && solv->multiversion.size && MAPTST(&solv->multiversion, p) && ISRELDEP(con))
934 /* our patch conflicts with a multiversion package */
935 p = -makemultiversionconflict(solv, p, con);
937 /* rule: -n|-p: either solvable _or_ provider of conflict */
938 addrpmrule(solv, -n, -p, p ? SOLVER_RULE_RPM_PACKAGE_CONFLICT : SOLVER_RULE_RPM_SELF_CONFLICT, con);
943 /*-----------------------------------------
944 * check obsoletes and implicit obsoletes of a package
945 * if ignoreinstalledsobsoletes is not set, we're also checking
946 * obsoletes of installed packages (like newer rpm versions)
948 if ((!installed || s->repo != installed) || !pool->noinstalledobsoletes)
950 int multi = solv->multiversion.size && MAPTST(&solv->multiversion, n);
951 int isinstalled = (installed && s->repo == installed);
952 if (s->obsoletes && (!multi || solv->keepexplicitobsoletes))
954 obsp = s->repo->idarraydata + s->obsoletes;
955 /* foreach obsoletes */
956 while ((obs = *obsp++) != 0)
958 /* foreach provider of an obsoletes of 's' */
959 FOR_PROVIDES(p, pp, obs)
961 Solvable *ps = pool->solvables + p;
964 if (isinstalled && dontfix && ps->repo == installed)
965 continue; /* don't repair installed/installed problems */
966 if (!pool->obsoleteusesprovides /* obsoletes are matched names, not provides */
967 && !pool_match_nevr(pool, ps, obs))
969 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
972 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_PACKAGE_OBSOLETES, obs);
974 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES, obs);
978 /* check implicit obsoletes
979 * for installed packages we only need to check installed/installed problems (and
980 * only when dontfix is not set), as the others are picked up when looking at the
981 * uninstalled package.
983 if (!isinstalled || !dontfix)
985 FOR_PROVIDES(p, pp, s->name)
987 Solvable *ps = pool->solvables + p;
990 if (isinstalled && ps->repo != installed)
992 /* we still obsolete packages with same nevra, like rpm does */
993 /* (actually, rpm mixes those packages. yuck...) */
994 if (multi && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
996 if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
998 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, ps))
1000 if (s->name == ps->name)
1001 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_SAME_NAME, 0);
1003 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_IMPLICIT_OBSOLETES, s->name);
1008 /*-----------------------------------------
1009 * add recommends to the work queue
1011 if (s->recommends && m)
1013 recp = s->repo->idarraydata + s->recommends;
1014 while ((rec = *recp++) != 0)
1016 FOR_PROVIDES(p, pp, rec)
1018 queue_push(&workq, p);
1021 if (s->suggests && m)
1023 sugp = s->repo->idarraydata + s->suggests;
1024 while ((sug = *sugp++) != 0)
1026 FOR_PROVIDES(p, pp, sug)
1028 queue_push(&workq, p);
1035 #ifdef ENABLE_LINKED_PKGS
1037 solver_addrpmrulesforlinked(Solver *solv, Map *m)
1039 Pool *pool = solv->pool;
1046 for (i = 1; i < pool->nsolvables; i++)
1050 s = pool->solvables + i;
1051 if (!s->repo || s->repo == solv->installed)
1053 name = pool_id2str(pool, s->name);
1054 if (!strchr(name, ':'))
1056 if (!pool_installable(pool, s))
1058 add_package_link(solv, s, m, &workq);
1062 for (j = 0; j < workq.count; j++)
1063 solver_addrpmrulesforsolvable(solv, pool->solvables + workq.elements[j], m);
1064 queue_empty(&workq);
1071 /*-------------------------------------------------------------------
1073 * Add rules for packages possibly selected in by weak dependencies
1075 * m: already added solvables
1079 solver_addrpmrulesforweak(Solver *solv, Map *m)
1081 Pool *pool = solv->pool;
1086 /* foreach solvable in pool */
1087 for (i = n = 1; n < pool->nsolvables; i++, n++)
1089 if (i == pool->nsolvables) /* wrap i */
1091 if (MAPTST(m, i)) /* already added that one */
1094 s = pool->solvables + i;
1097 if (s->repo != pool->installed && !pool_installable(pool, s))
1098 continue; /* only look at installable ones */
1103 /* find possible supplements */
1104 supp = s->repo->idarraydata + s->supplements;
1105 while ((sup = *supp++) != 0)
1106 if (dep_possible(solv, sup, m))
1110 /* if nothing found, check for enhances */
1111 if (!sup && s->enhances)
1113 supp = s->repo->idarraydata + s->enhances;
1114 while ((sup = *supp++) != 0)
1115 if (dep_possible(solv, sup, m))
1118 /* if nothing found, goto next solvables */
1121 solver_addrpmrulesforsolvable(solv, s, m);
1122 n = 0; /* check all solvables again because we added solvables to m */
1127 /*-------------------------------------------------------------------
1129 * add package rules for possible updates
1132 * m: map of already visited solvables
1133 * allow_all: 0 = dont allow downgrades, 1 = allow all candidates
1137 solver_addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
1139 Pool *pool = solv->pool;
1141 /* queue and buffer for it */
1145 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1146 /* find update candidates for 's' */
1147 policy_findupdatepackages(solv, s, &qs, allow_all);
1148 /* add rule for 's' if not already done */
1149 if (!MAPTST(m, s - pool->solvables))
1150 solver_addrpmrulesforsolvable(solv, s, m);
1151 /* foreach update candidate, add rule if not already done */
1152 for (i = 0; i < qs.count; i++)
1153 if (!MAPTST(m, qs.elements[i]))
1154 solver_addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1159 /***********************************************************************
1161 *** Update/Feature rule part
1163 *** Those rules make sure an installed package isn't silently deleted
1168 finddistupgradepackages(Solver *solv, Solvable *s, Queue *qs, int allow_all)
1170 Pool *pool = solv->pool;
1173 policy_findupdatepackages(solv, s, qs, allow_all ? allow_all : 2);
1177 return 0; /* orphaned, don't create feature rule */
1178 /* check if this is an orphaned package */
1179 policy_findupdatepackages(solv, s, qs, 1);
1181 return 0; /* orphaned, don't create update rule */
1183 return -SYSTEMSOLVABLE; /* supported but not installable */
1186 return s - pool->solvables;
1187 /* check if it is ok to keep the installed package */
1188 for (i = 0; i < qs->count; i++)
1190 Solvable *ns = pool->solvables + qs->elements[i];
1191 if (s->evr == ns->evr && solvable_identical(s, ns))
1192 return s - pool->solvables;
1194 /* nope, it must be some other package */
1195 return -SYSTEMSOLVABLE;
1198 /* add packages from the dup repositories to the update candidates
1199 * this isn't needed for the global dup mode as all packages are
1200 * from dup repos in that case */
1202 addduppackages(Solver *solv, Solvable *s, Queue *qs)
1207 int oldnoupdateprovide = solv->noupdateprovide;
1209 queue_init_buffer(&dupqs, dupqsbuf, sizeof(dupqsbuf)/sizeof(*dupqsbuf));
1210 solv->noupdateprovide = 1;
1211 policy_findupdatepackages(solv, s, &dupqs, 2);
1212 solv->noupdateprovide = oldnoupdateprovide;
1213 for (i = 0; i < dupqs.count; i++)
1215 p = dupqs.elements[i];
1216 if (MAPTST(&solv->dupmap, p))
1217 queue_pushunique(qs, p);
1222 /*-------------------------------------------------------------------
1224 * add rule for update
1225 * (A|A1|A2|A3...) An = update candidates for A
1227 * s = (installed) solvable
1231 solver_addupdaterule(Solver *solv, Solvable *s, int allow_all)
1233 /* installed packages get a special upgrade allowed rule */
1234 Pool *pool = solv->pool;
1239 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1240 p = s - pool->solvables;
1241 /* find update candidates for 's' */
1242 if (solv->dupmap_all)
1243 p = finddistupgradepackages(solv, s, &qs, allow_all);
1245 policy_findupdatepackages(solv, s, &qs, allow_all);
1246 if (!allow_all && !solv->dupmap_all && solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
1247 addduppackages(solv, s, &qs);
1249 if (!allow_all && qs.count && solv->multiversion.size)
1253 d = pool_queuetowhatprovides(pool, &qs);
1254 /* filter out all multiversion packages as they don't update */
1255 for (i = j = 0; i < qs.count; i++)
1257 if (MAPTST(&solv->multiversion, qs.elements[i]))
1259 Solvable *ps = pool->solvables + qs.elements[i];
1260 /* if keepexplicitobsoletes is set and the name is different,
1261 * we assume that there is an obsoletes. XXX: not 100% correct */
1262 if (solv->keepexplicitobsoletes && ps->name != s->name)
1264 qs.elements[j++] = qs.elements[i];
1267 /* it's ok if they have same nevra */
1268 if (ps->name != s->name || ps->evr != s->evr || ps->arch != s->arch)
1271 qs.elements[j++] = qs.elements[i];
1275 if (d && solv->installed && s->repo == solv->installed &&
1276 (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, s - pool->solvables - solv->installed->start))))
1278 if (!solv->multiversionupdaters)
1279 solv->multiversionupdaters = solv_calloc(solv->installed->end - solv->installed->start, sizeof(Id));
1280 solv->multiversionupdaters[s - pool->solvables - solv->installed->start] = d;
1282 if (j == 0 && p == -SYSTEMSOLVABLE && solv->dupmap_all)
1284 queue_push(&solv->orphaned, s - pool->solvables); /* treat as orphaned */
1289 else if (p != -SYSTEMSOLVABLE)
1291 /* could fallthrough, but then we would do pool_queuetowhatprovides twice */
1293 solver_addrule(solv, p, d); /* allow update of s */
1297 if (qs.count && p == -SYSTEMSOLVABLE)
1298 p = queue_shift(&qs);
1299 d = qs.count ? pool_queuetowhatprovides(pool, &qs) : 0;
1301 solver_addrule(solv, p, d); /* allow update of s */
1305 disableupdaterule(Solver *solv, Id p)
1309 MAPSET(&solv->noupdate, p - solv->installed->start);
1310 r = solv->rules + solv->updaterules + (p - solv->installed->start);
1311 if (r->p && r->d >= 0)
1312 solver_disablerule(solv, r);
1313 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1314 if (r->p && r->d >= 0)
1315 solver_disablerule(solv, r);
1316 if (solv->bestrules_pkg)
1319 ni = solv->bestrules_end - solv->bestrules;
1320 for (i = 0; i < ni; i++)
1321 if (solv->bestrules_pkg[i] == p)
1322 solver_disablerule(solv, solv->rules + solv->bestrules + i);
1327 reenableupdaterule(Solver *solv, Id p)
1329 Pool *pool = solv->pool;
1332 MAPCLR(&solv->noupdate, p - solv->installed->start);
1333 r = solv->rules + solv->updaterules + (p - solv->installed->start);
1338 solver_enablerule(solv, r);
1339 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1341 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1342 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1348 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1349 if (r->p && r->d < 0)
1351 solver_enablerule(solv, r);
1352 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1354 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1355 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1359 if (solv->bestrules_pkg)
1362 ni = solv->bestrules_end - solv->bestrules;
1363 for (i = 0; i < ni; i++)
1364 if (solv->bestrules_pkg[i] == p)
1365 solver_enablerule(solv, solv->rules + solv->bestrules + i);
1370 /***********************************************************************
1372 *** Infarch rule part
1374 *** Infarch rules make sure the solver uses the best architecture of
1375 *** a package if multiple archetectures are available
1380 solver_addinfarchrules(Solver *solv, Map *addedmap)
1382 Pool *pool = solv->pool;
1384 Id p, pp, a, aa, bestarch;
1385 Solvable *s, *ps, *bests;
1386 Queue badq, allowedarchs;
1389 queue_init(&allowedarchs);
1390 solv->infarchrules = solv->nrules;
1391 for (i = 1; i < pool->nsolvables; i++)
1393 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1395 s = pool->solvables + i;
1399 queue_empty(&allowedarchs);
1400 FOR_PROVIDES(p, pp, s->name)
1402 ps = pool->solvables + p;
1403 if (ps->name != s->name || !MAPTST(addedmap, p))
1410 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1411 if (a != 1 && pool->installed && ps->repo == pool->installed)
1413 if (!solv->dupmap_all && !(solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
1414 queue_pushunique(&allowedarchs, ps->arch); /* also ok to keep this architecture */
1415 continue; /* ignore installed solvables when calculating the best arch */
1417 if (a && a != 1 && (!bestarch || a < bestarch))
1425 /* speed up common case where installed package already has best arch */
1426 if (allowedarchs.count == 1 && bests && allowedarchs.elements[0] == bests->arch)
1427 allowedarchs.count--; /* installed arch is best */
1429 FOR_PROVIDES(p, pp, s->name)
1431 ps = pool->solvables + p;
1432 if (ps->name != s->name || !MAPTST(addedmap, p))
1435 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1436 if (a != 1 && bestarch && ((a ^ bestarch) & 0xffff0000) != 0)
1438 if (pool->installed && ps->repo == pool->installed)
1439 continue; /* always ok to keep an installed package */
1440 for (j = 0; j < allowedarchs.count; j++)
1442 aa = allowedarchs.elements[j];
1445 aa = (aa <= pool->lastarch) ? pool->id2arch[aa] : 0;
1446 if (aa && ((a ^ aa) & 0xffff0000) == 0)
1447 break; /* compatible */
1449 if (j == allowedarchs.count)
1450 queue_push(&badq, p);
1455 /* block all solvables in the badq! */
1456 for (j = 0; j < badq.count; j++)
1458 p = badq.elements[j];
1459 solver_addrule(solv, -p, 0);
1463 queue_free(&allowedarchs);
1464 solv->infarchrules_end = solv->nrules;
1468 disableinfarchrule(Solver *solv, Id name)
1470 Pool *pool = solv->pool;
1473 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1475 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1476 solver_disablerule(solv, r);
1481 reenableinfarchrule(Solver *solv, Id name)
1483 Pool *pool = solv->pool;
1486 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1488 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1490 solver_enablerule(solv, r);
1491 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1493 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1494 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1501 /***********************************************************************
1505 *** Dup rules make sure a package is selected from the specified dup
1506 *** repositories if an update candidate is included in one of them.
1511 add_cleandeps_package(Solver *solv, Id p)
1513 if (!solv->cleandeps_updatepkgs)
1515 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
1516 queue_init(solv->cleandeps_updatepkgs);
1518 queue_pushunique(solv->cleandeps_updatepkgs, p);
1522 solver_addtodupmaps(Solver *solv, Id p, Id how, int targeted)
1524 Pool *pool = solv->pool;
1525 Solvable *ps, *s = pool->solvables + p;
1526 Repo *installed = solv->installed;
1527 Id pi, pip, obs, *obsp;
1529 MAPSET(&solv->dupinvolvedmap, p);
1531 MAPSET(&solv->dupmap, p);
1532 FOR_PROVIDES(pi, pip, s->name)
1534 ps = pool->solvables + pi;
1535 if (ps->name != s->name)
1537 MAPSET(&solv->dupinvolvedmap, pi);
1538 if (targeted && ps->repo == installed && solv->obsoletes && solv->obsoletes[pi - installed->start])
1541 for (opp = solv->obsoletes_data + solv->obsoletes[pi - installed->start]; (pi2 = *opp++) != 0;)
1542 if (pool->solvables[pi2].repo != installed)
1543 MAPSET(&solv->dupinvolvedmap, pi2);
1545 if (ps->repo == installed && (how & SOLVER_FORCEBEST) != 0)
1547 if (!solv->bestupdatemap.size)
1548 map_grow(&solv->bestupdatemap, installed->end - installed->start);
1549 MAPSET(&solv->bestupdatemap, pi - installed->start);
1551 if (ps->repo == installed && (how & SOLVER_CLEANDEPS) != 0)
1552 add_cleandeps_package(solv, pi);
1553 if (!targeted && ps->repo != installed)
1554 MAPSET(&solv->dupmap, pi);
1556 if (s->repo == installed && solv->obsoletes && solv->obsoletes[p - installed->start])
1559 for (opp = solv->obsoletes_data + solv->obsoletes[p - installed->start]; (pi = *opp++) != 0;)
1561 ps = pool->solvables + pi;
1562 if (ps->repo == installed)
1564 MAPSET(&solv->dupinvolvedmap, pi);
1566 MAPSET(&solv->dupmap, pi);
1569 if (targeted && s->repo != installed && s->obsoletes)
1571 /* XXX: check obsoletes/provides combination */
1572 obsp = s->repo->idarraydata + s->obsoletes;
1573 while ((obs = *obsp++) != 0)
1575 FOR_PROVIDES(pi, pip, obs)
1577 Solvable *ps = pool->solvables + pi;
1578 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
1580 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1582 MAPSET(&solv->dupinvolvedmap, pi);
1583 if (targeted && ps->repo == installed && solv->obsoletes && solv->obsoletes[pi - installed->start])
1586 for (opp = solv->obsoletes_data + solv->obsoletes[pi - installed->start]; (pi2 = *opp++) != 0;)
1587 if (pool->solvables[pi2].repo != installed)
1588 MAPSET(&solv->dupinvolvedmap, pi2);
1590 if (ps->repo == installed && (how & SOLVER_FORCEBEST) != 0)
1592 if (!solv->bestupdatemap.size)
1593 map_grow(&solv->bestupdatemap, installed->end - installed->start);
1594 MAPSET(&solv->bestupdatemap, pi - installed->start);
1596 if (ps->repo == installed && (how & SOLVER_CLEANDEPS) != 0)
1597 add_cleandeps_package(solv, pi);
1604 solver_createdupmaps(Solver *solv)
1606 Queue *job = &solv->job;
1607 Pool *pool = solv->pool;
1608 Repo *installed = solv->installed;
1609 Id select, how, what, p, pp;
1613 map_init(&solv->dupmap, pool->nsolvables);
1614 map_init(&solv->dupinvolvedmap, pool->nsolvables);
1615 for (i = 0; i < job->count; i += 2)
1617 how = job->elements[i];
1618 select = job->elements[i] & SOLVER_SELECTMASK;
1619 what = job->elements[i + 1];
1620 switch (how & SOLVER_JOBMASK)
1622 case SOLVER_DISTUPGRADE:
1623 if (select == SOLVER_SOLVABLE_REPO)
1626 if (what <= 0 || what > pool->nrepos)
1628 repo = pool_id2repo(pool, what);
1631 if (repo != installed && !(how & SOLVER_TARGETED) && solv->noautotarget)
1633 targeted = repo != installed || (how & SOLVER_TARGETED) != 0;
1634 FOR_REPO_SOLVABLES(repo, p, s)
1636 if (repo != installed && !pool_installable(pool, s))
1638 solver_addtodupmaps(solv, p, how, targeted);
1643 targeted = how & SOLVER_TARGETED ? 1 : 0;
1644 if (installed && !targeted && !solv->noautotarget)
1646 FOR_JOB_SELECT(p, pp, select, what)
1647 if (pool->solvables[p].repo == installed)
1651 else if (!installed && !solv->noautotarget)
1653 FOR_JOB_SELECT(p, pp, select, what)
1655 Solvable *s = pool->solvables + p;
1658 if (s->repo != installed && !targeted)
1660 if (s->repo != installed && !pool_installable(pool, s))
1662 solver_addtodupmaps(solv, p, how, targeted);
1670 MAPCLR(&solv->dupinvolvedmap, SYSTEMSOLVABLE);
1674 solver_freedupmaps(Solver *solv)
1676 map_free(&solv->dupmap);
1677 /* we no longer free solv->dupinvolvedmap as we need it in
1678 * policy's priority pruning code. sigh. */
1682 solver_addduprules(Solver *solv, Map *addedmap)
1684 Pool *pool = solv->pool;
1689 solv->duprules = solv->nrules;
1690 for (i = 1; i < pool->nsolvables; i++)
1692 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1694 s = pool->solvables + i;
1696 FOR_PROVIDES(p, pp, s->name)
1698 ps = pool->solvables + p;
1699 if (ps->name != s->name || !MAPTST(addedmap, p))
1705 if (!MAPTST(&solv->dupinvolvedmap, p))
1707 if (solv->installed && ps->repo == solv->installed)
1709 if (!solv->updatemap.size)
1710 map_grow(&solv->updatemap, solv->installed->end - solv->installed->start);
1711 MAPSET(&solv->updatemap, p - solv->installed->start);
1712 if (!MAPTST(&solv->dupmap, p))
1715 /* is installed identical to a good one? */
1716 FOR_PROVIDES(ip, ipp, ps->name)
1718 Solvable *is = pool->solvables + ip;
1719 if (!MAPTST(&solv->dupmap, ip))
1721 if (is->evr == ps->evr && solvable_identical(ps, is))
1725 solver_addrule(solv, -p, 0); /* no match, sorry */
1727 MAPSET(&solv->dupmap, p); /* for best rules processing */
1730 else if (!MAPTST(&solv->dupmap, p))
1731 solver_addrule(solv, -p, 0);
1734 solv->duprules_end = solv->nrules;
1739 disableduprule(Solver *solv, Id name)
1741 Pool *pool = solv->pool;
1744 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1746 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1747 solver_disablerule(solv, r);
1752 reenableduprule(Solver *solv, Id name)
1754 Pool *pool = solv->pool;
1757 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1759 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1761 solver_enablerule(solv, r);
1762 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1764 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1765 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1772 /***********************************************************************
1774 *** Policy rule disabling/reenabling
1776 *** Disable all policy rules that conflict with our jobs. If a job
1777 *** gets disabled later on, reenable the involved policy rules again.
1781 #define DISABLE_UPDATE 1
1782 #define DISABLE_INFARCH 2
1783 #define DISABLE_DUP 3
1786 * add all installed packages that package p obsoletes to Queue q.
1787 * Package p is not installed. Also, we know that if
1788 * solv->keepexplicitobsoletes is not set, p is not in the multiversion map.
1789 * Entries may get added multiple times.
1792 add_obsoletes(Solver *solv, Id p, Queue *q)
1794 Pool *pool = solv->pool;
1795 Repo *installed = solv->installed;
1797 Solvable *s = pool->solvables + p;
1801 if (!solv->keepexplicitobsoletes || !(solv->multiversion.size && MAPTST(&solv->multiversion, p)))
1803 FOR_PROVIDES(p2, pp2, s->name)
1805 Solvable *ps = pool->solvables + p2;
1806 if (ps->repo != installed)
1808 if (!pool->implicitobsoleteusesprovides && ps->name != s->name)
1810 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, ps))
1818 obsp = s->repo->idarraydata + s->obsoletes;
1819 while ((obs = *obsp++) != 0)
1820 FOR_PROVIDES(p2, pp2, obs)
1822 Solvable *ps = pool->solvables + p2;
1823 if (ps->repo != installed)
1825 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
1827 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1837 * Call add_obsoletes and intersect the result with the
1838 * elements in Queue q starting at qstart.
1839 * Assumes that it's the first call if qstart == q->count.
1840 * May use auxillary map m for the intersection process, all
1841 * elements of q starting at qstart must have their bit cleared.
1842 * (This is also true after the function returns.)
1845 intersect_obsoletes(Solver *solv, Id p, Queue *q, int qstart, Map *m)
1848 int qcount = q->count;
1850 add_obsoletes(solv, p, q);
1851 if (qcount == qstart)
1852 return; /* first call */
1853 if (qcount == q->count)
1855 else if (qcount == qstart + 1)
1857 /* easy if there's just one element */
1859 for (i = qcount; i < q->count; i++)
1860 if (q->elements[i] == q->elements[qstart])
1862 j++; /* keep the element */
1866 else if (!m->size && q->count - qstart <= 8)
1868 /* faster than a map most of the time */
1870 for (i = j = qstart; i < qcount; i++)
1872 Id ip = q->elements[i];
1873 for (k = qcount; k < q->count; k++)
1874 if (q->elements[k] == ip)
1876 q->elements[j++] = ip;
1883 /* for the really pathologic cases we use the map */
1884 Repo *installed = solv->installed;
1886 map_init(m, installed->end - installed->start);
1887 for (i = qcount; i < q->count; i++)
1888 MAPSET(m, q->elements[i] - installed->start);
1889 for (i = j = qstart; i < qcount; i++)
1890 if (MAPTST(m, q->elements[i] - installed->start))
1892 MAPCLR(m, q->elements[i] - installed->start);
1893 q->elements[j++] = q->elements[i];
1896 queue_truncate(q, j);
1900 jobtodisablelist(Solver *solv, Id how, Id what, Queue *q)
1902 Pool *pool = solv->pool;
1906 int i, j, set, qstart;
1909 installed = solv->installed;
1910 select = how & SOLVER_SELECTMASK;
1911 switch (how & SOLVER_JOBMASK)
1913 case SOLVER_INSTALL:
1914 set = how & SOLVER_SETMASK;
1915 if (!(set & SOLVER_NOAUTOSET))
1917 /* automatically add set bits by analysing the job */
1918 if (select == SOLVER_SOLVABLE_NAME)
1919 set |= SOLVER_SETNAME;
1920 if (select == SOLVER_SOLVABLE)
1921 set |= SOLVER_SETNAME | SOLVER_SETARCH | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_SETEVR;
1922 else if ((select == SOLVER_SOLVABLE_NAME || select == SOLVER_SOLVABLE_PROVIDES) && ISRELDEP(what))
1924 Reldep *rd = GETRELDEP(pool, what);
1925 if (rd->flags == REL_EQ && select == SOLVER_SOLVABLE_NAME)
1927 if (pool->disttype != DISTTYPE_DEB)
1929 const char *rel = strrchr(pool_id2str(pool, rd->evr), '-');
1930 set |= rel ? SOLVER_SETEVR : SOLVER_SETEV;
1933 set |= SOLVER_SETEVR;
1935 if (rd->flags <= 7 && ISRELDEP(rd->name))
1936 rd = GETRELDEP(pool, rd->name);
1937 if (rd->flags == REL_ARCH)
1938 set |= SOLVER_SETARCH;
1942 set &= ~SOLVER_NOAUTOSET;
1945 if ((set & SOLVER_SETARCH) != 0 && solv->infarchrules != solv->infarchrules_end)
1947 if (select == SOLVER_SOLVABLE)
1948 queue_push2(q, DISABLE_INFARCH, pool->solvables[what].name);
1951 int qcnt = q->count;
1952 /* does not work for SOLVER_SOLVABLE_ALL and SOLVER_SOLVABLE_REPO, but
1953 they are not useful for SOLVER_INSTALL jobs anyway */
1954 FOR_JOB_SELECT(p, pp, select, what)
1956 s = pool->solvables + p;
1958 for (i = qcnt; i < q->count; i += 2)
1959 if (q->elements[i + 1] == s->name)
1963 queue_push2(q, DISABLE_INFARCH, s->name);
1967 if ((set & SOLVER_SETREPO) != 0 && solv->duprules != solv->duprules_end)
1969 if (select == SOLVER_SOLVABLE)
1970 queue_push2(q, DISABLE_DUP, pool->solvables[what].name);
1973 int qcnt = q->count;
1974 FOR_JOB_SELECT(p, pp, select, what)
1976 s = pool->solvables + p;
1978 for (i = qcnt; i < q->count; i += 2)
1979 if (q->elements[i + 1] == s->name)
1983 queue_push2(q, DISABLE_DUP, s->name);
1987 if (!installed || installed->end == installed->start)
1989 /* now the hard part: disable some update rules */
1991 /* first check if we have multiversion or installed packages in the job */
1993 FOR_JOB_SELECT(p, pp, select, what)
1995 if (pool->solvables[p].repo == installed)
1997 else if (solv->multiversion.size && MAPTST(&solv->multiversion, p) && !solv->keepexplicitobsoletes)
2001 if (j) /* have installed packages */
2003 /* this is for dupmap_all jobs, it can go away if we create
2004 * duprules for them */
2005 if (i == 1 && (set & SOLVER_SETREPO) != 0)
2006 queue_push2(q, DISABLE_UPDATE, j);
2012 FOR_JOB_SELECT(p, pp, select, what)
2014 intersect_obsoletes(solv, p, q, qstart, &omap);
2015 if (q->count == qstart)
2021 if (qstart == q->count)
2022 return; /* nothing to prune */
2024 /* convert result to (DISABLE_UPDATE, p) pairs */
2026 for (j = qstart; j < i; j++)
2027 queue_push(q, q->elements[j]);
2028 for (j = qstart; j < q->count; j += 2)
2030 q->elements[j] = DISABLE_UPDATE;
2031 q->elements[j + 1] = q->elements[i++];
2034 /* now that we know which installed packages are obsoleted check each of them */
2035 if ((set & (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR)) == (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR))
2036 return; /* all is set, nothing to do */
2038 for (i = j = qstart; i < q->count; i += 2)
2040 Solvable *is = pool->solvables + q->elements[i + 1];
2041 FOR_JOB_SELECT(p, pp, select, what)
2044 s = pool->solvables + p;
2045 if ((set & SOLVER_SETEVR) != 0)
2046 illegal |= POLICY_ILLEGAL_DOWNGRADE; /* ignore */
2047 if ((set & SOLVER_SETNAME) != 0)
2048 illegal |= POLICY_ILLEGAL_NAMECHANGE; /* ignore */
2049 if ((set & SOLVER_SETARCH) != 0)
2050 illegal |= POLICY_ILLEGAL_ARCHCHANGE; /* ignore */
2051 if ((set & SOLVER_SETVENDOR) != 0)
2052 illegal |= POLICY_ILLEGAL_VENDORCHANGE; /* ignore */
2053 illegal = policy_is_illegal(solv, is, s, illegal);
2054 if (illegal && illegal == POLICY_ILLEGAL_DOWNGRADE && (set & SOLVER_SETEV) != 0)
2056 /* it's ok if the EV is different */
2057 if (pool_evrcmp(pool, is->evr, s->evr, EVRCMP_COMPARE_EVONLY) != 0)
2065 /* no package conflicts with the update rule */
2066 /* thus keep the DISABLE_UPDATE */
2067 q->elements[j + 1] = q->elements[i + 1];
2071 queue_truncate(q, j);
2077 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
2078 FOR_REPO_SOLVABLES(installed, p, s)
2079 queue_push2(q, DISABLE_UPDATE, p);
2080 FOR_JOB_SELECT(p, pp, select, what)
2081 if (pool->solvables[p].repo == installed)
2083 queue_push2(q, DISABLE_UPDATE, p);
2084 if (solv->instbuddy && solv->instbuddy[p - installed->start] > 1)
2085 queue_push2(q, DISABLE_UPDATE, solv->instbuddy[p - installed->start]);
2093 /* disable all policy rules that are in conflict with our job list */
2095 solver_disablepolicyrules(Solver *solv)
2097 Queue *job = &solv->job;
2104 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2106 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2108 r = solv->rules + i;
2109 if (r->d < 0) /* disabled? */
2111 j = solv->ruletojob.elements[i - solv->jobrules];
2115 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2117 if (solv->cleandepsmap.size)
2119 solver_createcleandepsmap(solv, &solv->cleandepsmap, 0);
2120 for (i = solv->installed->start; i < solv->installed->end; i++)
2121 if (MAPTST(&solv->cleandepsmap, i - solv->installed->start))
2122 queue_push2(&allq, DISABLE_UPDATE, i);
2124 MAPZERO(&solv->noupdate);
2125 for (i = 0; i < allq.count; i += 2)
2127 Id type = allq.elements[i], arg = allq.elements[i + 1];
2130 case DISABLE_UPDATE:
2131 disableupdaterule(solv, arg);
2133 case DISABLE_INFARCH:
2134 disableinfarchrule(solv, arg);
2137 disableduprule(solv, arg);
2146 /* we just disabled job #jobidx, now reenable all policy rules that were
2147 * disabled because of this job */
2149 solver_reenablepolicyrules(Solver *solv, int jobidx)
2151 Queue *job = &solv->job;
2156 Id qbuf[32], allqbuf[32];
2158 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
2159 jobtodisablelist(solv, job->elements[jobidx - 1], job->elements[jobidx], &q);
2165 /* now remove everything from q that is disabled by other jobs */
2167 /* first remove cleandeps packages, they count as DISABLE_UPDATE */
2168 if (solv->cleandepsmap.size)
2170 solver_createcleandepsmap(solv, &solv->cleandepsmap, 0);
2171 for (j = k = 0; j < q.count; j += 2)
2173 if (q.elements[j] == DISABLE_UPDATE)
2175 Id p = q.elements[j + 1];
2176 if (p >= solv->installed->start && p < solv->installed->end && MAPTST(&solv->cleandepsmap, p - solv->installed->start))
2177 continue; /* remove element from q */
2179 q.elements[k++] = q.elements[j];
2180 q.elements[k++] = q.elements[j + 1];
2190 /* now go through the disable list of all other jobs */
2191 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2192 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2194 r = solv->rules + i;
2195 if (r->d < 0) /* disabled? */
2197 j = solv->ruletojob.elements[i - solv->jobrules];
2201 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2204 /* remove all elements in allq from q */
2205 for (j = k = 0; j < q.count; j += 2)
2207 Id type = q.elements[j], arg = q.elements[j + 1];
2208 for (ai = 0; ai < allq.count; ai += 2)
2209 if (allq.elements[ai] == type && allq.elements[ai + 1] == arg)
2211 if (ai < allq.count)
2212 continue; /* found it in allq, remove element from q */
2213 q.elements[k++] = q.elements[j];
2214 q.elements[k++] = q.elements[j + 1];
2227 /* now re-enable anything that's left in q */
2228 for (j = 0; j < q.count; j += 2)
2230 Id type = q.elements[j], arg = q.elements[j + 1];
2233 case DISABLE_UPDATE:
2234 reenableupdaterule(solv, arg);
2236 case DISABLE_INFARCH:
2237 reenableinfarchrule(solv, arg);
2240 reenableduprule(solv, arg);
2247 /* we just removed a package from the cleandeps map, now reenable all policy rules that were
2248 * disabled because of this */
2250 solver_reenablepolicyrules_cleandeps(Solver *solv, Id pkg)
2252 Queue *job = &solv->job;
2259 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2260 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2262 r = solv->rules + i;
2263 if (r->d < 0) /* disabled? */
2265 j = solv->ruletojob.elements[i - solv->jobrules];
2269 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2271 for (i = 0; i < allq.count; i += 2)
2272 if (allq.elements[i] == DISABLE_UPDATE && allq.elements[i + 1] == pkg)
2274 if (i == allq.count)
2275 reenableupdaterule(solv, pkg);
2280 /***********************************************************************
2282 *** Rule info part, tell the user what the rule is about.
2287 addrpmruleinfo(Solver *solv, Id p, Id d, int type, Id dep)
2289 Pool *pool = solv->pool;
2293 /* check if this creates the rule we're searching for */
2294 r = solv->rules + solv->ruleinfoq->elements[0];
2296 od = r->d < 0 ? -r->d - 1 : r->d;
2301 if (p < 0 && d > 0 && (!pool->whatprovidesdata[d] || !pool->whatprovidesdata[d + 1]))
2303 w2 = pool->whatprovidesdata[d];
2306 if (p > 0 && d < 0) /* this hack is used for buddy deps */
2318 Id *dp = pool->whatprovidesdata + d;
2319 Id *odp = pool->whatprovidesdata + od;
2321 if (*dp++ != *odp++)
2327 /* handle multiversion conflict rules */
2328 if (p < 0 && pool->whatprovidesdata[d] < 0)
2330 w2 = pool->whatprovidesdata[d];
2331 /* XXX: free memory */
2341 if (w2 != op || p != ow2)
2346 if (p != op || w2 != ow2)
2350 /* yep, rule matches. record info */
2351 queue_push(solv->ruleinfoq, type);
2352 if (type == SOLVER_RULE_RPM_SAME_NAME)
2354 /* we normalize same name order */
2355 queue_push(solv->ruleinfoq, op < 0 ? -op : 0);
2356 queue_push(solv->ruleinfoq, ow2 < 0 ? -ow2 : 0);
2360 queue_push(solv->ruleinfoq, p < 0 ? -p : 0);
2361 queue_push(solv->ruleinfoq, w2 < 0 ? -w2 : 0);
2363 queue_push(solv->ruleinfoq, dep);
2367 solver_allruleinfos_cmp(const void *ap, const void *bp, void *dp)
2369 const Id *a = ap, *b = bp;
2388 getrpmruleinfos(Solver *solv, Rule *r, Queue *rq)
2390 Pool *pool = solv->pool;
2394 queue_push(rq, r - solv->rules); /* push the rule we're interested in */
2395 solv->ruleinfoq = rq;
2396 solver_addrpmrulesforsolvable(solv, pool->solvables - r->p, 0);
2397 /* also try reverse direction for conflicts */
2398 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
2399 solver_addrpmrulesforsolvable(solv, pool->solvables - r->w2, 0);
2400 #ifdef ENABLE_LINKED_PKGS
2401 /* check linked packages */
2403 if ((r->d == 0 || r->d == -1))
2407 d = r->d < 0 ? -r->d - 1 : r->d;
2408 l = pool->whatprovidesdata[d++];
2410 for (; l; l = (d ? pool->whatprovidesdata[d++] : 0))
2412 if (l <= 0 || !strchr(pool_id2str(pool, pool->solvables[l].name), ':'))
2414 add_package_link(solv, pool->solvables + l, 0, 0);
2417 solv->ruleinfoq = 0;
2422 solver_allruleinfos(Solver *solv, Id rid, Queue *rq)
2424 Rule *r = solv->rules + rid;
2428 if (rid <= 0 || rid >= solv->rpmrules_end)
2430 Id type, from, to, dep;
2431 type = solver_ruleinfo(solv, rid, &from, &to, &dep);
2432 queue_push(rq, type);
2433 queue_push(rq, from);
2435 queue_push(rq, dep);
2438 getrpmruleinfos(solv, r, rq);
2439 /* now sort & unify em */
2442 solv_sort(rq->elements, rq->count / 4, 4 * sizeof(Id), solver_allruleinfos_cmp, 0);
2443 /* throw out identical entries */
2444 for (i = j = 0; i < rq->count; i += 4)
2448 if (rq->elements[i] == rq->elements[j - 4] &&
2449 rq->elements[i + 1] == rq->elements[j - 3] &&
2450 rq->elements[i + 2] == rq->elements[j - 2] &&
2451 rq->elements[i + 3] == rq->elements[j - 1])
2454 rq->elements[j++] = rq->elements[i];
2455 rq->elements[j++] = rq->elements[i + 1];
2456 rq->elements[j++] = rq->elements[i + 2];
2457 rq->elements[j++] = rq->elements[i + 3];
2464 solver_ruleinfo(Solver *solv, Id rid, Id *fromp, Id *top, Id *depp)
2466 Pool *pool = solv->pool;
2467 Rule *r = solv->rules + rid;
2468 SolverRuleinfo type = SOLVER_RULE_UNKNOWN;
2476 if (rid > 0 && rid < solv->rpmrules_end)
2482 return SOLVER_RULE_RPM;
2486 getrpmruleinfos(solv, r, &rq);
2487 type = SOLVER_RULE_RPM;
2488 for (i = 0; i < rq.count; i += 4)
2491 qt = rq.elements[i];
2492 qp = rq.elements[i + 1];
2493 qo = rq.elements[i + 2];
2494 qd = rq.elements[i + 3];
2495 if (type == SOLVER_RULE_RPM || type > qt)
2509 if (rid >= solv->jobrules && rid < solv->jobrules_end)
2511 Id jidx = solv->ruletojob.elements[rid - solv->jobrules];
2515 *top = solv->job.elements[jidx];
2517 *depp = solv->job.elements[jidx + 1];
2518 if ((r->d == 0 || r->d == -1) && r->w2 == 0 && r->p == -SYSTEMSOLVABLE)
2520 Id how = solv->job.elements[jidx];
2521 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_INSTALL|SOLVER_SOLVABLE_NAME))
2522 return SOLVER_RULE_JOB_UNKNOWN_PACKAGE;
2523 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES))
2524 return SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP;
2525 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_ERASE|SOLVER_SOLVABLE_NAME))
2526 return SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM;
2527 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_ERASE|SOLVER_SOLVABLE_PROVIDES))
2528 return SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM;
2529 return SOLVER_RULE_JOB_UNSUPPORTED;
2531 return SOLVER_RULE_JOB;
2533 if (rid >= solv->updaterules && rid < solv->updaterules_end)
2536 *fromp = solv->installed->start + (rid - solv->updaterules);
2537 return SOLVER_RULE_UPDATE;
2539 if (rid >= solv->featurerules && rid < solv->featurerules_end)
2542 *fromp = solv->installed->start + (rid - solv->featurerules);
2543 return SOLVER_RULE_FEATURE;
2545 if (rid >= solv->duprules && rid < solv->duprules_end)
2550 *depp = pool->solvables[-r->p].name;
2551 return SOLVER_RULE_DISTUPGRADE;
2553 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
2558 *depp = pool->solvables[-r->p].name;
2559 return SOLVER_RULE_INFARCH;
2561 if (rid >= solv->bestrules && rid < solv->bestrules_end)
2563 return SOLVER_RULE_BEST;
2565 if (rid >= solv->choicerules && rid < solv->choicerules_end)
2567 return SOLVER_RULE_CHOICE;
2569 if (rid >= solv->learntrules)
2571 return SOLVER_RULE_LEARNT;
2573 return SOLVER_RULE_UNKNOWN;
2577 solver_ruleclass(Solver *solv, Id rid)
2580 return SOLVER_RULE_UNKNOWN;
2581 if (rid > 0 && rid < solv->rpmrules_end)
2582 return SOLVER_RULE_RPM;
2583 if (rid >= solv->jobrules && rid < solv->jobrules_end)
2584 return SOLVER_RULE_JOB;
2585 if (rid >= solv->updaterules && rid < solv->updaterules_end)
2586 return SOLVER_RULE_UPDATE;
2587 if (rid >= solv->featurerules && rid < solv->featurerules_end)
2588 return SOLVER_RULE_FEATURE;
2589 if (rid >= solv->duprules && rid < solv->duprules_end)
2590 return SOLVER_RULE_DISTUPGRADE;
2591 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
2592 return SOLVER_RULE_INFARCH;
2593 if (rid >= solv->bestrules && rid < solv->bestrules_end)
2594 return SOLVER_RULE_BEST;
2595 if (rid >= solv->choicerules && rid < solv->choicerules_end)
2596 return SOLVER_RULE_CHOICE;
2597 if (rid >= solv->learntrules)
2598 return SOLVER_RULE_LEARNT;
2599 return SOLVER_RULE_UNKNOWN;
2603 solver_ruleliterals(Solver *solv, Id rid, Queue *q)
2605 Pool *pool = solv->pool;
2610 r = solv->rules + rid;
2611 FOR_RULELITERALS(p, pp, r)
2612 if (p != -SYSTEMSOLVABLE)
2615 queue_push(q, -SYSTEMSOLVABLE); /* hmm, better to return an empty result? */
2619 solver_rule2jobidx(Solver *solv, Id rid)
2621 if (rid < solv->jobrules || rid >= solv->jobrules_end)
2623 return solv->ruletojob.elements[rid - solv->jobrules] + 1;
2626 /* job rule introspection */
2628 solver_rule2job(Solver *solv, Id rid, Id *whatp)
2631 if (rid < solv->jobrules || rid >= solv->jobrules_end)
2637 idx = solv->ruletojob.elements[rid - solv->jobrules];
2639 *whatp = solv->job.elements[idx + 1];
2640 return solv->job.elements[idx];
2643 /* update/feature rule introspection */
2645 solver_rule2solvable(Solver *solv, Id rid)
2647 if (rid >= solv->updaterules && rid < solv->updaterules_end)
2648 return rid - solv->updaterules;
2649 if (rid >= solv->featurerules && rid < solv->featurerules_end)
2650 return rid - solv->featurerules;
2655 solver_rule2rules_rec(Solver *solv, Id rid, Queue *q, Map *seen)
2662 for (i = solv->learnt_why.elements[rid - solv->learntrules]; (rid2 = solv->learnt_pool.elements[i]) != 0; i++)
2666 if (MAPTST(seen, rid2))
2668 if (rid2 >= solv->learntrules)
2669 solver_rule2rules_rec(solv, rid2, q, seen);
2672 queue_push(q, rid2);
2676 /* learnt rule introspection */
2678 solver_rule2rules(Solver *solv, Id rid, Queue *q, int recursive)
2681 if (rid < solv->learntrules || rid >= solv->nrules)
2686 map_init(&seen, solv->nrules);
2687 solver_rule2rules_rec(solv, rid, q, &seen);
2691 solver_rule2rules_rec(solv, rid, q, 0);
2695 /* check if the newest versions of pi still provides the dependency we're looking for */
2697 solver_choicerulecheck(Solver *solv, Id pi, Rule *r, Map *m)
2699 Pool *pool = solv->pool;
2705 ur = solv->rules + solv->updaterules + (pi - pool->installed->start);
2707 ur = solv->rules + solv->featurerules + (pi - pool->installed->start);
2710 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
2711 FOR_RULELITERALS(p, pp, ur)
2715 policy_filter_unwanted(solv, &q, POLICY_MODE_CHOOSE);
2716 for (i = 0; i < q.count; i++)
2717 if (MAPTST(m, q.elements[i]))
2719 /* 1: none of the newest versions provide it */
2720 i = i == q.count ? 1 : 0;
2726 queue_removeelement(Queue *q, Id el)
2729 for (i = 0; i < q->count; i++)
2730 if (q->elements[i] == el)
2734 for (j = i++; i < q->count; i++)
2735 if (q->elements[i] != el)
2736 q->elements[j++] = q->elements[i];
2737 queue_truncate(q, j);
2742 solver_addchoicerules(Solver *solv)
2744 Pool *pool = solv->pool;
2748 int i, j, rid, havechoice;
2752 Id lastaddedp, lastaddedd;
2756 solv->choicerules = solv->nrules;
2757 if (!pool->installed)
2759 solv->choicerules_end = solv->nrules;
2762 now = solv_timems(0);
2763 solv->choicerules_ref = solv_calloc(solv->rpmrules_end, sizeof(Id));
2766 map_init(&m, pool->nsolvables);
2767 map_init(&mneg, pool->nsolvables);
2768 /* set up negative assertion map from infarch and dup rules */
2769 for (rid = solv->infarchrules, r = solv->rules + rid; rid < solv->infarchrules_end; rid++, r++)
2770 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
2771 MAPSET(&mneg, -r->p);
2772 for (rid = solv->duprules, r = solv->rules + rid; rid < solv->duprules_end; rid++, r++)
2773 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
2774 MAPSET(&mneg, -r->p);
2778 for (rid = 1; rid < solv->rpmrules_end ; rid++)
2780 r = solv->rules + rid;
2781 if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 < 0))
2782 continue; /* only look at requires rules */
2783 /* solver_printrule(solv, SOLV_DEBUG_RESULT, r); */
2787 FOR_RULELITERALS(p, pp, r)
2791 s = pool->solvables + p;
2794 if (s->repo == pool->installed)
2799 /* check if this package is "blocked" by a installed package */
2801 FOR_PROVIDES(p2, pp2, s->name)
2803 s2 = pool->solvables + p2;
2804 if (s2->repo != pool->installed)
2806 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
2808 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, s2))
2814 /* found installed package p2 that we can update to p */
2815 if (MAPTST(&mneg, p))
2817 if (policy_is_illegal(solv, s2, s, 0))
2820 if (solver_choicerulecheck(solv, p2, r, &m))
2822 queue_push(&qi, p2);
2824 queue_push2(&qi, p2, p);
2831 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
2833 while ((obs = *obsp++) != 0)
2835 FOR_PROVIDES(p2, pp2, obs)
2837 s2 = pool->solvables + p2;
2838 if (s2->repo != pool->installed)
2840 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
2842 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
2851 /* found installed package p2 that we can update to p */
2852 if (MAPTST(&mneg, p))
2854 if (policy_is_illegal(solv, s2, s, 0))
2857 if (solver_choicerulecheck(solv, p2, r, &m))
2859 queue_push(&qi, p2);
2861 queue_push2(&qi, p2, p);
2867 /* package p is independent of the installed ones */
2870 if (!havechoice || !q.count || !qi.count)
2871 continue; /* no choice */
2873 FOR_RULELITERALS(p, pp, r)
2877 /* do extra checking */
2878 for (i = j = 0; i < qi.count; i += 2)
2880 p2 = qi.elements[i];
2883 if (solver_choicerulecheck(solv, p2, r, &m))
2885 /* oops, remove element p from q */
2886 queue_removeelement(&q, qi.elements[i + 1]);
2889 qi.elements[j++] = p2;
2891 queue_truncate(&qi, j);
2892 if (!q.count || !qi.count)
2894 FOR_RULELITERALS(p, pp, r)
2901 /* now check the update rules of the installed package.
2902 * if all packages of the update rules are contained in
2903 * the dependency rules, there's no need to set up the choice rule */
2904 for (i = 0; i < qi.count; i++)
2907 if (!qi.elements[i])
2909 ur = solv->rules + solv->updaterules + (qi.elements[i] - pool->installed->start);
2911 ur = solv->rules + solv->featurerules + (qi.elements[i] - pool->installed->start);
2914 FOR_RULELITERALS(p, pp, ur)
2919 for (j = i + 1; j < qi.count; j++)
2920 if (qi.elements[i] == qi.elements[j])
2923 /* empty map again */
2924 FOR_RULELITERALS(p, pp, r)
2930 printf("skipping choice ");
2931 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + rid);
2936 /* don't add identical rules */
2937 if (lastaddedp == r->p && lastaddedcnt == q.count)
2939 for (i = 0; i < q.count; i++)
2940 if (q.elements[i] != pool->whatprovidesdata[lastaddedd + i])
2943 continue; /* already added that one */
2945 d = q.count ? pool_queuetowhatprovides(pool, &q) : 0;
2949 lastaddedcnt = q.count;
2951 solver_addrule(solv, r->p, d);
2952 queue_push(&solv->weakruleq, solv->nrules - 1);
2953 solv->choicerules_ref[solv->nrules - 1 - solv->choicerules] = rid;
2956 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + rid);
2957 printf("WEAK CHOICE ");
2958 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + solv->nrules - 1);
2965 solv->choicerules_end = solv->nrules;
2966 /* shrink choicerules_ref */
2967 solv->choicerules_ref = solv_realloc2(solv->choicerules_ref, solv->choicerules_end - solv->choicerules, sizeof(Id));
2968 POOL_DEBUG(SOLV_DEBUG_STATS, "choice rule creation took %d ms\n", solv_timems(now));
2971 /* called when a choice rule is disabled by analyze_unsolvable. We also
2972 * have to disable all other choice rules so that the best packages get
2975 solver_disablechoicerules(Solver *solv, Rule *r)
2978 Pool *pool = solv->pool;
2982 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
2983 map_init(&m, pool->nsolvables);
2984 FOR_RULELITERALS(p, pp, or)
2987 FOR_RULELITERALS(p, pp, r)
2990 for (rid = solv->choicerules; rid < solv->choicerules_end; rid++)
2992 r = solv->rules + rid;
2995 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
2996 FOR_RULELITERALS(p, pp, or)
2997 if (p > 0 && MAPTST(&m, p))
3000 solver_disablerule(solv, r);
3005 prune_to_update_targets(Solver *solv, Id *cp, Queue *q)
3009 for (i = j = 0; i < q->count; i++)
3012 for (cp2 = cp; *cp2; cp2++)
3015 q->elements[j++] = p;
3019 queue_truncate(q, j);
3023 prune_to_dup_packages(Solver *solv, Id p, Queue *q)
3026 for (i = j = 0; i < q->count; i++)
3028 Id p = q->elements[i];
3029 if (MAPTST(&solv->dupmap, p))
3030 q->elements[j++] = p;
3032 queue_truncate(q, j);
3036 solver_addbestrules(Solver *solv, int havebestinstalljobs)
3038 Pool *pool = solv->pool;
3041 Repo *installed = solv->installed;
3047 solv->bestrules = solv->nrules;
3050 solv->bestrules_end = solv->nrules;
3057 if (havebestinstalljobs)
3059 for (i = 0; i < solv->job.count; i += 2)
3061 if ((solv->job.elements[i] & (SOLVER_JOBMASK | SOLVER_FORCEBEST)) == (SOLVER_INSTALL | SOLVER_FORCEBEST))
3065 for (j = 0; j < solv->ruletojob.count; j++)
3066 if (solv->ruletojob.elements[j] == i)
3068 if (j == solv->ruletojob.count)
3070 r = solv->rules + solv->jobrules + j;
3072 FOR_RULELITERALS(p2, pp2, r)
3076 continue; /* orphaned */
3077 /* select best packages, just look at prio and version */
3079 policy_filter_unwanted(solv, &q, POLICY_MODE_RECOMMEND);
3080 if (q.count == oldcnt)
3081 continue; /* nothing filtered */
3082 p2 = queue_shift(&q);
3083 solver_addrule(solv, p2, q.count ? pool_queuetowhatprovides(pool, &q) : 0);
3084 queue_push(&r2pkg, -(solv->jobrules + j));
3089 if (solv->bestupdatemap_all || solv->bestupdatemap.size)
3091 FOR_REPO_SOLVABLES(installed, p, s)
3094 if (!solv->updatemap_all && (!solv->updatemap.size || !MAPTST(&solv->updatemap, p - installed->start)))
3096 if (!solv->bestupdatemap_all && (!solv->bestupdatemap.size || !MAPTST(&solv->bestupdatemap, p - installed->start)))
3099 if (solv->bestobeypolicy)
3100 r = solv->rules + solv->updaterules + (p - installed->start);
3103 r = solv->rules + solv->featurerules + (p - installed->start);
3104 if (!r->p) /* identical to update rule? */
3105 r = solv->rules + solv->updaterules + (p - installed->start);
3107 if (solv->multiversionupdaters && (d = solv->multiversionupdaters[p - installed->start]) != 0 && r == solv->rules + solv->updaterules + (p - installed->start))
3109 /* need to check multiversionupdaters */
3110 if (r->p == p) /* be careful with the dup case */
3112 while ((p2 = pool->whatprovidesdata[d++]) != 0)
3117 FOR_RULELITERALS(p2, pp2, r)
3121 if (solv->update_targets && solv->update_targets->elements[p - installed->start])
3122 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[p - installed->start], &q);
3123 if (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
3124 prune_to_dup_packages(solv, p, &q);
3125 /* select best packages, just look at prio and version */
3126 policy_filter_unwanted(solv, &q, POLICY_MODE_RECOMMEND);
3128 continue; /* orphaned */
3129 if (solv->bestobeypolicy)
3131 /* also filter the best of the feature rule packages and add them */
3132 r = solv->rules + solv->featurerules + (p - installed->start);
3137 FOR_RULELITERALS(p2, pp2, r)
3139 queue_push(&q2, p2);
3140 if (solv->update_targets && solv->update_targets->elements[p - installed->start])
3141 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[p - installed->start], &q2);
3142 if (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
3143 prune_to_dup_packages(solv, p, &q);
3144 policy_filter_unwanted(solv, &q2, POLICY_MODE_RECOMMEND);
3145 for (j = 0; j < q2.count; j++)
3146 queue_pushunique(&q, q2.elements[j]);
3149 p2 = queue_shift(&q);
3150 solver_addrule(solv, p2, q.count ? pool_queuetowhatprovides(pool, &q) : 0);
3151 queue_push(&r2pkg, p);
3155 solv->bestrules_pkg = solv_memdup2(r2pkg.elements, r2pkg.count, sizeof(Id));
3156 solv->bestrules_end = solv->nrules;
3162 #undef CLEANDEPSDEBUG
3165 * This functions collects all packages that are looked at
3166 * when a dependency is checked. We need it to "pin" installed
3167 * packages when removing a supplemented package in createcleandepsmap.
3168 * Here's an not uncommon example:
3169 * A contains "Supplements: packageand(B, C)"
3170 * B contains "Requires: A"
3171 * Now if we remove C, the supplements is no longer true,
3172 * thus we also remove A. Without the dep_pkgcheck function, we
3173 * would now also remove B, but this is wrong, as adding back
3174 * C doesn't make the supplements true again. Thus we "pin" B
3176 * There's probably a better way to do this, but I haven't come
3180 dep_pkgcheck(Solver *solv, Id dep, Map *m, Queue *q)
3182 Pool *pool = solv->pool;
3187 Reldep *rd = GETRELDEP(pool, dep);
3190 if (rd->flags == REL_AND)
3192 dep_pkgcheck(solv, rd->name, m, q);
3193 dep_pkgcheck(solv, rd->evr, m, q);
3196 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
3198 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
3202 FOR_PROVIDES(p, pp, dep)
3203 if (!m || MAPTST(m, p))
3208 check_xsupp(Solver *solv, Queue *depq, Id dep)
3210 Pool *pool = solv->pool;
3215 Reldep *rd = GETRELDEP(pool, dep);
3218 if (rd->flags == REL_AND)
3220 if (!check_xsupp(solv, depq, rd->name))
3222 return check_xsupp(solv, depq, rd->evr);
3224 if (rd->flags == REL_OR)
3226 if (check_xsupp(solv, depq, rd->name))
3228 return check_xsupp(solv, depq, rd->evr);
3230 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
3231 return solver_splitprovides(solv, rd->evr);
3232 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
3233 return solver_dep_installed(solv, rd->evr);
3235 if (depq && rd->flags == REL_NAMESPACE)
3238 for (i = 0; i < depq->count; i++)
3239 if (depq->elements[i] == dep || depq->elements[i] == rd->name)
3243 FOR_PROVIDES(p, pp, dep)
3244 if (p == SYSTEMSOLVABLE || pool->solvables[p].repo == solv->installed)
3250 queue_contains(Queue *q, Id id)
3253 for (i = 0; i < q->count; i++)
3254 if (q->elements[i] == id)
3261 * Find all installed packages that are no longer
3262 * needed regarding the current solver job.
3265 * - remove pass: remove all packages that could have
3266 * been dragged in by the obsoleted packages.
3267 * i.e. if package A is obsolete and contains "Requires: B",
3268 * also remove B, as installing A will have pulled in B.
3269 * after this pass, we have a set of still installed packages
3270 * with broken dependencies.
3272 * now add back all packages that the still installed packages
3275 * The cleandeps packages are the packages removed in the first
3276 * pass and not added back in the second pass.
3278 * If we search for unneeded packages (unneeded is true), we
3279 * simply remove all packages except the userinstalled ones in
3283 solver_createcleandepsmap(Solver *solv, Map *cleandepsmap, int unneeded)
3285 Pool *pool = solv->pool;
3286 Repo *installed = solv->installed;
3287 Queue *job = &solv->job;
3292 Id rid, how, what, select;
3294 Id req, *reqp, sup, *supp;
3296 Queue iq, iqcopy, xsuppq;
3299 map_empty(cleandepsmap);
3300 if (!installed || installed->end == installed->start)
3302 map_init(&userinstalled, installed->end - installed->start);
3303 map_init(&im, pool->nsolvables);
3304 map_init(&installedm, pool->nsolvables);
3306 queue_init(&xsuppq);
3308 for (i = 0; i < job->count; i += 2)
3310 how = job->elements[i];
3311 if ((how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
3313 what = job->elements[i + 1];
3314 select = how & SOLVER_SELECTMASK;
3315 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
3316 FOR_REPO_SOLVABLES(installed, p, s)
3317 MAPSET(&userinstalled, p - installed->start);
3318 FOR_JOB_SELECT(p, pp, select, what)
3319 if (pool->solvables[p].repo == installed)
3320 MAPSET(&userinstalled, p - installed->start);
3322 if ((how & (SOLVER_JOBMASK | SOLVER_SELECTMASK)) == (SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES))
3324 what = job->elements[i + 1];
3327 Reldep *rd = GETRELDEP(pool, what);
3328 if (rd->flags != REL_NAMESPACE)
3332 queue_pushunique(&iq, rd->name);
3335 FOR_PROVIDES(p, pp, what)
3340 queue_pushunique(&iq, what);
3345 /* have special namespace cleandeps erases */
3348 for (ip = solv->installed->start; ip < solv->installed->end; ip++)
3350 s = pool->solvables + ip;
3351 if (s->repo != installed)
3353 if (!s->supplements)
3355 supp = s->repo->idarraydata + s->supplements;
3356 while ((sup = *supp++) != 0)
3357 if (check_xsupp(solv, &iq, sup) && !check_xsupp(solv, 0, sup))
3359 #ifdef CLEANDEPSDEBUG
3360 printf("xsupp %s from %s\n", pool_dep2str(pool, sup), pool_solvid2str(pool, ip));
3362 queue_pushunique(&xsuppq, sup);
3368 /* also add visible patterns to userinstalled for openSUSE */
3372 dataiterator_init(&di, pool, 0, 0, SOLVABLE_ISVISIBLE, 0, 0);
3373 while (dataiterator_step(&di))
3378 s = pool->solvables + di.solvid;
3379 if (!s->repo || !s->requires)
3381 if (s->repo != installed && !pool_installable(pool, s))
3383 if (strncmp(pool_id2str(pool, s->name), "pattern:", 8) != 0)
3385 dp = s->repo->idarraydata + s->requires;
3386 for (dp = s->repo->idarraydata + s->requires; *dp; dp++)
3387 FOR_PROVIDES(p, pp, *dp)
3388 if (pool->solvables[p].repo == installed)
3390 if (strncmp(pool_id2str(pool, pool->solvables[p].name), "pattern", 7) != 0)
3392 MAPSET(&userinstalled, p - installed->start);
3395 dataiterator_free(&di);
3399 /* all products and their buddies are userinstalled */
3400 for (p = installed->start; p < installed->end; p++)
3402 Solvable *s = pool->solvables + p;
3403 if (s->repo != installed)
3405 if (!strncmp("product:", pool_id2str(pool, s->name), 8))
3407 MAPSET(&userinstalled, p - installed->start);
3408 if (pool->nscallback)
3410 Id buddy = pool->nscallback(pool, pool->nscallbackdata, NAMESPACE_PRODUCTBUDDY, p);
3411 if (buddy >= installed->start && buddy < installed->end && pool->solvables[buddy].repo == installed)
3412 MAPSET(&userinstalled, buddy - installed->start);
3418 /* add all positive elements (e.g. locks) to "userinstalled" */
3419 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
3421 r = solv->rules + rid;
3424 i = solv->ruletojob.elements[rid - solv->jobrules];
3425 if ((job->elements[i] & SOLVER_CLEANDEPS) == SOLVER_CLEANDEPS)
3427 FOR_RULELITERALS(p, jp, r)
3428 if (p > 0 && pool->solvables[p].repo == installed)
3429 MAPSET(&userinstalled, p - installed->start);
3432 /* add all cleandeps candidates to iq */
3433 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
3435 r = solv->rules + rid;
3436 if (r->d < 0) /* disabled? */
3438 if (r->d == 0 && r->p < 0 && r->w2 == 0) /* negative assertion (erase job)? */
3441 if (pool->solvables[p].repo != installed)
3443 MAPCLR(&userinstalled, p - installed->start);
3446 i = solv->ruletojob.elements[rid - solv->jobrules];
3447 how = job->elements[i];
3448 if ((how & (SOLVER_JOBMASK|SOLVER_CLEANDEPS)) == (SOLVER_ERASE|SOLVER_CLEANDEPS))
3451 else if (r->p > 0) /* install job */
3455 i = solv->ruletojob.elements[rid - solv->jobrules];
3456 if ((job->elements[i] & SOLVER_CLEANDEPS) == SOLVER_CLEANDEPS)
3458 /* check if the literals all obsolete some installed package */
3462 /* just one installed literal */
3463 if (r->d == 0 && r->w2 == 0 && pool->solvables[r->p].repo == installed)
3465 /* multiversion is bad */
3466 if (solv->multiversion.size && !solv->keepexplicitobsoletes)
3468 FOR_RULELITERALS(p, jp, r)
3469 if (MAPTST(&solv->multiversion, p))
3477 FOR_RULELITERALS(p, jp, r)
3481 queue_truncate(&iq, iqstart); /* abort */
3484 if (pool->solvables[p].repo == installed)
3486 if (iq.count == iqstart)
3490 for (i = iqstart; i < iq.count; i++)
3491 if (iq.elements[i] == p)
3493 queue_truncate(&iq, iqstart);
3499 intersect_obsoletes(solv, p, &iq, iqstart, &om);
3500 if (iq.count == iqstart)
3508 queue_init_clone(&iqcopy, &iq);
3512 if (solv->cleandeps_updatepkgs)
3513 for (i = 0; i < solv->cleandeps_updatepkgs->count; i++)
3514 queue_push(&iq, solv->cleandeps_updatepkgs->elements[i]);
3518 queue_empty(&iq); /* just in case... */
3520 /* clear userinstalled bit for the packages we really want to delete/update */
3521 for (i = 0; i < iq.count; i++)
3524 if (pool->solvables[p].repo != installed)
3526 MAPCLR(&userinstalled, p - installed->start);
3529 for (p = installed->start; p < installed->end; p++)
3531 if (pool->solvables[p].repo != installed)
3533 MAPSET(&installedm, p);
3534 if (unneeded && !MAPTST(&userinstalled, p - installed->start))
3538 MAPSET(&installedm, SYSTEMSOLVABLE);
3539 MAPSET(&im, SYSTEMSOLVABLE);
3541 #ifdef CLEANDEPSDEBUG
3542 printf("REMOVE PASS\n");
3551 /* supplements pass */
3552 for (ip = installed->start; ip < installed->end; ip++)
3554 if (!MAPTST(&installedm, ip))
3556 s = pool->solvables + ip;
3557 if (!s->supplements)
3559 if (!MAPTST(&im, ip))
3561 if (MAPTST(&userinstalled, ip - installed->start))
3563 supp = s->repo->idarraydata + s->supplements;
3564 while ((sup = *supp++) != 0)
3565 if (dep_possible(solv, sup, &im))
3569 supp = s->repo->idarraydata + s->supplements;
3570 while ((sup = *supp++) != 0)
3571 if (dep_possible(solv, sup, &installedm) || (xsuppq.count && queue_contains(&xsuppq, sup)))
3573 /* no longer supplemented, also erase */
3574 int iqcount = iq.count;
3575 /* pin packages, see comment above dep_pkgcheck */
3576 dep_pkgcheck(solv, sup, &im, &iq);
3577 for (i = iqcount; i < iq.count; i++)
3579 Id pqp = iq.elements[i];
3580 if (pool->solvables[pqp].repo == installed)
3581 MAPSET(&userinstalled, pqp - installed->start);
3583 queue_truncate(&iq, iqcount);
3584 #ifdef CLEANDEPSDEBUG
3585 printf("%s supplemented [%s]\n", pool_solvid2str(pool, ip), pool_dep2str(pool, sup));
3587 queue_push(&iq, ip);
3592 break; /* no supplementing package found, we're done */
3594 ip = queue_shift(&iq);
3595 s = pool->solvables + ip;
3596 if (!MAPTST(&im, ip))
3598 if (!MAPTST(&installedm, ip))
3600 if (s->repo == installed && MAPTST(&userinstalled, ip - installed->start))
3603 #ifdef CLEANDEPSDEBUG
3604 printf("removing %s\n", pool_solvable2str(pool, s));
3608 reqp = s->repo->idarraydata + s->requires;
3609 while ((req = *reqp++) != 0)
3611 if (req == SOLVABLE_PREREQMARKER)
3614 /* count number of installed packages that match */
3616 FOR_PROVIDES(p, pp, req)
3617 if (MAPTST(&installedm, p))
3622 FOR_PROVIDES(p, pp, req)
3624 if (p != SYSTEMSOLVABLE && MAPTST(&im, p))
3626 #ifdef CLEANDEPSDEBUG
3627 printf("%s requires %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
3636 reqp = s->repo->idarraydata + s->recommends;
3637 while ((req = *reqp++) != 0)
3641 FOR_PROVIDES(p, pp, req)
3642 if (MAPTST(&installedm, p))
3647 FOR_PROVIDES(p, pp, req)
3649 if (p != SYSTEMSOLVABLE && MAPTST(&im, p))
3651 #ifdef CLEANDEPSDEBUG
3652 printf("%s recommends %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
3661 /* turn userinstalled into remove set for pruning */
3662 map_empty(&userinstalled);
3663 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
3665 r = solv->rules + rid;
3666 if (r->p >= 0 || r->d != 0 || r->w2 != 0)
3667 continue; /* disabled or not erase */
3670 if (pool->solvables[p].repo == installed)
3671 MAPSET(&userinstalled, p - installed->start);
3673 if (!unneeded && solv->cleandeps_updatepkgs)
3675 for (i = 0; i < solv->cleandeps_updatepkgs->count; i++)
3677 p = solv->cleandeps_updatepkgs->elements[i];
3678 if (pool->solvables[p].repo == installed)
3679 MAPSET(&userinstalled, p - installed->start);
3682 MAPSET(&im, SYSTEMSOLVABLE); /* in case we cleared it above */
3683 for (p = installed->start; p < installed->end; p++)
3686 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
3688 r = solv->rules + rid;
3691 FOR_RULELITERALS(p, jp, r)
3695 /* also put directly addressed packages on the install queue
3696 * so we can mark patterns as installed */
3697 for (i = 0; i < job->count; i += 2)
3699 how = job->elements[i];
3700 if ((how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
3702 what = job->elements[i + 1];
3703 select = how & SOLVER_SELECTMASK;
3704 if (select == SOLVER_SOLVABLE && pool->solvables[what].repo != installed)
3705 queue_push(&iq, what);
3709 #ifdef CLEANDEPSDEBUG
3710 printf("ADDBACK PASS\n");
3716 /* supplements pass */
3717 for (ip = installed->start; ip < installed->end; ip++)
3719 if (!MAPTST(&installedm, ip))
3721 if (MAPTST(&userinstalled, ip - installed->start))
3723 s = pool->solvables + ip;
3724 if (!s->supplements)
3726 if (MAPTST(&im, ip))
3728 supp = s->repo->idarraydata + s->supplements;
3729 while ((sup = *supp++) != 0)
3730 if (dep_possible(solv, sup, &im))
3734 #ifdef CLEANDEPSDEBUG
3735 printf("%s supplemented\n", pool_solvid2str(pool, ip));
3738 queue_push(&iq, ip);
3744 ip = queue_shift(&iq);
3745 s = pool->solvables + ip;
3746 #ifdef CLEANDEPSDEBUG
3747 printf("adding back %s\n", pool_solvable2str(pool, s));
3751 reqp = s->repo->idarraydata + s->requires;
3752 while ((req = *reqp++) != 0)
3754 FOR_PROVIDES(p, pp, req)
3759 FOR_PROVIDES(p, pp, req)
3761 if (!MAPTST(&im, p) && MAPTST(&installedm, p))
3765 if (MAPTST(&userinstalled, p - installed->start))
3767 #ifdef CLEANDEPSDEBUG
3768 printf("%s requires %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
3778 reqp = s->repo->idarraydata + s->recommends;
3779 while ((req = *reqp++) != 0)
3781 FOR_PROVIDES(p, pp, req)
3786 FOR_PROVIDES(p, pp, req)
3788 if (!MAPTST(&im, p) && MAPTST(&installedm, p))
3792 if (MAPTST(&userinstalled, p - installed->start))
3794 #ifdef CLEANDEPSDEBUG
3795 printf("%s recommends %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
3806 /* make sure the updatepkgs and mistakes are not in the cleandeps map */
3807 if (solv->cleandeps_updatepkgs)
3808 for (i = 0; i < solv->cleandeps_updatepkgs->count; i++)
3809 MAPSET(&im, solv->cleandeps_updatepkgs->elements[i]);
3810 if (solv->cleandeps_mistakes)
3811 for (i = 0; i < solv->cleandeps_mistakes->count; i++)
3812 MAPSET(&im, solv->cleandeps_mistakes->elements[i]);
3813 /* also remove original iq packages */
3814 for (i = 0; i < iqcopy.count; i++)
3815 MAPSET(&im, iqcopy.elements[i]);
3816 queue_free(&iqcopy);
3817 for (p = installed->start; p < installed->end; p++)
3819 if (pool->solvables[p].repo != installed)
3821 if (!MAPTST(&im, p))
3822 MAPSET(cleandepsmap, p - installed->start);
3825 map_free(&installedm);
3826 map_free(&userinstalled);
3827 queue_free(&xsuppq);
3828 #ifdef CLEANDEPSDEBUG
3829 printf("=== final cleandeps map:\n");
3830 for (p = installed->start; p < installed->end; p++)
3831 if (MAPTST(cleandepsmap, p - installed->start))
3832 printf(" - %s\n", pool_solvid2str(pool, p));
3845 /* Tarjan's SCC algorithm, slightly modifed */
3847 trj_visit(struct trj_data *trj, Id node)
3850 Queue *edges = trj->edges;
3851 Id nnode, myidx, stackstart;
3854 low[node] = myidx = trj->idx++;
3855 low[(stackstart = trj->nstack++)] = node;
3856 for (i = edges->elements[node]; (nnode = edges->elements[i]) != 0; i++)
3861 if (!edges->elements[edges->elements[nnode]])
3867 trj_visit(trj, nnode);
3872 if (l < trj->firstidx)
3875 for (k = l; low[low[k]] == l; k++)
3878 else if (l < low[node])
3881 if (low[node] == myidx)
3883 if (myidx != trj->firstidx)
3885 for (i = stackstart; i < trj->nstack; i++)
3886 low[low[i]] = myidx;
3887 trj->nstack = stackstart;
3893 solver_get_unneeded(Solver *solv, Queue *unneededq, int filtered)
3895 Repo *installed = solv->installed;
3899 queue_empty(unneededq);
3900 if (!installed || installed->end == installed->start)
3903 map_init(&cleandepsmap, installed->end - installed->start);
3904 solver_createcleandepsmap(solv, &cleandepsmap, 1);
3905 for (i = installed->start; i < installed->end; i++)
3906 if (MAPTST(&cleandepsmap, i - installed->start))
3907 queue_push(unneededq, i);
3909 if (filtered && unneededq->count > 1)
3911 Pool *pool = solv->pool;
3915 int j, pass, count = unneededq->count;
3918 map_init(&installedm, pool->nsolvables);
3919 for (i = installed->start; i < installed->end; i++)
3920 if (pool->solvables[i].repo == installed)
3921 MAPSET(&installedm, i);
3923 nrequires = solv_calloc(count, sizeof(Id));
3925 queue_prealloc(&edges, count * 4 + 10); /* pre-size */
3928 * Go through the solvables in the nodes queue and create edges for
3929 * all requires/recommends/supplements between the nodes.
3930 * The edges are stored in the edges queue, we add 1 to the node
3931 * index so that nodes in the edges queue are != 0 and we can
3932 * terminate the edge list with 0.
3933 * Thus for node element 5, the edges are stored starting at
3934 * edges.elements[6] and are 0-terminated.
3936 /* leave first element zero to make things easier */
3937 /* also add trailing zero */
3938 queue_insertn(&edges, 0, 1 + count + 1, 0);
3940 /* first requires and recommends */
3941 for (i = 0; i < count; i++)
3943 Solvable *s = pool->solvables + unneededq->elements[i];
3944 edges.elements[i + 1] = edges.count;
3945 for (pass = 0; pass < 2; pass++)
3948 unsigned int off = pass == 0 ? s->requires : s->recommends;
3951 for (dp = s->repo->idarraydata + off; *dp; dp++)
3952 FOR_PROVIDES(p, pp, *dp)
3954 Solvable *sp = pool->solvables + p;
3955 if (s == sp || sp->repo != installed || !MAPTST(&cleandepsmap, p - installed->start))
3957 for (j = 0; j < count; j++)
3958 if (p == unneededq->elements[j])
3962 if (num && edges.elements[edges.count - 1] == j + 1)
3964 queue_push(&edges, j + 1);
3970 queue_push(&edges, 0);
3973 printf("requires + recommends\n");
3974 for (i = 0; i < count; i++)
3977 printf(" %s (%d requires):\n", pool_solvid2str(pool, unneededq->elements[i]), nrequires[i]);
3978 for (j = edges.elements[i + 1]; edges.elements[j]; j++)
3979 printf(" - %s\n", pool_solvid2str(pool, unneededq->elements[edges.elements[j] - 1]));
3983 /* then add supplements */
3984 for (i = 0; i < count; i++)
3986 Solvable *s = pool->solvables + unneededq->elements[i];
3991 for (dp = s->repo->idarraydata + s->supplements; *dp; dp++)
3992 if (dep_possible(solv, *dp, &installedm))
3996 queue_init_buffer(&iq, iqbuf, sizeof(iqbuf)/sizeof(*iqbuf));
3997 dep_pkgcheck(solv, *dp, 0, &iq);
3998 for (k = 0; k < iq.count; k++)
4000 Id p = iq.elements[k];
4001 Solvable *sp = pool->solvables + p;
4002 if (p == unneededq->elements[i] || sp->repo != installed || !MAPTST(&cleandepsmap, p - installed->start))
4004 for (j = 0; j < count; j++)
4005 if (p == unneededq->elements[j])
4007 /* now add edge from j + 1 to i + 1 */
4008 queue_insert(&edges, edges.elements[j + 1] + nrequires[j], i + 1);
4009 /* addapt following edge pointers */
4010 for (k = j + 2; k < count + 2; k++)
4011 edges.elements[k]++;
4019 printf("+ supplements\n");
4020 for (i = 0; i < count; i++)
4023 printf(" %s (%d requires):\n", pool_solvid2str(pool, unneededq->elements[i]), nrequires[i]);
4024 for (j = edges.elements[i + 1]; edges.elements[j]; j++)
4025 printf(" - %s\n", pool_solvid2str(pool, unneededq->elements[edges.elements[j] - 1]));
4028 map_free(&installedm);
4030 /* now run SCC algo two times, first with requires+recommends+supplements,
4031 * then again without the requires. We run it the second time to get rid
4032 * of packages that got dragged in via recommends/supplements */
4034 * low will contain the result of the SCC search.
4035 * it must be of at least size 2 * (count + 1) and
4036 * must be zero initialized.
4038 * 0 low low ... low stack stack ...stack 0
4041 low = solv_calloc(count + 1, 2 * sizeof(Id));
4042 for (pass = 0; pass < 2; pass++)
4044 struct trj_data trj;
4047 memset(low, 0, (count + 1) * (2 * sizeof(Id)));
4048 for (i = 0; i < count; i++)
4050 edges.elements[i + 1] += nrequires[i];
4051 if (!unneededq->elements[i])
4052 low[i + 1] = -1; /* ignore this node */
4057 trj.idx = count + 1; /* stack starts here */
4058 for (i = 1; i <= count; i++)
4062 if (edges.elements[edges.elements[i]])
4064 trj.firstidx = trj.nstack = trj.idx;
4069 Id myidx = trj.idx++;
4074 /* prune packages */
4075 for (i = 0; i < count; i++)
4076 if (low[i + 1] <= 0)
4077 unneededq->elements[i] = 0;
4080 solv_free(nrequires);
4083 /* finally remove all pruned entries from unneededq */
4084 for (i = j = 0; i < count; i++)
4085 if (unneededq->elements[i])
4086 unneededq->elements[j++] = unneededq->elements[i];
4087 queue_truncate(unneededq, j);
4089 map_free(&cleandepsmap);