2 * Copyright (c) 2007-2008, 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"
27 #include "solverdebug.h"
29 #include "linkedpkg.h"
31 #define RULES_BLOCK 63
34 /********************************************************************
36 * dependency check helpers
40 /*-------------------------------------------------------------------
41 * handle split provides
43 * a splitprovides dep looks like
44 * namespace:splitprovides(pkg REL_WITH path)
45 * and is only true if pkg is installed and contains the specified path.
46 * we also make sure that pkg is selected for an update, otherwise the
47 * update would always be forced onto the user.
48 * Map m is the map used when called from dep_possible.
52 solver_is_updating(Solver *solv, Id p)
54 /* check if the update rule is true */
55 Pool *pool = solv->pool;
58 if (solv->decisionmap[p] >= 0)
59 return 0; /* old package stayed */
60 r = solv->rules + solv->updaterules + (p - solv->installed->start);
61 FOR_RULELITERALS(l, pp, r)
62 if (l > 0 && l != p && solv->decisionmap[l] > 0)
68 solver_splitprovides(Solver *solv, Id dep, Map *m)
70 Pool *pool = solv->pool;
75 if (!solv->dosplitprovides || !solv->installed)
79 rd = GETRELDEP(pool, dep);
80 if (rd->flags != REL_WITH)
83 * things are a bit tricky here if pool->addedprovides == 1, because most split-provides are in
84 * a non-standard location. If we simply call pool_whatprovides, we'll drag in the complete
85 * file list. Instead we rely on pool_addfileprovides ignoring the addfileprovidesfiltered flag
86 * for installed packages and check the lazywhatprovidesq (ignoring the REL_WITH part, but
87 * we filter the package name further down anyway).
89 if (pool->addedfileprovides == 1 && !ISRELDEP(rd->evr) && !pool->whatprovides[rd->evr])
90 pp = pool_searchlazywhatprovidesq(pool, rd->evr);
92 pp = pool_whatprovides(pool, dep);
93 while ((p = pool->whatprovidesdata[pp++]) != 0)
95 /* here we have packages that provide the correct name and contain the path,
96 * now do extra filtering */
97 s = pool->solvables + p;
98 if (s->repo != solv->installed || s->name != rd->name)
100 /* check if the package is updated. if m is set, we're called from dep_possible */
101 if (m || solver_is_updating(solv, p))
108 /* mirrors solver_dep_fulfilled, but returns 2 if a new package
111 solver_dep_fulfilled_alreadyinstalled(Solver *solv, Id dep)
113 Pool *pool = solv->pool;
119 Reldep *rd = GETRELDEP(pool, dep);
120 if (rd->flags == REL_COND)
123 if (ISRELDEP(rd->evr))
125 Reldep *rd2 = GETRELDEP(pool, rd->evr);
126 if (rd2->flags == REL_ELSE)
128 r1 = solver_dep_fulfilled_alreadyinstalled(solv, rd2->name);
131 r2 = solver_dep_fulfilled_alreadyinstalled(solv, rd->name);
132 return r2 && r1 == 2 ? 2 : r2;
134 return solver_dep_fulfilled_alreadyinstalled(solv, rd2->evr);
137 r1 = solver_dep_fulfilled_alreadyinstalled(solv, rd->name);
138 r2 = !solver_dep_fulfilled_alreadyinstalled(solv, rd->evr);
141 return r1 == 2 ? 2 : 1;
143 if (rd->flags == REL_AND)
145 int r2, r1 = solver_dep_fulfilled_alreadyinstalled(solv, rd->name);
148 r2 = solver_dep_fulfilled_alreadyinstalled(solv, rd->evr);
151 return r1 == 2 || r2 == 2 ? 2 : 1;
153 if (rd->flags == REL_OR)
155 int r2, r1 = solver_dep_fulfilled_alreadyinstalled(solv, rd->name);
156 r2 = solver_dep_fulfilled_alreadyinstalled(solv, rd->evr);
159 return r1 == 2 || r2 == 2 ? 2 : 1;
161 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
162 return solver_splitprovides(solv, rd->evr, 0);
163 if (rd->flags == REL_NAMESPACE && solv->installsuppdepq)
165 Queue *q = solv->installsuppdepq;
167 for (i = 0; i < q->count; i++)
168 if (q->elements[i] == dep || q->elements[i] == rd->name)
173 FOR_PROVIDES(p, pp, dep)
174 if (solv->decisionmap[p] > 0)
176 Solvable *s = pool->solvables + p;
177 if (s->repo && s->repo != solv->installed)
185 solver_is_supplementing_alreadyinstalled(Solver *solv, Solvable *s)
188 supp = s->repo->idarraydata + s->supplements;
189 while ((sup = *supp++) != 0)
190 if (solver_dep_fulfilled_alreadyinstalled(solv, sup) == 2)
196 autouninstall(Solver *solv, Id *problem)
198 Pool *pool = solv->pool;
200 int lastfeature = 0, lastupdate = 0;
205 if (!solv->allowuninstall && !solv->allowuninstall_all)
207 if (!solv->allowuninstallmap.size)
208 return 0; /* why did we get called? */
209 m = &solv->allowuninstallmap;
211 for (i = 0; (v = problem[i]) != 0; i++)
214 extraflags &= solv->job.elements[-v - 1];
215 if (v >= solv->updaterules && v < solv->updaterules_end)
218 if (m && !MAPTST(m, v - solv->updaterules))
220 /* check if identical to feature rule, we don't like that (except for orphans) */
221 r = solv->rules + solv->featurerules + (v - solv->updaterules);
224 /* update rule == feature rule */
227 /* prefer orphaned packages in dup mode */
228 if (solv->keep_orphans)
231 if (!r->d && !r->w2 && r->p == (solv->installed->start + (v - solv->updaterules)))
244 if (!lastupdate && !lastfeature)
246 v = lastupdate ? lastupdate : lastfeature;
247 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "allowuninstall disabling ");
248 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + v);
249 solver_disableproblem(solv, v);
250 if (extraflags != -1 && (extraflags & SOLVER_CLEANDEPS) != 0 && solv->cleandepsmap.size)
252 /* add the package to the updatepkgs list, this will automatically turn
253 * on cleandeps mode */
254 Id p = solv->rules[v].p;
255 if (!solv->cleandeps_updatepkgs)
257 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
258 queue_init(solv->cleandeps_updatepkgs);
262 int oldupdatepkgscnt = solv->cleandeps_updatepkgs->count;
263 queue_pushunique(solv->cleandeps_updatepkgs, p);
264 if (solv->cleandeps_updatepkgs->count != oldupdatepkgscnt)
265 solver_disablepolicyrules(solv);
271 /************************************************************************/
274 * enable/disable learnt rules
276 * we have enabled or disabled some of our rules. We now reenable all
277 * of our learnt rules except the ones that were learnt from rules that
281 enabledisablelearntrules(Solver *solv)
283 Pool *pool = solv->pool;
288 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
289 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
291 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
292 while ((why = *whyp++) != 0)
294 assert(why > 0 && why < i);
295 if (solv->rules[why].d < 0)
298 /* why != 0: we found a disabled rule, disable the learnt rule */
299 if (why && r->d >= 0)
301 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
303 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "disabling ");
304 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
306 solver_disablerule(solv, r);
308 else if (!why && r->d < 0)
310 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
312 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "re-enabling ");
313 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
315 solver_enablerule(solv, r);
322 * make assertion rules into decisions
324 * Go through rules and add direct assertions to the decisionqueue.
325 * If we find a conflict, disable rules and add them to problem queue.
329 makeruledecisions(Solver *solv)
331 Pool *pool = solv->pool;
336 int record_proof = 1;
338 int havedisabled = 0;
340 /* The system solvable is always installed first */
341 assert(solv->decisionq.count == 0);
342 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
343 queue_push(&solv->decisionq_why, 0);
344 queue_push2(&solv->decisionq_reason, 0, 0);
345 solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
347 decisionstart = solv->decisionq.count;
350 /* if we needed to re-run, back up decisions to decisionstart */
351 while (solv->decisionq.count > decisionstart)
353 v = solv->decisionq.elements[--solv->decisionq.count];
354 --solv->decisionq_why.count;
356 solv->decisionmap[vv] = 0;
359 /* note that the ruleassertions queue is ordered */
360 for (ii = 0; ii < solv->ruleassertions.count; ii++)
362 ri = solv->ruleassertions.elements[ii];
363 r = solv->rules + ri;
365 if (havedisabled && ri >= solv->learntrules)
367 /* just started with learnt rule assertions. If we have disabled
368 * some rules, adapt the learnt rule status */
369 enabledisablelearntrules(solv);
373 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
376 /* do weak rules in phase 2 */
377 if (ri < solv->learntrules && solv->weakrulemap.size && MAPTST(&solv->weakrulemap, ri))
383 if (!solv->decisionmap[vv]) /* if not yet decided */
385 queue_push(&solv->decisionq, v);
386 queue_push(&solv->decisionq_why, r - solv->rules);
387 solv->decisionmap[vv] = v > 0 ? 1 : -1;
388 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
390 Solvable *s = solv->pool->solvables + vv;
392 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", pool_solvable2str(solv->pool, s));
394 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (assertion)\n", pool_solvable2str(solv->pool, s));
399 /* check against previous decision: is there a conflict? */
400 if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
402 if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
408 * The rule (r) we're currently processing says something
409 * different (v = r->p) than a previous decision (decisionmap[abs(v)])
413 if (ri >= solv->learntrules)
415 /* conflict with a learnt rule */
416 /* can happen when packages cannot be installed for multiple reasons. */
417 /* we disable the learnt rule in this case */
418 /* (XXX: we should really call analyze_unsolvable_rule here!) */
419 solver_disablerule(solv, r);
424 * find the decision which is the "opposite" of the rule
426 for (i = 0; i < solv->decisionq.count; i++)
427 if (solv->decisionq.elements[i] == -v)
429 assert(i < solv->decisionq.count); /* assert that we found it */
430 oldproblemcount = solv->problems.count;
433 * conflict with system solvable ?
435 if (v == -SYSTEMSOLVABLE)
439 queue_push(&solv->problems, solv->learnt_pool.count);
440 queue_push(&solv->learnt_pool, ri);
441 queue_push(&solv->learnt_pool, 0);
444 queue_push(&solv->problems, 0);
445 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
446 if (ri >= solv->jobrules && ri < solv->jobrules_end)
447 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
450 queue_push(&solv->problems, v);
451 queue_push(&solv->problems, 0);
452 if (v >= solv->featurerules && v < solv->updaterules_end)
454 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
455 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
457 solv->problems.count = oldproblemcount;
459 break; /* start over */
462 solver_disableproblem(solv, v);
464 break; /* start over */
467 assert(solv->decisionq_why.elements[i] > 0);
470 * conflict with a pkg rule ?
472 if (solv->decisionq_why.elements[i] < solv->pkgrules_end)
476 queue_push(&solv->problems, solv->learnt_pool.count);
477 queue_push(&solv->learnt_pool, ri);
478 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
479 queue_push(&solv->learnt_pool, 0);
482 queue_push(&solv->problems, 0);
483 assert(v > 0 || v == -SYSTEMSOLVABLE);
484 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with pkg rule, disabling rule #%d\n", ri);
485 if (ri >= solv->jobrules && ri < solv->jobrules_end)
486 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
489 queue_push(&solv->problems, v);
490 queue_push(&solv->problems, 0);
491 if (v >= solv->featurerules && v < solv->updaterules_end)
493 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
494 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
496 solv->problems.count = oldproblemcount;
498 break; /* start over */
501 solver_disableproblem(solv, v);
503 break; /* start over */
507 * conflict with another job or update/feature rule
513 queue_push(&solv->problems, solv->learnt_pool.count);
514 queue_push(&solv->learnt_pool, ri);
515 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
516 queue_push(&solv->learnt_pool, 0);
519 queue_push(&solv->problems, 0);
521 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
524 * push all of our rules (can only be feature or job rules)
525 * asserting this literal on the problem stack
527 for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
529 if (rr->d < 0 /* disabled */
530 || rr->w2) /* or no assertion */
532 if (rr->p != vv /* not affecting the literal */
535 if (solv->weakrulemap.size && MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
538 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
539 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + i);
542 if (i >= solv->jobrules && i < solv->jobrules_end)
543 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
544 queue_push(&solv->problems, v);
546 queue_push(&solv->problems, 0);
548 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
549 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
551 solv->problems.count = oldproblemcount;
553 break; /* start over */
556 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
557 solver_disableproblem(solv, solv->problems.elements[i]);
559 break; /* start over */
561 if (ii < solv->ruleassertions.count)
565 * phase 2: now do the weak assertions
567 if (!solv->weakrulemap.size)
568 break; /* no weak rules, no phase 2 */
569 for (ii = 0; ii < solv->ruleassertions.count; ii++)
571 ri = solv->ruleassertions.elements[ii];
572 r = solv->rules + ri;
573 if (r->d < 0 || r->w2) /* disabled or no assertion */
575 if (ri >= solv->learntrules || !MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
580 if (!solv->decisionmap[vv]) /* if not yet decided */
582 queue_push(&solv->decisionq, v);
583 queue_push(&solv->decisionq_why, r - solv->rules);
584 solv->decisionmap[vv] = v > 0 ? 1 : -1;
585 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
587 Solvable *s = solv->pool->solvables + vv;
589 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
591 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
595 /* check against previous decision: is there a conflict? */
596 if (v > 0 && solv->decisionmap[vv] > 0)
598 if (v < 0 && solv->decisionmap[vv] < 0)
601 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
602 solver_printrule(solv, SOLV_DEBUG_UNSOLVABLE, r);
604 if (ri >= solv->jobrules && ri < solv->jobrules_end)
605 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
608 solver_disableproblem(solv, v);
610 solver_reenablepolicyrules(solv, -v);
612 break; /* start over */
614 if (ii == solv->ruleassertions.count)
615 break; /* finished! */
620 /********************************************************************/
624 /*-------------------------------------------------------------------
627 * initial setup for all watches
631 makewatches(Solver *solv)
635 int nsolvables = solv->pool->nsolvables;
637 solv_free(solv->watches);
638 /* lower half for removals, upper half for installs */
639 solv->watches = solv_calloc(2 * nsolvables, sizeof(Id));
640 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
642 if (!r->w2) /* assertions do not need watches */
645 /* see addwatches_rule(solv, r) */
646 r->n1 = solv->watches[nsolvables + r->w1];
647 solv->watches[nsolvables + r->w1] = r - solv->rules;
649 r->n2 = solv->watches[nsolvables + r->w2];
650 solv->watches[nsolvables + r->w2] = r - solv->rules;
655 /*-------------------------------------------------------------------
657 * add watches (for a new learned rule)
658 * sets up watches for a single rule
660 * see also makewatches() above.
664 addwatches_rule(Solver *solv, Rule *r)
666 int nsolvables = solv->pool->nsolvables;
668 r->n1 = solv->watches[nsolvables + r->w1];
669 solv->watches[nsolvables + r->w1] = r - solv->rules;
671 r->n2 = solv->watches[nsolvables + r->w2];
672 solv->watches[nsolvables + r->w2] = r - solv->rules;
676 /********************************************************************/
682 /* shortcuts to check if a literal (positive or negative) assignment
683 * evaluates to 'true' or 'false'
685 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
686 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
687 #define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
689 /*-------------------------------------------------------------------
693 * make decision and propagate to all rules
695 * Evaluate each term affected by the decision (linked through watches).
696 * If we find unit rules we make new decisions based on them.
698 * return : 0 = everything is OK
699 * rule = conflict found in this rule
703 propagate(Solver *solv, int level)
705 Pool *pool = solv->pool;
706 Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
708 Id p, pkg, other_watch;
710 Id *decisionmap = solv->decisionmap;
711 Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
713 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate -----\n");
715 /* foreach non-propagated decision */
716 while (solv->propagate_index < solv->decisionq.count)
719 * 'pkg' was just decided
720 * negate because our watches trigger if literal goes FALSE
722 pkg = -solv->decisionq.elements[solv->propagate_index++];
724 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
726 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
727 solver_printruleelement(solv, SOLV_DEBUG_PROPAGATE, 0, -pkg);
730 /* foreach rule where 'pkg' is now FALSE */
731 for (rp = watches + pkg; *rp; rp = next_rp)
733 r = solv->rules + *rp;
736 /* rule is disabled, goto next */
744 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
746 POOL_DEBUG(SOLV_DEBUG_PROPAGATE," watch triggered ");
747 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
751 * 'pkg' was just decided (was set to FALSE), so this rule
754 /* find the other watch */
767 * if the other watch is true we have nothing to do
769 if (DECISIONMAP_TRUE(other_watch))
773 * The other literal is FALSE or UNDEF
779 /* Not a binary clause, try to move our watch.
781 * Go over all literals and find one that is
785 * (TRUE is also ok, in that case the rule is fulfilled)
786 * As speed matters here we do not use the FOR_RULELITERALS
789 if (r->p /* we have a 'p' */
790 && r->p != other_watch /* which is not watched */
791 && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
795 else /* go find a 'd' to make 'true' */
798 we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
800 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
802 if (p != other_watch /* which is not watched */
803 && !DECISIONMAP_FALSE(p)) /* and not FALSE */
811 * if we found some p that is UNDEF or TRUE, move
814 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
817 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, p));
819 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, -p));
835 watches[p] = r - solv->rules;
838 /* search failed, thus all unwatched literals are FALSE */
843 * unit clause found, set literal other_watch to TRUE
846 if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
847 return r; /* eek, a conflict! */
849 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
851 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " unit ");
852 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
856 decisionmap[other_watch] = level; /* install! */
858 decisionmap[-other_watch] = -level; /* remove! */
860 queue_push(&solv->decisionq, other_watch);
861 queue_push(&solv->decisionq_why, r - solv->rules);
863 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
866 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to install %s\n", pool_solvid2str(pool, other_watch));
868 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to conflict %s\n", pool_solvid2str(pool, -other_watch));
871 } /* foreach rule involving 'pkg' */
873 } /* while we have non-decided decisions */
875 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate end-----\n");
877 return 0; /* all is well */
881 /********************************************************************/
884 /*-------------------------------------------------------------------
887 * revert decisionq to a level
891 revert(Solver *solv, int level)
893 Pool *pool = solv->pool;
895 while (solv->decisionq.count)
897 v = solv->decisionq.elements[solv->decisionq.count - 1];
899 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
901 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
902 solv->decisionmap[vv] = 0;
903 solv->decisionq.count--;
904 solv->decisionq_why.count--;
905 solv->propagate_index = solv->decisionq.count;
907 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= level)
908 solv->branches.count -= solv->branches.elements[solv->branches.count - 2];
909 if (solv->recommends_index > solv->decisionq.count)
910 solv->recommends_index = -1; /* rebuild recommends/suggests maps */
911 solv->decisionq_reason.count = level + 1;
914 /*-------------------------------------------------------------------
916 * watch2onhighest - put watch2 on literal with highest level
920 watch2onhighest(Solver *solv, Rule *r)
925 d = r->d < 0 ? -r->d - 1 : r->d;
927 return; /* binary rule, both watches are set */
928 dp = solv->pool->whatprovidesdata + d;
929 while ((v = *dp++) != 0)
931 l = solv->decisionmap[v < 0 ? -v : v];
943 /*-------------------------------------------------------------------
950 analyze(Solver *solv, int level, Rule *c, Rule **lrp)
952 Pool *pool = solv->pool;
957 Map seen; /* global? */
958 Id p = 0, pp, v, vv, why;
960 int num = 0, l1num = 0;
961 int learnt_why = solv->learnt_pool.count;
962 Id *decisionmap = solv->decisionmap;
964 queue_init_buffer(&q, q_buf, sizeof(q_buf)/sizeof(*q_buf));
966 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
967 map_init(&seen, pool->nsolvables);
968 idx = solv->decisionq.count;
971 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
972 solver_printruleclass(solv, SOLV_DEBUG_ANALYZE, c);
973 queue_push(&solv->learnt_pool, c - solv->rules);
974 FOR_RULELITERALS(v, pp, c)
976 if (DECISIONMAP_TRUE(v)) /* the one true literal */
979 if (MAPTST(&seen, vv))
981 MAPSET(&seen, vv); /* mark that we also need to look at this literal */
982 l = solv->decisionmap[vv];
986 l1num++; /* need to do this one in level1 pass */
988 num++; /* need to do this one as well */
991 queue_push(&q, v); /* not level1 or conflict level, add to new rule */
997 if (!num && !--l1num)
998 break; /* all literals done */
1000 /* find the next literal to investigate */
1001 /* (as num + l1num > 0, we know that we'll always find one) */
1005 v = solv->decisionq.elements[--idx];
1006 vv = v > 0 ? v : -v;
1007 if (MAPTST(&seen, vv))
1012 if (num && --num == 0)
1014 /* done with normal literals, now start level 1 literal processing */
1015 p = -v; /* so that v doesn't get lost */
1018 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1019 /* clear non-l1 bits from seen map */
1020 for (i = 0; i < q.count; i++)
1023 MAPCLR(&seen, v > 0 ? v : -v);
1025 /* only level 1 marks left in seen map */
1026 l1num++; /* as l1retry decrements it */
1030 why = solv->decisionq_why.elements[idx];
1031 if (why <= 0) /* just in case, maybe for SYSTEMSOLVABLE */
1033 c = solv->rules + why;
1037 assert(rlevel > 0 && rlevel < level);
1038 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
1040 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1041 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, p);
1042 for (i = 0; i < q.count; i++)
1043 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, q.elements[i]);
1045 /* push end marker on learnt reasons stack */
1046 queue_push(&solv->learnt_pool, 0);
1047 solv->stats_learned++;
1049 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, rlevel);
1051 revert(solv, level);
1054 Id d = q.count ? q.elements[0] : 0;
1056 r = solver_addrule(solv, p, d, 0);
1060 Id d = pool_queuetowhatprovides(pool, &q);
1062 r = solver_addrule(solv, p, 0, d);
1064 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
1065 queue_push(&solv->learnt_why, learnt_why);
1069 watch2onhighest(solv, r);
1070 addwatches_rule(solv, r);
1074 /* rule is an assertion */
1075 queue_push(&solv->ruleassertions, r - solv->rules);
1082 /*-------------------------------------------------------------------
1086 * reset all solver decisions
1087 * called after rules have been enabled/disabled
1091 solver_reset(Solver *solv)
1096 /* rewind all decisions */
1097 for (i = solv->decisionq.count - 1; i >= 0; i--)
1099 v = solv->decisionq.elements[i];
1100 solv->decisionmap[v > 0 ? v : -v] = 0;
1102 queue_empty(&solv->decisionq_why);
1103 queue_empty(&solv->decisionq);
1104 queue_empty(&solv->decisionq_reason);
1105 solv->recommends_index = -1;
1106 solv->propagate_index = 0;
1107 queue_empty(&solv->branches);
1109 /* adapt learnt rule status to new set of enabled/disabled rules */
1110 enabledisablelearntrules(solv);
1114 /*-------------------------------------------------------------------
1116 * analyze_unsolvable_rule
1118 * recursion helper used by analyze_unsolvable
1122 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp, Map *rseen)
1124 Pool *pool = solv->pool;
1126 Id why = r - solv->rules;
1128 IF_POOLDEBUG (SOLV_DEBUG_UNSOLVABLE)
1129 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, r);
1130 if (solv->learntrules && why >= solv->learntrules)
1132 if (MAPTST(rseen, why - solv->learntrules))
1134 MAPSET(rseen, why - solv->learntrules);
1135 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1136 if (solv->learnt_pool.elements[i] > 0)
1137 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp, rseen);
1140 if (solv->weakrulemap.size && MAPTST(&solv->weakrulemap, why))
1141 if (!*lastweakp || why > *lastweakp)
1143 /* do not add pkg rules to problem */
1144 if (why < solv->pkgrules_end)
1146 /* turn rule into problem */
1147 if (why >= solv->jobrules && why < solv->jobrules_end)
1148 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1149 /* normalize dup/infarch rules */
1150 if (why > solv->infarchrules && why < solv->infarchrules_end)
1152 Id name = pool->solvables[-solv->rules[why].p].name;
1153 while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
1156 if (why > solv->duprules && why < solv->duprules_end)
1158 Id name = pool->solvables[-solv->rules[why].p].name;
1159 while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
1163 /* return if problem already countains our rule */
1164 if (solv->problems.count)
1166 for (i = solv->problems.count - 1; i >= 0; i--)
1167 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1169 else if (solv->problems.elements[i] == why)
1172 queue_push(&solv->problems, why);
1176 /*-------------------------------------------------------------------
1178 * analyze_unsolvable (called from setpropagatelearn)
1180 * We know that the problem is not solvable. Record all involved
1181 * rules (i.e. the "proof") into solv->learnt_pool.
1182 * Record the learnt pool index and all non-pkg rules into
1183 * solv->problems. (Our solutions to fix the problems are to
1184 * disable those rules.)
1186 * If the proof contains at least one weak rule, we disable the
1189 * Otherwise we return -1 if disablerules is not set or disable
1190 * _all_ of the problem rules and return 0.
1192 * return: 0 - disabled some rules, try again
1197 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1199 Pool *pool = solv->pool;
1201 Map involved; /* global to speed things up? */
1205 Id *decisionmap = solv->decisionmap;
1206 int oldproblemcount;
1207 int oldlearntpoolcount;
1209 int record_proof = 1;
1211 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1212 solv->stats_unsolvable++;
1213 oldproblemcount = solv->problems.count;
1214 oldlearntpoolcount = solv->learnt_pool.count;
1216 /* make room for proof index */
1217 /* must update it later, as analyze_unsolvable_rule would confuse
1218 * it with a rule index if we put the real value in already */
1219 queue_push(&solv->problems, 0);
1222 map_init(&involved, pool->nsolvables);
1223 map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
1225 queue_push(&solv->learnt_pool, r - solv->rules);
1227 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1228 FOR_RULELITERALS(v, pp, r)
1230 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1232 vv = v > 0 ? v : -v;
1233 MAPSET(&involved, vv);
1235 idx = solv->decisionq.count;
1238 v = solv->decisionq.elements[--idx];
1239 vv = v > 0 ? v : -v;
1240 if (!MAPTST(&involved, vv) || vv == SYSTEMSOLVABLE)
1242 why = solv->decisionq_why.elements[idx];
1245 queue_push(&solv->learnt_pool, why);
1246 r = solv->rules + why;
1247 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1248 FOR_RULELITERALS(v, pp, r)
1250 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1252 vv = v > 0 ? v : -v;
1253 MAPSET(&involved, vv);
1256 map_free(&involved);
1258 queue_push(&solv->problems, 0); /* mark end of this problem */
1262 /* disable last weak rule */
1263 solv->problems.count = oldproblemcount;
1264 solv->learnt_pool.count = oldlearntpoolcount;
1265 if (lastweak >= solv->jobrules && lastweak < solv->jobrules_end)
1266 v = -(solv->ruletojob.elements[lastweak - solv->jobrules] + 1);
1269 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "disabling ");
1270 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + lastweak);
1271 if (lastweak >= solv->choicerules && lastweak < solv->choicerules_end)
1272 solver_disablechoicerules(solv, solv->rules + lastweak);
1273 solver_disableproblem(solv, v);
1275 solver_reenablepolicyrules(solv, -v);
1280 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
1281 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
1283 solv->problems.count = oldproblemcount;
1284 solv->learnt_pool.count = oldlearntpoolcount;
1292 queue_push(&solv->learnt_pool, 0);
1293 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1296 /* + 2: index + trailing zero */
1297 if (disablerules && oldproblemcount + 2 < solv->problems.count)
1299 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1300 solver_disableproblem(solv, solv->problems.elements[i]);
1301 /* XXX: might want to enable all weak rules again */
1305 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1310 /*-------------------------------------------------------------------
1314 * add free decision (solvable to install) to decisionq
1315 * increase level and propagate decision
1316 * return if no conflict.
1318 * in conflict case, analyze conflict rule, add resulting
1319 * rule to learnt rule set, make decision from learnt
1320 * rule (always unit) and re-propagate.
1322 * returns the new solver level or -1 if unsolvable
1327 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules, Id ruleid, Id reason)
1329 Pool *pool = solv->pool;
1336 solv->decisionmap[decision] = level;
1338 solv->decisionmap[-decision] = -level;
1339 queue_push(&solv->decisionq, decision);
1340 queue_push(&solv->decisionq_why, -ruleid); /* <= 0 -> free decision */
1341 queue_push(&solv->decisionq_reason, reason);
1343 assert(ruleid >= 0 && level > 0);
1346 r = propagate(solv, level);
1350 return analyze_unsolvable(solv, r, disablerules);
1351 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1352 level = analyze(solv, level, r, &lr);
1353 /* the new rule is unit by design */
1355 solv->decisionmap[decision > 0 ? decision : -decision] = decision > 0 ? level : -level;
1356 queue_push(&solv->decisionq, decision);
1357 queue_push(&solv->decisionq_why, lr - solv->rules);
1358 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
1360 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "decision: ");
1361 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, decision);
1362 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "new rule: ");
1363 solver_printrule(solv, SOLV_DEBUG_ANALYZE, lr);
1370 reorder_dq_for_future_installed(Solver *solv, int level, Queue *dq)
1372 Pool *pool = solv->pool;
1373 int i, j, haveone = 0, dqcount = dq->count;
1374 int decisionqcount = solv->decisionq.count;
1378 /* at the time we process jobrules the installed packages are not kept yet */
1379 /* reorder so that "future-supplemented" packages come first */
1380 FOR_REPO_SOLVABLES(solv->installed, p, s)
1382 if (MAPTST(&solv->noupdate, p - solv->installed->start))
1384 if (solv->decisionmap[p] == 0)
1386 if (s->recommends || s->suggests)
1387 queue_push(&solv->decisionq, p);
1388 solv->decisionmap[p] = level + 1;
1394 policy_update_recommendsmap(solv);
1395 for (i = 0; i < dqcount; i++)
1397 p = dq->elements[i];
1398 if (!(pool->solvables[p].repo == solv->installed || MAPTST(&solv->suggestsmap, p) || solver_is_enhancing(solv, pool->solvables + p)))
1401 dq->elements[i] = 0;
1404 dqcount = dq->count;
1405 for (i = 0; i < dqcount; i++)
1407 p = dq->elements[i];
1408 if (p && !(pool->solvables[p].repo == solv->installed || MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
1411 dq->elements[i] = 0;
1414 for (i = j = 0; i < dq->count; i++)
1415 if (dq->elements[i])
1416 dq->elements[j++] = dq->elements[i];
1417 queue_truncate(dq, j);
1418 FOR_REPO_SOLVABLES(solv->installed, p, s)
1419 if (solv->decisionmap[p] == level + 1)
1420 solv->decisionmap[p] = 0;
1421 if (solv->decisionq.count != decisionqcount)
1423 solv->recommends_index = -1;
1424 queue_truncate(&solv->decisionq, decisionqcount);
1426 /* but obey favored maps */
1427 policy_prefer_favored(solv, dq);
1430 /*-------------------------------------------------------------------
1436 createbranch(Solver *solv, int level, Queue *dq, Id p, Id data)
1438 Pool *pool = solv->pool;
1440 IF_POOLDEBUG (SOLV_DEBUG_POLICY)
1442 POOL_DEBUG (SOLV_DEBUG_POLICY, "creating a branch:\n");
1443 for (i = 0; i < dq->count; i++)
1444 POOL_DEBUG (SOLV_DEBUG_POLICY, " - %s\n", pool_solvid2str(pool, dq->elements[i]));
1446 queue_push(&solv->branches, -dq->elements[0]);
1447 for (i = 1; i < dq->count; i++)
1448 queue_push(&solv->branches, dq->elements[i]);
1449 queue_push2(&solv->branches, p, data);
1450 queue_push2(&solv->branches, dq->count + 4, level);
1454 takebranch(Solver *solv, int pos, int end, const char *msg, int disablerules)
1456 Pool *pool = solv->pool;
1462 printf("branch group level %d [%d-%d] %d %d:\n", solv->branches.elements[end - 1], start, end, solv->branches.elements[end - 4], solv->branches.elements[end - 3]);
1463 for (i = end - solv->branches.elements[end - 2]; i < end - 4; i++)
1464 printf("%c %c%s\n", i == pos ? 'x' : ' ', solv->branches.elements[i] >= 0 ? ' ' : '-', pool_solvid2str(pool, solv->branches.elements[i] >= 0 ? solv->branches.elements[i] : -solv->branches.elements[i]));
1467 level = solv->branches.elements[end - 1];
1468 p = solv->branches.elements[pos];
1469 solv->branches.elements[pos] = -p;
1470 POOL_DEBUG(SOLV_DEBUG_SOLVER, "%s %d -> %d with %s\n", msg, solv->decisionmap[p], level, pool_solvid2str(pool, p));
1471 /* hack: set level to zero so that revert does not remove the branch */
1472 solv->branches.elements[end - 1] = 0;
1473 revert(solv, level);
1474 solv->branches.elements[end - 1] = level;
1475 /* hack: revert simply sets the count, so we can still access the reverted elements */
1476 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
1478 reason = solv->decisionq_reason.elements[level + 1];
1479 return setpropagatelearn(solv, level, p, disablerules, why, reason);
1482 /*-------------------------------------------------------------------
1484 * select and install
1486 * install best package from the queue. We add an extra package, inst, if
1487 * provided. See comment in weak install section.
1489 * returns the new solver level or -1 if unsolvable
1494 selectandinstall(Solver *solv, int level, Queue *dq, int disablerules, Id ruleid, Id reason)
1496 Pool *pool = solv->pool;
1500 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
1501 /* if we're resolving rules and didn't resolve the installed packages yet,
1502 * do some special supplements ordering */
1503 if (dq->count > 1 && solv->do_extra_reordering)
1504 reorder_dq_for_future_installed(solv, level, dq);
1505 /* if we have multiple candidates we open a branch */
1507 createbranch(solv, level, dq, 0, ruleid);
1508 p = dq->elements[0];
1509 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing %s\n", pool_solvid2str(pool, p));
1510 return setpropagatelearn(solv, level, p, disablerules, ruleid, reason);
1514 /********************************************************************/
1515 /* Main solver interface */
1518 /*-------------------------------------------------------------------
1521 * create solver structure
1523 * pool: all available solvables
1524 * installed: installed Solvables
1527 * Upon solving, rules are created to flag the Solvables
1528 * of the 'installed' Repo as installed.
1532 solver_create(Pool *pool)
1535 solv = (Solver *)solv_calloc(1, sizeof(Solver));
1537 solv->installed = pool->installed;
1539 solv->allownamechange = 1;
1541 solv->dup_allowdowngrade = 1;
1542 solv->dup_allownamechange = 1;
1543 solv->dup_allowarchchange = 1;
1544 solv->dup_allowvendorchange = 1;
1546 solv->keepexplicitobsoletes = pool->noobsoletesmultiversion ? 0 : 1;
1548 queue_init(&solv->ruletojob);
1549 queue_init(&solv->decisionq);
1550 queue_init(&solv->decisionq_why);
1551 queue_init(&solv->decisionq_reason);
1552 queue_init(&solv->problems);
1553 queue_init(&solv->orphaned);
1554 queue_init(&solv->learnt_why);
1555 queue_init(&solv->learnt_pool);
1556 queue_init(&solv->branches);
1557 queue_init(&solv->weakruleq);
1558 queue_init(&solv->ruleassertions);
1559 queue_init(&solv->addedmap_deduceq);
1561 queue_push(&solv->learnt_pool, 0); /* so that 0 does not describe a proof */
1563 map_init(&solv->recommendsmap, pool->nsolvables);
1564 map_init(&solv->suggestsmap, pool->nsolvables);
1565 map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
1566 solv->recommends_index = 0;
1568 solv->decisionmap = (Id *)solv_calloc(pool->nsolvables, sizeof(Id));
1570 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
1571 memset(solv->rules, 0, sizeof(Rule));
1578 /*-------------------------------------------------------------------
1584 queuep_free(Queue **qp)
1589 *qp = solv_free(*qp);
1593 map_zerosize(Map *m)
1603 solver_free(Solver *solv)
1605 queue_free(&solv->job);
1606 queue_free(&solv->ruletojob);
1607 queue_free(&solv->decisionq);
1608 queue_free(&solv->decisionq_why);
1609 queue_free(&solv->decisionq_reason);
1610 queue_free(&solv->learnt_why);
1611 queue_free(&solv->learnt_pool);
1612 queue_free(&solv->problems);
1613 queue_free(&solv->solutions);
1614 queue_free(&solv->orphaned);
1615 queue_free(&solv->branches);
1616 queue_free(&solv->weakruleq);
1617 queue_free(&solv->ruleassertions);
1618 queue_free(&solv->addedmap_deduceq);
1619 queuep_free(&solv->cleandeps_updatepkgs);
1620 queuep_free(&solv->cleandeps_mistakes);
1621 queuep_free(&solv->update_targets);
1622 queuep_free(&solv->installsuppdepq);
1623 queuep_free(&solv->recommendscplxq);
1624 queuep_free(&solv->suggestscplxq);
1625 queuep_free(&solv->brokenorphanrules);
1626 queuep_free(&solv->favorq);
1627 queuep_free(&solv->recommendsruleq);
1629 map_free(&solv->recommendsmap);
1630 map_free(&solv->suggestsmap);
1631 map_free(&solv->noupdate);
1632 map_free(&solv->weakrulemap);
1633 map_free(&solv->multiversion);
1635 map_free(&solv->updatemap);
1636 map_free(&solv->bestupdatemap);
1637 map_free(&solv->fixmap);
1638 map_free(&solv->dupmap);
1639 map_free(&solv->dupinvolvedmap);
1640 map_free(&solv->droporphanedmap);
1641 map_free(&solv->cleandepsmap);
1642 map_free(&solv->allowuninstallmap);
1643 map_free(&solv->favormap);
1644 map_free(&solv->isdisfavormap);
1646 solv_free(solv->decisionmap);
1647 solv_free(solv->rules);
1648 solv_free(solv->watches);
1649 solv_free(solv->obsoletes);
1650 solv_free(solv->obsoletes_data);
1651 solv_free(solv->specialupdaters);
1652 solv_free(solv->choicerules_ref);
1653 solv_free(solv->bestrules_pkg);
1654 solv_free(solv->yumobsrules_info);
1655 solv_free(solv->instbuddy);
1660 solver_get_flag(Solver *solv, int flag)
1664 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1665 return solv->allowdowngrade;
1666 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1667 return solv->allownamechange;
1668 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1669 return solv->allowarchchange;
1670 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1671 return solv->allowvendorchange;
1672 case SOLVER_FLAG_ALLOW_UNINSTALL:
1673 return solv->allowuninstall;
1674 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1675 return solv->noupdateprovide;
1676 case SOLVER_FLAG_SPLITPROVIDES:
1677 return solv->dosplitprovides;
1678 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1679 return solv->dontinstallrecommended;
1680 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1681 return solv->addalreadyrecommended;
1682 case SOLVER_FLAG_NO_INFARCHCHECK:
1683 return solv->noinfarchcheck;
1684 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1685 return solv->keepexplicitobsoletes;
1686 case SOLVER_FLAG_BEST_OBEY_POLICY:
1687 return solv->bestobeypolicy;
1688 case SOLVER_FLAG_NO_AUTOTARGET:
1689 return solv->noautotarget;
1690 case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
1691 return solv->dup_allowdowngrade;
1692 case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
1693 return solv->dup_allownamechange;
1694 case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
1695 return solv->dup_allowarchchange;
1696 case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
1697 return solv->dup_allowvendorchange;
1698 case SOLVER_FLAG_KEEP_ORPHANS:
1699 return solv->keep_orphans;
1700 case SOLVER_FLAG_BREAK_ORPHANS:
1701 return solv->break_orphans;
1702 case SOLVER_FLAG_FOCUS_INSTALLED:
1703 return solv->focus_installed;
1704 case SOLVER_FLAG_FOCUS_BEST:
1705 return solv->focus_best;
1706 case SOLVER_FLAG_YUM_OBSOLETES:
1707 return solv->do_yum_obsoletes;
1708 case SOLVER_FLAG_NEED_UPDATEPROVIDE:
1709 return solv->needupdateprovide;
1710 case SOLVER_FLAG_URPM_REORDER:
1711 return solv->urpmreorder;
1712 case SOLVER_FLAG_STRONG_RECOMMENDS:
1713 return solv->strongrecommends;
1714 case SOLVER_FLAG_INSTALL_ALSO_UPDATES:
1715 return solv->install_also_updates;
1723 solver_set_flag(Solver *solv, int flag, int value)
1725 int old = solver_get_flag(solv, flag);
1728 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1729 solv->allowdowngrade = value;
1731 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1732 solv->allownamechange = value;
1734 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1735 solv->allowarchchange = value;
1737 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1738 solv->allowvendorchange = value;
1740 case SOLVER_FLAG_ALLOW_UNINSTALL:
1741 solv->allowuninstall = value;
1743 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1744 solv->noupdateprovide = value;
1746 case SOLVER_FLAG_SPLITPROVIDES:
1747 solv->dosplitprovides = value;
1749 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1750 solv->dontinstallrecommended = value;
1752 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1753 solv->addalreadyrecommended = value;
1755 case SOLVER_FLAG_NO_INFARCHCHECK:
1756 solv->noinfarchcheck = value;
1758 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1759 solv->keepexplicitobsoletes = value;
1761 case SOLVER_FLAG_BEST_OBEY_POLICY:
1762 solv->bestobeypolicy = value;
1764 case SOLVER_FLAG_NO_AUTOTARGET:
1765 solv->noautotarget = value;
1767 case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
1768 solv->dup_allowdowngrade = value;
1770 case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
1771 solv->dup_allownamechange = value;
1773 case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
1774 solv->dup_allowarchchange = value;
1776 case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
1777 solv->dup_allowvendorchange = value;
1779 case SOLVER_FLAG_KEEP_ORPHANS:
1780 solv->keep_orphans = value;
1782 case SOLVER_FLAG_BREAK_ORPHANS:
1783 solv->break_orphans = value;
1785 case SOLVER_FLAG_FOCUS_INSTALLED:
1786 solv->focus_installed = value;
1788 case SOLVER_FLAG_FOCUS_BEST:
1789 solv->focus_best = value;
1791 case SOLVER_FLAG_YUM_OBSOLETES:
1792 solv->do_yum_obsoletes = value;
1794 case SOLVER_FLAG_NEED_UPDATEPROVIDE:
1795 solv->needupdateprovide = value;
1797 case SOLVER_FLAG_URPM_REORDER:
1798 solv->urpmreorder = value;
1800 case SOLVER_FLAG_STRONG_RECOMMENDS:
1801 solv->strongrecommends = value;
1803 case SOLVER_FLAG_INSTALL_ALSO_UPDATES:
1804 solv->install_also_updates = value;
1813 resolve_jobrules(Solver *solv, int level, int disablerules, Queue *dq)
1815 Pool *pool = solv->pool;
1816 int oldlevel = level;
1820 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving job rules\n");
1821 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
1824 if (r->d < 0) /* ignore disabled rules */
1827 FOR_RULELITERALS(l, pp, r)
1831 if (solv->decisionmap[-l] <= 0)
1836 if (solv->decisionmap[l] > 0)
1838 if (solv->decisionmap[l] == 0)
1842 if (l || !dq->count)
1844 /* prune to installed if not updating */
1845 if (dq->count > 1 && solv->installed && !solv->updatemap_all &&
1846 !solv->install_also_updates &&
1847 !(solv->job.elements[solv->ruletojob.elements[i - solv->jobrules]] & SOLVER_ORUPDATE))
1849 int j = dq->count, k;
1850 if (solv->updatemap.size)
1852 /* do not prune if an installed package wants to be updated */
1853 for (j = 0; j < dq->count; j++)
1854 if (pool->solvables[dq->elements[j]].repo == solv->installed
1855 && MAPTST(&solv->updatemap, dq->elements[j] - solv->installed->start))
1860 for (j = k = 0; j < dq->count; j++)
1861 if (pool->solvables[dq->elements[j]].repo == solv->installed)
1862 dq->elements[k++] = dq->elements[j];
1868 level = selectandinstall(solv, level, dq, disablerules, i, SOLVER_REASON_RESOLVE_JOB);
1869 if (level <= olevel)
1871 if (level == olevel)
1875 continue; /* try something else */
1877 if (level < oldlevel)
1879 /* redo from start of jobrules */
1880 i = solv->jobrules - 1;
1881 r = solv->rules + i;
1888 cleandeps_check_mistakes(Solver *solv)
1890 Pool *pool = solv->pool;
1894 int mademistake = 0;
1896 if (!solv->cleandepsmap.size)
1898 /* check for mistakes */
1899 for (i = solv->installed->start; i < solv->installed->end; i++)
1901 if (!MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1903 r = solv->rules + solv->featurerules + (i - solv->installed->start);
1904 /* a mistake is when the featurerule is true but the updaterule is false */
1907 FOR_RULELITERALS(p, pp, r)
1908 if (p > 0 && solv->decisionmap[p] > 0)
1911 continue; /* feature rule is not true */
1912 r = solv->rules + solv->updaterules + (i - solv->installed->start);
1915 FOR_RULELITERALS(p, pp, r)
1916 if (p > 0 && solv->decisionmap[p] > 0)
1919 continue; /* update rule is true */
1920 POOL_DEBUG(SOLV_DEBUG_SOLVER, "cleandeps mistake: ");
1921 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, r);
1922 POOL_DEBUG(SOLV_DEBUG_SOLVER, "feature rule: ");
1923 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, solv->rules + solv->featurerules + (i - solv->installed->start));
1924 if (!solv->cleandeps_mistakes)
1926 solv->cleandeps_mistakes = solv_calloc(1, sizeof(Queue));
1927 queue_init(solv->cleandeps_mistakes);
1929 queue_push(solv->cleandeps_mistakes, i);
1930 MAPCLR(&solv->cleandepsmap, i - solv->installed->start);
1931 solver_reenablepolicyrules_cleandeps(solv, i);
1938 prune_to_update_targets(Solver *solv, Id *cp, Queue *q)
1942 for (i = j = 0; i < q->count; i++)
1945 for (cp2 = cp; *cp2; cp2++)
1948 q->elements[j++] = p;
1952 queue_truncate(q, j);
1956 resolve_installed(Solver *solv, int level, int disablerules, Queue *dq)
1958 Pool *pool = solv->pool;
1959 Repo *installed = solv->installed;
1961 int installedpos = solv->installedpos;
1964 int olevel, origlevel = level;
1966 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving installed packages\n");
1968 installedpos = installed->start;
1969 /* we use two passes if we need to update packages
1970 * to create a better user experience */
1971 for (pass = solv->updatemap.size ? 0 : 1; pass < 2; )
1973 int passlevel = level;
1974 Id *specialupdaters = solv->specialupdaters;
1975 /* start with installedpos, the position that gave us problems the last time */
1976 for (i = installedpos, n = installed->start; n < installed->end; i++, n++)
1981 if (i == installed->end)
1982 i = installed->start;
1983 s = pool->solvables + i;
1984 if (s->repo != installed)
1987 if (solv->decisionmap[i] > 0 && (!specialupdaters || !specialupdaters[i - installed->start]))
1988 continue; /* already decided */
1989 if (!pass && solv->updatemap.size && !MAPTST(&solv->updatemap, i - installed->start))
1990 continue; /* updates first */
1991 r = solv->rules + solv->updaterules + (i - installed->start);
1993 if (!rr->p || rr->d < 0) /* disabled -> look at feature rule */
1994 rr -= solv->installed->end - solv->installed->start;
1995 if (!rr->p) /* identical to update rule? */
1998 continue; /* orpaned package or pseudo package */
2000 /* check if we should update this package to the latest version
2001 * noupdate is set for erase jobs, in that case we want to deinstall
2002 * the installed package and not replace it with a newer version
2003 * rr->p != i is for dup jobs where the installed package cannot be kept */
2006 if (!MAPTST(&solv->noupdate, i - installed->start) && (solv->decisionmap[i] < 0 || solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, i - installed->start)) || (rr->p && rr->p != i)))
2008 if (specialupdaters && (d = specialupdaters[i - installed->start]) != 0)
2010 /* special multiversion handling, make sure best version is chosen */
2011 if (rr->p == i && solv->decisionmap[i] >= 0)
2013 while ((p = pool->whatprovidesdata[d++]) != 0)
2014 if (solv->decisionmap[p] >= 0)
2016 if (dq->count && solv->update_targets && solv->update_targets->elements[i - installed->start])
2017 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], dq);
2020 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
2021 p = dq->elements[0];
2022 if (p != i && solv->decisionmap[p] == 0)
2024 rr = solv->rules + solv->featurerules + (i - solv->installed->start);
2025 if (!rr->p) /* update rule == feature rule? */
2026 rr = rr - solv->featurerules + solv->updaterules;
2035 /* update to best package of the update rule */
2036 FOR_RULELITERALS(p, pp, rr)
2038 if (solv->decisionmap[p] > 0)
2040 dq->count = 0; /* already fulfilled */
2043 if (!solv->decisionmap[p])
2048 if (dq->count && solv->update_targets && solv->update_targets->elements[i - installed->start])
2049 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], dq);
2050 /* install best version */
2054 level = selectandinstall(solv, level, dq, disablerules, rr - solv->rules, SOLVER_REASON_UPDATE_INSTALLED);
2055 if (level <= olevel)
2057 if (level < passlevel)
2058 break; /* trouble */
2060 n = installed->start; /* redo all */
2066 /* if still undecided keep package */
2067 if (solv->decisionmap[i] == 0)
2070 if (solv->cleandepsmap.size && MAPTST(&solv->cleandepsmap, i - installed->start))
2073 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, i));
2074 level = setpropagatelearn(solv, level, -i, disablerules, 0, SOLVER_REASON_CLEANDEPS_ERASE);
2081 POOL_DEBUG(SOLV_DEBUG_POLICY, "keeping %s\n", pool_solvid2str(pool, i));
2082 level = setpropagatelearn(solv, level, i, disablerules, r - solv->rules, SOLVER_REASON_KEEP_INSTALLED);
2084 if (level <= olevel)
2086 if (level < passlevel)
2087 break; /* trouble */
2089 n = installed->start; /* redo all */
2092 continue; /* retry with learnt rule */
2096 if (n < installed->end)
2098 installedpos = i; /* retry problem solvable next time */
2099 if (level < origlevel)
2100 break; /* ran into trouble */
2101 /* re-run all passes */
2102 pass = solv->updatemap.size ? 0 : 1;
2105 /* reset installedpos, advance to next pass */
2106 installedpos = installed->start;
2109 solv->installedpos = installedpos;
2114 resolve_dependencies(Solver *solv, int level, int disablerules, Queue *dq)
2116 Pool *pool = solv->pool;
2120 int origlevel = level;
2126 POOL_DEBUG(SOLV_DEBUG_POLICY, "deciding unresolved rules\n");
2128 for (i = 1, n = 1; ; i++, n++)
2130 if (n >= solv->nrules)
2138 if (i == solv->nrules)
2140 r = solv->rules + i;
2141 if (r->d < 0) /* ignore disabled rules */
2143 if (r->p < 0) /* most common cases first */
2145 if (r->d == 0 || solv->decisionmap[-r->p] <= 0)
2152 /* binary or unary rule */
2153 /* need two positive undecided literals, r->p already checked above */
2156 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2158 queue_push(dq, r->p);
2159 queue_push(dq, r->w2);
2164 * all negative literals are installed
2165 * no positive literal is installed
2166 * i.e. the rule is not fulfilled and we
2167 * just need to decide on the positive literals
2168 * (decisionmap[-r->p] for the r->p < 0 case is already checked above)
2172 if (solv->decisionmap[r->p] > 0)
2174 if (solv->decisionmap[r->p] == 0)
2175 queue_push(dq, r->p);
2177 dp = pool->whatprovidesdata + r->d;
2178 while ((p = *dp++) != 0)
2182 if (solv->decisionmap[-p] <= 0)
2187 if (solv->decisionmap[p] > 0)
2189 if (solv->decisionmap[p] == 0)
2196 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
2198 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "unfulfilled ");
2199 solver_printruleclass(solv, SOLV_DEBUG_PROPAGATE, r);
2201 /* dq->count < 2 cannot happen as this means that
2202 * the rule is unit */
2203 assert(dq->count > 1);
2205 /* prune to cleandeps packages */
2206 if (solv->cleandepsmap.size && solv->installed)
2208 Repo *installed = solv->installed;
2209 for (j = 0; j < dq->count; j++)
2210 if (pool->solvables[dq->elements[j]].repo == installed && MAPTST(&solv->cleandepsmap, dq->elements[j] - installed->start))
2214 dq->elements[0] = dq->elements[j];
2215 queue_truncate(dq, 1);
2219 if (dq->count > 1 && postponed >= 0)
2221 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE_NOREORDER);
2230 level = selectandinstall(solv, level, dq, disablerules, r - solv->rules, SOLVER_REASON_RESOLVE);
2231 if (level < origlevel)
2232 break; /* trouble */
2233 /* something changed, so look at all rules again */
2240 #ifdef ENABLE_COMPLEX_DEPS
2243 add_complex_recommends(Solver *solv, Id rec, Queue *dq, Map *dqmap)
2245 Pool *pool = solv->pool;
2246 int oldcnt = dq->count;
2252 printf("ADD_COMPLEX_RECOMMENDS %s\n", pool_dep2str(pool, rec));
2254 i = pool_normalize_complex_dep(pool, rec, dq, CPLXDEPS_EXPAND);
2255 if (i == 0 || i == 1)
2258 for (i = oldcnt; i < cutcnt; i++)
2261 for (; (p = dq->elements[i]) != 0; i++)
2265 if (solv->decisionmap[-p] <= 0)
2269 if (solv->decisionmap[p] > 0)
2271 queue_truncate(dq, blkcnt);
2276 if (!MAPTST(dqmap, p))
2281 if (solv->decisionmap[p] < 0)
2283 if (solv->dupmap_all && solv->installed && pool->solvables[p].repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))))
2288 while (dq->elements[i])
2291 queue_deleten(dq, oldcnt, cutcnt - oldcnt);
2293 if (dq->count != oldcnt)
2295 for (j = oldcnt; j < dq->count; j++)
2297 p = dq->elements[j];
2298 for (i = 0; i < j; i++)
2299 if (dq->elements[i] == p)
2301 dq->elements[j] = 0;
2305 for (i = j = oldcnt; j < dq->count; j++)
2306 if (dq->elements[j])
2307 dq->elements[i++] = dq->elements[j];
2308 queue_truncate(dq, i);
2311 printf("RETURN:\n");
2312 for (i = oldcnt; i < dq->count; i++)
2313 printf(" - %s\n", pool_solvid2str(pool, dq->elements[i]));
2318 do_complex_recommendations(Solver *solv, Id rec, Map *m, int noselected)
2320 Pool *pool = solv->pool;
2326 printf("DO_COMPLEX_RECOMMENDATIONS %s\n", pool_dep2str(pool, rec));
2329 i = pool_normalize_complex_dep(pool, rec, &dq, CPLXDEPS_EXPAND);
2330 if (i == 0 || i == 1)
2335 for (i = 0; i < dq.count; i++)
2338 for (; (p = dq.elements[i]) != 0; i++)
2342 if (solv->decisionmap[-p] <= 0)
2346 if (solv->decisionmap[p] > 0)
2351 for (i++; (p = dq.elements[i]) != 0; i++)
2352 if (p > 0 && solv->decisionmap[p] > 0)
2360 for (i = blk; (p = dq.elements[i]) != 0; i++)
2364 while (dq.elements[i])
2373 prune_disfavored(Solver *solv, Queue *plist)
2376 if (!solv->isdisfavormap.size)
2378 for (i = j = 0; i < plist->count; i++)
2380 Id p = plist->elements[i];
2381 if (!MAPTST(&solv->isdisfavormap, p))
2382 plist->elements[j++] = p;
2385 queue_truncate(plist, j);
2389 resolve_weak(Solver *solv, int level, int disablerules, Queue *dq, Queue *dqs, int *rerunp)
2391 Pool *pool = solv->pool;
2399 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended packages\n");
2401 queue_empty(dq); /* recommended packages */
2403 queue_empty(dqs); /* supplemented packages */
2404 for (i = 1; i < pool->nsolvables; i++)
2406 if (solv->decisionmap[i] < 0)
2408 s = pool->solvables + i;
2409 if (solv->decisionmap[i] > 0)
2411 /* installed, check for recommends */
2412 Id *recp, rec, pp, p;
2413 if (!solv->addalreadyrecommended && s->repo == solv->installed)
2415 /* XXX need to special case AND ? */
2418 recp = s->repo->idarraydata + s->recommends;
2419 while ((rec = *recp++) != 0)
2421 #ifdef ENABLE_COMPLEX_DEPS
2422 if (pool_is_complex_dep(pool, rec))
2424 add_complex_recommends(solv, rec, dq, 0);
2429 FOR_PROVIDES(p, pp, rec)
2431 if (solv->decisionmap[p] > 0)
2436 else if (solv->decisionmap[p] == 0)
2438 if (solv->dupmap_all && solv->installed && pool->solvables[p].repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))))
2440 queue_pushunique(dq, p);
2448 /* not yet installed, check if supplemented */
2449 if (!s->supplements)
2451 if (!pool_installable(pool, s))
2453 if (!solver_is_supplementing(solv, s))
2455 if (solv->dupmap_all && solv->installed && s->repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, i - solv->installed->start))))
2457 if (solv->isdisfavormap.size && MAPTST(&solv->isdisfavormap, i))
2458 continue; /* disfavored supplements, do not install */
2463 /* filter out disfavored recommended packages */
2464 if (dq->count && solv->isdisfavormap.size)
2465 prune_disfavored(solv, dq);
2467 /* filter out all packages obsoleted by installed packages */
2468 /* this is no longer needed if we have (and trust) reverse obsoletes */
2469 if ((dqs->count || dq->count) && solv->installed)
2472 Id obs, *obsp, po, ppo;
2474 map_init(&obsmap, pool->nsolvables);
2475 for (p = solv->installed->start; p < solv->installed->end; p++)
2477 s = pool->solvables + p;
2478 if (s->repo != solv->installed || !s->obsoletes)
2480 if (solv->decisionmap[p] <= 0)
2482 if (!solv->keepexplicitobsoletes && solv->multiversion.size && MAPTST(&solv->multiversion, p))
2484 obsp = s->repo->idarraydata + s->obsoletes;
2485 /* foreach obsoletes */
2486 while ((obs = *obsp++) != 0)
2487 FOR_PROVIDES(po, ppo, obs)
2489 Solvable *pos = pool->solvables + po;
2490 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pos, obs))
2492 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, pos))
2494 MAPSET(&obsmap, po);
2497 for (i = j = 0; i < dqs->count; i++)
2498 if (!MAPTST(&obsmap, dqs->elements[i]))
2499 dqs->elements[j++] = dqs->elements[i];
2501 for (i = j = 0; i < dq->count; i++)
2502 if (!MAPTST(&obsmap, dq->elements[i]))
2503 dq->elements[j++] = dq->elements[i];
2508 /* filter out all already supplemented packages if requested */
2509 if (!solv->addalreadyrecommended && dqs->count)
2511 /* filter out old supplements */
2512 for (i = j = 0; i < dqs->count; i++)
2514 p = dqs->elements[i];
2515 s = pool->solvables + p;
2516 if (s->supplements && solver_is_supplementing_alreadyinstalled(solv, s))
2517 dqs->elements[j++] = p;
2522 /* multiversion doesn't mix well with supplements.
2523 * filter supplemented packages where we already decided
2524 * to install a different version (see bnc#501088) */
2525 if (dqs->count && solv->multiversion.size)
2527 for (i = j = 0; i < dqs->count; i++)
2529 p = dqs->elements[i];
2530 if (MAPTST(&solv->multiversion, p))
2533 s = pool->solvables + p;
2534 FOR_PROVIDES(p2, pp2, s->name)
2535 if (solv->decisionmap[p2] > 0 && pool->solvables[p2].name == s->name)
2538 continue; /* ignore this package */
2540 dqs->elements[j++] = p;
2545 /* implicitobsoleteusescolors doesn't mix well with supplements.
2546 * filter supplemented packages where we already decided
2547 * to install a different architecture */
2548 if (dqs->count && pool->implicitobsoleteusescolors)
2550 for (i = j = 0; i < dqs->count; i++)
2553 p = dqs->elements[i];
2554 s = pool->solvables + p;
2555 FOR_PROVIDES(p2, pp2, s->name)
2556 if (solv->decisionmap[p2] > 0 && pool->solvables[p2].name == s->name && pool->solvables[p2].arch != s->arch)
2559 continue; /* ignore this package */
2560 dqs->elements[j++] = p;
2565 /* make dq contain both recommended and supplemented pkgs */
2568 for (i = 0; i < dqs->count; i++)
2569 queue_pushunique(dq, dqs->elements[i]);
2578 /* simple case, just one package. no need to choose to best version */
2579 p = dq->elements[0];
2581 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2583 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2584 return setpropagatelearn(solv, level, p, 0, 0, SOLVER_REASON_WEAKDEP);
2587 /* filter packages, this gives us the best versions */
2588 policy_filter_unwanted(solv, dq, POLICY_MODE_RECOMMEND);
2590 /* create map of result */
2591 map_init(&dqmap, pool->nsolvables);
2592 for (i = 0; i < dq->count; i++)
2593 MAPSET(&dqmap, dq->elements[i]);
2595 /* prune dqs so that it only contains the best versions */
2596 for (i = j = 0; i < dqs->count; i++)
2598 p = dqs->elements[i];
2599 if (MAPTST(&dqmap, p))
2600 dqs->elements[j++] = p;
2604 /* install all supplemented packages, but order first */
2606 policy_filter_unwanted(solv, dqs, POLICY_MODE_SUPPLEMENT);
2607 decisioncount = solv->decisionq.count;
2608 for (i = 0; i < dqs->count; i++)
2610 p = dqs->elements[i];
2611 if (solv->decisionmap[p])
2613 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2615 level = setpropagatelearn(solv, level, p, 0, 0, SOLVER_REASON_WEAKDEP);
2616 if (level <= olevel)
2619 if (i < dqs->count || solv->decisionq.count < decisioncount)
2625 /* install all recommended packages */
2626 /* more work as we want to created branches if multiple
2627 * choices are valid */
2628 for (i = 0; i < decisioncount; i++)
2631 p = solv->decisionq.elements[i];
2634 s = pool->solvables + p;
2635 if (!s->repo || (!solv->addalreadyrecommended && s->repo == solv->installed))
2639 recp = s->repo->idarraydata + s->recommends;
2640 while ((rec = *recp++) != 0)
2643 #ifdef ENABLE_COMPLEX_DEPS
2644 if (pool_is_complex_dep(pool, rec))
2645 add_complex_recommends(solv, rec, dq, &dqmap);
2648 FOR_PROVIDES(p, pp, rec)
2650 if (solv->decisionmap[p] > 0)
2655 else if (solv->decisionmap[p] == 0 && MAPTST(&dqmap, p))
2661 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
2662 /* if we have multiple candidates we open a branch */
2664 createbranch(solv, level, dq, s - pool->solvables, rec);
2665 p = dq->elements[0];
2666 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2668 level = setpropagatelearn(solv, level, p, 0, 0, SOLVER_REASON_WEAKDEP);
2669 if (level <= olevel || solv->decisionq.count < decisioncount)
2670 break; /* we had to revert some decisions */
2673 break; /* had a problem above, quit loop */
2681 resolve_orphaned(Solver *solv, int level, int disablerules, Queue *dq, int *rerunp)
2683 Pool *pool = solv->pool;
2686 int installedone = 0;
2689 /* let's see if we can install some unsupported package */
2690 POOL_DEBUG(SOLV_DEBUG_SOLVER, "deciding orphaned packages\n");
2691 for (i = 0; i < solv->orphaned.count; i++)
2693 p = solv->orphaned.elements[i];
2694 if (solv->decisionmap[p])
2695 continue; /* already decided */
2696 if (solv->droporphanedmap_all)
2698 if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))
2700 POOL_DEBUG(SOLV_DEBUG_SOLVER, "keeping orphaned %s\n", pool_solvid2str(pool, p));
2702 level = setpropagatelearn(solv, level, p, 0, 0, SOLVER_REASON_RESOLVE_ORPHAN);
2707 if (installedone || i < solv->orphaned.count)
2712 for (i = 0; i < solv->orphaned.count; i++)
2714 p = solv->orphaned.elements[i];
2715 if (solv->decisionmap[p])
2716 continue; /* already decided */
2717 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing orphaned %s\n", pool_solvid2str(pool, p));
2719 level = setpropagatelearn(solv, level, -p, 0, 0, SOLVER_REASON_RESOLVE_ORPHAN);
2726 if (solv->brokenorphanrules)
2728 solver_check_brokenorphanrules(solv, dq);
2731 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
2732 for (i = 0; i < dq->count; i++)
2734 p = dq->elements[i];
2735 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing orphaned dep %s\n", pool_solvid2str(pool, p));
2737 level = setpropagatelearn(solv, level, p, 0, 0, SOLVER_REASON_RESOLVE_ORPHAN);
2747 /*-------------------------------------------------------------------
2751 * all rules have been set up, now actually run the solver
2756 solver_run_sat(Solver *solv, int disablerules, int doweak)
2758 Queue dq; /* local decisionqueue */
2759 Queue dqs; /* local decisionqueue for supplements */
2765 Pool *pool = solv->pool;
2767 int minimizationsteps;
2769 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
2771 POOL_DEBUG (SOLV_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2772 for (i = 1; i < solv->nrules; i++)
2773 solver_printruleclass(solv, SOLV_DEBUG_RULE_CREATION, solv->rules + i);
2776 /* start SAT algorithm */
2778 systemlevel = level + 1;
2779 POOL_DEBUG(SOLV_DEBUG_SOLVER, "solving...\n");
2783 solv->installedpos = 0;
2784 solv->do_extra_reordering = 0;
2787 * here's the main loop:
2788 * 1) decide assertion rules and propagate
2790 * 3) try to keep installed packages
2791 * 4) fulfill all unresolved rules
2792 * 5) install recommended packages
2793 * 6) minimalize solution if we had choices
2794 * if we encounter a problem, we rewind to a safe level and restart
2798 minimizationsteps = 0;
2802 * initial propagation of the assertions
2808 makeruledecisions(solv);
2810 if (!disablerules && solv->problems.count)
2815 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "initial propagate (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2816 if ((r = propagate(solv, level)) != 0)
2818 level = analyze_unsolvable(solv, r, disablerules);
2821 systemlevel = level + 1;
2825 * resolve jobs first (unless focus_installed is set)
2827 if (level < systemlevel && !solv->focus_installed)
2829 if (solv->installed && solv->installed->nsolvables && !solv->installed->disabled)
2830 solv->do_extra_reordering = 1;
2832 level = resolve_jobrules(solv, level, disablerules, &dq);
2833 solv->do_extra_reordering = 0;
2836 systemlevel = level + 1;
2839 /* resolve job dependencies in the focus_best case */
2840 if (level < systemlevel && solv->focus_best && !solv->focus_installed && solv->installed && solv->installed->nsolvables && !solv->installed->disabled)
2842 solv->do_extra_reordering = 1;
2844 level = resolve_dependencies(solv, level, disablerules, &dq);
2845 solv->do_extra_reordering = 0;
2847 continue; /* start over */
2848 systemlevel = level + 1;
2852 * installed packages
2854 if (level < systemlevel && solv->installed && solv->installed->nsolvables && !solv->installed->disabled)
2857 level = resolve_installed(solv, level, disablerules, &dq);
2860 systemlevel = level + 1;
2863 /* resolve jobs in focus_installed case */
2864 if (level < systemlevel && solv->focus_installed)
2867 level = resolve_jobrules(solv, level, disablerules, &dq);
2870 systemlevel = level + 1;
2873 if (level < systemlevel)
2874 systemlevel = level;
2876 /* resolve all dependencies */
2878 level = resolve_dependencies(solv, level, disablerules, &dq);
2880 continue; /* start over */
2882 /* decide leftover cleandeps packages */
2883 if (solv->cleandepsmap.size && solv->installed)
2885 for (p = solv->installed->start; p < solv->installed->end; p++)
2887 s = pool->solvables + p;
2888 if (s->repo != solv->installed)
2890 if (solv->decisionmap[p] == 0 && MAPTST(&solv->cleandepsmap, p - solv->installed->start))
2892 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, p));
2894 level = setpropagatelearn(solv, level, -p, 0, 0, SOLVER_REASON_CLEANDEPS_ERASE);
2899 if (p < solv->installed->end)
2903 /* at this point we have a consistent system. now do the extras... */
2908 level = resolve_weak(solv, level, disablerules, &dq, &dqs, &rerun);
2913 if (solv->installed && (solv->orphaned.count || solv->brokenorphanrules))
2916 level = resolve_orphaned(solv, level, disablerules, &dq, &rerun);
2921 /* one final pass to make sure we decided all installed packages */
2922 if (solv->installed)
2924 for (p = solv->installed->start; p < solv->installed->end; p++)
2926 if (solv->decisionmap[p])
2927 continue; /* already decided */
2928 s = pool->solvables + p;
2929 if (s->repo != solv->installed)
2931 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing unwanted %s\n", pool_solvid2str(pool, p));
2933 level = setpropagatelearn(solv, level, -p, 0, 0, SOLVER_REASON_CLEANDEPS_ERASE);
2937 if (p < solv->installed->end)
2938 continue; /* back to main loop */
2941 if (solv->installed && solv->cleandepsmap.size && cleandeps_check_mistakes(solv))
2944 level = 0; /* restart from scratch */
2948 if (solv->solution_callback)
2950 solv->solution_callback(solv, solv->solution_callback_data);
2951 if (solv->branches.count)
2955 for (i = solv->branches.count - 1; i >= 0; i--)
2957 p = solv->branches.elements[i];
2962 i -= 3; /* skip: p data count */
2971 while (i > 0 && solv->branches.elements[i - 1] > 0)
2973 level = takebranch(solv, i, endi, "branching", disablerules);
2977 /* all branches done, we're finally finished */
2981 /* auto-minimization step */
2982 if (solv->branches.count)
2984 int endi, lasti = -1, lastiend = -1;
2985 if (solv->recommends_index < solv->decisionq.count)
2986 policy_update_recommendsmap(solv);
2987 for (endi = solv->branches.count; endi > 0;)
2989 int l, lastsi = -1, starti = endi - solv->branches.elements[endi - 2];
2990 l = solv->branches.elements[endi - 1];
2991 for (i = starti; i < endi - 4; i++)
2993 p = solv->branches.elements[i];
2996 if (solv->decisionmap[p] > l)
3003 if (solv->isdisfavormap.size && MAPTST(&solv->isdisfavormap, p))
3005 if (lastsi < 0 && (MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
3010 /* we have a recommended package that could not be installed */
3011 /* take it if our current selection is not recommended */
3012 for (i = starti; i < endi - 4; i++)
3014 p = -solv->branches.elements[i];
3015 if (p <= 0 || solv->decisionmap[p] != l + 1)
3017 if (solv->favormap.size && MAPTST(&solv->favormap, p))
3018 if (!(solv->isdisfavormap.size && MAPTST(&solv->isdisfavormap, p)))
3019 continue; /* current selection is favored */
3020 if (!(MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
3032 minimizationsteps++;
3033 level = takebranch(solv, lasti, lastiend, "minimizing", disablerules);
3034 continue; /* back to main loop */
3037 /* no minimization found, we're finally finished! */
3040 assert(level == -1 || level + 1 == solv->decisionq_reason.count);
3042 POOL_DEBUG(SOLV_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
3044 POOL_DEBUG(SOLV_DEBUG_STATS, "done solving.\n\n");
3048 solver_printdecisionq(solv, SOLV_DEBUG_RESULT);
3053 /*-------------------------------------------------------------------
3055 * remove disabled conflicts
3057 * purpose: update the decisionmap after some rules were disabled.
3058 * this is used to calculate the suggested/recommended package list.
3059 * Also returns a "removed" list to undo the discisionmap changes.
3063 removedisabledconflicts(Solver *solv, Queue *removed)
3065 Pool *pool = solv->pool;
3070 Id *decisionmap = solv->decisionmap;
3072 queue_empty(removed);
3073 for (i = 0; i < solv->decisionq.count; i++)
3075 p = solv->decisionq.elements[i];
3077 continue; /* conflicts only, please */
3078 why = solv->decisionq_why.elements[i];
3081 /* no rule involved, must be a orphan package drop */
3084 /* we never do conflicts on free decisions, so there
3085 * must have been an unit rule */
3087 r = solv->rules + why;
3088 if (r->d < 0 && decisionmap[-p])
3090 /* rule is now disabled, remove from decisionmap */
3091 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing conflict for package %s[%d]\n", pool_solvid2str(pool, -p), -p);
3092 queue_push(removed, -p);
3093 queue_push(removed, decisionmap[-p]);
3094 decisionmap[-p] = 0;
3097 if (!removed->count)
3099 /* we removed some confliced packages. some of them might still
3100 * be in conflict, so search for unit rules and re-conflict */
3102 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
3104 if (i == solv->nrules)
3107 r = solv->rules + i;
3113 if (r->p < 0 && !decisionmap[-r->p])
3119 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
3121 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
3126 if (r->p < 0 && decisionmap[-r->p] == 0)
3128 if (new || DECISIONMAP_FALSE(r->p))
3130 dp = pool->whatprovidesdata + r->d;
3131 while ((p = *dp++) != 0)
3133 if (new && p == new)
3135 if (p < 0 && decisionmap[-p] == 0)
3144 else if (!DECISIONMAP_FALSE(p))
3154 POOL_DEBUG(SOLV_DEBUG_SOLVER, "re-conflicting package %s[%d]\n", pool_solvid2str(pool, -new), -new);
3155 decisionmap[-new] = -1;
3157 n = 0; /* redo all rules */
3163 undo_removedisabledconflicts(Solver *solv, Queue *removed)
3166 for (i = 0; i < removed->count; i += 2)
3167 solv->decisionmap[removed->elements[i]] = removed->elements[i + 1];
3171 /*-------------------------------------------------------------------
3173 * weaken solvable dependencies
3177 weaken_solvable_deps(Solver *solv, Id p)
3182 for (i = 1, r = solv->rules + i; i < solv->pkgrules_end; i++, r++)
3186 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3187 continue; /* conflict */
3188 queue_push(&solv->weakruleq, i);
3193 /********************************************************************/
3198 solver_calculate_multiversionmap(Pool *pool, Queue *job, Map *multiversionmap)
3201 Id how, what, select;
3203 for (i = 0; i < job->count; i += 2)
3205 how = job->elements[i];
3206 if ((how & SOLVER_JOBMASK) != SOLVER_MULTIVERSION)
3208 what = job->elements[i + 1];
3209 select = how & SOLVER_SELECTMASK;
3210 if (!multiversionmap->size)
3211 map_grow(multiversionmap, pool->nsolvables);
3212 if (select == SOLVER_SOLVABLE_ALL)
3214 FOR_POOL_SOLVABLES(p)
3215 MAPSET(multiversionmap, p);
3217 else if (select == SOLVER_SOLVABLE_REPO)
3220 Repo *repo = pool_id2repo(pool, what);
3223 FOR_REPO_SOLVABLES(repo, p, s)
3224 MAPSET(multiversionmap, p);
3227 FOR_JOB_SELECT(p, pp, select, what)
3228 MAPSET(multiversionmap, p);
3233 solver_calculate_noobsmap(Pool *pool, Queue *job, Map *multiversionmap)
3235 solver_calculate_multiversionmap(pool, job, multiversionmap);
3239 * add a rule created by a job, record job number and weak flag
3242 solver_addjobrule(Solver *solv, Id p, Id p2, Id d, Id job, int weak)
3244 solver_addrule(solv, p, p2, d);
3245 queue_push(&solv->ruletojob, job);
3247 queue_push(&solv->weakruleq, solv->nrules - 1);
3251 add_cleandeps_package(Solver *solv, Id p)
3253 if (!solv->cleandeps_updatepkgs)
3255 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
3256 queue_init(solv->cleandeps_updatepkgs);
3258 queue_pushunique(solv->cleandeps_updatepkgs, p);
3262 add_update_target(Solver *solv, Id p, Id how)
3264 Pool *pool = solv->pool;
3265 Solvable *s = pool->solvables + p;
3266 Repo *installed = solv->installed;
3268 if (!solv->update_targets)
3270 solv->update_targets = solv_calloc(1, sizeof(Queue));
3271 queue_init(solv->update_targets);
3273 if (s->repo == installed)
3275 queue_push2(solv->update_targets, p, p);
3278 FOR_PROVIDES(pi, pip, s->name)
3280 Solvable *si = pool->solvables + pi;
3281 if (si->repo != installed || si->name != s->name)
3283 if (how & SOLVER_FORCEBEST)
3285 if (!solv->bestupdatemap.size)
3286 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3287 MAPSET(&solv->bestupdatemap, pi - installed->start);
3289 if (how & SOLVER_CLEANDEPS)
3290 add_cleandeps_package(solv, pi);
3291 queue_push2(solv->update_targets, pi, p);
3292 /* check if it's ok to keep the installed package */
3293 if (s->evr == si->evr && solvable_identical(s, si))
3294 queue_push2(solv->update_targets, pi, pi);
3298 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
3299 while ((obs = *obsp++) != 0)
3301 FOR_PROVIDES(pi, pip, obs)
3303 Solvable *si = pool->solvables + pi;
3304 if (si->repo != installed)
3306 if (si->name == s->name)
3307 continue; /* already handled above */
3308 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
3310 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
3312 if (how & SOLVER_FORCEBEST)
3314 if (!solv->bestupdatemap.size)
3315 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3316 MAPSET(&solv->bestupdatemap, pi - installed->start);
3318 if (how & SOLVER_CLEANDEPS)
3319 add_cleandeps_package(solv, pi);
3320 queue_push2(solv->update_targets, pi, p);
3327 transform_update_targets_sortfn(const void *ap, const void *bp, void *dp)
3337 transform_update_targets(Solver *solv)
3339 Repo *installed = solv->installed;
3340 Queue *update_targets = solv->update_targets;
3342 Id p, q, lastp, lastq;
3344 if (!update_targets->count)
3346 queue_free(update_targets);
3347 solv->update_targets = solv_free(update_targets);
3350 if (update_targets->count > 2)
3351 solv_sort(update_targets->elements, update_targets->count >> 1, 2 * sizeof(Id), transform_update_targets_sortfn, solv);
3352 queue_insertn(update_targets, 0, installed->end - installed->start, 0);
3354 for (i = j = installed->end - installed->start; i < update_targets->count; i += 2)
3356 if ((p = update_targets->elements[i]) != lastp)
3358 if (!solv->updatemap.size)
3359 map_grow(&solv->updatemap, installed->end - installed->start);
3360 MAPSET(&solv->updatemap, p - installed->start);
3361 update_targets->elements[j++] = 0; /* finish old set */
3362 update_targets->elements[p - installed->start] = j; /* start new set */
3366 if ((q = update_targets->elements[i + 1]) != lastq)
3368 update_targets->elements[j++] = q;
3372 queue_truncate(update_targets, j);
3373 queue_push(update_targets, 0); /* finish last set */
3378 addedmap2deduceq(Solver *solv, Map *addedmap)
3380 Pool *pool = solv->pool;
3385 queue_empty(&solv->addedmap_deduceq);
3386 for (i = 2, j = solv->pkgrules_end - 1; i < pool->nsolvables && j > 0; j--)
3388 r = solv->rules + j;
3391 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3394 if (!MAPTST(addedmap, p))
3396 /* should never happen, but... */
3397 if (!solv->addedmap_deduceq.count || solv->addedmap_deduceq.elements[solv->addedmap_deduceq.count - 1] != -p)
3398 queue_push(&solv->addedmap_deduceq, -p);
3402 if (MAPTST(addedmap, i))
3403 queue_push(&solv->addedmap_deduceq, i);
3407 for (; i < pool->nsolvables; i++)
3408 if (MAPTST(addedmap, i))
3409 queue_push(&solv->addedmap_deduceq, i);
3411 for (i = 2; i < pool->nsolvables; i++)
3412 if (MAPTST(addedmap, i))
3417 deduceq2addedmap(Solver *solv, Map *addedmap)
3422 for (j = solv->pkgrules_end - 1; j > 0; j--)
3424 r = solv->rules + j;
3425 if (r->d < 0 && r->p)
3426 solver_enablerule(solv, r);
3429 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3432 MAPSET(addedmap, p);
3434 for (j = 0; j < solv->addedmap_deduceq.count; j++)
3436 p = solv->addedmap_deduceq.elements[j];
3438 MAPSET(addedmap, p);
3440 MAPCLR(addedmap, p);
3444 #ifdef ENABLE_COMPLEX_DEPS
3446 add_complex_jobrules(Solver *solv, Id dep, int flags, int jobidx, int weak)
3448 Pool *pool = solv->pool;
3453 i = pool_normalize_complex_dep(pool, dep, &bq, flags | CPLXDEPS_EXPAND);
3454 if (i == 0 || i == 1)
3458 solver_addjobrule(solv, -SYSTEMSOLVABLE, 0, 0, jobidx, weak);
3461 for (i = 0; i < bq.count; i++)
3463 if (!bq.elements[i])
3465 for (j = 0; bq.elements[i + j + 1]; j++)
3468 solver_addjobrule(solv, bq.elements[i], 0, pool_ids2whatprovides(pool, bq.elements + i + 1, j), jobidx, weak);
3470 solver_addjobrule(solv, bq.elements[i], bq.elements[i + 1], 0, jobidx, weak);
3478 /* sort by package id, last entry wins */
3480 setup_favormaps_cmp(const void *ap, const void *bp, void *dp)
3482 const Id *a = ap, *b = bp;
3485 return (b[1] < 0 ? -b[1] : b[1]) - (a[1] < 0 ? -a[1] : a[1]);
3489 setup_favormaps(Solver *solv)
3491 Queue *q = solv->favorq;
3492 Pool *pool = solv->pool;
3496 solv_sort(q->elements, q->count / 2, 2 * sizeof(Id), setup_favormaps_cmp, solv);
3497 map_grow(&solv->favormap, pool->nsolvables);
3498 for (i = 0; i < q->count; i += 2)
3500 Id p = q->elements[i];
3504 MAPSET(&solv->favormap, p);
3505 if (q->elements[i + 1] < 0)
3507 if (!solv->isdisfavormap.size)
3508 map_grow(&solv->isdisfavormap, pool->nsolvables);
3509 MAPSET(&solv->isdisfavormap, p);
3521 solver_solve(Solver *solv, Queue *job)
3523 Pool *pool = solv->pool;
3524 Repo *installed = solv->installed;
3526 int oldnrules, initialnrules;
3527 Map addedmap; /* '1' == have pkg-rules for solvable */
3528 Map installcandidatemap;
3529 Id how, what, select, name, weak, p, pp, d;
3531 Solvable *s, *name_s;
3533 int now, solve_start;
3534 int needduprules = 0;
3535 int hasbestinstalljob = 0;
3537 solve_start = solv_timems(0);
3539 /* log solver options */
3540 POOL_DEBUG(SOLV_DEBUG_STATS, "solver started\n");
3541 POOL_DEBUG(SOLV_DEBUG_STATS, "dosplitprovides=%d, noupdateprovide=%d, noinfarchcheck=%d\n", solv->dosplitprovides, solv->noupdateprovide, solv->noinfarchcheck);
3542 POOL_DEBUG(SOLV_DEBUG_STATS, "allowuninstall=%d, allowdowngrade=%d, allownamechange=%d, allowarchchange=%d, allowvendorchange=%d\n", solv->allowuninstall, solv->allowdowngrade, solv->allownamechange, solv->allowarchchange, solv->allowvendorchange);
3543 POOL_DEBUG(SOLV_DEBUG_STATS, "promoteepoch=%d, forbidselfconflicts=%d\n", pool->promoteepoch, pool->forbidselfconflicts);
3544 POOL_DEBUG(SOLV_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d, obsoleteusescolors=%d, implicitobsoleteusescolors=%d\n", pool->obsoleteusesprovides, pool->implicitobsoleteusesprovides, pool->obsoleteusescolors, pool->implicitobsoleteusescolors);
3545 POOL_DEBUG(SOLV_DEBUG_STATS, "dontinstallrecommended=%d, addalreadyrecommended=%d\n", solv->dontinstallrecommended, solv->addalreadyrecommended);
3547 /* create whatprovides if not already there */
3548 if (!pool->whatprovides)
3549 pool_createwhatprovides(pool);
3551 /* create obsolete index */
3552 policy_create_obsolete_index(solv);
3555 queue_free(&solv->job);
3556 queue_init_clone(&solv->job, job);
3557 solv->pooljobcnt = pool->pooljobs.count;
3558 if (pool->pooljobs.count)
3559 queue_insertn(&solv->job, 0, pool->pooljobs.count, pool->pooljobs.elements);
3562 /* free old stuff in jase we re-run a solver */
3563 queuep_free(&solv->update_targets);
3564 queuep_free(&solv->cleandeps_updatepkgs);
3565 queue_empty(&solv->ruleassertions);
3566 solv->bestrules_pkg = solv_free(solv->bestrules_pkg);
3567 solv->yumobsrules_info = solv_free(solv->yumobsrules_info);
3568 solv->choicerules_ref = solv_free(solv->choicerules_ref);
3569 if (solv->noupdate.size)
3570 map_empty(&solv->noupdate);
3571 map_zerosize(&solv->multiversion);
3572 solv->updatemap_all = 0;
3573 map_zerosize(&solv->updatemap);
3574 solv->bestupdatemap_all = 0;
3575 map_zerosize(&solv->bestupdatemap);
3576 solv->fixmap_all = 0;
3577 map_zerosize(&solv->fixmap);
3578 solv->dupmap_all = 0;
3579 map_zerosize(&solv->dupmap);
3580 map_zerosize(&solv->dupinvolvedmap);
3581 solv->droporphanedmap_all = 0;
3582 map_zerosize(&solv->droporphanedmap);
3583 solv->allowuninstall_all = 0;
3584 map_zerosize(&solv->allowuninstallmap);
3585 map_zerosize(&solv->cleandepsmap);
3586 map_zerosize(&solv->weakrulemap);
3587 map_zerosize(&solv->favormap);
3588 map_zerosize(&solv->isdisfavormap);
3589 queue_empty(&solv->weakruleq);
3590 solv->watches = solv_free(solv->watches);
3591 queue_empty(&solv->ruletojob);
3592 if (solv->decisionq.count)
3593 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
3594 queue_empty(&solv->decisionq);
3595 queue_empty(&solv->decisionq_why);
3596 queue_empty(&solv->decisionq_reason);
3597 queue_empty(&solv->learnt_why);
3598 queue_empty(&solv->learnt_pool);
3599 queue_empty(&solv->branches);
3600 solv->propagate_index = 0;
3601 queue_empty(&solv->problems);
3602 queue_empty(&solv->solutions);
3603 queue_empty(&solv->orphaned);
3604 solv->stats_learned = solv->stats_unsolvable = 0;
3605 if (solv->recommends_index)
3607 map_empty(&solv->recommendsmap);
3608 map_empty(&solv->suggestsmap);
3609 queuep_free(&solv->recommendscplxq);
3610 queuep_free(&solv->suggestscplxq);
3611 solv->recommends_index = 0;
3613 queuep_free(&solv->brokenorphanrules);
3614 solv->specialupdaters = solv_free(solv->specialupdaters);
3618 * create basic rule set of all involved packages
3619 * use addedmap bitmap to make sure we don't create rules twice
3622 /* create multiversion map if needed */
3623 solver_calculate_multiversionmap(pool, job, &solv->multiversion);
3625 map_init(&addedmap, pool->nsolvables);
3626 MAPSET(&addedmap, SYSTEMSOLVABLE);
3628 map_init(&installcandidatemap, pool->nsolvables);
3631 now = solv_timems(0);
3633 * create rules for all package that could be involved with the solving
3634 * so called: pkg rules
3637 initialnrules = solv->pkgrules_end ? solv->pkgrules_end : 1;
3638 if (initialnrules > 1)
3639 deduceq2addedmap(solv, &addedmap);
3640 if (solv->nrules != initialnrules)
3641 solver_shrinkrules(solv, initialnrules);
3642 solv->nrules = initialnrules;
3643 solv->lastpkgrule = 0;
3644 solv->pkgrules_end = 0;
3648 /* check for update/verify jobs as they need to be known early */
3649 /* also setup the droporphaned map, we need it when creating update rules */
3650 for (i = 0; i < job->count; i += 2)
3652 how = job->elements[i];
3653 what = job->elements[i + 1];
3654 select = how & SOLVER_SELECTMASK;
3655 switch (how & SOLVER_JOBMASK)
3658 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
3659 solv->fixmap_all = 1;
3660 FOR_JOB_SELECT(p, pp, select, what)
3662 s = pool->solvables + p;
3663 if (s->repo != installed)
3665 if (!solv->fixmap.size)
3666 map_grow(&solv->fixmap, installed->end - installed->start);
3667 MAPSET(&solv->fixmap, p - installed->start);
3671 if (select == SOLVER_SOLVABLE_ALL)
3673 solv->updatemap_all = 1;
3674 if (how & SOLVER_FORCEBEST)
3675 solv->bestupdatemap_all = 1;
3676 if (how & SOLVER_CLEANDEPS)
3678 FOR_REPO_SOLVABLES(installed, p, s)
3679 add_cleandeps_package(solv, p);
3682 else if (select == SOLVER_SOLVABLE_REPO)
3684 Repo *repo = pool_id2repo(pool, what);
3687 if (repo == installed && !(how & SOLVER_TARGETED))
3689 solv->updatemap_all = 1;
3690 if (how & SOLVER_FORCEBEST)
3691 solv->bestupdatemap_all = 1;
3692 if (how & SOLVER_CLEANDEPS)
3694 FOR_REPO_SOLVABLES(installed, p, s)
3695 add_cleandeps_package(solv, p);
3699 if (solv->noautotarget && !(how & SOLVER_TARGETED))
3701 /* targeted update */
3702 FOR_REPO_SOLVABLES(repo, p, s)
3703 add_update_target(solv, p, how);
3707 if (!(how & SOLVER_TARGETED))
3710 FOR_JOB_SELECT(p, pp, select, what)
3712 s = pool->solvables + p;
3713 if (s->repo != installed)
3715 if (!solv->updatemap.size)
3716 map_grow(&solv->updatemap, installed->end - installed->start);
3717 MAPSET(&solv->updatemap, p - installed->start);
3718 if (how & SOLVER_FORCEBEST)
3720 if (!solv->bestupdatemap.size)
3721 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3722 MAPSET(&solv->bestupdatemap, p - installed->start);
3724 if (how & SOLVER_CLEANDEPS)
3725 add_cleandeps_package(solv, p);
3728 if (!targeted || solv->noautotarget)
3731 FOR_JOB_SELECT(p, pp, select, what)
3732 add_update_target(solv, p, how);
3735 case SOLVER_DROP_ORPHANED:
3736 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
3737 solv->droporphanedmap_all = 1;
3738 FOR_JOB_SELECT(p, pp, select, what)
3740 s = pool->solvables + p;
3741 if (s->repo != installed)
3743 if (!solv->droporphanedmap.size)
3744 map_grow(&solv->droporphanedmap, installed->end - installed->start);
3745 MAPSET(&solv->droporphanedmap, p - installed->start);
3748 case SOLVER_ALLOWUNINSTALL:
3749 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
3750 solv->allowuninstall_all = 1;
3751 FOR_JOB_SELECT(p, pp, select, what)
3753 s = pool->solvables + p;
3754 if (s->repo != installed)
3756 if (!solv->allowuninstallmap.size)
3757 map_grow(&solv->allowuninstallmap, installed->end - installed->start);
3758 MAPSET(&solv->allowuninstallmap, p - installed->start);
3766 if (solv->update_targets)
3767 transform_update_targets(solv);
3769 oldnrules = solv->nrules;
3770 FOR_REPO_SOLVABLES(installed, p, s)
3771 solver_addpkgrulesforsolvable(solv, s, &addedmap);
3772 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules for installed solvables\n", solv->nrules - oldnrules);
3773 oldnrules = solv->nrules;
3774 FOR_REPO_SOLVABLES(installed, p, s)
3775 solver_addpkgrulesforupdaters(solv, s, &addedmap, 1);
3776 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3780 * create rules for all packages involved in the job
3781 * (to be installed or removed)
3784 oldnrules = solv->nrules;
3785 for (i = 0; i < job->count; i += 2)
3787 how = job->elements[i];
3788 what = job->elements[i + 1];
3789 select = how & SOLVER_SELECTMASK;
3791 switch (how & SOLVER_JOBMASK)
3793 case SOLVER_INSTALL:
3794 FOR_JOB_SELECT(p, pp, select, what)
3796 MAPSET(&installcandidatemap, p);
3797 solver_addpkgrulesforsolvable(solv, pool->solvables + p, &addedmap);
3800 case SOLVER_DISTUPGRADE:
3801 if (select == SOLVER_SOLVABLE_ALL)
3803 solv->dupmap_all = 1;
3804 solv->updatemap_all = 1;
3805 if (how & SOLVER_FORCEBEST)
3806 solv->bestupdatemap_all = 1;
3808 if ((how & SOLVER_TARGETED) != 0)
3810 if (!solv->dupmap_all || solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size || solv->keep_orphans)
3817 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules for packages involved in a job\n", solv->nrules - oldnrules);
3821 * add rules for suggests, enhances
3823 oldnrules = solv->nrules;
3824 solver_addpkgrulesforweak(solv, &addedmap);
3825 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules because of weak dependencies\n", solv->nrules - oldnrules);
3827 #ifdef ENABLE_LINKED_PKGS
3828 oldnrules = solv->nrules;
3829 solver_addpkgrulesforlinked(solv, &addedmap);
3830 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules because of linked packages\n", solv->nrules - oldnrules);
3834 * first pass done, we now have all the pkg rules we need.
3835 * unify existing rules before going over all job rules and
3837 * at this point the system is always solvable,
3838 * as an empty system (remove all packages) is a valid solution
3841 IF_POOLDEBUG (SOLV_DEBUG_STATS)
3843 int possible = 0, installable = 0;
3844 for (i = 1; i < pool->nsolvables; i++)
3846 if (pool_installable(pool, pool->solvables + i))
3848 if (MAPTST(&addedmap, i))
3851 POOL_DEBUG(SOLV_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
3854 if (solv->nrules > initialnrules)
3855 solver_unifyrules(solv); /* remove duplicate pkg rules */
3856 solv->pkgrules_end = solv->nrules; /* mark end of pkg rules */
3857 solv->lastpkgrule = 0;
3859 if (solv->nrules > initialnrules)
3860 addedmap2deduceq(solv, &addedmap); /* so that we can recreate the addedmap */
3862 POOL_DEBUG(SOLV_DEBUG_STATS, "pkg rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
3863 POOL_DEBUG(SOLV_DEBUG_STATS, "pkg rule creation took %d ms\n", solv_timems(now));
3865 /* create dup maps if needed. We need the maps early to create our
3868 solver_createdupmaps(solv);
3871 * create feature rules
3873 * foreach installed:
3874 * create assertion (keep installed, if no update available)
3876 * create update rule (A|update1(A)|update2(A)|...)
3878 * those are used later on to keep a version of the installed packages in
3882 solv->featurerules = solv->nrules; /* mark start of feature rules */
3885 /* foreach possibly installed solvable */
3886 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3888 if (s->repo != installed)
3890 solver_addrule(solv, 0, 0, 0); /* create dummy rule */
3893 solver_addfeaturerule(solv, s);
3895 /* make sure we accounted for all rules */
3896 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
3898 solv->featurerules_end = solv->nrules;
3901 * Add update rules for installed solvables
3903 * almost identical to feature rules
3904 * except that downgrades/archchanges/vendorchanges are not allowed
3907 solv->updaterules = solv->nrules;
3910 { /* foreach installed solvables */
3911 /* we create all update rules, but disable some later on depending on the job */
3912 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3916 if (s->repo != installed)
3918 solver_addrule(solv, 0, 0, 0); /* create dummy rule */
3921 solver_addupdaterule(solv, s);
3923 * check for and remove duplicate
3925 r = solv->rules + solv->nrules - 1; /* r: update rule */
3926 sr = r - (installed->end - installed->start); /* sr: feature rule */
3930 memset(sr, 0, sizeof(*sr)); /* no feature rules without update rules */
3933 /* it's also orphaned if the feature rule consists just of the installed package */
3934 if (!solv->dupmap_all && sr->p == i && !sr->d && !sr->w2)
3935 queue_push(&solv->orphaned, i);
3937 if (!solver_rulecmp(solv, r, sr))
3938 memset(sr, 0, sizeof(*sr)); /* delete unneeded feature rule */
3940 solver_disablerule(solv, sr); /* disable feature rule for now */
3942 /* consistency check: we added a rule for _every_ installed solvable */
3943 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
3945 solv->updaterules_end = solv->nrules;
3949 * now add all job rules
3952 solv->jobrules = solv->nrules;
3953 for (i = 0; i < job->count; i += 2)
3955 oldnrules = solv->nrules;
3957 if (i && i == solv->pooljobcnt)
3958 POOL_DEBUG(SOLV_DEBUG_JOB, "end of pool jobs\n");
3959 how = job->elements[i];
3960 what = job->elements[i + 1];
3961 weak = how & SOLVER_WEAK;
3962 select = how & SOLVER_SELECTMASK;
3963 switch (how & SOLVER_JOBMASK)
3965 case SOLVER_INSTALL:
3966 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3967 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
3968 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3969 if (select == SOLVER_SOLVABLE)
3974 #ifdef ENABLE_COMPLEX_DEPS
3975 else if ((select == SOLVER_SOLVABLE_PROVIDES || select == SOLVER_SOLVABLE_NAME) && pool_is_complex_dep(pool, what))
3977 if (add_complex_jobrules(solv, what, select == SOLVER_SOLVABLE_NAME ? CPLXDEPS_NAME : 0, i, weak))
3978 if (how & SOLVER_FORCEBEST)
3979 hasbestinstalljob = 1;
3986 FOR_JOB_SELECT(p, pp, select, what)
3990 if (select == SOLVER_SOLVABLE_ONE_OF)
3991 break; /* ignore empty installs */
3992 /* no candidate found or unsupported, make this an impossible rule */
3993 queue_push(&q, -SYSTEMSOLVABLE);
3995 p = queue_shift(&q); /* get first candidate */
3996 d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
3998 /* force install of namespace supplements hack */
3999 if (select == SOLVER_SOLVABLE_PROVIDES && !d && (p == SYSTEMSOLVABLE || p == -SYSTEMSOLVABLE) && ISRELDEP(what))
4001 Reldep *rd = GETRELDEP(pool, what);
4002 if (rd->flags == REL_NAMESPACE)
4005 if (!solv->installsuppdepq)
4007 solv->installsuppdepq = solv_calloc(1, sizeof(Queue));
4008 queue_init(solv->installsuppdepq);
4010 queue_pushunique(solv->installsuppdepq, rd->evr == 0 ? rd->name : what);
4013 solver_addjobrule(solv, p, 0, d, i, weak);
4014 if (how & SOLVER_FORCEBEST)
4015 hasbestinstalljob = 1;
4018 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %s%serase %s\n", weak ? "weak " : "", how & SOLVER_CLEANDEPS ? "clean deps " : "", solver_select2str(pool, select, what));
4019 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
4020 map_grow(&solv->cleandepsmap, installed->end - installed->start);
4021 /* specific solvable: by id or by nevra */
4022 name = (select == SOLVER_SOLVABLE || (select == SOLVER_SOLVABLE_NAME && ISRELDEP(what))) ? 0 : -1;
4024 if (select == SOLVER_SOLVABLE_ALL) /* hmmm ;) */
4026 FOR_POOL_SOLVABLES(p)
4027 solver_addjobrule(solv, -p, 0, 0, i, weak);
4029 else if (select == SOLVER_SOLVABLE_REPO)
4031 Repo *repo = pool_id2repo(pool, what);
4034 FOR_REPO_SOLVABLES(repo, p, s)
4035 solver_addjobrule(solv, -p, 0, 0, i, weak);
4038 #ifdef ENABLE_COMPLEX_DEPS
4039 else if ((select == SOLVER_SOLVABLE_PROVIDES || select == SOLVER_SOLVABLE_NAME) && pool_is_complex_dep(pool, what))
4041 /* no special "erase a specific solvable" handling? */
4042 add_complex_jobrules(solv, what, select == SOLVER_SOLVABLE_NAME ? (CPLXDEPS_NAME | CPLXDEPS_TODNF | CPLXDEPS_INVERT) : (CPLXDEPS_TODNF | CPLXDEPS_INVERT), i, weak);
4046 FOR_JOB_SELECT(p, pp, select, what)
4048 s = pool->solvables + p;
4049 if (installed && s->repo == installed)
4051 name = !name ? s->name : -1;
4054 solver_addjobrule(solv, -p, 0, 0, i, weak);
4056 /* special case for "erase a specific solvable": we also
4057 * erase all other solvables with that name, so that they
4058 * don't get picked up as replacement.
4059 * name is > 0 if exactly one installed solvable matched.
4061 /* XXX: look also at packages that obsolete this package? */
4066 FOR_PROVIDES(p, pp, name)
4068 s = pool->solvables + p;
4069 if (s->name != name)
4071 /* keep other versions installed */
4072 if (s->repo == installed)
4074 /* keep installcandidates of other jobs */
4075 if (MAPTST(&installcandidatemap, p))
4077 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, name_s, s))
4079 /* don't add the same rule twice */
4080 for (j = oldnrules; j < k; j++)
4081 if (solv->rules[j].p == -p)
4084 solver_addjobrule(solv, -p, 0, 0, i, weak); /* remove by id */
4090 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
4093 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sverify %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
4095 case SOLVER_WEAKENDEPS:
4096 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
4097 if (select != SOLVER_SOLVABLE)
4099 s = pool->solvables + what;
4100 weaken_solvable_deps(solv, what);
4102 case SOLVER_MULTIVERSION:
4103 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %smultiversion %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
4106 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
4107 if (select == SOLVER_SOLVABLE_ALL)
4109 FOR_POOL_SOLVABLES(p)
4110 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, 0, i, weak);
4112 else if (select == SOLVER_SOLVABLE_REPO)
4114 Repo *repo = pool_id2repo(pool, what);
4117 FOR_REPO_SOLVABLES(repo, p, s)
4118 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, 0, i, weak);
4121 FOR_JOB_SELECT(p, pp, select, what)
4122 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, 0, i, weak);
4124 case SOLVER_DISTUPGRADE:
4125 POOL_DEBUG(SOLV_DEBUG_JOB, "job: distupgrade %s\n", solver_select2str(pool, select, what));
4127 case SOLVER_DROP_ORPHANED:
4128 POOL_DEBUG(SOLV_DEBUG_JOB, "job: drop orphaned %s\n", solver_select2str(pool, select, what));
4130 case SOLVER_USERINSTALLED:
4131 POOL_DEBUG(SOLV_DEBUG_JOB, "job: user installed %s\n", solver_select2str(pool, select, what));
4133 case SOLVER_ALLOWUNINSTALL:
4134 POOL_DEBUG(SOLV_DEBUG_JOB, "job: allowuninstall %s\n", solver_select2str(pool, select, what));
4137 case SOLVER_DISFAVOR:
4138 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %s %s\n", (how & SOLVER_JOBMASK) == SOLVER_FAVOR ? "favor" : "disfavor", solver_select2str(pool, select, what));
4139 FOR_JOB_SELECT(p, pp, select, what)
4144 solv->favorq = solv_calloc(1, sizeof(Queue));
4145 queue_init(solv->favorq);
4147 j = solv->favorq->count + 1;
4148 queue_push2(solv->favorq, p, (how & SOLVER_JOBMASK) == SOLVER_FAVOR ? j : -j);
4152 POOL_DEBUG(SOLV_DEBUG_JOB, "job: unknown job\n");
4156 IF_POOLDEBUG (SOLV_DEBUG_JOB)
4159 if (solv->nrules == oldnrules)
4160 POOL_DEBUG(SOLV_DEBUG_JOB, " - no rule created\n");
4161 for (j = oldnrules; j < solv->nrules; j++)
4163 POOL_DEBUG(SOLV_DEBUG_JOB, " - job ");
4164 solver_printrule(solv, SOLV_DEBUG_JOB, solv->rules + j);
4168 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
4169 solv->jobrules_end = solv->nrules;
4171 /* transform favorq into two maps */
4173 setup_favormaps(solv);
4175 /* now create infarch and dup rules */
4176 if (!solv->noinfarchcheck)
4178 solver_addinfarchrules(solv, &addedmap);
4180 if (pool->implicitobsoleteusescolors)
4182 /* currently doesn't work well with infarch rules, so make
4184 for (i = solv->infarchrules; i < solv->infarchrules_end; i++)
4185 queue_push(&solv->weakruleq, i);
4190 solv->infarchrules = solv->infarchrules_end = solv->nrules;
4193 solver_addduprules(solv, &addedmap);
4195 solv->duprules = solv->duprules_end = solv->nrules;
4197 #ifdef ENABLE_LINKED_PKGS
4198 if (solv->instbuddy && solv->updatemap.size)
4199 extend_updatemap_to_buddies(solv);
4202 if (solv->bestupdatemap_all || solv->bestupdatemap.size || hasbestinstalljob)
4203 solver_addbestrules(solv, hasbestinstalljob);
4205 solv->bestrules = solv->bestrules_end = solv->nrules;
4208 solver_freedupmaps(solv); /* no longer needed */
4210 if (solv->do_yum_obsoletes)
4211 solver_addyumobsrules(solv);
4213 solv->yumobsrules = solv->yumobsrules_end = solv->nrules;
4216 solver_addchoicerules(solv);
4218 solv->choicerules = solv->choicerules_end = solv->nrules;
4222 for (i = solv->featurerules; i < solv->nrules; i++)
4223 solver_printruleclass(solv, SOLV_DEBUG_RESULT, solv->rules + i);
4225 /* all rules created
4226 * --------------------------------------------------------------
4227 * prepare for solving
4230 /* free unneeded memory */
4231 map_free(&addedmap);
4232 map_free(&installcandidatemap);
4235 POOL_DEBUG(SOLV_DEBUG_STATS, "%d pkg rules, 2 * %d update rules, %d job rules, %d infarch rules, %d dup rules, %d choice rules, %d best rules\n", solv->pkgrules_end - 1, solv->updaterules_end - solv->updaterules, solv->jobrules_end - solv->jobrules, solv->infarchrules_end - solv->infarchrules, solv->duprules_end - solv->duprules, solv->choicerules_end - solv->choicerules, solv->bestrules_end - solv->bestrules);
4236 POOL_DEBUG(SOLV_DEBUG_STATS, "overall rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
4238 /* create weak map */
4239 if (solv->weakruleq.count || solv->recommendsruleq)
4241 map_grow(&solv->weakrulemap, solv->nrules);
4242 for (i = 0; i < solv->weakruleq.count; i++)
4244 p = solv->weakruleq.elements[i];
4245 MAPSET(&solv->weakrulemap, p);
4247 if (solv->recommendsruleq)
4249 for (i = 0; i < solv->recommendsruleq->count; i++)
4251 p = solv->recommendsruleq->elements[i];
4252 MAPSET(&solv->weakrulemap, p);
4257 /* enable cleandepsmap creation if we have updatepkgs */
4258 if (solv->cleandeps_updatepkgs && !solv->cleandepsmap.size)
4259 map_grow(&solv->cleandepsmap, installed->end - installed->start);
4261 if (solv->cleandeps_mistakes)
4263 queue_free(solv->cleandeps_mistakes);
4264 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
4267 /* all new rules are learnt after this point */
4268 solv->learntrules = solv->nrules;
4270 /* create watches chains */
4273 /* create assertion index. it is only used to speed up
4274 * makeruledecsions() a bit */
4275 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
4276 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
4277 queue_push(&solv->ruleassertions, i);
4279 /* disable update rules that conflict with our job */
4280 solver_disablepolicyrules(solv);
4282 /* break orphans if requested */
4283 if (solv->dupmap_all && solv->orphaned.count && solv->break_orphans)
4284 solver_breakorphans(solv);
4287 * ********************************************
4289 * ********************************************
4292 now = solv_timems(0);
4293 solver_run_sat(solv, 1, solv->dontinstallrecommended ? 0 : 1);
4294 POOL_DEBUG(SOLV_DEBUG_STATS, "solver took %d ms\n", solv_timems(now));
4297 * prepare solution queue if there were problems
4299 solver_prepare_solutions(solv);
4301 POOL_DEBUG(SOLV_DEBUG_STATS, "final solver statistics: %d problems, %d learned rules, %d unsolvable\n", solv->problems.count / 2, solv->stats_learned, solv->stats_unsolvable);
4302 POOL_DEBUG(SOLV_DEBUG_STATS, "solver_solve took %d ms\n", solv_timems(solve_start));
4304 /* return number of problems */
4305 return solv->problems.count ? solv->problems.count / 2 : 0;
4309 solver_create_transaction(Solver *solv)
4311 return transaction_create_decisionq(solv->pool, &solv->decisionq, &solv->multiversion);
4314 void solver_get_orphaned(Solver *solv, Queue *orphanedq)
4316 queue_free(orphanedq);
4317 queue_init_clone(orphanedq, &solv->orphaned);
4320 void solver_get_recommendations(Solver *solv, Queue *recommendationsq, Queue *suggestionsq, int noselected)
4322 Pool *pool = solv->pool;
4323 Queue redoq, disabledq;
4329 if (!recommendationsq && !suggestionsq)
4332 map_init(&obsmap, pool->nsolvables);
4333 if (solv->installed)
4335 Id obs, *obsp, p, po, ppo;
4336 for (p = solv->installed->start; p < solv->installed->end; p++)
4338 s = pool->solvables + p;
4339 if (s->repo != solv->installed || !s->obsoletes)
4341 if (solv->decisionmap[p] <= 0)
4343 if (solv->multiversion.size && MAPTST(&solv->multiversion, p))
4345 obsp = s->repo->idarraydata + s->obsoletes;
4346 /* foreach obsoletes */
4347 while ((obs = *obsp++) != 0)
4348 FOR_PROVIDES(po, ppo, obs)
4349 MAPSET(&obsmap, po);
4354 queue_init(&disabledq);
4356 /* disable all erase jobs (including weak "keep uninstalled" rules) */
4357 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
4359 if (r->d < 0) /* disabled ? */
4361 if (r->p >= 0) /* install job? */
4363 queue_push(&disabledq, i);
4364 solver_disablerule(solv, r);
4370 enabledisablelearntrules(solv);
4371 removedisabledconflicts(solv, &redoq);
4375 * find recommended packages
4377 if (recommendationsq)
4379 Id rec, *recp, p, pp;
4381 queue_empty(recommendationsq);
4382 /* create map of all recommened packages */
4383 solv->recommends_index = -1;
4384 MAPZERO(&solv->recommendsmap);
4386 /* put all packages the solver already chose in the map */
4387 for (i = 1; i < solv->decisionq.count; i++)
4388 if ((p = solv->decisionq.elements[i]) > 0 && solv->decisionq_why.elements[i] == 0)
4390 if (solv->decisionq_reason.elements[solv->decisionmap[p]] == SOLVER_REASON_WEAKDEP)
4391 MAPSET(&solv->recommendsmap, p);
4394 for (i = 0; i < solv->decisionq.count; i++)
4396 p = solv->decisionq.elements[i];
4399 s = pool->solvables + p;
4402 recp = s->repo->idarraydata + s->recommends;
4403 while ((rec = *recp++) != 0)
4405 #ifdef ENABLE_COMPLEX_DEPS
4406 if (pool_is_complex_dep(pool, rec))
4408 do_complex_recommendations(solv, rec, &solv->recommendsmap, noselected);
4412 FOR_PROVIDES(p, pp, rec)
4413 if (solv->decisionmap[p] > 0)
4419 FOR_PROVIDES(p, pp, rec)
4420 if (solv->decisionmap[p] > 0)
4421 MAPSET(&solv->recommendsmap, p);
4423 continue; /* p != 0: already fulfilled */
4425 FOR_PROVIDES(p, pp, rec)
4426 MAPSET(&solv->recommendsmap, p);
4430 for (i = 1; i < pool->nsolvables; i++)
4432 if (solv->decisionmap[i] < 0)
4434 if (solv->decisionmap[i] > 0 && noselected)
4436 if (MAPTST(&obsmap, i))
4438 s = pool->solvables + i;
4439 if (!MAPTST(&solv->recommendsmap, i))
4441 if (!s->supplements)
4443 if (!pool_installable(pool, s))
4445 if (!solver_is_supplementing(solv, s))
4448 queue_push(recommendationsq, i);
4450 /* we use MODE_SUGGEST here so that repo prio is ignored */
4451 policy_filter_unwanted(solv, recommendationsq, POLICY_MODE_SUGGEST);
4455 * find suggested packages
4460 Id sug, *sugp, p, pp;
4462 queue_empty(suggestionsq);
4463 /* create map of all suggests that are still open */
4464 solv->recommends_index = -1;
4465 MAPZERO(&solv->suggestsmap);
4466 for (i = 0; i < solv->decisionq.count; i++)
4468 p = solv->decisionq.elements[i];
4471 s = pool->solvables + p;
4474 sugp = s->repo->idarraydata + s->suggests;
4475 while ((sug = *sugp++) != 0)
4477 #ifdef ENABLE_COMPLEX_DEPS
4478 if (pool_is_complex_dep(pool, sug))
4480 do_complex_recommendations(solv, sug, &solv->suggestsmap, noselected);
4484 FOR_PROVIDES(p, pp, sug)
4485 if (solv->decisionmap[p] > 0)
4491 FOR_PROVIDES(p, pp, sug)
4492 if (solv->decisionmap[p] > 0)
4493 MAPSET(&solv->suggestsmap, p);
4495 continue; /* already fulfilled */
4497 FOR_PROVIDES(p, pp, sug)
4498 MAPSET(&solv->suggestsmap, p);
4502 for (i = 1; i < pool->nsolvables; i++)
4504 if (solv->decisionmap[i] < 0)
4506 if (solv->decisionmap[i] > 0 && noselected)
4508 if (MAPTST(&obsmap, i))
4510 s = pool->solvables + i;
4511 if (!MAPTST(&solv->suggestsmap, i))
4515 if (!pool_installable(pool, s))
4517 if (!solver_is_enhancing(solv, s))
4520 queue_push(suggestionsq, i);
4522 policy_filter_unwanted(solv, suggestionsq, POLICY_MODE_SUGGEST);
4525 /* undo removedisabledconflicts */
4527 undo_removedisabledconflicts(solv, &redoq);
4530 /* undo job rule disabling */
4531 for (i = 0; i < disabledq.count; i++)
4532 solver_enablerule(solv, solv->rules + disabledq.elements[i]);
4533 queue_free(&disabledq);
4538 /***********************************************************************/
4539 /* disk usage computations */
4541 /*-------------------------------------------------------------------
4543 * calculate DU changes
4547 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
4551 solver_create_state_maps(solv, &installedmap, 0);
4552 pool_calc_duchanges(solv->pool, &installedmap, mps, nmps);
4553 map_free(&installedmap);
4557 /*-------------------------------------------------------------------
4559 * calculate changes in install size
4563 solver_calc_installsizechange(Solver *solv)
4568 solver_create_state_maps(solv, &installedmap, 0);
4569 change = pool_calc_installsizechange(solv->pool, &installedmap);
4570 map_free(&installedmap);
4575 solver_create_state_maps(Solver *solv, Map *installedmap, Map *conflictsmap)
4577 pool_create_state_maps(solv->pool, &solv->decisionq, installedmap, conflictsmap);
4580 /*-------------------------------------------------------------------
4582 * decision introspection
4586 solver_get_decisionlevel(Solver *solv, Id p)
4588 return solv->decisionmap[p];
4592 solver_get_decisionqueue(Solver *solv, Queue *decisionq)
4594 queue_free(decisionq);
4595 queue_init_clone(decisionq, &solv->decisionq);
4599 solver_get_lastdecisionblocklevel(Solver *solv)
4602 if (solv->decisionq.count == 0)
4604 p = solv->decisionq.elements[solv->decisionq.count - 1];
4607 return solv->decisionmap[p] < 0 ? -solv->decisionmap[p] : solv->decisionmap[p];
4611 solver_get_decisionblock(Solver *solv, int level, Queue *decisionq)
4616 queue_empty(decisionq);
4617 for (i = 0; i < solv->decisionq.count; i++)
4619 p = solv->decisionq.elements[i];
4622 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
4625 if (i == solv->decisionq.count)
4627 for (i = 0; i < solv->decisionq.count; i++)
4629 p = solv->decisionq.elements[i];
4632 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
4633 queue_push(decisionq, p);
4640 solver_describe_decision(Solver *solv, Id p, Id *infop)
4647 if (!solv->decisionmap[p])
4648 return SOLVER_REASON_UNRELATED;
4649 pp = solv->decisionmap[p] < 0 ? -p : p;
4650 for (i = 0; i < solv->decisionq.count; i++)
4651 if (solv->decisionq.elements[i] == pp)
4653 if (i == solv->decisionq.count) /* just in case... */
4654 return SOLVER_REASON_UNRELATED;
4655 why = solv->decisionq_why.elements[i];
4657 *infop = why > 0 ? why : -why;
4659 return SOLVER_REASON_UNIT_RULE;
4660 i = solv->decisionmap[p] >= 0 ? solv->decisionmap[p] : -solv->decisionmap[p];
4661 return solv->decisionq_reason.elements[i];
4666 solver_describe_weakdep_decision(Solver *solv, Id p, Queue *whyq)
4668 Pool *pool = solv->pool;
4670 int level = solv->decisionmap[p];
4677 for (decisionno = 0; decisionno < solv->decisionq.count; decisionno++)
4678 if (solv->decisionq.elements[decisionno] == p)
4680 if (decisionno == solv->decisionq.count)
4682 i = solv->decisionmap[p] >= 0 ? solv->decisionmap[p] : -solv->decisionmap[p];
4683 if (solv->decisionq_reason.elements[i] != SOLVER_REASON_WEAKDEP)
4686 /* 1) list all packages that recommend us */
4687 for (i = 1; i < pool->nsolvables; i++)
4689 Id *recp, rec, pp2, p2;
4690 if (solv->decisionmap[i] < 0 || solv->decisionmap[i] >= level)
4692 s = pool->solvables + i;
4695 if (!solv->addalreadyrecommended && s->repo == solv->installed)
4697 recp = s->repo->idarraydata + s->recommends;
4698 while ((rec = *recp++) != 0)
4701 FOR_PROVIDES(p2, pp2, rec)
4707 /* if p2 is already installed, this recommends is ignored */
4708 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4714 queue_push(whyq, SOLVER_REASON_RECOMMENDED);
4715 queue_push2(whyq, i, rec);
4719 /* 2) list all supplements */
4720 s = pool->solvables + p;
4721 if (s->supplements && level > 0)
4723 Id *supp, sup, pp2, p2;
4724 /* this is a hack. to use solver_dep_fulfilled we temporarily clear
4725 * everything above our level in the decisionmap */
4726 for (i = decisionno; i < solv->decisionq.count; i++ )
4728 p2 = solv->decisionq.elements[i];
4730 solv->decisionmap[p2] = -solv->decisionmap[p2];
4732 supp = s->repo->idarraydata + s->supplements;
4733 while ((sup = *supp++) != 0)
4734 if (solver_dep_fulfilled(solv, sup))
4737 /* let's see if this is an easy supp */
4738 FOR_PROVIDES(p2, pp2, sup)
4740 if (!solv->addalreadyrecommended && solv->installed)
4742 if (pool->solvables[p2].repo == solv->installed)
4745 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4747 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4748 queue_push2(whyq, p2, sup);
4754 /* hard case, just note dependency with no package */
4755 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4756 queue_push2(whyq, 0, sup);
4759 for (i = decisionno; i < solv->decisionq.count; i++)
4761 p2 = solv->decisionq.elements[i];
4763 solv->decisionmap[p2] = -solv->decisionmap[p2];
4769 pool_job2solvables(Pool *pool, Queue *pkgs, Id how, Id what)
4772 how &= SOLVER_SELECTMASK;
4774 if (how == SOLVER_SOLVABLE_ALL)
4776 FOR_POOL_SOLVABLES(p)
4777 queue_push(pkgs, p);
4779 else if (how == SOLVER_SOLVABLE_REPO)
4781 Repo *repo = pool_id2repo(pool, what);
4785 FOR_REPO_SOLVABLES(repo, p, s)
4786 queue_push(pkgs, p);
4791 FOR_JOB_SELECT(p, pp, how, what)
4792 queue_push(pkgs, p);
4797 pool_isemptyupdatejob(Pool *pool, Id how, Id what)
4800 Id select = how & SOLVER_SELECTMASK;
4801 if ((how & SOLVER_JOBMASK) != SOLVER_UPDATE)
4803 if (select == SOLVER_SOLVABLE_ALL || select == SOLVER_SOLVABLE_REPO)
4805 if (!pool->installed)
4807 FOR_JOB_SELECT(p, pp, select, what)
4808 if (pool->solvables[p].repo == pool->installed)
4811 FOR_JOB_SELECT(p, pp, select, what)
4813 Solvable *s = pool->solvables + p;
4814 FOR_PROVIDES(pi, pip, s->name)
4816 Solvable *si = pool->solvables + pi;
4817 if (si->repo != pool->installed || si->name != s->name)
4823 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
4824 while ((obs = *obsp++) != 0)
4826 FOR_PROVIDES(pi, pip, obs)
4828 Solvable *si = pool->solvables + pi;
4829 if (si->repo != pool->installed)
4831 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
4833 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
4844 get_userinstalled_cmp(const void *ap, const void *bp, void *dp)
4846 return *(Id *)ap - *(Id *)bp;
4850 get_userinstalled_cmp_names(const void *ap, const void *bp, void *dp)
4853 return strcmp(pool_id2str(pool, *(Id *)ap), pool_id2str(pool, *(Id *)bp));
4857 get_userinstalled_cmp_namearch(const void *ap, const void *bp, void *dp)
4861 r = strcmp(pool_id2str(pool, ((Id *)ap)[0]), pool_id2str(pool, ((Id *)bp)[0]));
4864 return strcmp(pool_id2str(pool, ((Id *)ap)[1]), pool_id2str(pool, ((Id *)bp)[1]));
4868 get_userinstalled_sort_uniq(Pool *pool, Queue *q, int flags)
4870 Id lastp = -1, lasta = -1;
4872 if (q->count < ((flags & GET_USERINSTALLED_NAMEARCH) ? 4 : 2))
4874 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4875 solv_sort(q->elements, q->count / 2, 2 * sizeof(Id), get_userinstalled_cmp_namearch, pool);
4876 else if ((flags & GET_USERINSTALLED_NAMES) != 0)
4877 solv_sort(q->elements, q->count, sizeof(Id), get_userinstalled_cmp_names, pool);
4879 solv_sort(q->elements, q->count, sizeof(Id), get_userinstalled_cmp, 0);
4880 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4882 for (i = j = 0; i < q->count; i += 2)
4883 if (q->elements[i] != lastp || q->elements[i + 1] != lasta)
4885 q->elements[j++] = lastp = q->elements[i];
4886 q->elements[j++] = lasta = q->elements[i + 1];
4891 for (i = j = 0; i < q->count; i++)
4892 if (q->elements[i] != lastp)
4893 q->elements[j++] = lastp = q->elements[i];
4895 queue_truncate(q, j);
4899 namearch2solvables(Pool *pool, Queue *q, Queue *qout, int job)
4902 if (!pool->installed)
4904 for (i = 0; i < q->count; i += 2)
4906 Id p, pp, name = q->elements[i], arch = q->elements[i + 1];
4907 FOR_PROVIDES(p, pp, name)
4909 Solvable *s = pool->solvables + p;
4910 if (s->repo != pool->installed || s->name != name || (arch && s->arch != arch))
4913 queue_push(qout, job);
4914 queue_push(qout, p);
4920 solver_get_userinstalled(Solver *solv, Queue *q, int flags)
4922 Pool *pool = solv->pool;
4925 Repo *installed = solv->installed;
4929 map_init(&userinstalled, 0);
4931 /* first process jobs */
4932 for (i = 0; i < solv->job.count; i += 2)
4934 Id how = solv->job.elements[i];
4936 if (installed && (how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
4938 if (!userinstalled.size)
4939 map_grow(&userinstalled, installed->end - installed->start);
4940 what = solv->job.elements[i + 1];
4941 select = how & SOLVER_SELECTMASK;
4942 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
4944 FOR_REPO_SOLVABLES(installed, p, s)
4945 MAPSET(&userinstalled, p - installed->start);
4947 FOR_JOB_SELECT(p, pp, select, what)
4948 if (pool->solvables[p].repo == installed)
4949 MAPSET(&userinstalled, p - installed->start);
4952 if ((how & SOLVER_JOBMASK) != SOLVER_INSTALL)
4954 if ((how & SOLVER_NOTBYUSER) != 0)
4956 what = solv->job.elements[i + 1];
4957 select = how & SOLVER_SELECTMASK;
4958 FOR_JOB_SELECT(p, pp, select, what)
4959 if (solv->decisionmap[p] > 0)
4962 #ifdef ENABLE_LINKED_PKGS
4963 if (has_package_link(pool, pool->solvables + p))
4968 find_package_link(pool, pool->solvables + p, 0, &lq, 0, 0);
4969 for (j = 0; j < lq.count; j++)
4970 if (solv->decisionmap[lq.elements[j]] > 0)
4971 queue_push(q, lq.elements[j]);
4976 /* now process updates of userinstalled packages */
4977 if (installed && userinstalled.size)
4979 for (i = 1; i < solv->decisionq.count; i++)
4981 p = solv->decisionq.elements[i];
4984 s = pool->solvables + p;
4987 if (s->repo == installed)
4989 if (MAPTST(&userinstalled, p - installed->start))
4993 /* new package, check if we replace a userinstalled one */
4994 FOR_PROVIDES(p2, pp, s->name)
4996 Solvable *ps = pool->solvables + p2;
4997 if (p2 == p || ps->repo != installed || !MAPTST(&userinstalled, p2 - installed->start))
4999 if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
5001 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, ps))
5006 if (!p2 && s->repo != installed && s->obsoletes)
5008 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
5009 while ((obs = *obsp++) != 0)
5011 FOR_PROVIDES(p2, pp, obs)
5013 Solvable *ps = pool->solvables + p2;
5014 if (p2 == p || ps->repo != installed || !MAPTST(&userinstalled, p2 - installed->start))
5016 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
5018 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
5029 map_free(&userinstalled);
5031 /* convert to desired output format */
5032 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
5034 int qcount = q->count;
5035 queue_insertn(q, 0, qcount, 0);
5036 for (i = j = 0; i < qcount; i++)
5038 s = pool->solvables + q->elements[i + qcount];
5039 q->elements[j++] = s->name;
5040 q->elements[j++] = s->arch;
5043 else if ((flags & GET_USERINSTALLED_NAMES) != 0)
5045 for (i = 0; i < q->count; i++)
5047 s = pool->solvables + q->elements[i];
5048 q->elements[i] = s->name;
5051 /* sort and unify */
5052 get_userinstalled_sort_uniq(pool, q, flags);
5054 /* invert if asked for */
5055 if ((flags & GET_USERINSTALLED_INVERTED) != 0)
5057 /* first generate queue with all installed packages */
5060 for (i = 1; i < solv->decisionq.count; i++)
5062 p = solv->decisionq.elements[i];
5065 s = pool->solvables + p;
5068 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
5069 queue_push2(&invq, s->name, s->arch);
5070 else if ((flags & GET_USERINSTALLED_NAMES) != 0)
5071 queue_push(&invq, s->name);
5073 queue_push(&invq, p);
5075 /* push q on invq, just in case... */
5076 queue_insertn(&invq, invq.count, q->count, q->elements);
5077 get_userinstalled_sort_uniq(pool, &invq, flags);
5078 /* subtract queues (easy as they are sorted and invq is a superset of q) */
5079 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
5083 for (i = j = 0; i < invq.count; i += 2)
5084 if (invq.elements[i] == q->elements[j] && invq.elements[i + 1] == q->elements[j + 1])
5086 invq.elements[i] = invq.elements[i + 1] = 0;
5093 for (i = 0; i < invq.count; i += 2)
5094 if (invq.elements[i])
5095 queue_push2(q, invq.elements[i], invq.elements[i + 1]);
5101 for (i = j = 0; i < invq.count; i++)
5102 if (invq.elements[i] == q->elements[j])
5104 invq.elements[i] = 0;
5105 if (++j >= q->count)
5110 for (i = 0; i < invq.count; i++)
5111 if (invq.elements[i])
5112 queue_push(q, invq.elements[i]);
5119 pool_add_userinstalled_jobs(Pool *pool, Queue *q, Queue *job, int flags)
5123 if ((flags & GET_USERINSTALLED_INVERTED) != 0)
5129 if (!pool->installed)
5132 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
5133 flags &= ~GET_USERINSTALLED_NAMES; /* just in case */
5134 FOR_REPO_SOLVABLES(pool->installed, p, s)
5135 queue_push(&invq, flags & GET_USERINSTALLED_NAMES ? s->name : p);
5136 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
5138 /* for namearch we convert to packages */
5139 namearch2solvables(pool, q, &invq, 0);
5140 get_userinstalled_sort_uniq(pool, &invq, flags);
5141 namearch2solvables(pool, q, &invq, 0);
5146 queue_insertn(&invq, invq.count, q->count, q->elements);
5147 get_userinstalled_sort_uniq(pool, &invq, flags);
5148 /* now the fun part, add q again, sort, and remove all dups */
5149 queue_insertn(&invq, invq.count, q->count, q->elements);
5153 if ((flags & GET_USERINSTALLED_NAMES) != 0)
5154 solv_sort(invq.elements, invq.count, sizeof(Id), get_userinstalled_cmp_names, pool);
5156 solv_sort(invq.elements, invq.count, sizeof(Id), get_userinstalled_cmp, 0);
5160 for (i = 0; i < invq.count; i++)
5162 if (invq.elements[i] == lastid)
5168 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), lastid);
5170 lastid = invq.elements[i];
5173 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), lastid);
5178 if (flags & GET_USERINSTALLED_NAMEARCH)
5179 namearch2solvables(pool, q, job, SOLVER_USERINSTALLED | SOLVER_SOLVABLE);
5182 for (i = 0; i < q->count; i++)
5183 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), q->elements[i]);
5189 solver_alternatives_count(Solver *solv)
5191 Id *elements = solv->branches.elements;
5193 for (res = 0, count = solv->branches.count; count; res++)
5194 count -= elements[count - 2];
5199 solver_get_alternative(Solver *solv, Id alternative, Id *idp, Id *fromp, Id *chosenp, Queue *choices, int *levelp)
5201 int cnt = solver_alternatives_count(solv);
5202 int count = solv->branches.count;
5203 Id *elements = solv->branches.elements;
5205 queue_empty(choices);
5206 if (alternative <= 0 || alternative > cnt)
5209 for (; cnt > alternative; cnt--)
5210 elements -= elements[-2];
5212 *levelp = elements[-1];
5214 *fromp = elements[-4];
5216 *idp = elements[-3];
5221 for (i = elements[-2]; i > 4; i--)
5223 Id p = -elements[-i];
5224 if (p > 0 && solv->decisionmap[p] == elements[-1] + 1)
5232 queue_insertn(choices, 0, elements[-2] - 4, elements - elements[-2]);
5233 return elements[-4] ? SOLVER_ALTERNATIVE_TYPE_RECOMMENDS : SOLVER_ALTERNATIVE_TYPE_RULE;
5237 solver_select2str(Pool *pool, Id select, Id what)
5241 select &= SOLVER_SELECTMASK;
5242 if (select == SOLVER_SOLVABLE)
5243 return pool_solvid2str(pool, what);
5244 if (select == SOLVER_SOLVABLE_NAME)
5245 return pool_dep2str(pool, what);
5246 if (select == SOLVER_SOLVABLE_PROVIDES)
5248 s = pool_dep2str(pool, what);
5249 b = pool_alloctmpspace(pool, 11 + strlen(s));
5250 sprintf(b, "providing %s", s);
5253 if (select == SOLVER_SOLVABLE_ONE_OF)
5257 while ((p = pool->whatprovidesdata[what++]) != 0)
5259 s = pool_solvid2str(pool, p);
5261 b = pool_tmpappend(pool, b, ", ", s);
5263 b = pool_tmpjoin(pool, s, 0, 0);
5264 pool_freetmpspace(pool, s);
5266 return b ? b : "nothing";
5268 if (select == SOLVER_SOLVABLE_REPO)
5270 b = pool_alloctmpspace(pool, 20);
5271 sprintf(b, "repo #%d", what);
5274 if (select == SOLVER_SOLVABLE_ALL)
5275 return "all packages";
5276 return "unknown job select";
5280 pool_job2str(Pool *pool, Id how, Id what, Id flagmask)
5282 Id select = how & SOLVER_SELECTMASK;
5283 const char *strstart = 0, *strend = 0;
5287 switch (how & SOLVER_JOBMASK)
5290 return "do nothing";
5291 case SOLVER_INSTALL:
5292 if (select == SOLVER_SOLVABLE && pool->installed && pool->solvables[what].repo == pool->installed)
5293 strstart = "keep ", strend = " installed";
5294 else if (select == SOLVER_SOLVABLE || select == SOLVER_SOLVABLE_NAME)
5295 strstart = "install ";
5296 else if (select == SOLVER_SOLVABLE_PROVIDES)
5297 strstart = "install a package ";
5299 strstart = "install one of ";
5302 if (select == SOLVER_SOLVABLE && !(pool->installed && pool->solvables[what].repo == pool->installed))
5303 strstart = "keep ", strend = " uninstalled";
5304 else if (select == SOLVER_SOLVABLE_PROVIDES)
5305 strstart = "deinstall all packages ";
5307 strstart = "deinstall ";
5310 strstart = "update ";
5312 case SOLVER_WEAKENDEPS:
5313 strstart = "weaken deps of ";
5315 case SOLVER_MULTIVERSION:
5316 strstart = "multi version ";
5321 case SOLVER_DISTUPGRADE:
5322 strstart = "dist upgrade ";
5325 strstart = "verify ";
5327 case SOLVER_DROP_ORPHANED:
5328 strstart = "deinstall ", strend = " if orphaned";
5330 case SOLVER_USERINSTALLED:
5331 strstart = "regard ", strend = " as userinstalled";
5333 case SOLVER_ALLOWUNINSTALL:
5334 strstart = "allow deinstallation of ";
5337 strstart = "favor ";
5339 case SOLVER_DISFAVOR:
5340 strstart = "disfavor ";
5343 strstart = "unknown job ";
5346 s = pool_tmpjoin(pool, strstart, solver_select2str(pool, select, what), strend);
5348 if ((how & ~(SOLVER_SELECTMASK|SOLVER_JOBMASK)) == 0)
5351 s = pool_tmpappend(pool, s, " ", 0);
5352 if (how & SOLVER_WEAK)
5353 s = pool_tmpappend(pool, s, ",weak", 0);
5354 if (how & SOLVER_ESSENTIAL)
5355 s = pool_tmpappend(pool, s, ",essential", 0);
5356 if (how & SOLVER_CLEANDEPS)
5357 s = pool_tmpappend(pool, s, ",cleandeps", 0);
5358 if (how & SOLVER_ORUPDATE)
5359 s = pool_tmpappend(pool, s, ",orupdate", 0);
5360 if (how & SOLVER_FORCEBEST)
5361 s = pool_tmpappend(pool, s, ",forcebest", 0);
5362 if (how & SOLVER_TARGETED)
5363 s = pool_tmpappend(pool, s, ",targeted", 0);
5364 if (how & SOLVER_SETEV)
5365 s = pool_tmpappend(pool, s, ",setev", 0);
5366 if (how & SOLVER_SETEVR)
5367 s = pool_tmpappend(pool, s, ",setevr", 0);
5368 if (how & SOLVER_SETARCH)
5369 s = pool_tmpappend(pool, s, ",setarch", 0);
5370 if (how & SOLVER_SETVENDOR)
5371 s = pool_tmpappend(pool, s, ",setvendor", 0);
5372 if (how & SOLVER_SETREPO)
5373 s = pool_tmpappend(pool, s, ",setrepo", 0);
5374 if (how & SOLVER_SETNAME)
5375 s = pool_tmpappend(pool, s, ",setname", 0);
5376 if (how & SOLVER_NOAUTOSET)
5377 s = pool_tmpappend(pool, s, ",noautoset", 0);
5378 if (s[o + 1] != ',')
5379 s = pool_tmpappend(pool, s, ",?", 0);
5381 return pool_tmpappend(pool, s, "]", 0);
5385 solver_alternative2str(Solver *solv, int type, Id id, Id from)
5387 Pool *pool = solv->pool;
5388 if (type == SOLVER_ALTERNATIVE_TYPE_RECOMMENDS)
5390 const char *s = pool_dep2str(pool, id);
5391 return pool_tmpappend(pool, s, ", recommended by ", pool_solvid2str(pool, from));
5393 if (type == SOLVER_ALTERNATIVE_TYPE_RULE)
5396 Id depfrom, depto, dep;
5398 if (solver_ruleclass(solv, id) == SOLVER_RULE_CHOICE)
5399 id = solver_rule2pkgrule(solv, id);
5400 rtype = solver_ruleinfo(solv, id, &depfrom, &depto, &dep);
5401 if ((rtype & SOLVER_RULE_TYPEMASK) == SOLVER_RULE_JOB)
5403 if ((depto & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_PROVIDES)
5404 return pool_dep2str(pool, dep);
5405 return solver_select2str(pool, depto & SOLVER_SELECTMASK, dep);
5407 if (rtype == SOLVER_RULE_PKG_REQUIRES)
5409 const char *s = pool_dep2str(pool, dep);
5410 return pool_tmpappend(pool, s, ", required by ", pool_solvid2str(pool, depfrom));
5412 sprintf(buf, "Rule #%d", id);
5413 return pool_tmpjoin(pool, buf, 0, 0);
5415 return "unknown alternative type";