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->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 solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
346 decisionstart = solv->decisionq.count;
349 /* if we needed to re-run, back up decisions to decisionstart */
350 while (solv->decisionq.count > decisionstart)
352 v = solv->decisionq.elements[--solv->decisionq.count];
353 --solv->decisionq_why.count;
355 solv->decisionmap[vv] = 0;
358 /* note that the ruleassertions queue is ordered */
359 for (ii = 0; ii < solv->ruleassertions.count; ii++)
361 ri = solv->ruleassertions.elements[ii];
362 r = solv->rules + ri;
364 if (havedisabled && ri >= solv->learntrules)
366 /* just started with learnt rule assertions. If we have disabled
367 * some rules, adapt the learnt rule status */
368 enabledisablelearntrules(solv);
372 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
375 /* do weak rules in phase 2 */
376 if (ri < solv->learntrules && solv->weakrulemap.size && MAPTST(&solv->weakrulemap, ri))
382 if (!solv->decisionmap[vv]) /* if not yet decided */
384 queue_push(&solv->decisionq, v);
385 queue_push(&solv->decisionq_why, r - solv->rules);
386 solv->decisionmap[vv] = v > 0 ? 1 : -1;
387 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
389 Solvable *s = solv->pool->solvables + vv;
391 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", pool_solvable2str(solv->pool, s));
393 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (assertion)\n", pool_solvable2str(solv->pool, s));
398 /* check against previous decision: is there a conflict? */
399 if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
401 if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
407 * The rule (r) we're currently processing says something
408 * different (v = r->p) than a previous decision (decisionmap[abs(v)])
412 if (ri >= solv->learntrules)
414 /* conflict with a learnt rule */
415 /* can happen when packages cannot be installed for multiple reasons. */
416 /* we disable the learnt rule in this case */
417 /* (XXX: we should really call analyze_unsolvable_rule here!) */
418 solver_disablerule(solv, r);
423 * find the decision which is the "opposite" of the rule
425 for (i = 0; i < solv->decisionq.count; i++)
426 if (solv->decisionq.elements[i] == -v)
428 assert(i < solv->decisionq.count); /* assert that we found it */
429 oldproblemcount = solv->problems.count;
432 * conflict with system solvable ?
434 if (v == -SYSTEMSOLVABLE)
438 queue_push(&solv->problems, solv->learnt_pool.count);
439 queue_push(&solv->learnt_pool, ri);
440 queue_push(&solv->learnt_pool, 0);
443 queue_push(&solv->problems, 0);
444 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
445 if (ri >= solv->jobrules && ri < solv->jobrules_end)
446 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
449 queue_push(&solv->problems, v);
450 queue_push(&solv->problems, 0);
451 if (v >= solv->featurerules && v < solv->updaterules_end)
453 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
454 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
456 solv->problems.count = oldproblemcount;
458 break; /* start over */
461 solver_disableproblem(solv, v);
463 break; /* start over */
466 assert(solv->decisionq_why.elements[i] > 0);
469 * conflict with a pkg rule ?
471 if (solv->decisionq_why.elements[i] < solv->pkgrules_end)
475 queue_push(&solv->problems, solv->learnt_pool.count);
476 queue_push(&solv->learnt_pool, ri);
477 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
478 queue_push(&solv->learnt_pool, 0);
481 queue_push(&solv->problems, 0);
482 assert(v > 0 || v == -SYSTEMSOLVABLE);
483 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with pkg rule, disabling rule #%d\n", ri);
484 if (ri >= solv->jobrules && ri < solv->jobrules_end)
485 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
488 queue_push(&solv->problems, v);
489 queue_push(&solv->problems, 0);
490 if (v >= solv->featurerules && v < solv->updaterules_end)
492 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
493 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
495 solv->problems.count = oldproblemcount;
497 break; /* start over */
500 solver_disableproblem(solv, v);
502 break; /* start over */
506 * conflict with another job or update/feature rule
512 queue_push(&solv->problems, solv->learnt_pool.count);
513 queue_push(&solv->learnt_pool, ri);
514 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
515 queue_push(&solv->learnt_pool, 0);
518 queue_push(&solv->problems, 0);
520 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
523 * push all of our rules (can only be feature or job rules)
524 * asserting this literal on the problem stack
526 for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
528 if (rr->d < 0 /* disabled */
529 || rr->w2) /* or no assertion */
531 if (rr->p != vv /* not affecting the literal */
534 if (solv->weakrulemap.size && MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
537 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
538 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + i);
541 if (i >= solv->jobrules && i < solv->jobrules_end)
542 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
543 queue_push(&solv->problems, v);
545 queue_push(&solv->problems, 0);
547 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
548 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
550 solv->problems.count = oldproblemcount;
552 break; /* start over */
555 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
556 solver_disableproblem(solv, solv->problems.elements[i]);
558 break; /* start over */
560 if (ii < solv->ruleassertions.count)
564 * phase 2: now do the weak assertions
566 if (!solv->weakrulemap.size)
567 break; /* no weak rules, no phase 2 */
568 for (ii = 0; ii < solv->ruleassertions.count; ii++)
570 ri = solv->ruleassertions.elements[ii];
571 r = solv->rules + ri;
572 if (r->d < 0 || r->w2) /* disabled or no assertion */
574 if (ri >= solv->learntrules || !MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
579 if (!solv->decisionmap[vv]) /* if not yet decided */
581 queue_push(&solv->decisionq, v);
582 queue_push(&solv->decisionq_why, r - solv->rules);
583 solv->decisionmap[vv] = v > 0 ? 1 : -1;
584 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
586 Solvable *s = solv->pool->solvables + vv;
588 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
590 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
594 /* check against previous decision: is there a conflict? */
595 if (v > 0 && solv->decisionmap[vv] > 0)
597 if (v < 0 && solv->decisionmap[vv] < 0)
600 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
601 solver_printrule(solv, SOLV_DEBUG_UNSOLVABLE, r);
603 if (ri >= solv->jobrules && ri < solv->jobrules_end)
604 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
607 solver_disableproblem(solv, v);
609 solver_reenablepolicyrules(solv, -v);
611 break; /* start over */
613 if (ii == solv->ruleassertions.count)
614 break; /* finished! */
619 /********************************************************************/
623 /*-------------------------------------------------------------------
626 * initial setup for all watches
630 makewatches(Solver *solv)
634 int nsolvables = solv->pool->nsolvables;
636 solv_free(solv->watches);
637 /* lower half for removals, upper half for installs */
638 solv->watches = solv_calloc(2 * nsolvables, sizeof(Id));
639 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
641 if (!r->w2) /* assertions do not need watches */
644 /* see addwatches_rule(solv, r) */
645 r->n1 = solv->watches[nsolvables + r->w1];
646 solv->watches[nsolvables + r->w1] = r - solv->rules;
648 r->n2 = solv->watches[nsolvables + r->w2];
649 solv->watches[nsolvables + r->w2] = r - solv->rules;
654 /*-------------------------------------------------------------------
656 * add watches (for a new learned rule)
657 * sets up watches for a single rule
659 * see also makewatches() above.
663 addwatches_rule(Solver *solv, Rule *r)
665 int nsolvables = solv->pool->nsolvables;
667 r->n1 = solv->watches[nsolvables + r->w1];
668 solv->watches[nsolvables + r->w1] = r - solv->rules;
670 r->n2 = solv->watches[nsolvables + r->w2];
671 solv->watches[nsolvables + r->w2] = r - solv->rules;
675 /********************************************************************/
681 /* shortcuts to check if a literal (positive or negative) assignment
682 * evaluates to 'true' or 'false'
684 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
685 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
686 #define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
688 /*-------------------------------------------------------------------
692 * make decision and propagate to all rules
694 * Evaluate each term affected by the decision (linked through watches).
695 * If we find unit rules we make new decisions based on them.
697 * return : 0 = everything is OK
698 * rule = conflict found in this rule
702 propagate(Solver *solv, int level)
704 Pool *pool = solv->pool;
705 Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
707 Id p, pkg, other_watch;
709 Id *decisionmap = solv->decisionmap;
710 Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
712 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate -----\n");
714 /* foreach non-propagated decision */
715 while (solv->propagate_index < solv->decisionq.count)
718 * 'pkg' was just decided
719 * negate because our watches trigger if literal goes FALSE
721 pkg = -solv->decisionq.elements[solv->propagate_index++];
723 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
725 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
726 solver_printruleelement(solv, SOLV_DEBUG_PROPAGATE, 0, -pkg);
729 /* foreach rule where 'pkg' is now FALSE */
730 for (rp = watches + pkg; *rp; rp = next_rp)
732 r = solv->rules + *rp;
735 /* rule is disabled, goto next */
743 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
745 POOL_DEBUG(SOLV_DEBUG_PROPAGATE," watch triggered ");
746 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
750 * 'pkg' was just decided (was set to FALSE), so this rule
753 /* find the other watch */
766 * if the other watch is true we have nothing to do
768 if (DECISIONMAP_TRUE(other_watch))
772 * The other literal is FALSE or UNDEF
778 /* Not a binary clause, try to move our watch.
780 * Go over all literals and find one that is
784 * (TRUE is also ok, in that case the rule is fulfilled)
785 * As speed matters here we do not use the FOR_RULELITERALS
788 if (r->p /* we have a 'p' */
789 && r->p != other_watch /* which is not watched */
790 && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
794 else /* go find a 'd' to make 'true' */
797 we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
799 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
801 if (p != other_watch /* which is not watched */
802 && !DECISIONMAP_FALSE(p)) /* and not FALSE */
810 * if we found some p that is UNDEF or TRUE, move
813 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
816 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, p));
818 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, -p));
834 watches[p] = r - solv->rules;
837 /* search failed, thus all unwatched literals are FALSE */
842 * unit clause found, set literal other_watch to TRUE
845 if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
846 return r; /* eek, a conflict! */
848 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
850 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " unit ");
851 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
855 decisionmap[other_watch] = level; /* install! */
857 decisionmap[-other_watch] = -level; /* remove! */
859 queue_push(&solv->decisionq, other_watch);
860 queue_push(&solv->decisionq_why, r - solv->rules);
862 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
865 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to install %s\n", pool_solvid2str(pool, other_watch));
867 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to conflict %s\n", pool_solvid2str(pool, -other_watch));
870 } /* foreach rule involving 'pkg' */
872 } /* while we have non-decided decisions */
874 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate end-----\n");
876 return 0; /* all is well */
880 /********************************************************************/
883 /*-------------------------------------------------------------------
886 * revert decisionq to a level
890 revert(Solver *solv, int level)
892 Pool *pool = solv->pool;
894 while (solv->decisionq.count)
896 v = solv->decisionq.elements[solv->decisionq.count - 1];
898 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
900 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
901 solv->decisionmap[vv] = 0;
902 solv->decisionq.count--;
903 solv->decisionq_why.count--;
904 solv->propagate_index = solv->decisionq.count;
906 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= level)
907 solv->branches.count -= solv->branches.elements[solv->branches.count - 2];
908 if (solv->recommends_index > solv->decisionq.count)
909 solv->recommends_index = -1; /* rebuild recommends/suggests maps */
910 if (solv->decisionq.count < solv->decisioncnt_jobs)
911 solv->decisioncnt_jobs = 0;
912 if (solv->decisionq.count < solv->decisioncnt_update)
913 solv->decisioncnt_update = 0;
914 if (solv->decisionq.count < solv->decisioncnt_keep)
915 solv->decisioncnt_keep = 0;
916 if (solv->decisionq.count < solv->decisioncnt_resolve)
917 solv->decisioncnt_resolve = 0;
918 if (solv->decisionq.count < solv->decisioncnt_weak)
919 solv->decisioncnt_weak= 0;
920 if (solv->decisionq.count < solv->decisioncnt_orphan)
921 solv->decisioncnt_orphan = 0;
924 /*-------------------------------------------------------------------
926 * watch2onhighest - put watch2 on literal with highest level
930 watch2onhighest(Solver *solv, Rule *r)
935 d = r->d < 0 ? -r->d - 1 : r->d;
937 return; /* binary rule, both watches are set */
938 dp = solv->pool->whatprovidesdata + d;
939 while ((v = *dp++) != 0)
941 l = solv->decisionmap[v < 0 ? -v : v];
953 /*-------------------------------------------------------------------
960 analyze(Solver *solv, int level, Rule *c, Rule **lrp)
962 Pool *pool = solv->pool;
967 Map seen; /* global? */
968 Id p = 0, pp, v, vv, why;
970 int num = 0, l1num = 0;
971 int learnt_why = solv->learnt_pool.count;
972 Id *decisionmap = solv->decisionmap;
974 queue_init_buffer(&q, q_buf, sizeof(q_buf)/sizeof(*q_buf));
976 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
977 map_init(&seen, pool->nsolvables);
978 idx = solv->decisionq.count;
981 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
982 solver_printruleclass(solv, SOLV_DEBUG_ANALYZE, c);
983 queue_push(&solv->learnt_pool, c - solv->rules);
984 FOR_RULELITERALS(v, pp, c)
986 if (DECISIONMAP_TRUE(v)) /* the one true literal */
989 if (MAPTST(&seen, vv))
991 MAPSET(&seen, vv); /* mark that we also need to look at this literal */
992 l = solv->decisionmap[vv];
996 l1num++; /* need to do this one in level1 pass */
998 num++; /* need to do this one as well */
1001 queue_push(&q, v); /* not level1 or conflict level, add to new rule */
1007 if (!num && !--l1num)
1008 break; /* all literals done */
1010 /* find the next literal to investigate */
1011 /* (as num + l1num > 0, we know that we'll always find one) */
1015 v = solv->decisionq.elements[--idx];
1016 vv = v > 0 ? v : -v;
1017 if (MAPTST(&seen, vv))
1022 if (num && --num == 0)
1024 /* done with normal literals, now start level 1 literal processing */
1025 p = -v; /* so that v doesn't get lost */
1028 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1029 /* clear non-l1 bits from seen map */
1030 for (i = 0; i < q.count; i++)
1033 MAPCLR(&seen, v > 0 ? v : -v);
1035 /* only level 1 marks left in seen map */
1036 l1num++; /* as l1retry decrements it */
1040 why = solv->decisionq_why.elements[idx];
1041 if (why <= 0) /* just in case, maybe for SYSTEMSOLVABLE */
1043 c = solv->rules + why;
1047 assert(rlevel > 0 && rlevel < level);
1048 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
1050 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1051 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, p);
1052 for (i = 0; i < q.count; i++)
1053 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, q.elements[i]);
1055 /* push end marker on learnt reasons stack */
1056 queue_push(&solv->learnt_pool, 0);
1057 solv->stats_learned++;
1059 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, rlevel);
1061 revert(solv, level);
1064 Id d = q.count ? q.elements[0] : 0;
1066 r = solver_addrule(solv, p, d, 0);
1070 Id d = pool_queuetowhatprovides(pool, &q);
1072 r = solver_addrule(solv, p, 0, d);
1074 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
1075 queue_push(&solv->learnt_why, learnt_why);
1079 watch2onhighest(solv, r);
1080 addwatches_rule(solv, r);
1084 /* rule is an assertion */
1085 queue_push(&solv->ruleassertions, r - solv->rules);
1092 /*-------------------------------------------------------------------
1096 * reset all solver decisions
1097 * called after rules have been enabled/disabled
1101 solver_reset(Solver *solv)
1106 /* rewind all decisions */
1107 for (i = solv->decisionq.count - 1; i >= 0; i--)
1109 v = solv->decisionq.elements[i];
1110 solv->decisionmap[v > 0 ? v : -v] = 0;
1112 queue_empty(&solv->decisionq_why);
1113 queue_empty(&solv->decisionq);
1114 solv->recommends_index = -1;
1115 solv->propagate_index = 0;
1116 solv->decisioncnt_update = solv->decisioncnt_keep = solv->decisioncnt_resolve = solv->decisioncnt_weak = solv->decisioncnt_orphan = 0;
1117 queue_empty(&solv->branches);
1119 /* adapt learnt rule status to new set of enabled/disabled rules */
1120 enabledisablelearntrules(solv);
1124 /*-------------------------------------------------------------------
1126 * analyze_unsolvable_rule
1128 * recursion helper used by analyze_unsolvable
1132 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp, Map *rseen)
1134 Pool *pool = solv->pool;
1136 Id why = r - solv->rules;
1138 IF_POOLDEBUG (SOLV_DEBUG_UNSOLVABLE)
1139 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, r);
1140 if (solv->learntrules && why >= solv->learntrules)
1142 if (MAPTST(rseen, why - solv->learntrules))
1144 MAPSET(rseen, why - solv->learntrules);
1145 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1146 if (solv->learnt_pool.elements[i] > 0)
1147 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp, rseen);
1150 if (solv->weakrulemap.size && MAPTST(&solv->weakrulemap, why))
1151 if (!*lastweakp || why > *lastweakp)
1153 /* do not add pkg rules to problem */
1154 if (why < solv->pkgrules_end)
1156 /* turn rule into problem */
1157 if (why >= solv->jobrules && why < solv->jobrules_end)
1158 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1159 /* normalize dup/infarch rules */
1160 if (why > solv->infarchrules && why < solv->infarchrules_end)
1162 Id name = pool->solvables[-solv->rules[why].p].name;
1163 while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
1166 if (why > solv->duprules && why < solv->duprules_end)
1168 Id name = pool->solvables[-solv->rules[why].p].name;
1169 while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
1173 /* return if problem already countains our rule */
1174 if (solv->problems.count)
1176 for (i = solv->problems.count - 1; i >= 0; i--)
1177 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1179 else if (solv->problems.elements[i] == why)
1182 queue_push(&solv->problems, why);
1186 /*-------------------------------------------------------------------
1188 * analyze_unsolvable (called from setpropagatelearn)
1190 * We know that the problem is not solvable. Record all involved
1191 * rules (i.e. the "proof") into solv->learnt_pool.
1192 * Record the learnt pool index and all non-pkg rules into
1193 * solv->problems. (Our solutions to fix the problems are to
1194 * disable those rules.)
1196 * If the proof contains at least one weak rule, we disable the
1199 * Otherwise we return -1 if disablerules is not set or disable
1200 * _all_ of the problem rules and return 0.
1202 * return: 0 - disabled some rules, try again
1207 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1209 Pool *pool = solv->pool;
1211 Map involved; /* global to speed things up? */
1215 Id *decisionmap = solv->decisionmap;
1216 int oldproblemcount;
1217 int oldlearntpoolcount;
1219 int record_proof = 1;
1221 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1222 solv->stats_unsolvable++;
1223 oldproblemcount = solv->problems.count;
1224 oldlearntpoolcount = solv->learnt_pool.count;
1226 /* make room for proof index */
1227 /* must update it later, as analyze_unsolvable_rule would confuse
1228 * it with a rule index if we put the real value in already */
1229 queue_push(&solv->problems, 0);
1232 map_init(&involved, pool->nsolvables);
1233 map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
1235 queue_push(&solv->learnt_pool, r - solv->rules);
1237 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1238 FOR_RULELITERALS(v, pp, r)
1240 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1242 vv = v > 0 ? v : -v;
1243 MAPSET(&involved, vv);
1245 idx = solv->decisionq.count;
1248 v = solv->decisionq.elements[--idx];
1249 vv = v > 0 ? v : -v;
1250 if (!MAPTST(&involved, vv) || vv == SYSTEMSOLVABLE)
1252 why = solv->decisionq_why.elements[idx];
1255 queue_push(&solv->learnt_pool, why);
1256 r = solv->rules + why;
1257 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1258 FOR_RULELITERALS(v, pp, r)
1260 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1262 vv = v > 0 ? v : -v;
1263 MAPSET(&involved, vv);
1266 map_free(&involved);
1268 queue_push(&solv->problems, 0); /* mark end of this problem */
1272 /* disable last weak rule */
1273 solv->problems.count = oldproblemcount;
1274 solv->learnt_pool.count = oldlearntpoolcount;
1275 if (lastweak >= solv->jobrules && lastweak < solv->jobrules_end)
1276 v = -(solv->ruletojob.elements[lastweak - solv->jobrules] + 1);
1279 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "disabling ");
1280 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + lastweak);
1281 if (lastweak >= solv->choicerules && lastweak < solv->choicerules_end)
1282 solver_disablechoicerules(solv, solv->rules + lastweak);
1283 solver_disableproblem(solv, v);
1285 solver_reenablepolicyrules(solv, -v);
1290 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
1291 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
1293 solv->problems.count = oldproblemcount;
1294 solv->learnt_pool.count = oldlearntpoolcount;
1302 queue_push(&solv->learnt_pool, 0);
1303 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1306 /* + 2: index + trailing zero */
1307 if (disablerules && oldproblemcount + 2 < solv->problems.count)
1309 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1310 solver_disableproblem(solv, solv->problems.elements[i]);
1311 /* XXX: might want to enable all weak rules again */
1315 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1320 /*-------------------------------------------------------------------
1324 * add free decision (solvable to install) to decisionq
1325 * increase level and propagate decision
1326 * return if no conflict.
1328 * in conflict case, analyze conflict rule, add resulting
1329 * rule to learnt rule set, make decision from learnt
1330 * rule (always unit) and re-propagate.
1332 * returns the new solver level or -1 if unsolvable
1337 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules, Id ruleid)
1339 Pool *pool = solv->pool;
1346 solv->decisionmap[decision] = level;
1348 solv->decisionmap[-decision] = -level;
1349 queue_push(&solv->decisionq, decision);
1350 queue_push(&solv->decisionq_why, -ruleid); /* <= 0 -> free decision */
1352 assert(ruleid >= 0 && level > 0);
1355 r = propagate(solv, level);
1359 return analyze_unsolvable(solv, r, disablerules);
1360 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1361 level = analyze(solv, level, r, &lr);
1362 /* the new rule is unit by design */
1364 solv->decisionmap[decision > 0 ? decision : -decision] = decision > 0 ? level : -level;
1365 queue_push(&solv->decisionq, decision);
1366 queue_push(&solv->decisionq_why, lr - solv->rules);
1367 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
1369 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "decision: ");
1370 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, decision);
1371 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "new rule: ");
1372 solver_printrule(solv, SOLV_DEBUG_ANALYZE, lr);
1379 reorder_dq_for_jobrules(Solver *solv, int level, Queue *dq)
1381 Pool *pool = solv->pool;
1382 int i, j, haveone = 0, dqcount = dq->count;
1383 int decisionqcount = solv->decisionq.count;
1387 /* at the time we process jobrules the installed packages are not kept yet */
1388 /* reorder so that "future-supplemented" packages come first */
1389 FOR_REPO_SOLVABLES(solv->installed, p, s)
1391 if (MAPTST(&solv->noupdate, p - solv->installed->start))
1393 if (solv->decisionmap[p] == 0)
1395 if (s->recommends || s->suggests)
1396 queue_push(&solv->decisionq, p);
1397 solv->decisionmap[p] = level + 1;
1403 policy_update_recommendsmap(solv);
1404 for (i = 0; i < dqcount; i++)
1406 p = dq->elements[i];
1407 if (!(pool->solvables[p].repo == solv->installed || MAPTST(&solv->suggestsmap, p) || solver_is_enhancing(solv, pool->solvables + p)))
1410 dq->elements[i] = 0;
1413 dqcount = dq->count;
1414 for (i = 0; i < dqcount; i++)
1416 p = dq->elements[i];
1417 if (p && !(pool->solvables[p].repo == solv->installed || MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
1420 dq->elements[i] = 0;
1423 for (i = j = 0; i < dq->count; i++)
1424 if (dq->elements[i])
1425 dq->elements[j++] = dq->elements[i];
1426 queue_truncate(dq, j);
1427 FOR_REPO_SOLVABLES(solv->installed, p, s)
1428 if (solv->decisionmap[p] == level + 1)
1429 solv->decisionmap[p] = 0;
1430 if (solv->decisionq.count != decisionqcount)
1432 solv->recommends_index = -1;
1433 queue_truncate(&solv->decisionq, decisionqcount);
1437 /*-------------------------------------------------------------------
1443 createbranch(Solver *solv, int level, Queue *dq, Id p, Id data)
1445 Pool *pool = solv->pool;
1447 IF_POOLDEBUG (SOLV_DEBUG_POLICY)
1449 POOL_DEBUG (SOLV_DEBUG_POLICY, "creating a branch:\n");
1450 for (i = 0; i < dq->count; i++)
1451 POOL_DEBUG (SOLV_DEBUG_POLICY, " - %s\n", pool_solvid2str(pool, dq->elements[i]));
1453 queue_push(&solv->branches, -dq->elements[0]);
1454 for (i = 1; i < dq->count; i++)
1455 queue_push(&solv->branches, dq->elements[i]);
1456 queue_push2(&solv->branches, p, data);
1457 queue_push2(&solv->branches, dq->count + 4, level);
1461 takebranch(Solver *solv, int pos, int end, const char *msg, int disablerules)
1463 Pool *pool = solv->pool;
1469 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]);
1470 for (i = end - solv->branches.elements[end - 2]; i < end - 4; i++)
1471 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]));
1474 level = solv->branches.elements[end - 1];
1475 p = solv->branches.elements[pos];
1476 solv->branches.elements[pos] = -p;
1477 POOL_DEBUG(SOLV_DEBUG_SOLVER, "%s %d -> %d with %s\n", msg, solv->decisionmap[p], level, pool_solvid2str(pool, p));
1478 /* hack: set level to zero so that revert does not remove the branch */
1479 solv->branches.elements[end - 1] = 0;
1480 revert(solv, level);
1481 solv->branches.elements[end - 1] = level;
1482 /* hack: revert simply sets the count, so we can still access the reverted elements */
1483 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
1485 return setpropagatelearn(solv, level, p, disablerules, why);
1488 /*-------------------------------------------------------------------
1490 * select and install
1492 * install best package from the queue. We add an extra package, inst, if
1493 * provided. See comment in weak install section.
1495 * returns the new solver level or -1 if unsolvable
1500 selectandinstall(Solver *solv, int level, Queue *dq, int disablerules, Id ruleid)
1502 Pool *pool = solv->pool;
1506 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
1507 /* if we're resolving job rules and didn't resolve the installed packages yet,
1508 * do some special supplements ordering */
1509 if (dq->count > 1 && ruleid >= solv->jobrules && ruleid < solv->jobrules_end && solv->installed && !solv->focus_installed)
1510 reorder_dq_for_jobrules(solv, level, dq);
1511 /* if we have multiple candidates we open a branch */
1513 createbranch(solv, level, dq, 0, ruleid);
1514 p = dq->elements[0];
1515 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing %s\n", pool_solvid2str(pool, p));
1516 return setpropagatelearn(solv, level, p, disablerules, ruleid);
1520 /********************************************************************/
1521 /* Main solver interface */
1524 /*-------------------------------------------------------------------
1527 * create solver structure
1529 * pool: all available solvables
1530 * installed: installed Solvables
1533 * Upon solving, rules are created to flag the Solvables
1534 * of the 'installed' Repo as installed.
1538 solver_create(Pool *pool)
1541 solv = (Solver *)solv_calloc(1, sizeof(Solver));
1543 solv->installed = pool->installed;
1545 solv->allownamechange = 1;
1547 solv->dup_allowdowngrade = 1;
1548 solv->dup_allownamechange = 1;
1549 solv->dup_allowarchchange = 1;
1550 solv->dup_allowvendorchange = 1;
1552 solv->keepexplicitobsoletes = pool->noobsoletesmultiversion ? 0 : 1;
1554 queue_init(&solv->ruletojob);
1555 queue_init(&solv->decisionq);
1556 queue_init(&solv->decisionq_why);
1557 queue_init(&solv->problems);
1558 queue_init(&solv->orphaned);
1559 queue_init(&solv->learnt_why);
1560 queue_init(&solv->learnt_pool);
1561 queue_init(&solv->branches);
1562 queue_init(&solv->weakruleq);
1563 queue_init(&solv->ruleassertions);
1564 queue_init(&solv->addedmap_deduceq);
1566 queue_push(&solv->learnt_pool, 0); /* so that 0 does not describe a proof */
1568 map_init(&solv->recommendsmap, pool->nsolvables);
1569 map_init(&solv->suggestsmap, pool->nsolvables);
1570 map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
1571 solv->recommends_index = 0;
1573 solv->decisionmap = (Id *)solv_calloc(pool->nsolvables, sizeof(Id));
1575 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
1576 memset(solv->rules, 0, sizeof(Rule));
1583 resolve_jobrules(Solver *solv, int level, int disablerules, Queue *dq)
1585 Pool *pool = solv->pool;
1586 int oldlevel = level;
1590 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving job rules\n");
1591 if (!solv->decisioncnt_jobs)
1592 solv->decisioncnt_jobs = solv->decisionq.count;
1593 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
1596 if (r->d < 0) /* ignore disabled rules */
1599 FOR_RULELITERALS(l, pp, r)
1603 if (solv->decisionmap[-l] <= 0)
1608 if (solv->decisionmap[l] > 0)
1610 if (solv->decisionmap[l] == 0)
1614 if (l || !dq->count)
1616 /* prune to installed if not updating */
1617 if (dq->count > 1 && solv->installed && !solv->updatemap_all &&
1618 !(solv->job.elements[solv->ruletojob.elements[i - solv->jobrules]] & SOLVER_ORUPDATE))
1621 for (j = k = 0; j < dq->count; j++)
1623 Solvable *s = pool->solvables + dq->elements[j];
1624 if (s->repo == solv->installed)
1626 dq->elements[k++] = dq->elements[j];
1627 if (solv->updatemap.size && MAPTST(&solv->updatemap, dq->elements[j] - solv->installed->start))
1629 k = 0; /* package wants to be updated, do not prune */
1638 level = selectandinstall(solv, level, dq, disablerules, i);
1639 if (level <= olevel)
1641 if (level == olevel)
1645 continue; /* try something else */
1647 if (level < oldlevel)
1649 /* redo from start of jobrules */
1650 i = solv->jobrules - 1;
1651 r = solv->rules + i;
1657 /*-------------------------------------------------------------------
1663 queuep_free(Queue **qp)
1668 *qp = solv_free(*qp);
1672 map_zerosize(Map *m)
1682 solver_free(Solver *solv)
1684 queue_free(&solv->job);
1685 queue_free(&solv->ruletojob);
1686 queue_free(&solv->decisionq);
1687 queue_free(&solv->decisionq_why);
1688 queue_free(&solv->learnt_why);
1689 queue_free(&solv->learnt_pool);
1690 queue_free(&solv->problems);
1691 queue_free(&solv->solutions);
1692 queue_free(&solv->orphaned);
1693 queue_free(&solv->branches);
1694 queue_free(&solv->weakruleq);
1695 queue_free(&solv->ruleassertions);
1696 queue_free(&solv->addedmap_deduceq);
1697 queuep_free(&solv->cleandeps_updatepkgs);
1698 queuep_free(&solv->cleandeps_mistakes);
1699 queuep_free(&solv->update_targets);
1700 queuep_free(&solv->installsuppdepq);
1701 queuep_free(&solv->recommendscplxq);
1702 queuep_free(&solv->suggestscplxq);
1703 queuep_free(&solv->brokenorphanrules);
1705 map_free(&solv->recommendsmap);
1706 map_free(&solv->suggestsmap);
1707 map_free(&solv->noupdate);
1708 map_free(&solv->weakrulemap);
1709 map_free(&solv->multiversion);
1711 map_free(&solv->updatemap);
1712 map_free(&solv->bestupdatemap);
1713 map_free(&solv->fixmap);
1714 map_free(&solv->dupmap);
1715 map_free(&solv->dupinvolvedmap);
1716 map_free(&solv->droporphanedmap);
1717 map_free(&solv->cleandepsmap);
1718 map_free(&solv->allowuninstallmap);
1720 solv_free(solv->decisionmap);
1721 solv_free(solv->rules);
1722 solv_free(solv->watches);
1723 solv_free(solv->obsoletes);
1724 solv_free(solv->obsoletes_data);
1725 solv_free(solv->specialupdaters);
1726 solv_free(solv->choicerules_ref);
1727 solv_free(solv->bestrules_pkg);
1728 solv_free(solv->yumobsrules_info);
1729 solv_free(solv->instbuddy);
1734 solver_get_flag(Solver *solv, int flag)
1738 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1739 return solv->allowdowngrade;
1740 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1741 return solv->allownamechange;
1742 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1743 return solv->allowarchchange;
1744 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1745 return solv->allowvendorchange;
1746 case SOLVER_FLAG_ALLOW_UNINSTALL:
1747 return solv->allowuninstall;
1748 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1749 return solv->noupdateprovide;
1750 case SOLVER_FLAG_SPLITPROVIDES:
1751 return solv->dosplitprovides;
1752 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1753 return solv->dontinstallrecommended;
1754 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1755 return solv->addalreadyrecommended;
1756 case SOLVER_FLAG_NO_INFARCHCHECK:
1757 return solv->noinfarchcheck;
1758 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1759 return solv->keepexplicitobsoletes;
1760 case SOLVER_FLAG_BEST_OBEY_POLICY:
1761 return solv->bestobeypolicy;
1762 case SOLVER_FLAG_NO_AUTOTARGET:
1763 return solv->noautotarget;
1764 case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
1765 return solv->dup_allowdowngrade;
1766 case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
1767 return solv->dup_allownamechange;
1768 case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
1769 return solv->dup_allowarchchange;
1770 case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
1771 return solv->dup_allowvendorchange;
1772 case SOLVER_FLAG_KEEP_ORPHANS:
1773 return solv->keep_orphans;
1774 case SOLVER_FLAG_BREAK_ORPHANS:
1775 return solv->break_orphans;
1776 case SOLVER_FLAG_FOCUS_INSTALLED:
1777 return solv->focus_installed;
1778 case SOLVER_FLAG_YUM_OBSOLETES:
1779 return solv->do_yum_obsoletes;
1780 case SOLVER_FLAG_NEED_UPDATEPROVIDE:
1781 return solv->needupdateprovide;
1789 solver_set_flag(Solver *solv, int flag, int value)
1791 int old = solver_get_flag(solv, flag);
1794 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1795 solv->allowdowngrade = value;
1797 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1798 solv->allownamechange = value;
1800 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1801 solv->allowarchchange = value;
1803 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1804 solv->allowvendorchange = value;
1806 case SOLVER_FLAG_ALLOW_UNINSTALL:
1807 solv->allowuninstall = value;
1809 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1810 solv->noupdateprovide = value;
1812 case SOLVER_FLAG_SPLITPROVIDES:
1813 solv->dosplitprovides = value;
1815 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1816 solv->dontinstallrecommended = value;
1818 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1819 solv->addalreadyrecommended = value;
1821 case SOLVER_FLAG_NO_INFARCHCHECK:
1822 solv->noinfarchcheck = value;
1824 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1825 solv->keepexplicitobsoletes = value;
1827 case SOLVER_FLAG_BEST_OBEY_POLICY:
1828 solv->bestobeypolicy = value;
1830 case SOLVER_FLAG_NO_AUTOTARGET:
1831 solv->noautotarget = value;
1833 case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
1834 solv->dup_allowdowngrade = value;
1836 case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
1837 solv->dup_allownamechange = value;
1839 case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
1840 solv->dup_allowarchchange = value;
1842 case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
1843 solv->dup_allowvendorchange = value;
1845 case SOLVER_FLAG_KEEP_ORPHANS:
1846 solv->keep_orphans = value;
1848 case SOLVER_FLAG_BREAK_ORPHANS:
1849 solv->break_orphans = value;
1851 case SOLVER_FLAG_FOCUS_INSTALLED:
1852 solv->focus_installed = value;
1854 case SOLVER_FLAG_YUM_OBSOLETES:
1855 solv->do_yum_obsoletes = value;
1857 case SOLVER_FLAG_NEED_UPDATEPROVIDE:
1858 solv->needupdateprovide = value;
1867 cleandeps_check_mistakes(Solver *solv)
1869 Pool *pool = solv->pool;
1873 int mademistake = 0;
1875 if (!solv->cleandepsmap.size)
1877 /* check for mistakes */
1878 for (i = solv->installed->start; i < solv->installed->end; i++)
1880 if (!MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1882 r = solv->rules + solv->featurerules + (i - solv->installed->start);
1883 /* a mistake is when the featurerule is true but the updaterule is false */
1886 FOR_RULELITERALS(p, pp, r)
1887 if (p > 0 && solv->decisionmap[p] > 0)
1890 continue; /* feature rule is not true */
1891 r = solv->rules + solv->updaterules + (i - solv->installed->start);
1894 FOR_RULELITERALS(p, pp, r)
1895 if (p > 0 && solv->decisionmap[p] > 0)
1898 continue; /* update rule is true */
1899 POOL_DEBUG(SOLV_DEBUG_SOLVER, "cleandeps mistake: ");
1900 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, r);
1901 POOL_DEBUG(SOLV_DEBUG_SOLVER, "feature rule: ");
1902 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, solv->rules + solv->featurerules + (i - solv->installed->start));
1903 if (!solv->cleandeps_mistakes)
1905 solv->cleandeps_mistakes = solv_calloc(1, sizeof(Queue));
1906 queue_init(solv->cleandeps_mistakes);
1908 queue_push(solv->cleandeps_mistakes, i);
1909 MAPCLR(&solv->cleandepsmap, i - solv->installed->start);
1910 solver_reenablepolicyrules_cleandeps(solv, i);
1917 prune_to_update_targets(Solver *solv, Id *cp, Queue *q)
1921 for (i = j = 0; i < q->count; i++)
1924 for (cp2 = cp; *cp2; cp2++)
1927 q->elements[j++] = p;
1931 queue_truncate(q, j);
1934 #ifdef ENABLE_COMPLEX_DEPS
1937 add_complex_recommends(Solver *solv, Id rec, Queue *dq, Map *dqmap)
1939 Pool *pool = solv->pool;
1940 int oldcnt = dq->count;
1946 printf("ADD_COMPLEX_RECOMMENDS %s\n", pool_dep2str(pool, rec));
1948 i = pool_normalize_complex_dep(pool, rec, dq, CPLXDEPS_EXPAND);
1949 if (i == 0 || i == 1)
1952 for (i = oldcnt; i < cutcnt; i++)
1955 for (; (p = dq->elements[i]) != 0; i++)
1959 if (solv->decisionmap[-p] <= 0)
1963 if (solv->decisionmap[p] > 0)
1965 queue_truncate(dq, blkcnt);
1970 if (!MAPTST(dqmap, p))
1975 if (solv->decisionmap[p] < 0)
1977 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))))
1982 while (dq->elements[i])
1985 queue_deleten(dq, oldcnt, cutcnt - oldcnt);
1987 if (dq->count != oldcnt)
1989 for (j = oldcnt; j < dq->count; j++)
1991 p = dq->elements[j];
1992 for (i = 0; i < j; i++)
1993 if (dq->elements[i] == p)
1995 dq->elements[j] = 0;
1999 for (i = j = oldcnt; j < dq->count; j++)
2000 if (dq->elements[j])
2001 dq->elements[i++] = dq->elements[j];
2002 queue_truncate(dq, i);
2005 printf("RETURN:\n");
2006 for (i = oldcnt; i < dq->count; i++)
2007 printf(" - %s\n", pool_solvid2str(pool, dq->elements[i]));
2012 do_complex_recommendations(Solver *solv, Id rec, Map *m, int noselected)
2014 Pool *pool = solv->pool;
2020 printf("DO_COMPLEX_RECOMMENDATIONS %s\n", pool_dep2str(pool, rec));
2023 i = pool_normalize_complex_dep(pool, rec, &dq, CPLXDEPS_EXPAND);
2024 if (i == 0 || i == 1)
2029 for (i = 0; i < dq.count; i++)
2032 for (; (p = dq.elements[i]) != 0; i++)
2036 if (solv->decisionmap[-p] <= 0)
2040 if (solv->decisionmap[p] > 0)
2045 for (i++; (p = dq.elements[i]) != 0; i++)
2046 if (p > 0 && solv->decisionmap[p] > 0)
2054 for (i = blk; (p = dq.elements[i]) != 0; i++)
2058 while (dq.elements[i])
2066 /*-------------------------------------------------------------------
2070 * all rules have been set up, now actually run the solver
2075 solver_run_sat(Solver *solv, int disablerules, int doweak)
2077 Queue dq; /* local decisionqueue */
2078 Queue dqs; /* local decisionqueue for supplements */
2084 Pool *pool = solv->pool;
2085 Id p, pp, *dp, postponed;
2086 int minimizationsteps;
2087 int installedpos = solv->installed ? solv->installed->start : 0;
2089 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
2091 POOL_DEBUG (SOLV_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2092 for (i = 1; i < solv->nrules; i++)
2093 solver_printruleclass(solv, SOLV_DEBUG_RULE_CREATION, solv->rules + i);
2096 /* start SAT algorithm */
2098 systemlevel = level + 1;
2099 POOL_DEBUG(SOLV_DEBUG_SOLVER, "solving...\n");
2105 * here's the main loop:
2106 * 1) decide assertion rules and propagate
2108 * 3) try to keep installed packages
2109 * 4) fulfill all unresolved rules
2110 * 5) install recommended packages
2111 * 6) minimalize solution if we had choices
2112 * if we encounter a problem, we rewind to a safe level and restart
2116 minimizationsteps = 0;
2120 * initial propagation of the assertions
2126 makeruledecisions(solv);
2128 if (!disablerules && solv->problems.count)
2133 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "initial propagate (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2134 if ((r = propagate(solv, level)) != 0)
2136 level = analyze_unsolvable(solv, r, disablerules);
2139 systemlevel = level + 1;
2143 * resolve jobs first (unless focus_installed is set)
2145 if (level < systemlevel && !solv->focus_installed)
2148 level = resolve_jobrules(solv, level, disablerules, &dq);
2151 systemlevel = level + 1;
2156 * installed packages
2158 if (!solv->decisioncnt_update)
2159 solv->decisioncnt_update = solv->decisionq.count;
2160 if (level < systemlevel && solv->installed && solv->installed->nsolvables && !solv->installed->disabled)
2162 Repo *installed = solv->installed;
2165 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving installed packages\n");
2166 /* we use two passes if we need to update packages
2167 * to create a better user experience */
2168 for (pass = solv->updatemap.size ? 0 : 1; pass < 2; pass++)
2170 int passlevel = level;
2171 Id *specialupdaters = solv->specialupdaters;
2172 if (pass == 1 && !solv->decisioncnt_keep)
2173 solv->decisioncnt_keep = solv->decisionq.count;
2174 /* start with installedpos, the position that gave us problems the last time */
2175 for (i = installedpos, n = installed->start; n < installed->end; i++, n++)
2180 if (i == installed->end)
2181 i = installed->start;
2182 s = pool->solvables + i;
2183 if (s->repo != installed)
2186 if (solv->decisionmap[i] > 0 && (!specialupdaters || !specialupdaters[i - installed->start]))
2187 continue; /* already decided */
2188 if (!pass && solv->updatemap.size && !MAPTST(&solv->updatemap, i - installed->start))
2189 continue; /* updates first */
2190 r = solv->rules + solv->updaterules + (i - installed->start);
2192 if (!rr->p || rr->d < 0) /* disabled -> look at feature rule */
2193 rr -= solv->installed->end - solv->installed->start;
2194 if (!rr->p) /* identical to update rule? */
2196 if (!rr->p && !(specialupdaters && specialupdaters[i - installed->start]))
2197 continue; /* orpaned package */
2199 /* check if we should update this package to the latest version
2200 * noupdate is set for erase jobs, in that case we want to deinstall
2201 * the installed package and not replace it with a newer version
2202 * rr->p != i is for dup jobs where the installed package cannot be kept */
2204 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)))
2208 /* specialupdater with no update/feature rule */
2209 for (d = specialupdaters[i - installed->start]; (p = pool->whatprovidesdata[d++]) != 0; )
2211 if (solv->decisionmap[p] > 0)
2216 if (!solv->decisionmap[p])
2220 else if (specialupdaters && (d = specialupdaters[i - installed->start]) != 0)
2222 /* special multiversion handling, make sure best version is chosen */
2223 if (rr->p == i && solv->decisionmap[i] >= 0)
2225 while ((p = pool->whatprovidesdata[d++]) != 0)
2226 if (solv->decisionmap[p] >= 0)
2228 if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
2229 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
2232 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2234 if (p != i && solv->decisionmap[p] == 0)
2236 rr = solv->rules + solv->featurerules + (i - solv->installed->start);
2237 if (!rr->p) /* update rule == feature rule? */
2238 rr = rr - solv->featurerules + solv->updaterules;
2247 /* update to best package of the update rule */
2248 FOR_RULELITERALS(p, pp, rr)
2250 if (solv->decisionmap[p] > 0)
2252 dq.count = 0; /* already fulfilled */
2255 if (!solv->decisionmap[p])
2260 if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
2261 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
2262 /* install best version */
2266 level = selectandinstall(solv, level, &dq, disablerules, rr - solv->rules);
2267 if (level <= olevel)
2269 if (level < passlevel)
2270 break; /* trouble */
2272 n = installed->start; /* redo all */
2278 /* if still undecided keep package */
2279 if (solv->decisionmap[i] == 0)
2282 if (solv->cleandepsmap.size && MAPTST(&solv->cleandepsmap, i - installed->start))
2285 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, i));
2286 level = setpropagatelearn(solv, level, -i, disablerules, 0);
2293 POOL_DEBUG(SOLV_DEBUG_POLICY, "keeping %s\n", pool_solvid2str(pool, i));
2294 level = setpropagatelearn(solv, level, i, disablerules, r - solv->rules);
2296 if (level <= olevel)
2298 if (level < passlevel)
2299 break; /* trouble */
2301 n = installed->start; /* redo all */
2304 continue; /* retry with learnt rule */
2308 if (n < installed->end)
2310 installedpos = i; /* retry problem solvable next time */
2311 break; /* ran into trouble */
2313 installedpos = installed->start; /* reset installedpos */
2315 systemlevel = level + 1;
2317 continue; /* had trouble, retry */
2319 if (!solv->decisioncnt_keep)
2320 solv->decisioncnt_keep = solv->decisionq.count;
2322 if (level < systemlevel && solv->focus_installed)
2325 level = resolve_jobrules(solv, level, disablerules, &dq);
2328 systemlevel = level + 1;
2331 if (level < systemlevel)
2332 systemlevel = level;
2337 if (!solv->decisioncnt_resolve)
2338 solv->decisioncnt_resolve = solv->decisionq.count;
2339 POOL_DEBUG(SOLV_DEBUG_POLICY, "deciding unresolved rules\n");
2341 for (i = 1, n = 1; ; i++, n++)
2343 if (n >= solv->nrules)
2351 if (i == solv->nrules)
2353 r = solv->rules + i;
2354 if (r->d < 0) /* ignore disabled rules */
2356 if (r->p < 0) /* most common cases first */
2358 if (r->d == 0 || solv->decisionmap[-r->p] <= 0)
2365 /* binary or unary rule */
2366 /* need two positive undecided literals, r->p already checked above */
2369 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2371 queue_push(&dq, r->p);
2372 queue_push(&dq, r->w2);
2377 * all negative literals are installed
2378 * no positive literal is installed
2379 * i.e. the rule is not fulfilled and we
2380 * just need to decide on the positive literals
2381 * (decisionmap[-r->p] for the r->p < 0 case is already checked above)
2385 if (solv->decisionmap[r->p] > 0)
2387 if (solv->decisionmap[r->p] == 0)
2388 queue_push(&dq, r->p);
2390 dp = pool->whatprovidesdata + r->d;
2391 while ((p = *dp++) != 0)
2395 if (solv->decisionmap[-p] <= 0)
2400 if (solv->decisionmap[p] > 0)
2402 if (solv->decisionmap[p] == 0)
2409 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
2411 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "unfulfilled ");
2412 solver_printruleclass(solv, SOLV_DEBUG_PROPAGATE, r);
2414 /* dq.count < 2 cannot happen as this means that
2415 * the rule is unit */
2416 assert(dq.count > 1);
2418 /* prune to cleandeps packages */
2419 if (solv->cleandepsmap.size && solv->installed)
2421 Repo *installed = solv->installed;
2422 for (j = 0; j < dq.count; j++)
2423 if (pool->solvables[dq.elements[j]].repo == installed && MAPTST(&solv->cleandepsmap, dq.elements[j] - installed->start))
2427 dq.elements[0] = dq.elements[j];
2428 queue_truncate(&dq, 1);
2432 if (dq.count > 1 && postponed >= 0)
2434 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE_NOREORDER);
2444 level = selectandinstall(solv, level, &dq, disablerules, r - solv->rules);
2445 if (level < systemlevel)
2446 break; /* trouble */
2447 /* something changed, so look at all rules again */
2451 if (n < solv->nrules) /* ran into trouble? */
2452 continue; /* start over */
2454 /* decide leftover cleandeps packages */
2455 if (solv->cleandepsmap.size && solv->installed)
2457 for (p = solv->installed->start; p < solv->installed->end; p++)
2459 s = pool->solvables + p;
2460 if (s->repo != solv->installed)
2462 if (solv->decisionmap[p] == 0 && MAPTST(&solv->cleandepsmap, p - solv->installed->start))
2464 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, p));
2466 level = setpropagatelearn(solv, level, -p, 0, 0);
2471 if (p < solv->installed->end)
2475 /* at this point we have a consistent system. now do the extras... */
2477 if (!solv->decisioncnt_weak)
2478 solv->decisioncnt_weak = solv->decisionq.count;
2483 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended packages\n");
2484 queue_empty(&dq); /* recommended packages */
2485 queue_empty(&dqs); /* supplemented packages */
2486 for (i = 1; i < pool->nsolvables; i++)
2488 if (solv->decisionmap[i] < 0)
2490 if (solv->decisionmap[i] > 0)
2492 /* installed, check for recommends */
2493 Id *recp, rec, pp, p;
2494 s = pool->solvables + i;
2495 if (!solv->addalreadyrecommended && s->repo == solv->installed)
2497 /* XXX need to special case AND ? */
2500 recp = s->repo->idarraydata + s->recommends;
2501 while ((rec = *recp++) != 0)
2503 #ifdef ENABLE_COMPLEX_DEPS
2504 if (pool_is_complex_dep(pool, rec))
2506 add_complex_recommends(solv, rec, &dq, 0);
2511 FOR_PROVIDES(p, pp, rec)
2513 if (solv->decisionmap[p] > 0)
2518 else if (solv->decisionmap[p] == 0)
2520 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))))
2522 queue_pushunique(&dq, p);
2530 s = pool->solvables + i;
2531 if (!s->supplements)
2533 if (!pool_installable(pool, s))
2535 if (!solver_is_supplementing(solv, s))
2537 if (solv->dupmap_all && solv->installed && s->repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, i - solv->installed->start))))
2539 queue_push(&dqs, i);
2543 /* filter out all packages obsoleted by installed packages */
2544 /* this is no longer needed if we have reverse obsoletes */
2545 if ((dqs.count || dq.count) && solv->installed)
2548 Id obs, *obsp, po, ppo;
2550 map_init(&obsmap, pool->nsolvables);
2551 for (p = solv->installed->start; p < solv->installed->end; p++)
2553 s = pool->solvables + p;
2554 if (s->repo != solv->installed || !s->obsoletes)
2556 if (solv->decisionmap[p] <= 0)
2558 if (!solv->keepexplicitobsoletes && solv->multiversion.size && MAPTST(&solv->multiversion, p))
2560 obsp = s->repo->idarraydata + s->obsoletes;
2561 /* foreach obsoletes */
2562 while ((obs = *obsp++) != 0)
2563 FOR_PROVIDES(po, ppo, obs)
2565 Solvable *pos = pool->solvables + po;
2566 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pos, obs))
2568 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, pos))
2570 MAPSET(&obsmap, po);
2573 for (i = j = 0; i < dqs.count; i++)
2574 if (!MAPTST(&obsmap, dqs.elements[i]))
2575 dqs.elements[j++] = dqs.elements[i];
2577 for (i = j = 0; i < dq.count; i++)
2578 if (!MAPTST(&obsmap, dq.elements[i]))
2579 dq.elements[j++] = dq.elements[i];
2584 /* filter out all already supplemented packages if requested */
2585 if (!solv->addalreadyrecommended && dqs.count)
2587 /* filter out old supplements */
2588 for (i = j = 0; i < dqs.count; i++)
2590 p = dqs.elements[i];
2591 s = pool->solvables + p;
2592 if (s->supplements && solver_is_supplementing_alreadyinstalled(solv, s))
2593 dqs.elements[j++] = p;
2598 /* multiversion doesn't mix well with supplements.
2599 * filter supplemented packages where we already decided
2600 * to install a different version (see bnc#501088) */
2601 if (dqs.count && solv->multiversion.size)
2603 for (i = j = 0; i < dqs.count; i++)
2605 p = dqs.elements[i];
2606 if (MAPTST(&solv->multiversion, p))
2609 s = pool->solvables + p;
2610 FOR_PROVIDES(p2, pp2, s->name)
2611 if (solv->decisionmap[p2] > 0 && pool->solvables[p2].name == s->name)
2614 continue; /* ignore this package */
2616 dqs.elements[j++] = p;
2621 /* make dq contain both recommended and supplemented pkgs */
2624 for (i = 0; i < dqs.count; i++)
2625 queue_pushunique(&dq, dqs.elements[i]);
2631 int decisioncount = solv->decisionq.count;
2635 /* simple case, just one package. no need to choose to best version */
2638 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2640 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2641 level = setpropagatelearn(solv, level, p, 0, 0);
2642 continue; /* back to main loop */
2645 /* filter packages, this gives us the best versions */
2646 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
2648 /* create map of result */
2649 map_init(&dqmap, pool->nsolvables);
2650 for (i = 0; i < dq.count; i++)
2651 MAPSET(&dqmap, dq.elements[i]);
2653 /* install all supplemented packages */
2654 for (i = 0; i < dqs.count; i++)
2656 p = dqs.elements[i];
2657 if (solv->decisionmap[p] || !MAPTST(&dqmap, p))
2659 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2661 level = setpropagatelearn(solv, level, p, 0, 0);
2662 if (level <= olevel)
2665 if (i < dqs.count || solv->decisionq.count < decisioncount)
2671 /* install all recommended packages */
2672 /* more work as we want to created branches if multiple
2673 * choices are valid */
2674 for (i = 0; i < decisioncount; i++)
2677 p = solv->decisionq.elements[i];
2680 s = pool->solvables + p;
2681 if (!s->repo || (!solv->addalreadyrecommended && s->repo == solv->installed))
2685 recp = s->repo->idarraydata + s->recommends;
2686 while ((rec = *recp++) != 0)
2689 #ifdef ENABLE_COMPLEX_DEPS
2690 if (pool_is_complex_dep(pool, rec))
2691 add_complex_recommends(solv, rec, &dq, &dqmap);
2694 FOR_PROVIDES(p, pp, rec)
2696 if (solv->decisionmap[p] > 0)
2701 else if (solv->decisionmap[p] == 0 && MAPTST(&dqmap, p))
2707 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2708 /* if we have multiple candidates we open a branch */
2710 createbranch(solv, level, &dq, s - pool->solvables, rec);
2712 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2714 level = setpropagatelearn(solv, level, p, 0, 0);
2715 if (level <= olevel || solv->decisionq.count < decisioncount)
2716 break; /* we had to revert some decisions */
2719 break; /* had a problem above, quit loop */
2722 continue; /* back to main loop so that all deps are checked */
2726 if (!solv->decisioncnt_orphan)
2727 solv->decisioncnt_orphan = solv->decisionq.count;
2728 if (solv->installed && (solv->orphaned.count || solv->brokenorphanrules))
2730 int installedone = 0;
2732 /* let's see if we can install some unsupported package */
2733 POOL_DEBUG(SOLV_DEBUG_SOLVER, "deciding orphaned packages\n");
2734 for (i = 0; i < solv->orphaned.count; i++)
2736 p = solv->orphaned.elements[i];
2737 if (solv->decisionmap[p])
2738 continue; /* already decided */
2739 if (solv->droporphanedmap_all)
2741 if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))
2743 POOL_DEBUG(SOLV_DEBUG_SOLVER, "keeping orphaned %s\n", pool_solvid2str(pool, p));
2745 level = setpropagatelearn(solv, level, p, 0, 0);
2750 if (installedone || i < solv->orphaned.count)
2751 continue; /* back to main loop */
2752 for (i = 0; i < solv->orphaned.count; i++)
2754 p = solv->orphaned.elements[i];
2755 if (solv->decisionmap[p])
2756 continue; /* already decided */
2757 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing orphaned %s\n", pool_solvid2str(pool, p));
2759 level = setpropagatelearn(solv, level, -p, 0, 0);
2763 if (i < solv->orphaned.count)
2764 continue; /* back to main loop */
2765 if (solv->brokenorphanrules)
2767 solver_check_brokenorphanrules(solv, &dq);
2770 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2771 for (i = 0; i < dq.count; i++)
2774 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing orphaned dep %s\n", pool_solvid2str(pool, p));
2776 level = setpropagatelearn(solv, level, p, 0, 0);
2785 /* one final pass to make sure we decided all installed packages */
2786 if (solv->installed)
2788 for (p = solv->installed->start; p < solv->installed->end; p++)
2790 if (solv->decisionmap[p])
2791 continue; /* already decided */
2792 s = pool->solvables + p;
2793 if (s->repo != solv->installed)
2795 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing unwanted %s\n", pool_solvid2str(pool, p));
2797 level = setpropagatelearn(solv, level, -p, 0, 0);
2801 if (p < solv->installed->end)
2802 continue; /* back to main loop */
2805 if (solv->installed && solv->cleandepsmap.size && cleandeps_check_mistakes(solv))
2808 level = 0; /* restart from scratch */
2812 if (solv->solution_callback)
2814 solv->solution_callback(solv, solv->solution_callback_data);
2815 if (solv->branches.count)
2819 for (i = solv->branches.count - 1; i >= 0; i--)
2821 p = solv->branches.elements[i];
2826 i -= 3; /* skip: p data count */
2835 while (i > 0 && solv->branches.elements[i - 1] > 0)
2837 level = takebranch(solv, i, endi, "branching", disablerules);
2841 /* all branches done, we're finally finished */
2845 /* auto-minimization step */
2846 if (solv->branches.count)
2848 int endi, lasti = -1, lastiend = -1;
2849 if (solv->recommends_index < solv->decisionq.count)
2850 policy_update_recommendsmap(solv);
2851 for (endi = solv->branches.count; endi > 0;)
2853 int l, lastsi = -1, starti = endi - solv->branches.elements[endi - 2];
2854 l = solv->branches.elements[endi - 1];
2855 for (i = starti; i < endi - 4; i++)
2857 p = solv->branches.elements[i];
2860 if (solv->decisionmap[p] > l)
2867 if (lastsi < 0 && (MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
2872 /* we have a recommended package that could not be installed */
2873 /* take it if our current selection is not recommended */
2874 for (i = starti; i < endi - 4; i++)
2876 p = -solv->branches.elements[i];
2877 if (p <= 0 || solv->decisionmap[p] != l + 1)
2879 if (!(MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
2891 minimizationsteps++;
2892 level = takebranch(solv, lasti, lastiend, "minimizing", disablerules);
2893 continue; /* back to main loop */
2896 /* no minimization found, we're finally finished! */
2900 POOL_DEBUG(SOLV_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
2902 POOL_DEBUG(SOLV_DEBUG_STATS, "done solving.\n\n");
2908 solv->decisioncnt_jobs = solv->decisionq.count;
2909 solv->decisioncnt_update = solv->decisionq.count;
2910 solv->decisioncnt_keep = solv->decisionq.count;
2911 solv->decisioncnt_resolve = solv->decisionq.count;
2912 solv->decisioncnt_weak = solv->decisionq.count;
2913 solv->decisioncnt_orphan = solv->decisionq.count;
2916 solver_printdecisionq(solv, SOLV_DEBUG_RESULT);
2921 /*-------------------------------------------------------------------
2923 * remove disabled conflicts
2925 * purpose: update the decisionmap after some rules were disabled.
2926 * this is used to calculate the suggested/recommended package list.
2927 * Also returns a "removed" list to undo the discisionmap changes.
2931 removedisabledconflicts(Solver *solv, Queue *removed)
2933 Pool *pool = solv->pool;
2938 Id *decisionmap = solv->decisionmap;
2940 queue_empty(removed);
2941 for (i = 0; i < solv->decisionq.count; i++)
2943 p = solv->decisionq.elements[i];
2945 continue; /* conflicts only, please */
2946 why = solv->decisionq_why.elements[i];
2949 /* no rule involved, must be a orphan package drop */
2952 /* we never do conflicts on free decisions, so there
2953 * must have been an unit rule */
2955 r = solv->rules + why;
2956 if (r->d < 0 && decisionmap[-p])
2958 /* rule is now disabled, remove from decisionmap */
2959 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing conflict for package %s[%d]\n", pool_solvid2str(pool, -p), -p);
2960 queue_push(removed, -p);
2961 queue_push(removed, decisionmap[-p]);
2962 decisionmap[-p] = 0;
2965 if (!removed->count)
2967 /* we removed some confliced packages. some of them might still
2968 * be in conflict, so search for unit rules and re-conflict */
2970 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
2972 if (i == solv->nrules)
2975 r = solv->rules + i;
2981 if (r->p < 0 && !decisionmap[-r->p])
2987 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
2989 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
2994 if (r->p < 0 && decisionmap[-r->p] == 0)
2996 if (new || DECISIONMAP_FALSE(r->p))
2998 dp = pool->whatprovidesdata + r->d;
2999 while ((p = *dp++) != 0)
3001 if (new && p == new)
3003 if (p < 0 && decisionmap[-p] == 0)
3012 else if (!DECISIONMAP_FALSE(p))
3022 POOL_DEBUG(SOLV_DEBUG_SOLVER, "re-conflicting package %s[%d]\n", pool_solvid2str(pool, -new), -new);
3023 decisionmap[-new] = -1;
3025 n = 0; /* redo all rules */
3031 undo_removedisabledconflicts(Solver *solv, Queue *removed)
3034 for (i = 0; i < removed->count; i += 2)
3035 solv->decisionmap[removed->elements[i]] = removed->elements[i + 1];
3039 /*-------------------------------------------------------------------
3041 * weaken solvable dependencies
3045 weaken_solvable_deps(Solver *solv, Id p)
3050 for (i = 1, r = solv->rules + i; i < solv->pkgrules_end; i++, r++)
3054 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3055 continue; /* conflict */
3056 queue_push(&solv->weakruleq, i);
3061 /********************************************************************/
3066 solver_calculate_multiversionmap(Pool *pool, Queue *job, Map *multiversionmap)
3069 Id how, what, select;
3071 for (i = 0; i < job->count; i += 2)
3073 how = job->elements[i];
3074 if ((how & SOLVER_JOBMASK) != SOLVER_MULTIVERSION)
3076 what = job->elements[i + 1];
3077 select = how & SOLVER_SELECTMASK;
3078 if (!multiversionmap->size)
3079 map_grow(multiversionmap, pool->nsolvables);
3080 if (select == SOLVER_SOLVABLE_ALL)
3082 FOR_POOL_SOLVABLES(p)
3083 MAPSET(multiversionmap, p);
3085 else if (select == SOLVER_SOLVABLE_REPO)
3088 Repo *repo = pool_id2repo(pool, what);
3090 FOR_REPO_SOLVABLES(repo, p, s)
3091 MAPSET(multiversionmap, p);
3093 FOR_JOB_SELECT(p, pp, select, what)
3094 MAPSET(multiversionmap, p);
3099 solver_calculate_noobsmap(Pool *pool, Queue *job, Map *multiversionmap)
3101 solver_calculate_multiversionmap(pool, job, multiversionmap);
3105 * add a rule created by a job, record job number and weak flag
3108 solver_addjobrule(Solver *solv, Id p, Id p2, Id d, Id job, int weak)
3110 solver_addrule(solv, p, p2, d);
3111 queue_push(&solv->ruletojob, job);
3113 queue_push(&solv->weakruleq, solv->nrules - 1);
3117 add_cleandeps_package(Solver *solv, Id p)
3119 if (!solv->cleandeps_updatepkgs)
3121 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
3122 queue_init(solv->cleandeps_updatepkgs);
3124 queue_pushunique(solv->cleandeps_updatepkgs, p);
3128 add_update_target(Solver *solv, Id p, Id how)
3130 Pool *pool = solv->pool;
3131 Solvable *s = pool->solvables + p;
3132 Repo *installed = solv->installed;
3134 if (!solv->update_targets)
3136 solv->update_targets = solv_calloc(1, sizeof(Queue));
3137 queue_init(solv->update_targets);
3139 if (s->repo == installed)
3141 queue_push2(solv->update_targets, p, p);
3144 FOR_PROVIDES(pi, pip, s->name)
3146 Solvable *si = pool->solvables + pi;
3147 if (si->repo != installed || si->name != s->name)
3149 if (how & SOLVER_FORCEBEST)
3151 if (!solv->bestupdatemap.size)
3152 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3153 MAPSET(&solv->bestupdatemap, pi - installed->start);
3155 if (how & SOLVER_CLEANDEPS)
3156 add_cleandeps_package(solv, pi);
3157 queue_push2(solv->update_targets, pi, p);
3158 /* check if it's ok to keep the installed package */
3159 if (s->evr == si->evr && solvable_identical(s, si))
3160 queue_push2(solv->update_targets, pi, pi);
3164 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
3165 while ((obs = *obsp++) != 0)
3167 FOR_PROVIDES(pi, pip, obs)
3169 Solvable *si = pool->solvables + pi;
3170 if (si->repo != installed)
3172 if (si->name == s->name)
3173 continue; /* already handled above */
3174 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
3176 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
3178 if (how & SOLVER_FORCEBEST)
3180 if (!solv->bestupdatemap.size)
3181 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3182 MAPSET(&solv->bestupdatemap, pi - installed->start);
3184 if (how & SOLVER_CLEANDEPS)
3185 add_cleandeps_package(solv, pi);
3186 queue_push2(solv->update_targets, pi, p);
3193 transform_update_targets_sortfn(const void *ap, const void *bp, void *dp)
3203 transform_update_targets(Solver *solv)
3205 Repo *installed = solv->installed;
3206 Queue *update_targets = solv->update_targets;
3208 Id p, q, lastp, lastq;
3210 if (!update_targets->count)
3212 queue_free(update_targets);
3213 solv->update_targets = solv_free(update_targets);
3216 if (update_targets->count > 2)
3217 solv_sort(update_targets->elements, update_targets->count >> 1, 2 * sizeof(Id), transform_update_targets_sortfn, solv);
3218 queue_insertn(update_targets, 0, installed->end - installed->start, 0);
3220 for (i = j = installed->end - installed->start; i < update_targets->count; i += 2)
3222 if ((p = update_targets->elements[i]) != lastp)
3224 if (!solv->updatemap.size)
3225 map_grow(&solv->updatemap, installed->end - installed->start);
3226 MAPSET(&solv->updatemap, p - installed->start);
3227 update_targets->elements[j++] = 0; /* finish old set */
3228 update_targets->elements[p - installed->start] = j; /* start new set */
3232 if ((q = update_targets->elements[i + 1]) != lastq)
3234 update_targets->elements[j++] = q;
3238 queue_truncate(update_targets, j);
3239 queue_push(update_targets, 0); /* finish last set */
3244 addedmap2deduceq(Solver *solv, Map *addedmap)
3246 Pool *pool = solv->pool;
3251 queue_empty(&solv->addedmap_deduceq);
3252 for (i = 2, j = solv->pkgrules_end - 1; i < pool->nsolvables && j > 0; j--)
3254 r = solv->rules + j;
3257 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3260 if (!MAPTST(addedmap, p))
3262 /* should never happen, but... */
3263 if (!solv->addedmap_deduceq.count || solv->addedmap_deduceq.elements[solv->addedmap_deduceq.count - 1] != -p)
3264 queue_push(&solv->addedmap_deduceq, -p);
3268 if (MAPTST(addedmap, i))
3269 queue_push(&solv->addedmap_deduceq, i);
3273 for (; i < pool->nsolvables; i++)
3274 if (MAPTST(addedmap, i))
3275 queue_push(&solv->addedmap_deduceq, i);
3277 for (i = 2; i < pool->nsolvables; i++)
3278 if (MAPTST(addedmap, i))
3283 deduceq2addedmap(Solver *solv, Map *addedmap)
3288 for (j = solv->pkgrules_end - 1; j > 0; j--)
3290 r = solv->rules + j;
3291 if (r->d < 0 && r->p)
3292 solver_enablerule(solv, r);
3295 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3298 MAPSET(addedmap, p);
3300 for (j = 0; j < solv->addedmap_deduceq.count; j++)
3302 p = solv->addedmap_deduceq.elements[j];
3304 MAPSET(addedmap, p);
3306 MAPCLR(addedmap, p);
3310 #ifdef ENABLE_COMPLEX_DEPS
3312 add_complex_jobrules(Solver *solv, Id dep, int flags, int jobidx, int weak)
3314 Pool *pool = solv->pool;
3319 i = pool_normalize_complex_dep(pool, dep, &bq, flags | CPLXDEPS_EXPAND);
3320 if (i == 0 || i == 1)
3324 solver_addjobrule(solv, -SYSTEMSOLVABLE, 0, 0, jobidx, weak);
3327 for (i = 0; i < bq.count; i++)
3329 if (!bq.elements[i])
3331 for (j = 0; bq.elements[i + j + 1]; j++)
3334 solver_addjobrule(solv, bq.elements[i], 0, pool_ids2whatprovides(pool, bq.elements + i + 1, j), jobidx, weak);
3336 solver_addjobrule(solv, bq.elements[i], bq.elements[i + 1], 0, jobidx, weak);
3351 solver_solve(Solver *solv, Queue *job)
3353 Pool *pool = solv->pool;
3354 Repo *installed = solv->installed;
3356 int oldnrules, initialnrules;
3357 Map addedmap; /* '1' == have pkg-rules for solvable */
3358 Map installcandidatemap;
3359 Id how, what, select, name, weak, p, pp, d;
3363 int now, solve_start;
3364 int needduprules = 0;
3365 int hasbestinstalljob = 0;
3367 solve_start = solv_timems(0);
3369 /* log solver options */
3370 POOL_DEBUG(SOLV_DEBUG_STATS, "solver started\n");
3371 POOL_DEBUG(SOLV_DEBUG_STATS, "dosplitprovides=%d, noupdateprovide=%d, noinfarchcheck=%d\n", solv->dosplitprovides, solv->noupdateprovide, solv->noinfarchcheck);
3372 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);
3373 POOL_DEBUG(SOLV_DEBUG_STATS, "promoteepoch=%d, forbidselfconflicts=%d\n", pool->promoteepoch, pool->forbidselfconflicts);
3374 POOL_DEBUG(SOLV_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d, obsoleteusescolors=%d, implicitobsoleteusescolors=%d\n", pool->obsoleteusesprovides, pool->implicitobsoleteusesprovides, pool->obsoleteusescolors, pool->implicitobsoleteusescolors);
3375 POOL_DEBUG(SOLV_DEBUG_STATS, "dontinstallrecommended=%d, addalreadyrecommended=%d\n", solv->dontinstallrecommended, solv->addalreadyrecommended);
3377 /* create whatprovides if not already there */
3378 if (!pool->whatprovides)
3379 pool_createwhatprovides(pool);
3381 /* create obsolete index */
3382 policy_create_obsolete_index(solv);
3385 queue_free(&solv->job);
3386 queue_init_clone(&solv->job, job);
3387 solv->pooljobcnt = pool->pooljobs.count;
3388 if (pool->pooljobs.count)
3389 queue_insertn(&solv->job, 0, pool->pooljobs.count, pool->pooljobs.elements);
3392 /* free old stuff in jase we re-run a solver */
3393 queuep_free(&solv->update_targets);
3394 queuep_free(&solv->cleandeps_updatepkgs);
3395 queue_empty(&solv->ruleassertions);
3396 solv->bestrules_pkg = solv_free(solv->bestrules_pkg);
3397 solv->yumobsrules_info = solv_free(solv->yumobsrules_info);
3398 solv->choicerules_ref = solv_free(solv->choicerules_ref);
3399 if (solv->noupdate.size)
3400 map_empty(&solv->noupdate);
3401 map_zerosize(&solv->multiversion);
3402 solv->updatemap_all = 0;
3403 map_zerosize(&solv->updatemap);
3404 solv->bestupdatemap_all = 0;
3405 map_zerosize(&solv->bestupdatemap);
3406 solv->fixmap_all = 0;
3407 map_zerosize(&solv->fixmap);
3408 solv->dupmap_all = 0;
3409 map_zerosize(&solv->dupmap);
3410 map_zerosize(&solv->dupinvolvedmap);
3411 solv->droporphanedmap_all = 0;
3412 map_zerosize(&solv->droporphanedmap);
3413 solv->allowuninstall_all = 0;
3414 map_zerosize(&solv->allowuninstallmap);
3415 map_zerosize(&solv->cleandepsmap);
3416 map_zerosize(&solv->weakrulemap);
3417 queue_empty(&solv->weakruleq);
3418 solv->watches = solv_free(solv->watches);
3419 queue_empty(&solv->ruletojob);
3420 if (solv->decisionq.count)
3421 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
3422 queue_empty(&solv->decisionq);
3423 queue_empty(&solv->decisionq_why);
3424 solv->decisioncnt_jobs = solv->decisioncnt_update = solv->decisioncnt_keep = solv->decisioncnt_resolve = solv->decisioncnt_weak = solv->decisioncnt_orphan = 0;
3425 queue_empty(&solv->learnt_why);
3426 queue_empty(&solv->learnt_pool);
3427 queue_empty(&solv->branches);
3428 solv->propagate_index = 0;
3429 queue_empty(&solv->problems);
3430 queue_empty(&solv->solutions);
3431 queue_empty(&solv->orphaned);
3432 solv->stats_learned = solv->stats_unsolvable = 0;
3433 if (solv->recommends_index)
3435 map_empty(&solv->recommendsmap);
3436 map_empty(&solv->suggestsmap);
3437 queuep_free(&solv->recommendscplxq);
3438 queuep_free(&solv->suggestscplxq);
3439 solv->recommends_index = 0;
3441 queuep_free(&solv->brokenorphanrules);
3442 solv->specialupdaters = solv_free(solv->specialupdaters);
3446 * create basic rule set of all involved packages
3447 * use addedmap bitmap to make sure we don't create rules twice
3450 /* create multiversion map if needed */
3451 solver_calculate_multiversionmap(pool, job, &solv->multiversion);
3453 map_init(&addedmap, pool->nsolvables);
3454 MAPSET(&addedmap, SYSTEMSOLVABLE);
3456 map_init(&installcandidatemap, pool->nsolvables);
3459 now = solv_timems(0);
3461 * create rules for all package that could be involved with the solving
3462 * so called: pkg rules
3465 initialnrules = solv->pkgrules_end ? solv->pkgrules_end : 1;
3466 if (initialnrules > 1)
3467 deduceq2addedmap(solv, &addedmap);
3468 if (solv->nrules != initialnrules)
3469 solver_shrinkrules(solv, initialnrules);
3470 solv->nrules = initialnrules;
3471 solv->pkgrules_end = 0;
3475 /* check for update/verify jobs as they need to be known early */
3476 /* also setup the droporphaned map, we need it when creating update rules */
3477 for (i = 0; i < job->count; i += 2)
3479 how = job->elements[i];
3480 what = job->elements[i + 1];
3481 select = how & SOLVER_SELECTMASK;
3482 switch (how & SOLVER_JOBMASK)
3485 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
3486 solv->fixmap_all = 1;
3487 FOR_JOB_SELECT(p, pp, select, what)
3489 s = pool->solvables + p;
3490 if (s->repo != installed)
3492 if (!solv->fixmap.size)
3493 map_grow(&solv->fixmap, installed->end - installed->start);
3494 MAPSET(&solv->fixmap, p - installed->start);
3498 if (select == SOLVER_SOLVABLE_ALL)
3500 solv->updatemap_all = 1;
3501 if (how & SOLVER_FORCEBEST)
3502 solv->bestupdatemap_all = 1;
3503 if (how & SOLVER_CLEANDEPS)
3505 FOR_REPO_SOLVABLES(installed, p, s)
3506 add_cleandeps_package(solv, p);
3509 else if (select == SOLVER_SOLVABLE_REPO)
3511 Repo *repo = pool_id2repo(pool, what);
3514 if (repo == installed && !(how & SOLVER_TARGETED))
3516 solv->updatemap_all = 1;
3517 if (how & SOLVER_FORCEBEST)
3518 solv->bestupdatemap_all = 1;
3519 if (how & SOLVER_CLEANDEPS)
3521 FOR_REPO_SOLVABLES(installed, p, s)
3522 add_cleandeps_package(solv, p);
3526 if (solv->noautotarget && !(how & SOLVER_TARGETED))
3528 /* targeted update */
3529 FOR_REPO_SOLVABLES(repo, p, s)
3530 add_update_target(solv, p, how);
3534 if (!(how & SOLVER_TARGETED))
3537 FOR_JOB_SELECT(p, pp, select, what)
3539 s = pool->solvables + p;
3540 if (s->repo != installed)
3542 if (!solv->updatemap.size)
3543 map_grow(&solv->updatemap, installed->end - installed->start);
3544 MAPSET(&solv->updatemap, p - installed->start);
3545 if (how & SOLVER_FORCEBEST)
3547 if (!solv->bestupdatemap.size)
3548 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3549 MAPSET(&solv->bestupdatemap, p - installed->start);
3551 if (how & SOLVER_CLEANDEPS)
3552 add_cleandeps_package(solv, p);
3555 if (!targeted || solv->noautotarget)
3558 FOR_JOB_SELECT(p, pp, select, what)
3559 add_update_target(solv, p, how);
3562 case SOLVER_DROP_ORPHANED:
3563 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
3564 solv->droporphanedmap_all = 1;
3565 FOR_JOB_SELECT(p, pp, select, what)
3567 s = pool->solvables + p;
3568 if (s->repo != installed)
3570 if (!solv->droporphanedmap.size)
3571 map_grow(&solv->droporphanedmap, installed->end - installed->start);
3572 MAPSET(&solv->droporphanedmap, p - installed->start);
3575 case SOLVER_ALLOWUNINSTALL:
3576 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
3577 solv->allowuninstall_all = 1;
3578 FOR_JOB_SELECT(p, pp, select, what)
3580 s = pool->solvables + p;
3581 if (s->repo != installed)
3583 if (!solv->allowuninstallmap.size)
3584 map_grow(&solv->allowuninstallmap, installed->end - installed->start);
3585 MAPSET(&solv->allowuninstallmap, p - installed->start);
3593 if (solv->update_targets)
3594 transform_update_targets(solv);
3596 oldnrules = solv->nrules;
3597 FOR_REPO_SOLVABLES(installed, p, s)
3598 solver_addpkgrulesforsolvable(solv, s, &addedmap);
3599 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules for installed solvables\n", solv->nrules - oldnrules);
3600 oldnrules = solv->nrules;
3601 FOR_REPO_SOLVABLES(installed, p, s)
3602 solver_addpkgrulesforupdaters(solv, s, &addedmap, 1);
3603 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3607 * create rules for all packages involved in the job
3608 * (to be installed or removed)
3611 oldnrules = solv->nrules;
3612 for (i = 0; i < job->count; i += 2)
3614 how = job->elements[i];
3615 what = job->elements[i + 1];
3616 select = how & SOLVER_SELECTMASK;
3618 switch (how & SOLVER_JOBMASK)
3620 case SOLVER_INSTALL:
3621 FOR_JOB_SELECT(p, pp, select, what)
3623 MAPSET(&installcandidatemap, p);
3624 solver_addpkgrulesforsolvable(solv, pool->solvables + p, &addedmap);
3627 case SOLVER_DISTUPGRADE:
3628 if (select == SOLVER_SOLVABLE_ALL)
3630 solv->dupmap_all = 1;
3631 solv->updatemap_all = 1;
3632 if (how & SOLVER_FORCEBEST)
3633 solv->bestupdatemap_all = 1;
3635 if ((how & SOLVER_TARGETED) != 0)
3637 if (!solv->dupmap_all || solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size || solv->keep_orphans)
3644 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules for packages involved in a job\n", solv->nrules - oldnrules);
3648 * add rules for suggests, enhances
3650 oldnrules = solv->nrules;
3651 solver_addpkgrulesforweak(solv, &addedmap);
3652 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules because of weak dependencies\n", solv->nrules - oldnrules);
3654 #ifdef ENABLE_LINKED_PKGS
3655 oldnrules = solv->nrules;
3656 solver_addpkgrulesforlinked(solv, &addedmap);
3657 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules because of linked packages\n", solv->nrules - oldnrules);
3661 * first pass done, we now have all the pkg rules we need.
3662 * unify existing rules before going over all job rules and
3664 * at this point the system is always solvable,
3665 * as an empty system (remove all packages) is a valid solution
3668 IF_POOLDEBUG (SOLV_DEBUG_STATS)
3670 int possible = 0, installable = 0;
3671 for (i = 1; i < pool->nsolvables; i++)
3673 if (pool_installable(pool, pool->solvables + i))
3675 if (MAPTST(&addedmap, i))
3678 POOL_DEBUG(SOLV_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
3681 if (solv->nrules > initialnrules)
3682 solver_unifyrules(solv); /* remove duplicate pkg rules */
3683 solv->pkgrules_end = solv->nrules; /* mark end of pkg rules */
3685 if (solv->nrules > initialnrules)
3686 addedmap2deduceq(solv, &addedmap); /* so that we can recreate the addedmap */
3688 POOL_DEBUG(SOLV_DEBUG_STATS, "pkg rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
3689 POOL_DEBUG(SOLV_DEBUG_STATS, "pkg rule creation took %d ms\n", solv_timems(now));
3691 /* create dup maps if needed. We need the maps early to create our
3694 solver_createdupmaps(solv);
3697 * create feature rules
3699 * foreach installed:
3700 * create assertion (keep installed, if no update available)
3702 * create update rule (A|update1(A)|update2(A)|...)
3704 * those are used later on to keep a version of the installed packages in
3708 solv->featurerules = solv->nrules; /* mark start of feature rules */
3711 /* foreach possibly installed solvable */
3712 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3714 if (s->repo != installed)
3716 solver_addrule(solv, 0, 0, 0); /* create dummy rule */
3719 solver_addupdaterule(solv, s, 1); /* allow s to be updated */
3721 /* make sure we accounted for all rules */
3722 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
3724 solv->featurerules_end = solv->nrules;
3727 * Add update rules for installed solvables
3729 * almost identical to feature rules
3730 * except that downgrades/archchanges/vendorchanges are not allowed
3733 solv->updaterules = solv->nrules;
3736 { /* foreach installed solvables */
3737 /* we create all update rules, but disable some later on depending on the job */
3738 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3742 if (s->repo != installed)
3744 solver_addrule(solv, 0, 0, 0); /* create dummy rule */
3747 solver_addupdaterule(solv, s, 0); /* allowall = 0: downgrades not allowed */
3749 * check for and remove duplicate
3751 r = solv->rules + solv->nrules - 1; /* r: update rule */
3752 sr = r - (installed->end - installed->start); /* sr: feature rule */
3756 memset(sr, 0, sizeof(*sr)); /* no feature rules without update rules */
3759 /* it's also orphaned if the feature rule consists just of the installed package */
3760 if (!solv->dupmap_all && sr->p == i && !sr->d && !sr->w2)
3761 queue_push(&solv->orphaned, i);
3762 if (!solver_rulecmp(solv, r, sr))
3763 memset(sr, 0, sizeof(*sr)); /* delete unneeded feature rule */
3765 solver_disablerule(solv, sr); /* disable feature rule for now */
3767 /* consistency check: we added a rule for _every_ installed solvable */
3768 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
3770 solv->updaterules_end = solv->nrules;
3774 * now add all job rules
3777 solv->jobrules = solv->nrules;
3778 for (i = 0; i < job->count; i += 2)
3780 oldnrules = solv->nrules;
3782 if (i && i == solv->pooljobcnt)
3783 POOL_DEBUG(SOLV_DEBUG_JOB, "end of pool jobs\n");
3784 how = job->elements[i];
3785 what = job->elements[i + 1];
3786 weak = how & SOLVER_WEAK;
3787 select = how & SOLVER_SELECTMASK;
3788 switch (how & SOLVER_JOBMASK)
3790 case SOLVER_INSTALL:
3791 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3792 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
3793 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3794 if (select == SOLVER_SOLVABLE)
3799 #ifdef ENABLE_COMPLEX_DEPS
3800 else if ((select == SOLVER_SOLVABLE_PROVIDES || select == SOLVER_SOLVABLE_NAME) && pool_is_complex_dep(pool, what))
3802 if (add_complex_jobrules(solv, what, select == SOLVER_SOLVABLE_NAME ? CPLXDEPS_NAME : 0, i, weak))
3803 if (how & SOLVER_FORCEBEST)
3804 hasbestinstalljob = 1;
3811 FOR_JOB_SELECT(p, pp, select, what)
3815 if (select == SOLVER_SOLVABLE_ONE_OF)
3816 break; /* ignore empty installs */
3817 /* no candidate found or unsupported, make this an impossible rule */
3818 queue_push(&q, -SYSTEMSOLVABLE);
3820 p = queue_shift(&q); /* get first candidate */
3821 d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
3823 /* force install of namespace supplements hack */
3824 if (select == SOLVER_SOLVABLE_PROVIDES && !d && (p == SYSTEMSOLVABLE || p == -SYSTEMSOLVABLE) && ISRELDEP(what))
3826 Reldep *rd = GETRELDEP(pool, what);
3827 if (rd->flags == REL_NAMESPACE)
3830 if (!solv->installsuppdepq)
3832 solv->installsuppdepq = solv_calloc(1, sizeof(Queue));
3833 queue_init(solv->installsuppdepq);
3835 queue_pushunique(solv->installsuppdepq, rd->evr == 0 ? rd->name : what);
3838 solver_addjobrule(solv, p, 0, d, i, weak);
3839 if (how & SOLVER_FORCEBEST)
3840 hasbestinstalljob = 1;
3843 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %s%serase %s\n", weak ? "weak " : "", how & SOLVER_CLEANDEPS ? "clean deps " : "", solver_select2str(pool, select, what));
3844 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
3845 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3846 /* specific solvable: by id or by nevra */
3847 name = (select == SOLVER_SOLVABLE || (select == SOLVER_SOLVABLE_NAME && ISRELDEP(what))) ? 0 : -1;
3848 if (select == SOLVER_SOLVABLE_ALL) /* hmmm ;) */
3850 FOR_POOL_SOLVABLES(p)
3851 solver_addjobrule(solv, -p, 0, 0, i, weak);
3853 else if (select == SOLVER_SOLVABLE_REPO)
3855 Repo *repo = pool_id2repo(pool, what);
3857 FOR_REPO_SOLVABLES(repo, p, s)
3858 solver_addjobrule(solv, -p, 0, 0, i, weak);
3860 #ifdef ENABLE_COMPLEX_DEPS
3861 else if ((select == SOLVER_SOLVABLE_PROVIDES || select == SOLVER_SOLVABLE_NAME) && pool_is_complex_dep(pool, what))
3863 /* no special "erase a specific solvable" handling? */
3864 add_complex_jobrules(solv, what, select == SOLVER_SOLVABLE_NAME ? (CPLXDEPS_NAME | CPLXDEPS_TODNF | CPLXDEPS_INVERT) : (CPLXDEPS_TODNF | CPLXDEPS_INVERT), i, weak);
3868 FOR_JOB_SELECT(p, pp, select, what)
3870 s = pool->solvables + p;
3871 if (installed && s->repo == installed)
3872 name = !name ? s->name : -1;
3873 solver_addjobrule(solv, -p, 0, 0, i, weak);
3875 /* special case for "erase a specific solvable": we also
3876 * erase all other solvables with that name, so that they
3877 * don't get picked up as replacement.
3878 * name is > 0 if exactly one installed solvable matched.
3880 /* XXX: look also at packages that obsolete this package? */
3885 FOR_PROVIDES(p, pp, name)
3887 s = pool->solvables + p;
3888 if (s->name != name)
3890 /* keep other versions installed */
3891 if (s->repo == installed)
3893 /* keep installcandidates of other jobs */
3894 if (MAPTST(&installcandidatemap, p))
3896 /* don't add the same rule twice */
3897 for (j = oldnrules; j < k; j++)
3898 if (solv->rules[j].p == -p)
3901 solver_addjobrule(solv, -p, 0, 0, i, weak); /* remove by id */
3907 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3910 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sverify %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3912 case SOLVER_WEAKENDEPS:
3913 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3914 if (select != SOLVER_SOLVABLE)
3916 s = pool->solvables + what;
3917 weaken_solvable_deps(solv, what);
3919 case SOLVER_MULTIVERSION:
3920 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %smultiversion %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3923 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3924 if (select == SOLVER_SOLVABLE_ALL)
3926 FOR_POOL_SOLVABLES(p)
3927 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, 0, i, weak);
3929 else if (select == SOLVER_SOLVABLE_REPO)
3931 Repo *repo = pool_id2repo(pool, what);
3933 FOR_REPO_SOLVABLES(repo, p, s)
3934 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, 0, i, weak);
3936 FOR_JOB_SELECT(p, pp, select, what)
3937 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, 0, i, weak);
3939 case SOLVER_DISTUPGRADE:
3940 POOL_DEBUG(SOLV_DEBUG_JOB, "job: distupgrade %s\n", solver_select2str(pool, select, what));
3942 case SOLVER_DROP_ORPHANED:
3943 POOL_DEBUG(SOLV_DEBUG_JOB, "job: drop orphaned %s\n", solver_select2str(pool, select, what));
3945 case SOLVER_USERINSTALLED:
3946 POOL_DEBUG(SOLV_DEBUG_JOB, "job: user installed %s\n", solver_select2str(pool, select, what));
3948 case SOLVER_ALLOWUNINSTALL:
3949 POOL_DEBUG(SOLV_DEBUG_JOB, "job: allowuninstall %s\n", solver_select2str(pool, select, what));
3952 POOL_DEBUG(SOLV_DEBUG_JOB, "job: unknown job\n");
3956 IF_POOLDEBUG (SOLV_DEBUG_JOB)
3959 if (solv->nrules == oldnrules)
3960 POOL_DEBUG(SOLV_DEBUG_JOB, " - no rule created\n");
3961 for (j = oldnrules; j < solv->nrules; j++)
3963 POOL_DEBUG(SOLV_DEBUG_JOB, " - job ");
3964 solver_printrule(solv, SOLV_DEBUG_JOB, solv->rules + j);
3968 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3969 solv->jobrules_end = solv->nrules;
3971 /* now create infarch and dup rules */
3972 if (!solv->noinfarchcheck)
3974 solver_addinfarchrules(solv, &addedmap);
3976 if (pool->implicitobsoleteusescolors)
3978 /* currently doesn't work well with infarch rules, so make
3980 for (i = solv->infarchrules; i < solv->infarchrules_end; i++)
3981 queue_push(&solv->weakruleq, i);
3986 solv->infarchrules = solv->infarchrules_end = solv->nrules;
3989 solver_addduprules(solv, &addedmap);
3991 solv->duprules = solv->duprules_end = solv->nrules;
3993 if (solv->bestupdatemap_all || solv->bestupdatemap.size || hasbestinstalljob)
3994 solver_addbestrules(solv, hasbestinstalljob);
3996 solv->bestrules = solv->bestrules_end = solv->nrules;
3999 solver_freedupmaps(solv); /* no longer needed */
4001 if (solv->do_yum_obsoletes)
4002 solver_addyumobsrules(solv);
4004 solv->yumobsrules = solv->yumobsrules_end = solv->nrules;
4007 solver_addchoicerules(solv);
4009 solv->choicerules = solv->choicerules_end = solv->nrules;
4013 for (i = solv->featurerules; i < solv->nrules; i++)
4014 solver_printruleclass(solv, SOLV_DEBUG_RESULT, solv->rules + i);
4016 /* all rules created
4017 * --------------------------------------------------------------
4018 * prepare for solving
4021 /* free unneeded memory */
4022 map_free(&addedmap);
4023 map_free(&installcandidatemap);
4026 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);
4027 POOL_DEBUG(SOLV_DEBUG_STATS, "overall rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
4029 /* create weak map */
4030 if (solv->weakruleq.count)
4032 map_grow(&solv->weakrulemap, solv->nrules);
4033 for (i = 0; i < solv->weakruleq.count; i++)
4035 p = solv->weakruleq.elements[i];
4036 MAPSET(&solv->weakrulemap, p);
4040 /* enable cleandepsmap creation if we have updatepkgs */
4041 if (solv->cleandeps_updatepkgs && !solv->cleandepsmap.size)
4042 map_grow(&solv->cleandepsmap, installed->end - installed->start);
4044 if (solv->cleandeps_mistakes)
4046 queue_free(solv->cleandeps_mistakes);
4047 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
4050 /* all new rules are learnt after this point */
4051 solv->learntrules = solv->nrules;
4053 /* create watches chains */
4056 /* create assertion index. it is only used to speed up
4057 * makeruledecsions() a bit */
4058 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
4059 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
4060 queue_push(&solv->ruleassertions, i);
4062 /* disable update rules that conflict with our job */
4063 solver_disablepolicyrules(solv);
4065 /* break orphans if requested */
4066 if (solv->dupmap_all && solv->orphaned.count && solv->break_orphans)
4067 solver_breakorphans(solv);
4070 * ********************************************
4072 * ********************************************
4075 now = solv_timems(0);
4076 solver_run_sat(solv, 1, solv->dontinstallrecommended ? 0 : 1);
4077 POOL_DEBUG(SOLV_DEBUG_STATS, "solver took %d ms\n", solv_timems(now));
4080 * prepare solution queue if there were problems
4082 solver_prepare_solutions(solv);
4084 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);
4085 POOL_DEBUG(SOLV_DEBUG_STATS, "solver_solve took %d ms\n", solv_timems(solve_start));
4087 /* return number of problems */
4088 return solv->problems.count ? solv->problems.count / 2 : 0;
4092 solver_create_transaction(Solver *solv)
4094 return transaction_create_decisionq(solv->pool, &solv->decisionq, &solv->multiversion);
4097 void solver_get_orphaned(Solver *solv, Queue *orphanedq)
4099 queue_free(orphanedq);
4100 queue_init_clone(orphanedq, &solv->orphaned);
4103 void solver_get_recommendations(Solver *solv, Queue *recommendationsq, Queue *suggestionsq, int noselected)
4105 Pool *pool = solv->pool;
4106 Queue redoq, disabledq;
4112 if (!recommendationsq && !suggestionsq)
4115 map_init(&obsmap, pool->nsolvables);
4116 if (solv->installed)
4118 Id obs, *obsp, p, po, ppo;
4119 for (p = solv->installed->start; p < solv->installed->end; p++)
4121 s = pool->solvables + p;
4122 if (s->repo != solv->installed || !s->obsoletes)
4124 if (solv->decisionmap[p] <= 0)
4126 if (solv->multiversion.size && MAPTST(&solv->multiversion, p))
4128 obsp = s->repo->idarraydata + s->obsoletes;
4129 /* foreach obsoletes */
4130 while ((obs = *obsp++) != 0)
4131 FOR_PROVIDES(po, ppo, obs)
4132 MAPSET(&obsmap, po);
4137 queue_init(&disabledq);
4139 /* disable all erase jobs (including weak "keep uninstalled" rules) */
4140 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
4142 if (r->d < 0) /* disabled ? */
4144 if (r->p >= 0) /* install job? */
4146 queue_push(&disabledq, i);
4147 solver_disablerule(solv, r);
4153 enabledisablelearntrules(solv);
4154 removedisabledconflicts(solv, &redoq);
4158 * find recommended packages
4160 if (recommendationsq)
4162 Id rec, *recp, p, pp;
4164 queue_empty(recommendationsq);
4165 /* create map of all recommened packages */
4166 solv->recommends_index = -1;
4167 MAPZERO(&solv->recommendsmap);
4169 /* put all packages the solver already chose in the map */
4170 if (solv->decisioncnt_weak)
4172 for (i = solv->decisioncnt_weak; i < solv->decisioncnt_orphan; i++)
4175 why = solv->decisionq_why.elements[i];
4177 continue; /* forced by unit rule or dep resolving */
4178 p = solv->decisionq.elements[i];
4181 MAPSET(&solv->recommendsmap, p);
4185 for (i = 0; i < solv->decisionq.count; i++)
4187 p = solv->decisionq.elements[i];
4190 s = pool->solvables + p;
4193 recp = s->repo->idarraydata + s->recommends;
4194 while ((rec = *recp++) != 0)
4196 #ifdef ENABLE_COMPLEX_DEPS
4197 if (pool_is_complex_dep(pool, rec))
4199 do_complex_recommendations(solv, rec, &solv->recommendsmap, noselected);
4203 FOR_PROVIDES(p, pp, rec)
4204 if (solv->decisionmap[p] > 0)
4210 FOR_PROVIDES(p, pp, rec)
4211 if (solv->decisionmap[p] > 0)
4212 MAPSET(&solv->recommendsmap, p);
4214 continue; /* p != 0: already fulfilled */
4216 FOR_PROVIDES(p, pp, rec)
4217 MAPSET(&solv->recommendsmap, p);
4221 for (i = 1; i < pool->nsolvables; i++)
4223 if (solv->decisionmap[i] < 0)
4225 if (solv->decisionmap[i] > 0 && noselected)
4227 if (MAPTST(&obsmap, i))
4229 s = pool->solvables + i;
4230 if (!MAPTST(&solv->recommendsmap, i))
4232 if (!s->supplements)
4234 if (!pool_installable(pool, s))
4236 if (!solver_is_supplementing(solv, s))
4239 queue_push(recommendationsq, i);
4241 /* we use MODE_SUGGEST here so that repo prio is ignored */
4242 policy_filter_unwanted(solv, recommendationsq, POLICY_MODE_SUGGEST);
4246 * find suggested packages
4251 Id sug, *sugp, p, pp;
4253 queue_empty(suggestionsq);
4254 /* create map of all suggests that are still open */
4255 solv->recommends_index = -1;
4256 MAPZERO(&solv->suggestsmap);
4257 for (i = 0; i < solv->decisionq.count; i++)
4259 p = solv->decisionq.elements[i];
4262 s = pool->solvables + p;
4265 sugp = s->repo->idarraydata + s->suggests;
4266 while ((sug = *sugp++) != 0)
4268 #ifdef ENABLE_COMPLEX_DEPS
4269 if (pool_is_complex_dep(pool, sug))
4271 do_complex_recommendations(solv, sug, &solv->suggestsmap, noselected);
4275 FOR_PROVIDES(p, pp, sug)
4276 if (solv->decisionmap[p] > 0)
4282 FOR_PROVIDES(p, pp, sug)
4283 if (solv->decisionmap[p] > 0)
4284 MAPSET(&solv->suggestsmap, p);
4286 continue; /* already fulfilled */
4288 FOR_PROVIDES(p, pp, sug)
4289 MAPSET(&solv->suggestsmap, p);
4293 for (i = 1; i < pool->nsolvables; i++)
4295 if (solv->decisionmap[i] < 0)
4297 if (solv->decisionmap[i] > 0 && noselected)
4299 if (MAPTST(&obsmap, i))
4301 s = pool->solvables + i;
4302 if (!MAPTST(&solv->suggestsmap, i))
4306 if (!pool_installable(pool, s))
4308 if (!solver_is_enhancing(solv, s))
4311 queue_push(suggestionsq, i);
4313 policy_filter_unwanted(solv, suggestionsq, POLICY_MODE_SUGGEST);
4316 /* undo removedisabledconflicts */
4318 undo_removedisabledconflicts(solv, &redoq);
4321 /* undo job rule disabling */
4322 for (i = 0; i < disabledq.count; i++)
4323 solver_enablerule(solv, solv->rules + disabledq.elements[i]);
4324 queue_free(&disabledq);
4329 /***********************************************************************/
4330 /* disk usage computations */
4332 /*-------------------------------------------------------------------
4334 * calculate DU changes
4338 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
4342 solver_create_state_maps(solv, &installedmap, 0);
4343 pool_calc_duchanges(solv->pool, &installedmap, mps, nmps);
4344 map_free(&installedmap);
4348 /*-------------------------------------------------------------------
4350 * calculate changes in install size
4354 solver_calc_installsizechange(Solver *solv)
4359 solver_create_state_maps(solv, &installedmap, 0);
4360 change = pool_calc_installsizechange(solv->pool, &installedmap);
4361 map_free(&installedmap);
4366 solver_create_state_maps(Solver *solv, Map *installedmap, Map *conflictsmap)
4368 pool_create_state_maps(solv->pool, &solv->decisionq, installedmap, conflictsmap);
4372 solver_trivial_installable(Solver *solv, Queue *pkgs, Queue *res)
4374 Pool *pool = solv->pool;
4377 pool_create_state_maps(pool, &solv->decisionq, &installedmap, 0);
4378 pool_trivial_installable_multiversionmap(pool, &installedmap, pkgs, res, solv->multiversion.size ? &solv->multiversion : 0);
4379 for (i = 0; i < res->count; i++)
4380 if (res->elements[i] != -1)
4382 Solvable *s = pool->solvables + pkgs->elements[i];
4383 if (!strncmp("patch:", pool_id2str(pool, s->name), 6) && solvable_is_irrelevant_patch(s, &installedmap))
4384 res->elements[i] = -1;
4386 map_free(&installedmap);
4389 /*-------------------------------------------------------------------
4391 * decision introspection
4395 solver_get_decisionlevel(Solver *solv, Id p)
4397 return solv->decisionmap[p];
4401 solver_get_decisionqueue(Solver *solv, Queue *decisionq)
4403 queue_free(decisionq);
4404 queue_init_clone(decisionq, &solv->decisionq);
4408 solver_get_lastdecisionblocklevel(Solver *solv)
4411 if (solv->decisionq.count == 0)
4413 p = solv->decisionq.elements[solv->decisionq.count - 1];
4416 return solv->decisionmap[p] < 0 ? -solv->decisionmap[p] : solv->decisionmap[p];
4420 solver_get_decisionblock(Solver *solv, int level, Queue *decisionq)
4425 queue_empty(decisionq);
4426 for (i = 0; i < solv->decisionq.count; i++)
4428 p = solv->decisionq.elements[i];
4431 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
4434 if (i == solv->decisionq.count)
4436 for (i = 0; i < solv->decisionq.count; i++)
4438 p = solv->decisionq.elements[i];
4441 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
4442 queue_push(decisionq, p);
4449 solver_describe_decision(Solver *solv, Id p, Id *infop)
4456 if (!solv->decisionmap[p])
4457 return SOLVER_REASON_UNRELATED;
4458 pp = solv->decisionmap[p] < 0 ? -p : p;
4459 for (i = 0; i < solv->decisionq.count; i++)
4460 if (solv->decisionq.elements[i] == pp)
4462 if (i == solv->decisionq.count) /* just in case... */
4463 return SOLVER_REASON_UNRELATED;
4464 why = solv->decisionq_why.elements[i];
4466 *infop = why > 0 ? why : -why;
4468 return SOLVER_REASON_UNIT_RULE;
4471 return SOLVER_REASON_KEEP_INSTALLED; /* the systemsolvable */
4472 if (i < solv->decisioncnt_update)
4473 return SOLVER_REASON_RESOLVE_JOB;
4474 if (i < solv->decisioncnt_keep)
4476 if (why == 0 && pp < 0)
4477 return SOLVER_REASON_CLEANDEPS_ERASE;
4478 return SOLVER_REASON_UPDATE_INSTALLED;
4480 if (i < solv->decisioncnt_resolve)
4482 if (solv->focus_installed && i >= solv->decisioncnt_jobs)
4483 return SOLVER_REASON_RESOLVE_JOB;
4484 if (why == 0 && pp < 0)
4485 return SOLVER_REASON_CLEANDEPS_ERASE;
4486 return SOLVER_REASON_KEEP_INSTALLED;
4489 return SOLVER_REASON_RESOLVE;
4490 /* weak or orphaned */
4491 if (i < solv->decisioncnt_orphan)
4492 return SOLVER_REASON_WEAKDEP;
4493 return SOLVER_REASON_RESOLVE_ORPHAN;
4498 solver_describe_weakdep_decision(Solver *solv, Id p, Queue *whyq)
4500 Pool *pool = solv->pool;
4502 int level = solv->decisionmap[p];
4509 for (decisionno = 0; decisionno < solv->decisionq.count; decisionno++)
4510 if (solv->decisionq.elements[decisionno] == p)
4512 if (decisionno == solv->decisionq.count)
4514 if (decisionno < solv->decisioncnt_weak || decisionno >= solv->decisioncnt_orphan)
4517 /* 1) list all packages that recommend us */
4518 for (i = 1; i < pool->nsolvables; i++)
4520 Id *recp, rec, pp2, p2;
4521 if (solv->decisionmap[i] < 0 || solv->decisionmap[i] >= level)
4523 s = pool->solvables + i;
4526 if (!solv->addalreadyrecommended && s->repo == solv->installed)
4528 recp = s->repo->idarraydata + s->recommends;
4529 while ((rec = *recp++) != 0)
4532 FOR_PROVIDES(p2, pp2, rec)
4538 /* if p2 is already installed, this recommends is ignored */
4539 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4545 queue_push(whyq, SOLVER_REASON_RECOMMENDED);
4546 queue_push2(whyq, i, rec);
4550 /* 2) list all supplements */
4551 s = pool->solvables + p;
4552 if (s->supplements && level > 0)
4554 Id *supp, sup, pp2, p2;
4555 /* this is a hack. to use solver_dep_fulfilled we temporarily clear
4556 * everything above our level in the decisionmap */
4557 for (i = decisionno; i < solv->decisionq.count; i++ )
4559 p2 = solv->decisionq.elements[i];
4561 solv->decisionmap[p2] = -solv->decisionmap[p2];
4563 supp = s->repo->idarraydata + s->supplements;
4564 while ((sup = *supp++) != 0)
4565 if (solver_dep_fulfilled(solv, sup))
4568 /* let's see if this is an easy supp */
4569 FOR_PROVIDES(p2, pp2, sup)
4571 if (!solv->addalreadyrecommended && solv->installed)
4573 if (pool->solvables[p2].repo == solv->installed)
4576 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4578 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4579 queue_push2(whyq, p2, sup);
4585 /* hard case, just note dependency with no package */
4586 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4587 queue_push2(whyq, 0, sup);
4590 for (i = decisionno; i < solv->decisionq.count; i++)
4592 p2 = solv->decisionq.elements[i];
4594 solv->decisionmap[p2] = -solv->decisionmap[p2];
4600 pool_job2solvables(Pool *pool, Queue *pkgs, Id how, Id what)
4603 how &= SOLVER_SELECTMASK;
4605 if (how == SOLVER_SOLVABLE_ALL)
4607 FOR_POOL_SOLVABLES(p)
4608 queue_push(pkgs, p);
4610 else if (how == SOLVER_SOLVABLE_REPO)
4612 Repo *repo = pool_id2repo(pool, what);
4615 FOR_REPO_SOLVABLES(repo, p, s)
4616 queue_push(pkgs, p);
4620 FOR_JOB_SELECT(p, pp, how, what)
4621 queue_push(pkgs, p);
4626 pool_isemptyupdatejob(Pool *pool, Id how, Id what)
4629 Id select = how & SOLVER_SELECTMASK;
4630 if ((how & SOLVER_JOBMASK) != SOLVER_UPDATE)
4632 if (select == SOLVER_SOLVABLE_ALL || select == SOLVER_SOLVABLE_REPO)
4634 if (!pool->installed)
4636 FOR_JOB_SELECT(p, pp, select, what)
4637 if (pool->solvables[p].repo == pool->installed)
4640 FOR_JOB_SELECT(p, pp, select, what)
4642 Solvable *s = pool->solvables + p;
4643 FOR_PROVIDES(pi, pip, s->name)
4645 Solvable *si = pool->solvables + pi;
4646 if (si->repo != pool->installed || si->name != s->name)
4652 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
4653 while ((obs = *obsp++) != 0)
4655 FOR_PROVIDES(pi, pip, obs)
4657 Solvable *si = pool->solvables + pi;
4658 if (si->repo != pool->installed)
4660 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
4662 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
4673 get_userinstalled_cmp(const void *ap, const void *bp, void *dp)
4675 return *(Id *)ap - *(Id *)bp;
4679 get_userinstalled_cmp_names(const void *ap, const void *bp, void *dp)
4682 return strcmp(pool_id2str(pool, *(Id *)ap), pool_id2str(pool, *(Id *)bp));
4686 get_userinstalled_cmp_namearch(const void *ap, const void *bp, void *dp)
4690 r = strcmp(pool_id2str(pool, ((Id *)ap)[0]), pool_id2str(pool, ((Id *)bp)[0]));
4693 return strcmp(pool_id2str(pool, ((Id *)ap)[1]), pool_id2str(pool, ((Id *)bp)[1]));
4697 get_userinstalled_sort_uniq(Pool *pool, Queue *q, int flags)
4699 Id lastp = -1, lasta = -1;
4701 if (q->count < ((flags & GET_USERINSTALLED_NAMEARCH) ? 4 : 2))
4703 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4704 solv_sort(q->elements, q->count / 2, 2 * sizeof(Id), get_userinstalled_cmp_namearch, pool);
4705 else if ((flags & GET_USERINSTALLED_NAMES) != 0)
4706 solv_sort(q->elements, q->count, sizeof(Id), get_userinstalled_cmp_names, pool);
4708 solv_sort(q->elements, q->count, sizeof(Id), get_userinstalled_cmp, 0);
4709 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4711 for (i = j = 0; i < q->count; i += 2)
4712 if (q->elements[i] != lastp || q->elements[i + 1] != lasta)
4714 q->elements[j++] = lastp = q->elements[i];
4715 q->elements[j++] = lasta = q->elements[i + 1];
4720 for (i = j = 0; i < q->count; i++)
4721 if (q->elements[i] != lastp)
4722 q->elements[j++] = lastp = q->elements[i];
4724 queue_truncate(q, j);
4728 namearch2solvables(Pool *pool, Queue *q, Queue *qout, int job)
4731 if (!pool->installed)
4733 for (i = 0; i < q->count; i += 2)
4735 Id p, pp, name = q->elements[i], arch = q->elements[i + 1];
4736 FOR_PROVIDES(p, pp, name)
4738 Solvable *s = pool->solvables + p;
4739 if (s->repo != pool->installed || s->name != name || (arch && s->arch != arch))
4742 queue_push(qout, job);
4743 queue_push(qout, p);
4749 solver_get_userinstalled(Solver *solv, Queue *q, int flags)
4751 Pool *pool = solv->pool;
4754 Repo *installed = solv->installed;
4758 map_init(&userinstalled, 0);
4760 /* first process jobs */
4761 for (i = 0; i < solv->job.count; i += 2)
4763 Id how = solv->job.elements[i];
4765 if (installed && (how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
4767 if (!userinstalled.size)
4768 map_grow(&userinstalled, installed->end - installed->start);
4769 what = solv->job.elements[i + 1];
4770 select = how & SOLVER_SELECTMASK;
4771 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
4772 FOR_REPO_SOLVABLES(installed, p, s)
4773 MAPSET(&userinstalled, p - installed->start);
4774 FOR_JOB_SELECT(p, pp, select, what)
4775 if (pool->solvables[p].repo == installed)
4776 MAPSET(&userinstalled, p - installed->start);
4779 if ((how & SOLVER_JOBMASK) != SOLVER_INSTALL)
4781 if ((how & SOLVER_NOTBYUSER) != 0)
4783 what = solv->job.elements[i + 1];
4784 select = how & SOLVER_SELECTMASK;
4785 FOR_JOB_SELECT(p, pp, select, what)
4786 if (solv->decisionmap[p] > 0)
4789 #ifdef ENABLE_LINKED_PKGS
4790 if (has_package_link(pool, pool->solvables + p))
4795 find_package_link(pool, pool->solvables + p, 0, &lq, 0, 0);
4796 for (j = 0; j < lq.count; j++)
4797 if (solv->decisionmap[lq.elements[j]] > 0)
4798 queue_push(q, lq.elements[j]);
4803 /* now process updates of userinstalled packages */
4804 if (installed && userinstalled.size)
4806 for (i = 1; i < solv->decisionq.count; i++)
4808 p = solv->decisionq.elements[i];
4811 s = pool->solvables + p;
4814 if (s->repo == installed)
4816 if (MAPTST(&userinstalled, p - installed->start))
4820 /* new package, check if we replace a userinstalled one */
4821 FOR_PROVIDES(p2, pp, s->name)
4823 Solvable *ps = pool->solvables + p2;
4824 if (p2 == p || ps->repo != installed || !MAPTST(&userinstalled, p2 - installed->start))
4826 if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
4828 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, ps))
4833 if (!p2 && s->repo != installed && s->obsoletes)
4835 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
4836 while ((obs = *obsp++) != 0)
4838 FOR_PROVIDES(p2, pp, obs)
4840 Solvable *ps = pool->solvables + p2;
4841 if (p2 == p || ps->repo != installed || !MAPTST(&userinstalled, p2 - installed->start))
4843 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
4845 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
4856 map_free(&userinstalled);
4858 /* convert to desired output format */
4859 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4861 int qcount = q->count;
4862 queue_insertn(q, 0, qcount, 0);
4863 for (i = j = 0; i < qcount; i++)
4865 s = pool->solvables + q->elements[i + qcount];
4866 q->elements[j++] = s->name;
4867 q->elements[j++] = s->arch;
4870 else if ((flags & GET_USERINSTALLED_NAMES) != 0)
4872 for (i = 0; i < q->count; i++)
4874 s = pool->solvables + q->elements[i];
4875 q->elements[i] = s->name;
4878 /* sort and unify */
4879 get_userinstalled_sort_uniq(pool, q, flags);
4881 /* invert if asked for */
4882 if ((flags & GET_USERINSTALLED_INVERTED) != 0)
4884 /* first generate queue with all installed packages */
4887 for (i = 1; i < solv->decisionq.count; i++)
4889 p = solv->decisionq.elements[i];
4892 s = pool->solvables + p;
4895 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4896 queue_push2(&invq, s->name, s->arch);
4897 else if ((flags & GET_USERINSTALLED_NAMES) != 0)
4898 queue_push(&invq, s->name);
4900 queue_push(&invq, p);
4902 /* push q on invq, just in case... */
4903 queue_insertn(&invq, invq.count, q->count, q->elements);
4904 get_userinstalled_sort_uniq(pool, &invq, flags);
4905 /* subtract queues (easy as they are sorted and invq is a superset of q) */
4906 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4910 for (i = j = 0; i < invq.count; i += 2)
4911 if (invq.elements[i] == q->elements[j] && invq.elements[i + 1] == q->elements[j + 1])
4913 invq.elements[i] = invq.elements[i + 1] = 0;
4920 for (i = 0; i < invq.count; i += 2)
4921 if (invq.elements[i])
4922 queue_push2(q, invq.elements[i], invq.elements[i + 1]);
4928 for (i = j = 0; i < invq.count; i++)
4929 if (invq.elements[i] == q->elements[j])
4931 invq.elements[i] = 0;
4932 if (++j >= q->count)
4937 for (i = 0; i < invq.count; i++)
4938 if (invq.elements[i])
4939 queue_push(q, invq.elements[i]);
4946 pool_add_userinstalled_jobs(Pool *pool, Queue *q, Queue *job, int flags)
4950 if ((flags & GET_USERINSTALLED_INVERTED) != 0)
4956 if (!pool->installed)
4959 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4960 flags &= ~GET_USERINSTALLED_NAMES; /* just in case */
4961 FOR_REPO_SOLVABLES(pool->installed, p, s)
4962 queue_push(&invq, flags & GET_USERINSTALLED_NAMES ? s->name : p);
4963 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4965 /* for namearch we convert to packages */
4966 namearch2solvables(pool, q, &invq, 0);
4967 get_userinstalled_sort_uniq(pool, &invq, flags);
4968 namearch2solvables(pool, q, &invq, 0);
4973 queue_insertn(&invq, invq.count, q->count, q->elements);
4974 get_userinstalled_sort_uniq(pool, &invq, flags);
4975 /* now the fun part, add q again, sort, and remove all dups */
4976 queue_insertn(&invq, invq.count, q->count, q->elements);
4980 if ((flags & GET_USERINSTALLED_NAMES) != 0)
4981 solv_sort(invq.elements, invq.count, sizeof(Id), get_userinstalled_cmp_names, pool);
4983 solv_sort(invq.elements, invq.count, sizeof(Id), get_userinstalled_cmp, 0);
4987 for (i = 0; i < invq.count; i++)
4989 if (invq.elements[i] == lastid)
4995 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), lastid);
4997 lastid = invq.elements[i];
5000 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), lastid);
5005 if (flags & GET_USERINSTALLED_NAMEARCH)
5006 namearch2solvables(pool, q, job, SOLVER_USERINSTALLED | SOLVER_SOLVABLE);
5009 for (i = 0; i < q->count; i++)
5010 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), q->elements[i]);
5016 solver_alternatives_count(Solver *solv)
5018 Id *elements = solv->branches.elements;
5020 for (res = 0, count = solv->branches.count; count; res++)
5021 count -= elements[count - 2];
5026 solver_get_alternative(Solver *solv, Id alternative, Id *idp, Id *fromp, Id *chosenp, Queue *choices, int *levelp)
5028 int cnt = solver_alternatives_count(solv);
5029 int count = solv->branches.count;
5030 Id *elements = solv->branches.elements;
5032 queue_empty(choices);
5033 if (alternative <= 0 || alternative > cnt)
5036 for (; cnt > alternative; cnt--)
5037 elements -= elements[-2];
5039 *levelp = elements[-1];
5041 *fromp = elements[-4];
5043 *idp = elements[-3];
5048 for (i = elements[-2]; i > 4; i--)
5050 Id p = -elements[-i];
5051 if (p > 0 && solv->decisionmap[p] == elements[-1] + 1)
5059 queue_insertn(choices, 0, elements[-2] - 4, elements - elements[-2]);
5060 return elements[-4] ? SOLVER_ALTERNATIVE_TYPE_RECOMMENDS : SOLVER_ALTERNATIVE_TYPE_RULE;
5064 solver_select2str(Pool *pool, Id select, Id what)
5068 select &= SOLVER_SELECTMASK;
5069 if (select == SOLVER_SOLVABLE)
5070 return pool_solvid2str(pool, what);
5071 if (select == SOLVER_SOLVABLE_NAME)
5072 return pool_dep2str(pool, what);
5073 if (select == SOLVER_SOLVABLE_PROVIDES)
5075 s = pool_dep2str(pool, what);
5076 b = pool_alloctmpspace(pool, 11 + strlen(s));
5077 sprintf(b, "providing %s", s);
5080 if (select == SOLVER_SOLVABLE_ONE_OF)
5084 while ((p = pool->whatprovidesdata[what++]) != 0)
5086 s = pool_solvid2str(pool, p);
5088 b = pool_tmpappend(pool, b, ", ", s);
5090 b = pool_tmpjoin(pool, s, 0, 0);
5091 pool_freetmpspace(pool, s);
5093 return b ? b : "nothing";
5095 if (select == SOLVER_SOLVABLE_REPO)
5097 b = pool_alloctmpspace(pool, 20);
5098 sprintf(b, "repo #%d", what);
5101 if (select == SOLVER_SOLVABLE_ALL)
5102 return "all packages";
5103 return "unknown job select";
5107 pool_job2str(Pool *pool, Id how, Id what, Id flagmask)
5109 Id select = how & SOLVER_SELECTMASK;
5110 const char *strstart = 0, *strend = 0;
5114 switch (how & SOLVER_JOBMASK)
5117 return "do nothing";
5118 case SOLVER_INSTALL:
5119 if (select == SOLVER_SOLVABLE && pool->installed && pool->solvables[what].repo == pool->installed)
5120 strstart = "keep ", strend = " installed";
5121 else if (select == SOLVER_SOLVABLE || select == SOLVER_SOLVABLE_NAME)
5122 strstart = "install ";
5123 else if (select == SOLVER_SOLVABLE_PROVIDES)
5124 strstart = "install a package ";
5126 strstart = "install one of ";
5129 if (select == SOLVER_SOLVABLE && !(pool->installed && pool->solvables[what].repo == pool->installed))
5130 strstart = "keep ", strend = " uninstalled";
5131 else if (select == SOLVER_SOLVABLE_PROVIDES)
5132 strstart = "deinstall all packages ";
5134 strstart = "deinstall ";
5137 strstart = "update ";
5139 case SOLVER_WEAKENDEPS:
5140 strstart = "weaken deps of ";
5142 case SOLVER_MULTIVERSION:
5143 strstart = "multi version ";
5148 case SOLVER_DISTUPGRADE:
5149 strstart = "dist upgrade ";
5152 strstart = "verify ";
5154 case SOLVER_DROP_ORPHANED:
5155 strstart = "deinstall ", strend = " if orphaned";
5157 case SOLVER_USERINSTALLED:
5158 strstart = "regard ", strend = " as userinstalled";
5160 case SOLVER_ALLOWUNINSTALL:
5161 strstart = "allow deinstallation of ";
5164 strstart = "unknown job ";
5167 s = pool_tmpjoin(pool, strstart, solver_select2str(pool, select, what), strend);
5169 if ((how & ~(SOLVER_SELECTMASK|SOLVER_JOBMASK)) == 0)
5172 s = pool_tmpappend(pool, s, " ", 0);
5173 if (how & SOLVER_WEAK)
5174 s = pool_tmpappend(pool, s, ",weak", 0);
5175 if (how & SOLVER_ESSENTIAL)
5176 s = pool_tmpappend(pool, s, ",essential", 0);
5177 if (how & SOLVER_CLEANDEPS)
5178 s = pool_tmpappend(pool, s, ",cleandeps", 0);
5179 if (how & SOLVER_ORUPDATE)
5180 s = pool_tmpappend(pool, s, ",orupdate", 0);
5181 if (how & SOLVER_FORCEBEST)
5182 s = pool_tmpappend(pool, s, ",forcebest", 0);
5183 if (how & SOLVER_TARGETED)
5184 s = pool_tmpappend(pool, s, ",targeted", 0);
5185 if (how & SOLVER_SETEV)
5186 s = pool_tmpappend(pool, s, ",setev", 0);
5187 if (how & SOLVER_SETEVR)
5188 s = pool_tmpappend(pool, s, ",setevr", 0);
5189 if (how & SOLVER_SETARCH)
5190 s = pool_tmpappend(pool, s, ",setarch", 0);
5191 if (how & SOLVER_SETVENDOR)
5192 s = pool_tmpappend(pool, s, ",setvendor", 0);
5193 if (how & SOLVER_SETREPO)
5194 s = pool_tmpappend(pool, s, ",setrepo", 0);
5195 if (how & SOLVER_SETNAME)
5196 s = pool_tmpappend(pool, s, ",setname", 0);
5197 if (how & SOLVER_NOAUTOSET)
5198 s = pool_tmpappend(pool, s, ",noautoset", 0);
5199 if (s[o + 1] != ',')
5200 s = pool_tmpappend(pool, s, ",?", 0);
5202 return pool_tmpappend(pool, s, "]", 0);
5206 solver_alternative2str(Solver *solv, int type, Id id, Id from)
5208 Pool *pool = solv->pool;
5209 if (type == SOLVER_ALTERNATIVE_TYPE_RECOMMENDS)
5211 const char *s = pool_dep2str(pool, id);
5212 return pool_tmpappend(pool, s, ", recommended by ", pool_solvid2str(pool, from));
5214 if (type == SOLVER_ALTERNATIVE_TYPE_RULE)
5217 Id depfrom, depto, dep;
5219 if (solver_ruleclass(solv, id) == SOLVER_RULE_CHOICE)
5220 id = solver_rule2pkgrule(solv, id);
5221 rtype = solver_ruleinfo(solv, id, &depfrom, &depto, &dep);
5222 if ((rtype & SOLVER_RULE_TYPEMASK) == SOLVER_RULE_JOB)
5224 if ((depto & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_PROVIDES)
5225 return pool_dep2str(pool, dep);
5226 return solver_select2str(pool, depto & SOLVER_SELECTMASK, dep);
5228 if (rtype == SOLVER_RULE_PKG_REQUIRES)
5230 const char *s = pool_dep2str(pool, dep);
5231 return pool_tmpappend(pool, s, ", required by ", pool_solvid2str(pool, depfrom));
5233 sprintf(buf, "Rule #%d", id);
5234 return pool_tmpjoin(pool, buf, 0, 0);
5236 return "unknown alternative type";