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 */
221 r = solv->rules + solv->featurerules + (v - solv->updaterules);
224 /* update rule == feature rule */
233 if (!lastupdate && !lastfeature)
235 v = lastupdate ? lastupdate : lastfeature;
236 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "allowuninstall disabling ");
237 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + v);
238 solver_disableproblem(solv, v);
239 if (extraflags != -1 && (extraflags & SOLVER_CLEANDEPS) != 0 && solv->cleandepsmap.size)
241 /* add the package to the updatepkgs list, this will automatically turn
242 * on cleandeps mode */
243 Id p = solv->rules[v].p;
244 if (!solv->cleandeps_updatepkgs)
246 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
247 queue_init(solv->cleandeps_updatepkgs);
251 int oldupdatepkgscnt = solv->cleandeps_updatepkgs->count;
252 queue_pushunique(solv->cleandeps_updatepkgs, p);
253 if (solv->cleandeps_updatepkgs->count != oldupdatepkgscnt)
254 solver_disablepolicyrules(solv);
260 /************************************************************************/
263 * enable/disable learnt rules
265 * we have enabled or disabled some of our rules. We now reenable all
266 * of our learnt rules except the ones that were learnt from rules that
270 enabledisablelearntrules(Solver *solv)
272 Pool *pool = solv->pool;
277 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
278 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
280 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
281 while ((why = *whyp++) != 0)
283 assert(why > 0 && why < i);
284 if (solv->rules[why].d < 0)
287 /* why != 0: we found a disabled rule, disable the learnt rule */
288 if (why && r->d >= 0)
290 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
292 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "disabling ");
293 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
295 solver_disablerule(solv, r);
297 else if (!why && r->d < 0)
299 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
301 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "re-enabling ");
302 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
304 solver_enablerule(solv, r);
311 * make assertion rules into decisions
313 * Go through rules and add direct assertions to the decisionqueue.
314 * If we find a conflict, disable rules and add them to problem queue.
318 makeruledecisions(Solver *solv)
320 Pool *pool = solv->pool;
325 int record_proof = 1;
327 int havedisabled = 0;
329 /* The system solvable is always installed first */
330 assert(solv->decisionq.count == 0);
331 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
332 queue_push(&solv->decisionq_why, 0);
333 solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
335 decisionstart = solv->decisionq.count;
338 /* if we needed to re-run, back up decisions to decisionstart */
339 while (solv->decisionq.count > decisionstart)
341 v = solv->decisionq.elements[--solv->decisionq.count];
342 --solv->decisionq_why.count;
344 solv->decisionmap[vv] = 0;
347 /* note that the ruleassertions queue is ordered */
348 for (ii = 0; ii < solv->ruleassertions.count; ii++)
350 ri = solv->ruleassertions.elements[ii];
351 r = solv->rules + ri;
353 if (havedisabled && ri >= solv->learntrules)
355 /* just started with learnt rule assertions. If we have disabled
356 * some rules, adapt the learnt rule status */
357 enabledisablelearntrules(solv);
361 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
364 /* do weak rules in phase 2 */
365 if (ri < solv->learntrules && solv->weakrulemap.size && MAPTST(&solv->weakrulemap, ri))
371 if (!solv->decisionmap[vv]) /* if not yet decided */
373 queue_push(&solv->decisionq, v);
374 queue_push(&solv->decisionq_why, r - solv->rules);
375 solv->decisionmap[vv] = v > 0 ? 1 : -1;
376 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
378 Solvable *s = solv->pool->solvables + vv;
380 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", pool_solvable2str(solv->pool, s));
382 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (assertion)\n", pool_solvable2str(solv->pool, s));
387 /* check against previous decision: is there a conflict? */
388 if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
390 if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
396 * The rule (r) we're currently processing says something
397 * different (v = r->p) than a previous decision (decisionmap[abs(v)])
401 if (ri >= solv->learntrules)
403 /* conflict with a learnt rule */
404 /* can happen when packages cannot be installed for multiple reasons. */
405 /* we disable the learnt rule in this case */
406 /* (XXX: we should really call analyze_unsolvable_rule here!) */
407 solver_disablerule(solv, r);
412 * find the decision which is the "opposite" of the rule
414 for (i = 0; i < solv->decisionq.count; i++)
415 if (solv->decisionq.elements[i] == -v)
417 assert(i < solv->decisionq.count); /* assert that we found it */
418 oldproblemcount = solv->problems.count;
421 * conflict with system solvable ?
423 if (v == -SYSTEMSOLVABLE)
427 queue_push(&solv->problems, solv->learnt_pool.count);
428 queue_push(&solv->learnt_pool, ri);
429 queue_push(&solv->learnt_pool, 0);
432 queue_push(&solv->problems, 0);
433 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
434 if (ri >= solv->jobrules && ri < solv->jobrules_end)
435 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
438 queue_push(&solv->problems, v);
439 queue_push(&solv->problems, 0);
440 if (v >= solv->featurerules && v < solv->updaterules_end)
442 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
443 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
445 solv->problems.count = oldproblemcount;
447 break; /* start over */
450 solver_disableproblem(solv, v);
452 break; /* start over */
455 assert(solv->decisionq_why.elements[i] > 0);
458 * conflict with a pkg rule ?
460 if (solv->decisionq_why.elements[i] < solv->pkgrules_end)
464 queue_push(&solv->problems, solv->learnt_pool.count);
465 queue_push(&solv->learnt_pool, ri);
466 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
467 queue_push(&solv->learnt_pool, 0);
470 queue_push(&solv->problems, 0);
471 assert(v > 0 || v == -SYSTEMSOLVABLE);
472 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with pkg rule, disabling rule #%d\n", ri);
473 if (ri >= solv->jobrules && ri < solv->jobrules_end)
474 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
477 queue_push(&solv->problems, v);
478 queue_push(&solv->problems, 0);
479 if (v >= solv->featurerules && v < solv->updaterules_end)
481 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
482 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
484 solv->problems.count = oldproblemcount;
486 break; /* start over */
489 solver_disableproblem(solv, v);
491 break; /* start over */
495 * conflict with another job or update/feature rule
501 queue_push(&solv->problems, solv->learnt_pool.count);
502 queue_push(&solv->learnt_pool, ri);
503 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
504 queue_push(&solv->learnt_pool, 0);
507 queue_push(&solv->problems, 0);
509 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
512 * push all of our rules (can only be feature or job rules)
513 * asserting this literal on the problem stack
515 for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
517 if (rr->d < 0 /* disabled */
518 || rr->w2) /* or no assertion */
520 if (rr->p != vv /* not affecting the literal */
523 if (solv->weakrulemap.size && MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
526 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
527 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + i);
530 if (i >= solv->jobrules && i < solv->jobrules_end)
531 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
532 queue_push(&solv->problems, v);
534 queue_push(&solv->problems, 0);
536 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
537 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
539 solv->problems.count = oldproblemcount;
541 break; /* start over */
544 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
545 solver_disableproblem(solv, solv->problems.elements[i]);
547 break; /* start over */
549 if (ii < solv->ruleassertions.count)
553 * phase 2: now do the weak assertions
555 if (!solv->weakrulemap.size)
556 break; /* no weak rules, no phase 2 */
557 for (ii = 0; ii < solv->ruleassertions.count; ii++)
559 ri = solv->ruleassertions.elements[ii];
560 r = solv->rules + ri;
561 if (r->d < 0 || r->w2) /* disabled or no assertion */
563 if (ri >= solv->learntrules || !MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
568 if (!solv->decisionmap[vv]) /* if not yet decided */
570 queue_push(&solv->decisionq, v);
571 queue_push(&solv->decisionq_why, r - solv->rules);
572 solv->decisionmap[vv] = v > 0 ? 1 : -1;
573 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
575 Solvable *s = solv->pool->solvables + vv;
577 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
579 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
583 /* check against previous decision: is there a conflict? */
584 if (v > 0 && solv->decisionmap[vv] > 0)
586 if (v < 0 && solv->decisionmap[vv] < 0)
589 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
590 solver_printrule(solv, SOLV_DEBUG_UNSOLVABLE, r);
592 if (ri >= solv->jobrules && ri < solv->jobrules_end)
593 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
596 solver_disableproblem(solv, v);
598 solver_reenablepolicyrules(solv, -v);
600 break; /* start over */
602 if (ii == solv->ruleassertions.count)
603 break; /* finished! */
608 /********************************************************************/
612 /*-------------------------------------------------------------------
615 * initial setup for all watches
619 makewatches(Solver *solv)
623 int nsolvables = solv->pool->nsolvables;
625 solv_free(solv->watches);
626 /* lower half for removals, upper half for installs */
627 solv->watches = solv_calloc(2 * nsolvables, sizeof(Id));
628 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
630 if (!r->w2) /* assertions do not need watches */
633 /* see addwatches_rule(solv, r) */
634 r->n1 = solv->watches[nsolvables + r->w1];
635 solv->watches[nsolvables + r->w1] = r - solv->rules;
637 r->n2 = solv->watches[nsolvables + r->w2];
638 solv->watches[nsolvables + r->w2] = r - solv->rules;
643 /*-------------------------------------------------------------------
645 * add watches (for a new learned rule)
646 * sets up watches for a single rule
648 * see also makewatches() above.
652 addwatches_rule(Solver *solv, Rule *r)
654 int nsolvables = solv->pool->nsolvables;
656 r->n1 = solv->watches[nsolvables + r->w1];
657 solv->watches[nsolvables + r->w1] = r - solv->rules;
659 r->n2 = solv->watches[nsolvables + r->w2];
660 solv->watches[nsolvables + r->w2] = r - solv->rules;
664 /********************************************************************/
670 /* shortcuts to check if a literal (positive or negative) assignment
671 * evaluates to 'true' or 'false'
673 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
674 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
675 #define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
677 /*-------------------------------------------------------------------
681 * make decision and propagate to all rules
683 * Evaluate each term affected by the decision (linked through watches).
684 * If we find unit rules we make new decisions based on them.
686 * return : 0 = everything is OK
687 * rule = conflict found in this rule
691 propagate(Solver *solv, int level)
693 Pool *pool = solv->pool;
694 Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
696 Id p, pkg, other_watch;
698 Id *decisionmap = solv->decisionmap;
699 Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
701 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate -----\n");
703 /* foreach non-propagated decision */
704 while (solv->propagate_index < solv->decisionq.count)
707 * 'pkg' was just decided
708 * negate because our watches trigger if literal goes FALSE
710 pkg = -solv->decisionq.elements[solv->propagate_index++];
712 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
714 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
715 solver_printruleelement(solv, SOLV_DEBUG_PROPAGATE, 0, -pkg);
718 /* foreach rule where 'pkg' is now FALSE */
719 for (rp = watches + pkg; *rp; rp = next_rp)
721 r = solv->rules + *rp;
724 /* rule is disabled, goto next */
732 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
734 POOL_DEBUG(SOLV_DEBUG_PROPAGATE," watch triggered ");
735 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
739 * 'pkg' was just decided (was set to FALSE), so this rule
742 /* find the other watch */
755 * if the other watch is true we have nothing to do
757 if (DECISIONMAP_TRUE(other_watch))
761 * The other literal is FALSE or UNDEF
767 /* Not a binary clause, try to move our watch.
769 * Go over all literals and find one that is
773 * (TRUE is also ok, in that case the rule is fulfilled)
774 * As speed matters here we do not use the FOR_RULELITERALS
777 if (r->p /* we have a 'p' */
778 && r->p != other_watch /* which is not watched */
779 && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
783 else /* go find a 'd' to make 'true' */
786 we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
788 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
790 if (p != other_watch /* which is not watched */
791 && !DECISIONMAP_FALSE(p)) /* and not FALSE */
799 * if we found some p that is UNDEF or TRUE, move
802 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
805 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, p));
807 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, -p));
823 watches[p] = r - solv->rules;
826 /* search failed, thus all unwatched literals are FALSE */
831 * unit clause found, set literal other_watch to TRUE
834 if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
835 return r; /* eek, a conflict! */
837 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
839 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " unit ");
840 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
844 decisionmap[other_watch] = level; /* install! */
846 decisionmap[-other_watch] = -level; /* remove! */
848 queue_push(&solv->decisionq, other_watch);
849 queue_push(&solv->decisionq_why, r - solv->rules);
851 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
854 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to install %s\n", pool_solvid2str(pool, other_watch));
856 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to conflict %s\n", pool_solvid2str(pool, -other_watch));
859 } /* foreach rule involving 'pkg' */
861 } /* while we have non-decided decisions */
863 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate end-----\n");
865 return 0; /* all is well */
869 /********************************************************************/
872 /*-------------------------------------------------------------------
875 * revert decisionq to a level
879 revert(Solver *solv, int level)
881 Pool *pool = solv->pool;
883 while (solv->decisionq.count)
885 v = solv->decisionq.elements[solv->decisionq.count - 1];
887 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
889 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
890 solv->decisionmap[vv] = 0;
891 solv->decisionq.count--;
892 solv->decisionq_why.count--;
893 solv->propagate_index = solv->decisionq.count;
895 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= level)
896 solv->branches.count -= solv->branches.elements[solv->branches.count - 2];
897 if (solv->recommends_index > solv->decisionq.count)
898 solv->recommends_index = -1; /* rebuild recommends/suggests maps */
899 if (solv->decisionq.count < solv->decisioncnt_jobs)
900 solv->decisioncnt_jobs = 0;
901 if (solv->decisionq.count < solv->decisioncnt_update)
902 solv->decisioncnt_update = 0;
903 if (solv->decisionq.count < solv->decisioncnt_keep)
904 solv->decisioncnt_keep = 0;
905 if (solv->decisionq.count < solv->decisioncnt_resolve)
906 solv->decisioncnt_resolve = 0;
907 if (solv->decisionq.count < solv->decisioncnt_weak)
908 solv->decisioncnt_weak= 0;
909 if (solv->decisionq.count < solv->decisioncnt_orphan)
910 solv->decisioncnt_orphan = 0;
913 /*-------------------------------------------------------------------
915 * watch2onhighest - put watch2 on literal with highest level
919 watch2onhighest(Solver *solv, Rule *r)
924 d = r->d < 0 ? -r->d - 1 : r->d;
926 return; /* binary rule, both watches are set */
927 dp = solv->pool->whatprovidesdata + d;
928 while ((v = *dp++) != 0)
930 l = solv->decisionmap[v < 0 ? -v : v];
942 /*-------------------------------------------------------------------
949 analyze(Solver *solv, int level, Rule *c, Rule **lrp)
951 Pool *pool = solv->pool;
956 Map seen; /* global? */
957 Id p = 0, pp, v, vv, why;
959 int num = 0, l1num = 0;
960 int learnt_why = solv->learnt_pool.count;
961 Id *decisionmap = solv->decisionmap;
963 queue_init_buffer(&q, q_buf, sizeof(q_buf)/sizeof(*q_buf));
965 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
966 map_init(&seen, pool->nsolvables);
967 idx = solv->decisionq.count;
970 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
971 solver_printruleclass(solv, SOLV_DEBUG_ANALYZE, c);
972 queue_push(&solv->learnt_pool, c - solv->rules);
973 FOR_RULELITERALS(v, pp, c)
975 if (DECISIONMAP_TRUE(v)) /* the one true literal */
978 if (MAPTST(&seen, vv))
980 MAPSET(&seen, vv); /* mark that we also need to look at this literal */
981 l = solv->decisionmap[vv];
985 l1num++; /* need to do this one in level1 pass */
987 num++; /* need to do this one as well */
990 queue_push(&q, v); /* not level1 or conflict level, add to new rule */
996 if (!num && !--l1num)
997 break; /* all literals done */
999 /* find the next literal to investigate */
1000 /* (as num + l1num > 0, we know that we'll always find one) */
1004 v = solv->decisionq.elements[--idx];
1005 vv = v > 0 ? v : -v;
1006 if (MAPTST(&seen, vv))
1011 if (num && --num == 0)
1013 /* done with normal literals, now start level 1 literal processing */
1014 p = -v; /* so that v doesn't get lost */
1017 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
1018 /* clear non-l1 bits from seen map */
1019 for (i = 0; i < q.count; i++)
1022 MAPCLR(&seen, v > 0 ? v : -v);
1024 /* only level 1 marks left in seen map */
1025 l1num++; /* as l1retry decrements it */
1029 why = solv->decisionq_why.elements[idx];
1030 if (why <= 0) /* just in case, maybe for SYSTEMSOLVABLE */
1032 c = solv->rules + why;
1036 assert(rlevel > 0 && rlevel < level);
1037 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
1039 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
1040 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, p);
1041 for (i = 0; i < q.count; i++)
1042 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, q.elements[i]);
1044 /* push end marker on learnt reasons stack */
1045 queue_push(&solv->learnt_pool, 0);
1046 solv->stats_learned++;
1048 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, rlevel);
1050 revert(solv, level);
1053 Id d = q.count ? q.elements[0] : 0;
1055 r = solver_addrule(solv, p, d, 0);
1059 Id d = pool_queuetowhatprovides(pool, &q);
1061 r = solver_addrule(solv, p, 0, d);
1063 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
1064 queue_push(&solv->learnt_why, learnt_why);
1068 watch2onhighest(solv, r);
1069 addwatches_rule(solv, r);
1073 /* rule is an assertion */
1074 queue_push(&solv->ruleassertions, r - solv->rules);
1081 /*-------------------------------------------------------------------
1085 * reset all solver decisions
1086 * called after rules have been enabled/disabled
1090 solver_reset(Solver *solv)
1095 /* rewind all decisions */
1096 for (i = solv->decisionq.count - 1; i >= 0; i--)
1098 v = solv->decisionq.elements[i];
1099 solv->decisionmap[v > 0 ? v : -v] = 0;
1101 queue_empty(&solv->decisionq_why);
1102 queue_empty(&solv->decisionq);
1103 solv->recommends_index = -1;
1104 solv->propagate_index = 0;
1105 solv->decisioncnt_update = solv->decisioncnt_keep = solv->decisioncnt_resolve = solv->decisioncnt_weak = solv->decisioncnt_orphan = 0;
1106 queue_empty(&solv->branches);
1108 /* adapt learnt rule status to new set of enabled/disabled rules */
1109 enabledisablelearntrules(solv);
1113 /*-------------------------------------------------------------------
1115 * analyze_unsolvable_rule
1117 * recursion helper used by analyze_unsolvable
1121 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp, Map *rseen)
1123 Pool *pool = solv->pool;
1125 Id why = r - solv->rules;
1127 IF_POOLDEBUG (SOLV_DEBUG_UNSOLVABLE)
1128 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, r);
1129 if (solv->learntrules && why >= solv->learntrules)
1131 if (MAPTST(rseen, why - solv->learntrules))
1133 MAPSET(rseen, why - solv->learntrules);
1134 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1135 if (solv->learnt_pool.elements[i] > 0)
1136 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp, rseen);
1139 if (solv->weakrulemap.size && MAPTST(&solv->weakrulemap, why))
1140 if (!*lastweakp || why > *lastweakp)
1142 /* do not add pkg rules to problem */
1143 if (why < solv->pkgrules_end)
1145 /* turn rule into problem */
1146 if (why >= solv->jobrules && why < solv->jobrules_end)
1147 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1148 /* normalize dup/infarch rules */
1149 if (why > solv->infarchrules && why < solv->infarchrules_end)
1151 Id name = pool->solvables[-solv->rules[why].p].name;
1152 while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
1155 if (why > solv->duprules && why < solv->duprules_end)
1157 Id name = pool->solvables[-solv->rules[why].p].name;
1158 while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
1162 /* return if problem already countains our rule */
1163 if (solv->problems.count)
1165 for (i = solv->problems.count - 1; i >= 0; i--)
1166 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1168 else if (solv->problems.elements[i] == why)
1171 queue_push(&solv->problems, why);
1175 /*-------------------------------------------------------------------
1177 * analyze_unsolvable (called from setpropagatelearn)
1179 * We know that the problem is not solvable. Record all involved
1180 * rules (i.e. the "proof") into solv->learnt_pool.
1181 * Record the learnt pool index and all non-pkg rules into
1182 * solv->problems. (Our solutions to fix the problems are to
1183 * disable those rules.)
1185 * If the proof contains at least one weak rule, we disable the
1188 * Otherwise we return -1 if disablerules is not set or disable
1189 * _all_ of the problem rules and return 0.
1191 * return: 0 - disabled some rules, try again
1196 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1198 Pool *pool = solv->pool;
1200 Map involved; /* global to speed things up? */
1204 Id *decisionmap = solv->decisionmap;
1205 int oldproblemcount;
1206 int oldlearntpoolcount;
1208 int record_proof = 1;
1210 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1211 solv->stats_unsolvable++;
1212 oldproblemcount = solv->problems.count;
1213 oldlearntpoolcount = solv->learnt_pool.count;
1215 /* make room for proof index */
1216 /* must update it later, as analyze_unsolvable_rule would confuse
1217 * it with a rule index if we put the real value in already */
1218 queue_push(&solv->problems, 0);
1221 map_init(&involved, pool->nsolvables);
1222 map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
1224 queue_push(&solv->learnt_pool, r - solv->rules);
1226 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1227 FOR_RULELITERALS(v, pp, r)
1229 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1231 vv = v > 0 ? v : -v;
1232 MAPSET(&involved, vv);
1234 idx = solv->decisionq.count;
1237 v = solv->decisionq.elements[--idx];
1238 vv = v > 0 ? v : -v;
1239 if (!MAPTST(&involved, vv) || vv == SYSTEMSOLVABLE)
1241 why = solv->decisionq_why.elements[idx];
1244 queue_push(&solv->learnt_pool, why);
1245 r = solv->rules + why;
1246 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1247 FOR_RULELITERALS(v, pp, r)
1249 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1251 vv = v > 0 ? v : -v;
1252 MAPSET(&involved, vv);
1255 map_free(&involved);
1257 queue_push(&solv->problems, 0); /* mark end of this problem */
1261 /* disable last weak rule */
1262 solv->problems.count = oldproblemcount;
1263 solv->learnt_pool.count = oldlearntpoolcount;
1264 if (lastweak >= solv->jobrules && lastweak < solv->jobrules_end)
1265 v = -(solv->ruletojob.elements[lastweak - solv->jobrules] + 1);
1268 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "disabling ");
1269 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + lastweak);
1270 if (lastweak >= solv->choicerules && lastweak < solv->choicerules_end)
1271 solver_disablechoicerules(solv, solv->rules + lastweak);
1272 solver_disableproblem(solv, v);
1274 solver_reenablepolicyrules(solv, -v);
1279 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
1280 if (autouninstall(solv, solv->problems.elements + oldproblemcount + 1) != 0)
1282 solv->problems.count = oldproblemcount;
1283 solv->learnt_pool.count = oldlearntpoolcount;
1291 queue_push(&solv->learnt_pool, 0);
1292 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1295 /* + 2: index + trailing zero */
1296 if (disablerules && oldproblemcount + 2 < solv->problems.count)
1298 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1299 solver_disableproblem(solv, solv->problems.elements[i]);
1300 /* XXX: might want to enable all weak rules again */
1304 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1309 /*-------------------------------------------------------------------
1313 * add free decision (solvable to install) to decisionq
1314 * increase level and propagate decision
1315 * return if no conflict.
1317 * in conflict case, analyze conflict rule, add resulting
1318 * rule to learnt rule set, make decision from learnt
1319 * rule (always unit) and re-propagate.
1321 * returns the new solver level or -1 if unsolvable
1326 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules, Id ruleid)
1328 Pool *pool = solv->pool;
1335 solv->decisionmap[decision] = level;
1337 solv->decisionmap[-decision] = -level;
1338 queue_push(&solv->decisionq, decision);
1339 queue_push(&solv->decisionq_why, -ruleid); /* <= 0 -> free decision */
1341 assert(ruleid >= 0 && level > 0);
1344 r = propagate(solv, level);
1348 return analyze_unsolvable(solv, r, disablerules);
1349 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1350 level = analyze(solv, level, r, &lr);
1351 /* the new rule is unit by design */
1353 solv->decisionmap[decision > 0 ? decision : -decision] = decision > 0 ? level : -level;
1354 queue_push(&solv->decisionq, decision);
1355 queue_push(&solv->decisionq_why, lr - solv->rules);
1356 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
1358 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "decision: ");
1359 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, decision);
1360 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "new rule: ");
1361 solver_printrule(solv, SOLV_DEBUG_ANALYZE, lr);
1368 reorder_dq_for_jobrules(Solver *solv, int level, Queue *dq)
1370 Pool *pool = solv->pool;
1371 int i, j, haveone = 0, dqcount = dq->count;
1372 int decisionqcount = solv->decisionq.count;
1376 /* at the time we process jobrules the installed packages are not kept yet */
1377 /* reorder so that "future-supplemented" packages come first */
1378 FOR_REPO_SOLVABLES(solv->installed, p, s)
1380 if (MAPTST(&solv->noupdate, p - solv->installed->start))
1382 if (solv->decisionmap[p] == 0)
1384 if (s->recommends || s->suggests)
1385 queue_push(&solv->decisionq, p);
1386 solv->decisionmap[p] = level + 1;
1392 policy_update_recommendsmap(solv);
1393 for (i = 0; i < dqcount; i++)
1395 p = dq->elements[i];
1396 if (!(pool->solvables[p].repo == solv->installed || MAPTST(&solv->suggestsmap, p) || solver_is_enhancing(solv, pool->solvables + p)))
1399 dq->elements[i] = 0;
1402 dqcount = dq->count;
1403 for (i = 0; i < dqcount; i++)
1405 p = dq->elements[i];
1406 if (p && !(pool->solvables[p].repo == solv->installed || MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
1409 dq->elements[i] = 0;
1412 for (i = j = 0; i < dq->count; i++)
1413 if (dq->elements[i])
1414 dq->elements[j++] = dq->elements[i];
1415 queue_truncate(dq, j);
1416 FOR_REPO_SOLVABLES(solv->installed, p, s)
1417 if (solv->decisionmap[p] == level + 1)
1418 solv->decisionmap[p] = 0;
1419 if (solv->decisionq.count != decisionqcount)
1421 solv->recommends_index = -1;
1422 queue_truncate(&solv->decisionq, decisionqcount);
1426 /*-------------------------------------------------------------------
1432 createbranch(Solver *solv, int level, Queue *dq, Id p, Id data)
1434 Pool *pool = solv->pool;
1436 IF_POOLDEBUG (SOLV_DEBUG_POLICY)
1438 POOL_DEBUG (SOLV_DEBUG_POLICY, "creating a branch:\n");
1439 for (i = 0; i < dq->count; i++)
1440 POOL_DEBUG (SOLV_DEBUG_POLICY, " - %s\n", pool_solvid2str(pool, dq->elements[i]));
1442 queue_push(&solv->branches, -dq->elements[0]);
1443 for (i = 1; i < dq->count; i++)
1444 queue_push(&solv->branches, dq->elements[i]);
1445 queue_push2(&solv->branches, p, data);
1446 queue_push2(&solv->branches, dq->count + 4, level);
1450 takebranch(Solver *solv, int pos, int end, const char *msg, int disablerules)
1452 Pool *pool = solv->pool;
1458 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]);
1459 for (i = end - solv->branches.elements[end - 2]; i < end - 4; i++)
1460 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]));
1463 level = solv->branches.elements[end - 1];
1464 p = solv->branches.elements[pos];
1465 solv->branches.elements[pos] = -p;
1466 POOL_DEBUG(SOLV_DEBUG_SOLVER, "%s %d -> %d with %s\n", msg, solv->decisionmap[p], level, pool_solvid2str(pool, p));
1467 /* hack: set level to zero so that revert does not remove the branch */
1468 solv->branches.elements[end - 1] = 0;
1469 revert(solv, level);
1470 solv->branches.elements[end - 1] = level;
1471 /* hack: revert simply sets the count, so we can still access the reverted elements */
1472 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
1474 return setpropagatelearn(solv, level, p, disablerules, why);
1477 /*-------------------------------------------------------------------
1479 * select and install
1481 * install best package from the queue. We add an extra package, inst, if
1482 * provided. See comment in weak install section.
1484 * returns the new solver level or -1 if unsolvable
1489 selectandinstall(Solver *solv, int level, Queue *dq, int disablerules, Id ruleid)
1491 Pool *pool = solv->pool;
1495 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
1496 /* if we're resolving job rules and didn't resolve the installed packages yet,
1497 * do some special supplements ordering */
1498 if (dq->count > 1 && ruleid >= solv->jobrules && ruleid < solv->jobrules_end && solv->installed && !solv->focus_installed)
1499 reorder_dq_for_jobrules(solv, level, dq);
1500 /* if we have multiple candidates we open a branch */
1502 createbranch(solv, level, dq, 0, ruleid);
1503 p = dq->elements[0];
1504 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing %s\n", pool_solvid2str(pool, p));
1505 return setpropagatelearn(solv, level, p, disablerules, ruleid);
1509 /********************************************************************/
1510 /* Main solver interface */
1513 /*-------------------------------------------------------------------
1516 * create solver structure
1518 * pool: all available solvables
1519 * installed: installed Solvables
1522 * Upon solving, rules are created to flag the Solvables
1523 * of the 'installed' Repo as installed.
1527 solver_create(Pool *pool)
1530 solv = (Solver *)solv_calloc(1, sizeof(Solver));
1532 solv->installed = pool->installed;
1534 solv->allownamechange = 1;
1536 solv->dup_allowdowngrade = 1;
1537 solv->dup_allownamechange = 1;
1538 solv->dup_allowarchchange = 1;
1539 solv->dup_allowvendorchange = 1;
1541 solv->keepexplicitobsoletes = pool->noobsoletesmultiversion ? 0 : 1;
1543 queue_init(&solv->ruletojob);
1544 queue_init(&solv->decisionq);
1545 queue_init(&solv->decisionq_why);
1546 queue_init(&solv->problems);
1547 queue_init(&solv->orphaned);
1548 queue_init(&solv->learnt_why);
1549 queue_init(&solv->learnt_pool);
1550 queue_init(&solv->branches);
1551 queue_init(&solv->weakruleq);
1552 queue_init(&solv->ruleassertions);
1553 queue_init(&solv->addedmap_deduceq);
1555 queue_push(&solv->learnt_pool, 0); /* so that 0 does not describe a proof */
1557 map_init(&solv->recommendsmap, pool->nsolvables);
1558 map_init(&solv->suggestsmap, pool->nsolvables);
1559 map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
1560 solv->recommends_index = 0;
1562 solv->decisionmap = (Id *)solv_calloc(pool->nsolvables, sizeof(Id));
1564 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
1565 memset(solv->rules, 0, sizeof(Rule));
1572 resolve_jobrules(Solver *solv, int level, int disablerules, Queue *dq)
1574 Pool *pool = solv->pool;
1575 int oldlevel = level;
1579 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving job rules\n");
1580 if (!solv->decisioncnt_jobs)
1581 solv->decisioncnt_jobs = solv->decisionq.count;
1582 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
1585 if (r->d < 0) /* ignore disabled rules */
1588 FOR_RULELITERALS(l, pp, r)
1592 if (solv->decisionmap[-l] <= 0)
1597 if (solv->decisionmap[l] > 0)
1599 if (solv->decisionmap[l] == 0)
1603 if (l || !dq->count)
1605 /* prune to installed if not updating */
1606 if (dq->count > 1 && solv->installed && !solv->updatemap_all &&
1607 !(solv->job.elements[solv->ruletojob.elements[i - solv->jobrules]] & SOLVER_ORUPDATE))
1610 for (j = k = 0; j < dq->count; j++)
1612 Solvable *s = pool->solvables + dq->elements[j];
1613 if (s->repo == solv->installed)
1615 dq->elements[k++] = dq->elements[j];
1616 if (solv->updatemap.size && MAPTST(&solv->updatemap, dq->elements[j] - solv->installed->start))
1618 k = 0; /* package wants to be updated, do not prune */
1627 level = selectandinstall(solv, level, dq, disablerules, i);
1628 if (level <= olevel)
1630 if (level == olevel)
1634 continue; /* try something else */
1636 if (level < oldlevel)
1638 /* redo from start of jobrules */
1639 i = solv->jobrules - 1;
1640 r = solv->rules + i;
1646 /*-------------------------------------------------------------------
1652 queuep_free(Queue **qp)
1657 *qp = solv_free(*qp);
1661 map_zerosize(Map *m)
1671 solver_free(Solver *solv)
1673 queue_free(&solv->job);
1674 queue_free(&solv->ruletojob);
1675 queue_free(&solv->decisionq);
1676 queue_free(&solv->decisionq_why);
1677 queue_free(&solv->learnt_why);
1678 queue_free(&solv->learnt_pool);
1679 queue_free(&solv->problems);
1680 queue_free(&solv->solutions);
1681 queue_free(&solv->orphaned);
1682 queue_free(&solv->branches);
1683 queue_free(&solv->weakruleq);
1684 queue_free(&solv->ruleassertions);
1685 queue_free(&solv->addedmap_deduceq);
1686 queuep_free(&solv->cleandeps_updatepkgs);
1687 queuep_free(&solv->cleandeps_mistakes);
1688 queuep_free(&solv->update_targets);
1689 queuep_free(&solv->installsuppdepq);
1690 queuep_free(&solv->recommendscplxq);
1691 queuep_free(&solv->suggestscplxq);
1692 queuep_free(&solv->brokenorphanrules);
1694 map_free(&solv->recommendsmap);
1695 map_free(&solv->suggestsmap);
1696 map_free(&solv->noupdate);
1697 map_free(&solv->weakrulemap);
1698 map_free(&solv->multiversion);
1700 map_free(&solv->updatemap);
1701 map_free(&solv->bestupdatemap);
1702 map_free(&solv->fixmap);
1703 map_free(&solv->dupmap);
1704 map_free(&solv->dupinvolvedmap);
1705 map_free(&solv->droporphanedmap);
1706 map_free(&solv->cleandepsmap);
1707 map_free(&solv->allowuninstallmap);
1709 solv_free(solv->decisionmap);
1710 solv_free(solv->rules);
1711 solv_free(solv->watches);
1712 solv_free(solv->obsoletes);
1713 solv_free(solv->obsoletes_data);
1714 solv_free(solv->specialupdaters);
1715 solv_free(solv->choicerules_ref);
1716 solv_free(solv->bestrules_pkg);
1717 solv_free(solv->yumobsrules_info);
1718 solv_free(solv->instbuddy);
1723 solver_get_flag(Solver *solv, int flag)
1727 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1728 return solv->allowdowngrade;
1729 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1730 return solv->allownamechange;
1731 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1732 return solv->allowarchchange;
1733 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1734 return solv->allowvendorchange;
1735 case SOLVER_FLAG_ALLOW_UNINSTALL:
1736 return solv->allowuninstall;
1737 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1738 return solv->noupdateprovide;
1739 case SOLVER_FLAG_SPLITPROVIDES:
1740 return solv->dosplitprovides;
1741 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1742 return solv->dontinstallrecommended;
1743 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1744 return solv->addalreadyrecommended;
1745 case SOLVER_FLAG_NO_INFARCHCHECK:
1746 return solv->noinfarchcheck;
1747 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1748 return solv->keepexplicitobsoletes;
1749 case SOLVER_FLAG_BEST_OBEY_POLICY:
1750 return solv->bestobeypolicy;
1751 case SOLVER_FLAG_NO_AUTOTARGET:
1752 return solv->noautotarget;
1753 case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
1754 return solv->dup_allowdowngrade;
1755 case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
1756 return solv->dup_allownamechange;
1757 case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
1758 return solv->dup_allowarchchange;
1759 case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
1760 return solv->dup_allowvendorchange;
1761 case SOLVER_FLAG_KEEP_ORPHANS:
1762 return solv->keep_orphans;
1763 case SOLVER_FLAG_BREAK_ORPHANS:
1764 return solv->break_orphans;
1765 case SOLVER_FLAG_FOCUS_INSTALLED:
1766 return solv->focus_installed;
1767 case SOLVER_FLAG_YUM_OBSOLETES:
1768 return solv->do_yum_obsoletes;
1769 case SOLVER_FLAG_NEED_UPDATEPROVIDE:
1770 return solv->needupdateprovide;
1778 solver_set_flag(Solver *solv, int flag, int value)
1780 int old = solver_get_flag(solv, flag);
1783 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1784 solv->allowdowngrade = value;
1786 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1787 solv->allownamechange = value;
1789 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1790 solv->allowarchchange = value;
1792 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1793 solv->allowvendorchange = value;
1795 case SOLVER_FLAG_ALLOW_UNINSTALL:
1796 solv->allowuninstall = value;
1798 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1799 solv->noupdateprovide = value;
1801 case SOLVER_FLAG_SPLITPROVIDES:
1802 solv->dosplitprovides = value;
1804 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1805 solv->dontinstallrecommended = value;
1807 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1808 solv->addalreadyrecommended = value;
1810 case SOLVER_FLAG_NO_INFARCHCHECK:
1811 solv->noinfarchcheck = value;
1813 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1814 solv->keepexplicitobsoletes = value;
1816 case SOLVER_FLAG_BEST_OBEY_POLICY:
1817 solv->bestobeypolicy = value;
1819 case SOLVER_FLAG_NO_AUTOTARGET:
1820 solv->noautotarget = value;
1822 case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
1823 solv->dup_allowdowngrade = value;
1825 case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
1826 solv->dup_allownamechange = value;
1828 case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
1829 solv->dup_allowarchchange = value;
1831 case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
1832 solv->dup_allowvendorchange = value;
1834 case SOLVER_FLAG_KEEP_ORPHANS:
1835 solv->keep_orphans = value;
1837 case SOLVER_FLAG_BREAK_ORPHANS:
1838 solv->break_orphans = value;
1840 case SOLVER_FLAG_FOCUS_INSTALLED:
1841 solv->focus_installed = value;
1843 case SOLVER_FLAG_YUM_OBSOLETES:
1844 solv->do_yum_obsoletes = value;
1846 case SOLVER_FLAG_NEED_UPDATEPROVIDE:
1847 solv->needupdateprovide = value;
1856 cleandeps_check_mistakes(Solver *solv)
1858 Pool *pool = solv->pool;
1862 int mademistake = 0;
1864 if (!solv->cleandepsmap.size)
1866 /* check for mistakes */
1867 for (i = solv->installed->start; i < solv->installed->end; i++)
1869 if (!MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1871 r = solv->rules + solv->featurerules + (i - solv->installed->start);
1872 /* a mistake is when the featurerule is true but the updaterule is false */
1875 FOR_RULELITERALS(p, pp, r)
1876 if (p > 0 && solv->decisionmap[p] > 0)
1879 continue; /* feature rule is not true */
1880 r = solv->rules + solv->updaterules + (i - solv->installed->start);
1883 FOR_RULELITERALS(p, pp, r)
1884 if (p > 0 && solv->decisionmap[p] > 0)
1887 continue; /* update rule is true */
1888 POOL_DEBUG(SOLV_DEBUG_SOLVER, "cleandeps mistake: ");
1889 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, r);
1890 POOL_DEBUG(SOLV_DEBUG_SOLVER, "feature rule: ");
1891 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, solv->rules + solv->featurerules + (i - solv->installed->start));
1892 if (!solv->cleandeps_mistakes)
1894 solv->cleandeps_mistakes = solv_calloc(1, sizeof(Queue));
1895 queue_init(solv->cleandeps_mistakes);
1897 queue_push(solv->cleandeps_mistakes, i);
1898 MAPCLR(&solv->cleandepsmap, i - solv->installed->start);
1899 solver_reenablepolicyrules_cleandeps(solv, i);
1906 prune_to_update_targets(Solver *solv, Id *cp, Queue *q)
1910 for (i = j = 0; i < q->count; i++)
1913 for (cp2 = cp; *cp2; cp2++)
1916 q->elements[j++] = p;
1920 queue_truncate(q, j);
1923 #ifdef ENABLE_COMPLEX_DEPS
1926 add_complex_recommends(Solver *solv, Id rec, Queue *dq, Map *dqmap)
1928 Pool *pool = solv->pool;
1929 int oldcnt = dq->count;
1935 printf("ADD_COMPLEX_RECOMMENDS %s\n", pool_dep2str(pool, rec));
1937 i = pool_normalize_complex_dep(pool, rec, dq, CPLXDEPS_EXPAND);
1938 if (i == 0 || i == 1)
1941 for (i = oldcnt; i < cutcnt; i++)
1944 for (; (p = dq->elements[i]) != 0; i++)
1948 if (solv->decisionmap[-p] <= 0)
1952 if (solv->decisionmap[p] > 0)
1954 queue_truncate(dq, blkcnt);
1959 if (!MAPTST(dqmap, p))
1964 if (solv->decisionmap[p] < 0)
1966 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))))
1971 while (dq->elements[i])
1974 queue_deleten(dq, oldcnt, cutcnt - oldcnt);
1976 if (dq->count != oldcnt)
1978 for (j = oldcnt; j < dq->count; j++)
1980 p = dq->elements[j];
1981 for (i = 0; i < j; i++)
1982 if (dq->elements[i] == p)
1984 dq->elements[j] = 0;
1988 for (i = j = oldcnt; j < dq->count; j++)
1989 if (dq->elements[j])
1990 dq->elements[i++] = dq->elements[j];
1991 queue_truncate(dq, i);
1994 printf("RETURN:\n");
1995 for (i = oldcnt; i < dq->count; i++)
1996 printf(" - %s\n", pool_solvid2str(pool, dq->elements[i]));
2001 do_complex_recommendations(Solver *solv, Id rec, Map *m, int noselected)
2003 Pool *pool = solv->pool;
2009 printf("DO_COMPLEX_RECOMMENDATIONS %s\n", pool_dep2str(pool, rec));
2012 i = pool_normalize_complex_dep(pool, rec, &dq, CPLXDEPS_EXPAND);
2013 if (i == 0 || i == 1)
2018 for (i = 0; i < dq.count; i++)
2021 for (; (p = dq.elements[i]) != 0; i++)
2025 if (solv->decisionmap[-p] <= 0)
2029 if (solv->decisionmap[p] > 0)
2034 for (i++; (p = dq.elements[i]) != 0; i++)
2035 if (p > 0 && solv->decisionmap[p] > 0)
2043 for (i = blk; (p = dq.elements[i]) != 0; i++)
2047 while (dq.elements[i])
2055 /*-------------------------------------------------------------------
2059 * all rules have been set up, now actually run the solver
2064 solver_run_sat(Solver *solv, int disablerules, int doweak)
2066 Queue dq; /* local decisionqueue */
2067 Queue dqs; /* local decisionqueue for supplements */
2073 Pool *pool = solv->pool;
2074 Id p, pp, *dp, postponed;
2075 int minimizationsteps;
2076 int installedpos = solv->installed ? solv->installed->start : 0;
2078 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
2080 POOL_DEBUG (SOLV_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2081 for (i = 1; i < solv->nrules; i++)
2082 solver_printruleclass(solv, SOLV_DEBUG_RULE_CREATION, solv->rules + i);
2085 /* start SAT algorithm */
2087 systemlevel = level + 1;
2088 POOL_DEBUG(SOLV_DEBUG_SOLVER, "solving...\n");
2094 * here's the main loop:
2095 * 1) decide assertion rules and propagate
2097 * 3) try to keep installed packages
2098 * 4) fulfill all unresolved rules
2099 * 5) install recommended packages
2100 * 6) minimalize solution if we had choices
2101 * if we encounter a problem, we rewind to a safe level and restart
2105 minimizationsteps = 0;
2109 * initial propagation of the assertions
2115 makeruledecisions(solv);
2117 if (!disablerules && solv->problems.count)
2122 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "initial propagate (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2123 if ((r = propagate(solv, level)) != 0)
2125 level = analyze_unsolvable(solv, r, disablerules);
2128 systemlevel = level + 1;
2132 * resolve jobs first (unless focus_installed is set)
2134 if (level < systemlevel && !solv->focus_installed)
2137 level = resolve_jobrules(solv, level, disablerules, &dq);
2140 systemlevel = level + 1;
2145 * installed packages
2147 if (!solv->decisioncnt_update)
2148 solv->decisioncnt_update = solv->decisionq.count;
2149 if (level < systemlevel && solv->installed && solv->installed->nsolvables && !solv->installed->disabled)
2151 Repo *installed = solv->installed;
2154 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving installed packages\n");
2155 /* we use two passes if we need to update packages
2156 * to create a better user experience */
2157 for (pass = solv->updatemap.size ? 0 : 1; pass < 2; pass++)
2159 int passlevel = level;
2160 Id *specialupdaters = solv->specialupdaters;
2161 if (pass == 1 && !solv->decisioncnt_keep)
2162 solv->decisioncnt_keep = solv->decisionq.count;
2163 /* start with installedpos, the position that gave us problems the last time */
2164 for (i = installedpos, n = installed->start; n < installed->end; i++, n++)
2169 if (i == installed->end)
2170 i = installed->start;
2171 s = pool->solvables + i;
2172 if (s->repo != installed)
2175 if (solv->decisionmap[i] > 0 && (!specialupdaters || !specialupdaters[i - installed->start]))
2176 continue; /* already decided */
2177 if (!pass && solv->updatemap.size && !MAPTST(&solv->updatemap, i - installed->start))
2178 continue; /* updates first */
2179 r = solv->rules + solv->updaterules + (i - installed->start);
2181 if (!rr->p || rr->d < 0) /* disabled -> look at feature rule */
2182 rr -= solv->installed->end - solv->installed->start;
2183 if (!rr->p) /* identical to update rule? */
2185 if (!rr->p && !(specialupdaters && specialupdaters[i - installed->start]))
2186 continue; /* orpaned package */
2188 /* check if we should update this package to the latest version
2189 * noupdate is set for erase jobs, in that case we want to deinstall
2190 * the installed package and not replace it with a newer version
2191 * rr->p != i is for dup jobs where the installed package cannot be kept */
2193 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)))
2197 /* specialupdater with no update/feature rule */
2198 for (d = specialupdaters[i - installed->start]; (p = pool->whatprovidesdata[d++]) != 0; )
2200 if (solv->decisionmap[p] > 0)
2205 if (!solv->decisionmap[p])
2209 else if (specialupdaters && (d = specialupdaters[i - installed->start]) != 0)
2211 /* special multiversion handling, make sure best version is chosen */
2212 if (rr->p == i && solv->decisionmap[i] >= 0)
2214 while ((p = pool->whatprovidesdata[d++]) != 0)
2215 if (solv->decisionmap[p] >= 0)
2217 if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
2218 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
2221 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2223 if (p != i && solv->decisionmap[p] == 0)
2225 rr = solv->rules + solv->featurerules + (i - solv->installed->start);
2226 if (!rr->p) /* update rule == feature rule? */
2227 rr = rr - solv->featurerules + solv->updaterules;
2236 /* update to best package of the update rule */
2237 FOR_RULELITERALS(p, pp, rr)
2239 if (solv->decisionmap[p] > 0)
2241 dq.count = 0; /* already fulfilled */
2244 if (!solv->decisionmap[p])
2249 if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
2250 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
2251 /* install best version */
2255 level = selectandinstall(solv, level, &dq, disablerules, rr - solv->rules);
2256 if (level <= olevel)
2258 if (level < passlevel)
2259 break; /* trouble */
2261 n = installed->start; /* redo all */
2267 /* if still undecided keep package */
2268 if (solv->decisionmap[i] == 0)
2271 if (solv->cleandepsmap.size && MAPTST(&solv->cleandepsmap, i - installed->start))
2274 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, i));
2275 level = setpropagatelearn(solv, level, -i, disablerules, 0);
2282 POOL_DEBUG(SOLV_DEBUG_POLICY, "keeping %s\n", pool_solvid2str(pool, i));
2283 level = setpropagatelearn(solv, level, i, disablerules, r - solv->rules);
2285 if (level <= olevel)
2287 if (level < passlevel)
2288 break; /* trouble */
2290 n = installed->start; /* redo all */
2293 continue; /* retry with learnt rule */
2297 if (n < installed->end)
2299 installedpos = i; /* retry problem solvable next time */
2300 break; /* ran into trouble */
2302 installedpos = installed->start; /* reset installedpos */
2304 systemlevel = level + 1;
2306 continue; /* had trouble, retry */
2308 if (!solv->decisioncnt_keep)
2309 solv->decisioncnt_keep = solv->decisionq.count;
2311 if (level < systemlevel && solv->focus_installed)
2314 level = resolve_jobrules(solv, level, disablerules, &dq);
2317 systemlevel = level + 1;
2320 if (level < systemlevel)
2321 systemlevel = level;
2326 if (!solv->decisioncnt_resolve)
2327 solv->decisioncnt_resolve = solv->decisionq.count;
2328 POOL_DEBUG(SOLV_DEBUG_POLICY, "deciding unresolved rules\n");
2330 for (i = 1, n = 1; ; i++, n++)
2332 if (n >= solv->nrules)
2340 if (i == solv->nrules)
2342 r = solv->rules + i;
2343 if (r->d < 0) /* ignore disabled rules */
2345 if (r->p < 0) /* most common cases first */
2347 if (r->d == 0 || solv->decisionmap[-r->p] <= 0)
2354 /* binary or unary rule */
2355 /* need two positive undecided literals, r->p already checked above */
2358 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2360 queue_push(&dq, r->p);
2361 queue_push(&dq, r->w2);
2366 * all negative literals are installed
2367 * no positive literal is installed
2368 * i.e. the rule is not fulfilled and we
2369 * just need to decide on the positive literals
2370 * (decisionmap[-r->p] for the r->p < 0 case is already checked above)
2374 if (solv->decisionmap[r->p] > 0)
2376 if (solv->decisionmap[r->p] == 0)
2377 queue_push(&dq, r->p);
2379 dp = pool->whatprovidesdata + r->d;
2380 while ((p = *dp++) != 0)
2384 if (solv->decisionmap[-p] <= 0)
2389 if (solv->decisionmap[p] > 0)
2391 if (solv->decisionmap[p] == 0)
2398 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
2400 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "unfulfilled ");
2401 solver_printruleclass(solv, SOLV_DEBUG_PROPAGATE, r);
2403 /* dq.count < 2 cannot happen as this means that
2404 * the rule is unit */
2405 assert(dq.count > 1);
2407 /* prune to cleandeps packages */
2408 if (solv->cleandepsmap.size && solv->installed)
2410 Repo *installed = solv->installed;
2411 for (j = 0; j < dq.count; j++)
2412 if (pool->solvables[dq.elements[j]].repo == installed && MAPTST(&solv->cleandepsmap, dq.elements[j] - installed->start))
2416 dq.elements[0] = dq.elements[j];
2417 queue_truncate(&dq, 1);
2421 if (dq.count > 1 && postponed >= 0)
2423 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE_NOREORDER);
2433 level = selectandinstall(solv, level, &dq, disablerules, r - solv->rules);
2434 if (level < systemlevel)
2435 break; /* trouble */
2436 /* something changed, so look at all rules again */
2440 if (n < solv->nrules) /* ran into trouble? */
2441 continue; /* start over */
2443 /* decide leftover cleandeps packages */
2444 if (solv->cleandepsmap.size && solv->installed)
2446 for (p = solv->installed->start; p < solv->installed->end; p++)
2448 s = pool->solvables + p;
2449 if (s->repo != solv->installed)
2451 if (solv->decisionmap[p] == 0 && MAPTST(&solv->cleandepsmap, p - solv->installed->start))
2453 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, p));
2455 level = setpropagatelearn(solv, level, -p, 0, 0);
2460 if (p < solv->installed->end)
2464 /* at this point we have a consistent system. now do the extras... */
2466 if (!solv->decisioncnt_weak)
2467 solv->decisioncnt_weak = solv->decisionq.count;
2472 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended packages\n");
2473 queue_empty(&dq); /* recommended packages */
2474 queue_empty(&dqs); /* supplemented packages */
2475 for (i = 1; i < pool->nsolvables; i++)
2477 if (solv->decisionmap[i] < 0)
2479 if (solv->decisionmap[i] > 0)
2481 /* installed, check for recommends */
2482 Id *recp, rec, pp, p;
2483 s = pool->solvables + i;
2484 if (!solv->addalreadyrecommended && s->repo == solv->installed)
2486 /* XXX need to special case AND ? */
2489 recp = s->repo->idarraydata + s->recommends;
2490 while ((rec = *recp++) != 0)
2492 #ifdef ENABLE_COMPLEX_DEPS
2493 if (pool_is_complex_dep(pool, rec))
2495 add_complex_recommends(solv, rec, &dq, 0);
2500 FOR_PROVIDES(p, pp, rec)
2502 if (solv->decisionmap[p] > 0)
2507 else if (solv->decisionmap[p] == 0)
2509 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))))
2511 queue_pushunique(&dq, p);
2519 s = pool->solvables + i;
2520 if (!s->supplements)
2522 if (!pool_installable(pool, s))
2524 if (!solver_is_supplementing(solv, s))
2526 if (solv->dupmap_all && solv->installed && s->repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, i - solv->installed->start))))
2528 queue_push(&dqs, i);
2532 /* filter out all packages obsoleted by installed packages */
2533 /* this is no longer needed if we have reverse obsoletes */
2534 if ((dqs.count || dq.count) && solv->installed)
2537 Id obs, *obsp, po, ppo;
2539 map_init(&obsmap, pool->nsolvables);
2540 for (p = solv->installed->start; p < solv->installed->end; p++)
2542 s = pool->solvables + p;
2543 if (s->repo != solv->installed || !s->obsoletes)
2545 if (solv->decisionmap[p] <= 0)
2547 if (!solv->keepexplicitobsoletes && solv->multiversion.size && MAPTST(&solv->multiversion, p))
2549 obsp = s->repo->idarraydata + s->obsoletes;
2550 /* foreach obsoletes */
2551 while ((obs = *obsp++) != 0)
2552 FOR_PROVIDES(po, ppo, obs)
2554 Solvable *pos = pool->solvables + po;
2555 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pos, obs))
2557 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, pos))
2559 MAPSET(&obsmap, po);
2562 for (i = j = 0; i < dqs.count; i++)
2563 if (!MAPTST(&obsmap, dqs.elements[i]))
2564 dqs.elements[j++] = dqs.elements[i];
2566 for (i = j = 0; i < dq.count; i++)
2567 if (!MAPTST(&obsmap, dq.elements[i]))
2568 dq.elements[j++] = dq.elements[i];
2573 /* filter out all already supplemented packages if requested */
2574 if (!solv->addalreadyrecommended && dqs.count)
2576 /* filter out old supplements */
2577 for (i = j = 0; i < dqs.count; i++)
2579 p = dqs.elements[i];
2580 s = pool->solvables + p;
2581 if (s->supplements && solver_is_supplementing_alreadyinstalled(solv, s))
2582 dqs.elements[j++] = p;
2587 /* multiversion doesn't mix well with supplements.
2588 * filter supplemented packages where we already decided
2589 * to install a different version (see bnc#501088) */
2590 if (dqs.count && solv->multiversion.size)
2592 for (i = j = 0; i < dqs.count; i++)
2594 p = dqs.elements[i];
2595 if (MAPTST(&solv->multiversion, p))
2598 s = pool->solvables + p;
2599 FOR_PROVIDES(p2, pp2, s->name)
2600 if (solv->decisionmap[p2] > 0 && pool->solvables[p2].name == s->name)
2603 continue; /* ignore this package */
2605 dqs.elements[j++] = p;
2610 /* make dq contain both recommended and supplemented pkgs */
2613 for (i = 0; i < dqs.count; i++)
2614 queue_pushunique(&dq, dqs.elements[i]);
2620 int decisioncount = solv->decisionq.count;
2624 /* simple case, just one package. no need to choose to best version */
2627 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2629 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2630 level = setpropagatelearn(solv, level, p, 0, 0);
2631 continue; /* back to main loop */
2634 /* filter packages, this gives us the best versions */
2635 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
2637 /* create map of result */
2638 map_init(&dqmap, pool->nsolvables);
2639 for (i = 0; i < dq.count; i++)
2640 MAPSET(&dqmap, dq.elements[i]);
2642 /* install all supplemented packages */
2643 for (i = 0; i < dqs.count; i++)
2645 p = dqs.elements[i];
2646 if (solv->decisionmap[p] || !MAPTST(&dqmap, p))
2648 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2650 level = setpropagatelearn(solv, level, p, 0, 0);
2651 if (level <= olevel)
2654 if (i < dqs.count || solv->decisionq.count < decisioncount)
2660 /* install all recommended packages */
2661 /* more work as we want to created branches if multiple
2662 * choices are valid */
2663 for (i = 0; i < decisioncount; i++)
2666 p = solv->decisionq.elements[i];
2669 s = pool->solvables + p;
2670 if (!s->repo || (!solv->addalreadyrecommended && s->repo == solv->installed))
2674 recp = s->repo->idarraydata + s->recommends;
2675 while ((rec = *recp++) != 0)
2678 #ifdef ENABLE_COMPLEX_DEPS
2679 if (pool_is_complex_dep(pool, rec))
2680 add_complex_recommends(solv, rec, &dq, &dqmap);
2683 FOR_PROVIDES(p, pp, rec)
2685 if (solv->decisionmap[p] > 0)
2690 else if (solv->decisionmap[p] == 0 && MAPTST(&dqmap, p))
2696 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2697 /* if we have multiple candidates we open a branch */
2699 createbranch(solv, level, &dq, s - pool->solvables, rec);
2701 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2703 level = setpropagatelearn(solv, level, p, 0, 0);
2704 if (level <= olevel || solv->decisionq.count < decisioncount)
2705 break; /* we had to revert some decisions */
2708 break; /* had a problem above, quit loop */
2711 continue; /* back to main loop so that all deps are checked */
2715 if (!solv->decisioncnt_orphan)
2716 solv->decisioncnt_orphan = solv->decisionq.count;
2717 if (solv->dupmap_all && solv->installed)
2719 int installedone = 0;
2721 /* let's see if we can install some unsupported package */
2722 POOL_DEBUG(SOLV_DEBUG_SOLVER, "deciding orphaned packages\n");
2723 for (i = 0; i < solv->orphaned.count; i++)
2725 p = solv->orphaned.elements[i];
2726 if (solv->decisionmap[p])
2727 continue; /* already decided */
2728 if (solv->droporphanedmap_all)
2730 if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))
2732 POOL_DEBUG(SOLV_DEBUG_SOLVER, "keeping orphaned %s\n", pool_solvid2str(pool, p));
2734 level = setpropagatelearn(solv, level, p, 0, 0);
2739 if (installedone || i < solv->orphaned.count)
2740 continue; /* back to main loop */
2741 for (i = 0; i < solv->orphaned.count; i++)
2743 p = solv->orphaned.elements[i];
2744 if (solv->decisionmap[p])
2745 continue; /* already decided */
2746 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing orphaned %s\n", pool_solvid2str(pool, p));
2748 level = setpropagatelearn(solv, level, -p, 0, 0);
2752 if (i < solv->orphaned.count)
2753 continue; /* back to main loop */
2754 if (solv->brokenorphanrules)
2756 solver_check_brokenorphanrules(solv, &dq);
2759 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2760 for (i = 0; i < dq.count; i++)
2763 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing orphaned dep %s\n", pool_solvid2str(pool, p));
2765 level = setpropagatelearn(solv, level, p, 0, 0);
2774 /* one final pass to make sure we decided all installed packages */
2775 if (solv->installed)
2777 for (p = solv->installed->start; p < solv->installed->end; p++)
2779 if (solv->decisionmap[p])
2780 continue; /* already decided */
2781 s = pool->solvables + p;
2782 if (s->repo != solv->installed)
2784 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing unwanted %s\n", pool_solvid2str(pool, p));
2786 level = setpropagatelearn(solv, level, -p, 0, 0);
2790 if (p < solv->installed->end)
2791 continue; /* back to main loop */
2794 if (solv->installed && solv->cleandepsmap.size && cleandeps_check_mistakes(solv))
2797 level = 0; /* restart from scratch */
2801 if (solv->solution_callback)
2803 solv->solution_callback(solv, solv->solution_callback_data);
2804 if (solv->branches.count)
2808 for (i = solv->branches.count - 1; i >= 0; i--)
2810 p = solv->branches.elements[i];
2815 i -= 3; /* skip: p data count */
2824 while (i > 0 && solv->branches.elements[i - 1] > 0)
2826 level = takebranch(solv, i, endi, "branching", disablerules);
2830 /* all branches done, we're finally finished */
2834 /* auto-minimization step */
2835 if (solv->branches.count)
2837 int endi, lasti = -1, lastiend = -1;
2838 if (solv->recommends_index < solv->decisionq.count)
2839 policy_update_recommendsmap(solv);
2840 for (endi = solv->branches.count; endi > 0;)
2842 int l, lastsi = -1, starti = endi - solv->branches.elements[endi - 2];
2843 l = solv->branches.elements[endi - 1];
2844 for (i = starti; i < endi - 4; i++)
2846 p = solv->branches.elements[i];
2849 if (solv->decisionmap[p] > l)
2856 if (lastsi < 0 && (MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
2861 /* we have a recommended package that could not be installed */
2862 /* take it if our current selection is not recommended */
2863 for (i = starti; i < endi - 4; i++)
2865 p = -solv->branches.elements[i];
2866 if (p <= 0 || solv->decisionmap[p] != l + 1)
2868 if (!(MAPTST(&solv->recommendsmap, p) || solver_is_supplementing(solv, pool->solvables + p)))
2880 minimizationsteps++;
2881 level = takebranch(solv, lasti, lastiend, "minimizing", disablerules);
2882 continue; /* back to main loop */
2885 /* no minimization found, we're finally finished! */
2889 POOL_DEBUG(SOLV_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
2891 POOL_DEBUG(SOLV_DEBUG_STATS, "done solving.\n\n");
2897 solv->decisioncnt_jobs = solv->decisionq.count;
2898 solv->decisioncnt_update = solv->decisionq.count;
2899 solv->decisioncnt_keep = solv->decisionq.count;
2900 solv->decisioncnt_resolve = solv->decisionq.count;
2901 solv->decisioncnt_weak = solv->decisionq.count;
2902 solv->decisioncnt_orphan = solv->decisionq.count;
2905 solver_printdecisionq(solv, SOLV_DEBUG_RESULT);
2910 /*-------------------------------------------------------------------
2912 * remove disabled conflicts
2914 * purpose: update the decisionmap after some rules were disabled.
2915 * this is used to calculate the suggested/recommended package list.
2916 * Also returns a "removed" list to undo the discisionmap changes.
2920 removedisabledconflicts(Solver *solv, Queue *removed)
2922 Pool *pool = solv->pool;
2927 Id *decisionmap = solv->decisionmap;
2929 queue_empty(removed);
2930 for (i = 0; i < solv->decisionq.count; i++)
2932 p = solv->decisionq.elements[i];
2934 continue; /* conflicts only, please */
2935 why = solv->decisionq_why.elements[i];
2938 /* no rule involved, must be a orphan package drop */
2941 /* we never do conflicts on free decisions, so there
2942 * must have been an unit rule */
2944 r = solv->rules + why;
2945 if (r->d < 0 && decisionmap[-p])
2947 /* rule is now disabled, remove from decisionmap */
2948 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing conflict for package %s[%d]\n", pool_solvid2str(pool, -p), -p);
2949 queue_push(removed, -p);
2950 queue_push(removed, decisionmap[-p]);
2951 decisionmap[-p] = 0;
2954 if (!removed->count)
2956 /* we removed some confliced packages. some of them might still
2957 * be in conflict, so search for unit rules and re-conflict */
2959 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
2961 if (i == solv->nrules)
2964 r = solv->rules + i;
2970 if (r->p < 0 && !decisionmap[-r->p])
2976 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
2978 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
2983 if (r->p < 0 && decisionmap[-r->p] == 0)
2985 if (new || DECISIONMAP_FALSE(r->p))
2987 dp = pool->whatprovidesdata + r->d;
2988 while ((p = *dp++) != 0)
2990 if (new && p == new)
2992 if (p < 0 && decisionmap[-p] == 0)
3001 else if (!DECISIONMAP_FALSE(p))
3011 POOL_DEBUG(SOLV_DEBUG_SOLVER, "re-conflicting package %s[%d]\n", pool_solvid2str(pool, -new), -new);
3012 decisionmap[-new] = -1;
3014 n = 0; /* redo all rules */
3020 undo_removedisabledconflicts(Solver *solv, Queue *removed)
3023 for (i = 0; i < removed->count; i += 2)
3024 solv->decisionmap[removed->elements[i]] = removed->elements[i + 1];
3028 /*-------------------------------------------------------------------
3030 * weaken solvable dependencies
3034 weaken_solvable_deps(Solver *solv, Id p)
3039 for (i = 1, r = solv->rules + i; i < solv->pkgrules_end; i++, r++)
3043 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3044 continue; /* conflict */
3045 queue_push(&solv->weakruleq, i);
3050 /********************************************************************/
3055 solver_calculate_multiversionmap(Pool *pool, Queue *job, Map *multiversionmap)
3058 Id how, what, select;
3060 for (i = 0; i < job->count; i += 2)
3062 how = job->elements[i];
3063 if ((how & SOLVER_JOBMASK) != SOLVER_MULTIVERSION)
3065 what = job->elements[i + 1];
3066 select = how & SOLVER_SELECTMASK;
3067 if (!multiversionmap->size)
3068 map_grow(multiversionmap, pool->nsolvables);
3069 if (select == SOLVER_SOLVABLE_ALL)
3071 FOR_POOL_SOLVABLES(p)
3072 MAPSET(multiversionmap, p);
3074 else if (select == SOLVER_SOLVABLE_REPO)
3077 Repo *repo = pool_id2repo(pool, what);
3079 FOR_REPO_SOLVABLES(repo, p, s)
3080 MAPSET(multiversionmap, p);
3082 FOR_JOB_SELECT(p, pp, select, what)
3083 MAPSET(multiversionmap, p);
3088 solver_calculate_noobsmap(Pool *pool, Queue *job, Map *multiversionmap)
3090 solver_calculate_multiversionmap(pool, job, multiversionmap);
3094 * add a rule created by a job, record job number and weak flag
3097 solver_addjobrule(Solver *solv, Id p, Id p2, Id d, Id job, int weak)
3099 solver_addrule(solv, p, p2, d);
3100 queue_push(&solv->ruletojob, job);
3102 queue_push(&solv->weakruleq, solv->nrules - 1);
3106 add_cleandeps_package(Solver *solv, Id p)
3108 if (!solv->cleandeps_updatepkgs)
3110 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
3111 queue_init(solv->cleandeps_updatepkgs);
3113 queue_pushunique(solv->cleandeps_updatepkgs, p);
3117 add_update_target(Solver *solv, Id p, Id how)
3119 Pool *pool = solv->pool;
3120 Solvable *s = pool->solvables + p;
3121 Repo *installed = solv->installed;
3123 if (!solv->update_targets)
3125 solv->update_targets = solv_calloc(1, sizeof(Queue));
3126 queue_init(solv->update_targets);
3128 if (s->repo == installed)
3130 queue_push2(solv->update_targets, p, p);
3133 FOR_PROVIDES(pi, pip, s->name)
3135 Solvable *si = pool->solvables + pi;
3136 if (si->repo != installed || si->name != s->name)
3138 if (how & SOLVER_FORCEBEST)
3140 if (!solv->bestupdatemap.size)
3141 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3142 MAPSET(&solv->bestupdatemap, pi - installed->start);
3144 if (how & SOLVER_CLEANDEPS)
3145 add_cleandeps_package(solv, pi);
3146 queue_push2(solv->update_targets, pi, p);
3147 /* check if it's ok to keep the installed package */
3148 if (s->evr == si->evr && solvable_identical(s, si))
3149 queue_push2(solv->update_targets, pi, pi);
3153 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
3154 while ((obs = *obsp++) != 0)
3156 FOR_PROVIDES(pi, pip, obs)
3158 Solvable *si = pool->solvables + pi;
3159 if (si->repo != installed)
3161 if (si->name == s->name)
3162 continue; /* already handled above */
3163 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
3165 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
3167 if (how & SOLVER_FORCEBEST)
3169 if (!solv->bestupdatemap.size)
3170 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3171 MAPSET(&solv->bestupdatemap, pi - installed->start);
3173 if (how & SOLVER_CLEANDEPS)
3174 add_cleandeps_package(solv, pi);
3175 queue_push2(solv->update_targets, pi, p);
3182 transform_update_targets_sortfn(const void *ap, const void *bp, void *dp)
3192 transform_update_targets(Solver *solv)
3194 Repo *installed = solv->installed;
3195 Queue *update_targets = solv->update_targets;
3197 Id p, q, lastp, lastq;
3199 if (!update_targets->count)
3201 queue_free(update_targets);
3202 solv->update_targets = solv_free(update_targets);
3205 if (update_targets->count > 2)
3206 solv_sort(update_targets->elements, update_targets->count >> 1, 2 * sizeof(Id), transform_update_targets_sortfn, solv);
3207 queue_insertn(update_targets, 0, installed->end - installed->start, 0);
3209 for (i = j = installed->end - installed->start; i < update_targets->count; i += 2)
3211 if ((p = update_targets->elements[i]) != lastp)
3213 if (!solv->updatemap.size)
3214 map_grow(&solv->updatemap, installed->end - installed->start);
3215 MAPSET(&solv->updatemap, p - installed->start);
3216 update_targets->elements[j++] = 0; /* finish old set */
3217 update_targets->elements[p - installed->start] = j; /* start new set */
3221 if ((q = update_targets->elements[i + 1]) != lastq)
3223 update_targets->elements[j++] = q;
3227 queue_truncate(update_targets, j);
3228 queue_push(update_targets, 0); /* finish last set */
3233 addedmap2deduceq(Solver *solv, Map *addedmap)
3235 Pool *pool = solv->pool;
3240 queue_empty(&solv->addedmap_deduceq);
3241 for (i = 2, j = solv->pkgrules_end - 1; i < pool->nsolvables && j > 0; j--)
3243 r = solv->rules + j;
3246 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3249 if (!MAPTST(addedmap, p))
3251 /* should never happen, but... */
3252 if (!solv->addedmap_deduceq.count || solv->addedmap_deduceq.elements[solv->addedmap_deduceq.count - 1] != -p)
3253 queue_push(&solv->addedmap_deduceq, -p);
3257 if (MAPTST(addedmap, i))
3258 queue_push(&solv->addedmap_deduceq, i);
3262 for (; i < pool->nsolvables; i++)
3263 if (MAPTST(addedmap, i))
3264 queue_push(&solv->addedmap_deduceq, i);
3266 for (i = 2; i < pool->nsolvables; i++)
3267 if (MAPTST(addedmap, i))
3272 deduceq2addedmap(Solver *solv, Map *addedmap)
3277 for (j = solv->pkgrules_end - 1; j > 0; j--)
3279 r = solv->rules + j;
3280 if (r->d < 0 && r->p)
3281 solver_enablerule(solv, r);
3284 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3287 MAPSET(addedmap, p);
3289 for (j = 0; j < solv->addedmap_deduceq.count; j++)
3291 p = solv->addedmap_deduceq.elements[j];
3293 MAPSET(addedmap, p);
3295 MAPCLR(addedmap, p);
3299 #ifdef ENABLE_COMPLEX_DEPS
3301 add_complex_jobrules(Solver *solv, Id dep, int flags, int jobidx, int weak)
3303 Pool *pool = solv->pool;
3308 i = pool_normalize_complex_dep(pool, dep, &bq, flags | CPLXDEPS_EXPAND);
3309 if (i == 0 || i == 1)
3313 solver_addjobrule(solv, -SYSTEMSOLVABLE, 0, 0, jobidx, weak);
3316 for (i = 0; i < bq.count; i++)
3318 if (!bq.elements[i])
3320 for (j = 0; bq.elements[i + j + 1]; j++)
3323 solver_addjobrule(solv, bq.elements[i], 0, pool_ids2whatprovides(pool, bq.elements + i + 1, j), jobidx, weak);
3325 solver_addjobrule(solv, bq.elements[i], bq.elements[i + 1], 0, jobidx, weak);
3340 solver_solve(Solver *solv, Queue *job)
3342 Pool *pool = solv->pool;
3343 Repo *installed = solv->installed;
3345 int oldnrules, initialnrules;
3346 Map addedmap; /* '1' == have pkg-rules for solvable */
3347 Map installcandidatemap;
3348 Id how, what, select, name, weak, p, pp, d;
3352 int now, solve_start;
3354 int hasbestinstalljob = 0;
3356 solve_start = solv_timems(0);
3358 /* log solver options */
3359 POOL_DEBUG(SOLV_DEBUG_STATS, "solver started\n");
3360 POOL_DEBUG(SOLV_DEBUG_STATS, "dosplitprovides=%d, noupdateprovide=%d, noinfarchcheck=%d\n", solv->dosplitprovides, solv->noupdateprovide, solv->noinfarchcheck);
3361 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);
3362 POOL_DEBUG(SOLV_DEBUG_STATS, "promoteepoch=%d, forbidselfconflicts=%d\n", pool->promoteepoch, pool->forbidselfconflicts);
3363 POOL_DEBUG(SOLV_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d, obsoleteusescolors=%d, implicitobsoleteusescolors=%d\n", pool->obsoleteusesprovides, pool->implicitobsoleteusesprovides, pool->obsoleteusescolors, pool->implicitobsoleteusescolors);
3364 POOL_DEBUG(SOLV_DEBUG_STATS, "dontinstallrecommended=%d, addalreadyrecommended=%d\n", solv->dontinstallrecommended, solv->addalreadyrecommended);
3366 /* create whatprovides if not already there */
3367 if (!pool->whatprovides)
3368 pool_createwhatprovides(pool);
3370 /* create obsolete index */
3371 policy_create_obsolete_index(solv);
3374 queue_free(&solv->job);
3375 queue_init_clone(&solv->job, job);
3376 solv->pooljobcnt = pool->pooljobs.count;
3377 if (pool->pooljobs.count)
3378 queue_insertn(&solv->job, 0, pool->pooljobs.count, pool->pooljobs.elements);
3381 /* free old stuff in jase we re-run a solver */
3382 queuep_free(&solv->update_targets);
3383 queuep_free(&solv->cleandeps_updatepkgs);
3384 queue_empty(&solv->ruleassertions);
3385 solv->bestrules_pkg = solv_free(solv->bestrules_pkg);
3386 solv->yumobsrules_info = solv_free(solv->yumobsrules_info);
3387 solv->choicerules_ref = solv_free(solv->choicerules_ref);
3388 if (solv->noupdate.size)
3389 map_empty(&solv->noupdate);
3390 map_zerosize(&solv->multiversion);
3391 solv->updatemap_all = 0;
3392 map_zerosize(&solv->updatemap);
3393 solv->bestupdatemap_all = 0;
3394 map_zerosize(&solv->bestupdatemap);
3395 solv->fixmap_all = 0;
3396 map_zerosize(&solv->fixmap);
3397 solv->dupmap_all = 0;
3398 map_zerosize(&solv->dupmap);
3399 map_zerosize(&solv->dupinvolvedmap);
3400 solv->droporphanedmap_all = 0;
3401 map_zerosize(&solv->droporphanedmap);
3402 solv->allowuninstall_all = 0;
3403 map_zerosize(&solv->allowuninstallmap);
3404 map_zerosize(&solv->cleandepsmap);
3405 map_zerosize(&solv->weakrulemap);
3406 queue_empty(&solv->weakruleq);
3407 solv->watches = solv_free(solv->watches);
3408 queue_empty(&solv->ruletojob);
3409 if (solv->decisionq.count)
3410 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
3411 queue_empty(&solv->decisionq);
3412 queue_empty(&solv->decisionq_why);
3413 solv->decisioncnt_jobs = solv->decisioncnt_update = solv->decisioncnt_keep = solv->decisioncnt_resolve = solv->decisioncnt_weak = solv->decisioncnt_orphan = 0;
3414 queue_empty(&solv->learnt_why);
3415 queue_empty(&solv->learnt_pool);
3416 queue_empty(&solv->branches);
3417 solv->propagate_index = 0;
3418 queue_empty(&solv->problems);
3419 queue_empty(&solv->solutions);
3420 queue_empty(&solv->orphaned);
3421 solv->stats_learned = solv->stats_unsolvable = 0;
3422 if (solv->recommends_index)
3424 map_empty(&solv->recommendsmap);
3425 map_empty(&solv->suggestsmap);
3426 queuep_free(&solv->recommendscplxq);
3427 queuep_free(&solv->suggestscplxq);
3428 solv->recommends_index = 0;
3430 queuep_free(&solv->brokenorphanrules);
3431 solv->specialupdaters = solv_free(solv->specialupdaters);
3435 * create basic rule set of all involved packages
3436 * use addedmap bitmap to make sure we don't create rules twice
3439 /* create multiversion map if needed */
3440 solver_calculate_multiversionmap(pool, job, &solv->multiversion);
3442 map_init(&addedmap, pool->nsolvables);
3443 MAPSET(&addedmap, SYSTEMSOLVABLE);
3445 map_init(&installcandidatemap, pool->nsolvables);
3448 now = solv_timems(0);
3450 * create rules for all package that could be involved with the solving
3451 * so called: pkg rules
3454 initialnrules = solv->pkgrules_end ? solv->pkgrules_end : 1;
3455 if (initialnrules > 1)
3456 deduceq2addedmap(solv, &addedmap);
3457 if (solv->nrules != initialnrules)
3458 solver_shrinkrules(solv, initialnrules);
3459 solv->nrules = initialnrules;
3460 solv->pkgrules_end = 0;
3464 /* check for update/verify jobs as they need to be known early */
3465 /* also setup the droporphaned map, we need it when creating update rules */
3466 for (i = 0; i < job->count; i += 2)
3468 how = job->elements[i];
3469 what = job->elements[i + 1];
3470 select = how & SOLVER_SELECTMASK;
3471 switch (how & SOLVER_JOBMASK)
3474 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
3475 solv->fixmap_all = 1;
3476 FOR_JOB_SELECT(p, pp, select, what)
3478 s = pool->solvables + p;
3479 if (s->repo != installed)
3481 if (!solv->fixmap.size)
3482 map_grow(&solv->fixmap, installed->end - installed->start);
3483 MAPSET(&solv->fixmap, p - installed->start);
3487 if (select == SOLVER_SOLVABLE_ALL)
3489 solv->updatemap_all = 1;
3490 if (how & SOLVER_FORCEBEST)
3491 solv->bestupdatemap_all = 1;
3492 if (how & SOLVER_CLEANDEPS)
3494 FOR_REPO_SOLVABLES(installed, p, s)
3495 add_cleandeps_package(solv, p);
3498 else if (select == SOLVER_SOLVABLE_REPO)
3500 Repo *repo = pool_id2repo(pool, what);
3503 if (repo == installed && !(how & SOLVER_TARGETED))
3505 solv->updatemap_all = 1;
3506 if (how & SOLVER_FORCEBEST)
3507 solv->bestupdatemap_all = 1;
3508 if (how & SOLVER_CLEANDEPS)
3510 FOR_REPO_SOLVABLES(installed, p, s)
3511 add_cleandeps_package(solv, p);
3515 if (solv->noautotarget && !(how & SOLVER_TARGETED))
3517 /* targeted update */
3518 FOR_REPO_SOLVABLES(repo, p, s)
3519 add_update_target(solv, p, how);
3523 if (!(how & SOLVER_TARGETED))
3526 FOR_JOB_SELECT(p, pp, select, what)
3528 s = pool->solvables + p;
3529 if (s->repo != installed)
3531 if (!solv->updatemap.size)
3532 map_grow(&solv->updatemap, installed->end - installed->start);
3533 MAPSET(&solv->updatemap, p - installed->start);
3534 if (how & SOLVER_FORCEBEST)
3536 if (!solv->bestupdatemap.size)
3537 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3538 MAPSET(&solv->bestupdatemap, p - installed->start);
3540 if (how & SOLVER_CLEANDEPS)
3541 add_cleandeps_package(solv, p);
3544 if (!targeted || solv->noautotarget)
3547 FOR_JOB_SELECT(p, pp, select, what)
3548 add_update_target(solv, p, how);
3551 case SOLVER_DROP_ORPHANED:
3552 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
3553 solv->droporphanedmap_all = 1;
3554 FOR_JOB_SELECT(p, pp, select, what)
3556 s = pool->solvables + p;
3557 if (s->repo != installed)
3559 if (!solv->droporphanedmap.size)
3560 map_grow(&solv->droporphanedmap, installed->end - installed->start);
3561 MAPSET(&solv->droporphanedmap, p - installed->start);
3569 if (solv->update_targets)
3570 transform_update_targets(solv);
3572 oldnrules = solv->nrules;
3573 FOR_REPO_SOLVABLES(installed, p, s)
3574 solver_addpkgrulesforsolvable(solv, s, &addedmap);
3575 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules for installed solvables\n", solv->nrules - oldnrules);
3576 oldnrules = solv->nrules;
3577 FOR_REPO_SOLVABLES(installed, p, s)
3578 solver_addpkgrulesforupdaters(solv, s, &addedmap, 1);
3579 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3583 * create rules for all packages involved in the job
3584 * (to be installed or removed)
3587 oldnrules = solv->nrules;
3588 for (i = 0; i < job->count; i += 2)
3590 how = job->elements[i];
3591 what = job->elements[i + 1];
3592 select = how & SOLVER_SELECTMASK;
3594 switch (how & SOLVER_JOBMASK)
3596 case SOLVER_INSTALL:
3597 FOR_JOB_SELECT(p, pp, select, what)
3599 MAPSET(&installcandidatemap, p);
3600 solver_addpkgrulesforsolvable(solv, pool->solvables + p, &addedmap);
3603 case SOLVER_DISTUPGRADE:
3604 if (select == SOLVER_SOLVABLE_ALL)
3606 solv->dupmap_all = 1;
3607 solv->updatemap_all = 1;
3608 if (how & SOLVER_FORCEBEST)
3609 solv->bestupdatemap_all = 1;
3611 if (!solv->dupmap_all || solv->allowuninstall)
3618 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules for packages involved in a job\n", solv->nrules - oldnrules);
3622 * add rules for suggests, enhances
3624 oldnrules = solv->nrules;
3625 solver_addpkgrulesforweak(solv, &addedmap);
3626 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules because of weak dependencies\n", solv->nrules - oldnrules);
3628 #ifdef ENABLE_LINKED_PKGS
3629 oldnrules = solv->nrules;
3630 solver_addpkgrulesforlinked(solv, &addedmap);
3631 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d pkg rules because of linked packages\n", solv->nrules - oldnrules);
3635 * first pass done, we now have all the pkg rules we need.
3636 * unify existing rules before going over all job rules and
3638 * at this point the system is always solvable,
3639 * as an empty system (remove all packages) is a valid solution
3642 IF_POOLDEBUG (SOLV_DEBUG_STATS)
3644 int possible = 0, installable = 0;
3645 for (i = 1; i < pool->nsolvables; i++)
3647 if (pool_installable(pool, pool->solvables + i))
3649 if (MAPTST(&addedmap, i))
3652 POOL_DEBUG(SOLV_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
3655 if (solv->nrules > initialnrules)
3656 solver_unifyrules(solv); /* remove duplicate pkg rules */
3657 solv->pkgrules_end = solv->nrules; /* mark end of pkg rules */
3659 if (solv->nrules > initialnrules)
3660 addedmap2deduceq(solv, &addedmap); /* so that we can recreate the addedmap */
3662 POOL_DEBUG(SOLV_DEBUG_STATS, "pkg rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
3663 POOL_DEBUG(SOLV_DEBUG_STATS, "pkg rule creation took %d ms\n", solv_timems(now));
3665 /* create dup maps if needed. We need the maps early to create our
3668 solver_createdupmaps(solv);
3671 * create feature rules
3673 * foreach installed:
3674 * create assertion (keep installed, if no update available)
3676 * create update rule (A|update1(A)|update2(A)|...)
3678 * those are used later on to keep a version of the installed packages in
3682 solv->featurerules = solv->nrules; /* mark start of feature rules */
3685 /* foreach possibly installed solvable */
3686 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3688 if (s->repo != installed)
3690 solver_addrule(solv, 0, 0, 0); /* create dummy rule */
3693 solver_addupdaterule(solv, s, 1); /* allow s to be updated */
3695 /* make sure we accounted for all rules */
3696 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
3698 solv->featurerules_end = solv->nrules;
3701 * Add update rules for installed solvables
3703 * almost identical to feature rules
3704 * except that downgrades/archchanges/vendorchanges are not allowed
3707 solv->updaterules = solv->nrules;
3710 { /* foreach installed solvables */
3711 /* we create all update rules, but disable some later on depending on the job */
3712 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3716 if (s->repo != installed)
3718 solver_addrule(solv, 0, 0, 0); /* create dummy rule */
3721 solver_addupdaterule(solv, s, 0); /* allowall = 0: downgrades not allowed */
3723 * check for and remove duplicate
3725 r = solv->rules + solv->nrules - 1; /* r: update rule */
3728 sr = r - (installed->end - installed->start); /* sr: feature rule */
3729 /* it's also orphaned if the feature rule consists just of the installed package */
3730 if (!solv->dupmap_all && sr->p == i && !sr->d && !sr->w2)
3731 queue_push(&solv->orphaned, i);
3732 if (!solver_rulecmp(solv, r, sr))
3733 memset(sr, 0, sizeof(*sr)); /* delete unneeded feature rule */
3735 solver_disablerule(solv, sr); /* disable feature rule for now */
3737 /* consistency check: we added a rule for _every_ installed solvable */
3738 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
3740 solv->updaterules_end = solv->nrules;
3744 * now add all job rules
3747 solv->jobrules = solv->nrules;
3748 for (i = 0; i < job->count; i += 2)
3750 oldnrules = solv->nrules;
3752 if (i && i == solv->pooljobcnt)
3753 POOL_DEBUG(SOLV_DEBUG_JOB, "end of pool jobs\n");
3754 how = job->elements[i];
3755 what = job->elements[i + 1];
3756 weak = how & SOLVER_WEAK;
3757 select = how & SOLVER_SELECTMASK;
3758 switch (how & SOLVER_JOBMASK)
3760 case SOLVER_INSTALL:
3761 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3762 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
3763 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3764 if (select == SOLVER_SOLVABLE)
3769 #ifdef ENABLE_COMPLEX_DEPS
3770 else if ((select == SOLVER_SOLVABLE_PROVIDES || select == SOLVER_SOLVABLE_NAME) && pool_is_complex_dep(pool, what))
3772 if (add_complex_jobrules(solv, what, select == SOLVER_SOLVABLE_NAME ? CPLXDEPS_NAME : 0, i, weak))
3773 if (how & SOLVER_FORCEBEST)
3774 hasbestinstalljob = 1;
3781 FOR_JOB_SELECT(p, pp, select, what)
3785 if (select == SOLVER_SOLVABLE_ONE_OF)
3786 break; /* ignore empty installs */
3787 /* no candidate found or unsupported, make this an impossible rule */
3788 queue_push(&q, -SYSTEMSOLVABLE);
3790 p = queue_shift(&q); /* get first candidate */
3791 d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
3793 /* force install of namespace supplements hack */
3794 if (select == SOLVER_SOLVABLE_PROVIDES && !d && (p == SYSTEMSOLVABLE || p == -SYSTEMSOLVABLE) && ISRELDEP(what))
3796 Reldep *rd = GETRELDEP(pool, what);
3797 if (rd->flags == REL_NAMESPACE)
3800 if (!solv->installsuppdepq)
3802 solv->installsuppdepq = solv_calloc(1, sizeof(Queue));
3803 queue_init(solv->installsuppdepq);
3805 queue_pushunique(solv->installsuppdepq, rd->evr == 0 ? rd->name : what);
3808 solver_addjobrule(solv, p, 0, d, i, weak);
3809 if (how & SOLVER_FORCEBEST)
3810 hasbestinstalljob = 1;
3813 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %s%serase %s\n", weak ? "weak " : "", how & SOLVER_CLEANDEPS ? "clean deps " : "", solver_select2str(pool, select, what));
3814 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
3815 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3816 /* specific solvable: by id or by nevra */
3817 name = (select == SOLVER_SOLVABLE || (select == SOLVER_SOLVABLE_NAME && ISRELDEP(what))) ? 0 : -1;
3818 if (select == SOLVER_SOLVABLE_ALL) /* hmmm ;) */
3820 FOR_POOL_SOLVABLES(p)
3821 solver_addjobrule(solv, -p, 0, 0, i, weak);
3823 else if (select == SOLVER_SOLVABLE_REPO)
3825 Repo *repo = pool_id2repo(pool, what);
3827 FOR_REPO_SOLVABLES(repo, p, s)
3828 solver_addjobrule(solv, -p, 0, 0, i, weak);
3830 #ifdef ENABLE_COMPLEX_DEPS
3831 else if ((select == SOLVER_SOLVABLE_PROVIDES || select == SOLVER_SOLVABLE_NAME) && pool_is_complex_dep(pool, what))
3833 /* no special "erase a specific solvable" handling? */
3834 add_complex_jobrules(solv, what, select == SOLVER_SOLVABLE_NAME ? (CPLXDEPS_NAME | CPLXDEPS_TODNF | CPLXDEPS_INVERT) : (CPLXDEPS_TODNF | CPLXDEPS_INVERT), i, weak);
3838 FOR_JOB_SELECT(p, pp, select, what)
3840 s = pool->solvables + p;
3841 if (installed && s->repo == installed)
3842 name = !name ? s->name : -1;
3843 solver_addjobrule(solv, -p, 0, 0, i, weak);
3845 /* special case for "erase a specific solvable": we also
3846 * erase all other solvables with that name, so that they
3847 * don't get picked up as replacement.
3848 * name is > 0 if exactly one installed solvable matched.
3850 /* XXX: look also at packages that obsolete this package? */
3855 FOR_PROVIDES(p, pp, name)
3857 s = pool->solvables + p;
3858 if (s->name != name)
3860 /* keep other versions installed */
3861 if (s->repo == installed)
3863 /* keep installcandidates of other jobs */
3864 if (MAPTST(&installcandidatemap, p))
3866 /* don't add the same rule twice */
3867 for (j = oldnrules; j < k; j++)
3868 if (solv->rules[j].p == -p)
3871 solver_addjobrule(solv, -p, 0, 0, i, weak); /* remove by id */
3877 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3880 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sverify %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3882 case SOLVER_WEAKENDEPS:
3883 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3884 if (select != SOLVER_SOLVABLE)
3886 s = pool->solvables + what;
3887 weaken_solvable_deps(solv, what);
3889 case SOLVER_MULTIVERSION:
3890 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %smultiversion %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3893 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3894 if (select == SOLVER_SOLVABLE_ALL)
3896 FOR_POOL_SOLVABLES(p)
3897 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, 0, i, weak);
3899 else if (select == SOLVER_SOLVABLE_REPO)
3901 Repo *repo = pool_id2repo(pool, what);
3903 FOR_REPO_SOLVABLES(repo, p, s)
3904 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, 0, i, weak);
3906 FOR_JOB_SELECT(p, pp, select, what)
3907 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, 0, i, weak);
3909 case SOLVER_DISTUPGRADE:
3910 POOL_DEBUG(SOLV_DEBUG_JOB, "job: distupgrade %s\n", solver_select2str(pool, select, what));
3912 case SOLVER_DROP_ORPHANED:
3913 POOL_DEBUG(SOLV_DEBUG_JOB, "job: drop orphaned %s\n", solver_select2str(pool, select, what));
3915 case SOLVER_USERINSTALLED:
3916 POOL_DEBUG(SOLV_DEBUG_JOB, "job: user installed %s\n", solver_select2str(pool, select, what));
3918 case SOLVER_ALLOWUNINSTALL:
3919 POOL_DEBUG(SOLV_DEBUG_JOB, "job: allowuninstall %s\n", solver_select2str(pool, select, what));
3920 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
3921 solv->allowuninstall_all = 1;
3922 FOR_JOB_SELECT(p, pp, select, what)
3924 s = pool->solvables + p;
3925 if (s->repo != installed)
3927 if (!solv->allowuninstallmap.size)
3928 map_grow(&solv->allowuninstallmap, installed->end - installed->start);
3929 MAPSET(&solv->allowuninstallmap, p - installed->start);
3933 POOL_DEBUG(SOLV_DEBUG_JOB, "job: unknown job\n");
3937 IF_POOLDEBUG (SOLV_DEBUG_JOB)
3940 if (solv->nrules == oldnrules)
3941 POOL_DEBUG(SOLV_DEBUG_JOB, " - no rule created\n");
3942 for (j = oldnrules; j < solv->nrules; j++)
3944 POOL_DEBUG(SOLV_DEBUG_JOB, " - job ");
3945 solver_printrule(solv, SOLV_DEBUG_JOB, solv->rules + j);
3949 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3950 solv->jobrules_end = solv->nrules;
3952 /* now create infarch and dup rules */
3953 if (!solv->noinfarchcheck)
3955 solver_addinfarchrules(solv, &addedmap);
3957 if (pool->implicitobsoleteusescolors)
3959 /* currently doesn't work well with infarch rules, so make
3961 for (i = solv->infarchrules; i < solv->infarchrules_end; i++)
3962 queue_push(&solv->weakruleq, i);
3967 solv->infarchrules = solv->infarchrules_end = solv->nrules;
3970 solver_addduprules(solv, &addedmap);
3972 solv->duprules = solv->duprules_end = solv->nrules;
3974 if (solv->bestupdatemap_all || solv->bestupdatemap.size || hasbestinstalljob)
3975 solver_addbestrules(solv, hasbestinstalljob);
3977 solv->bestrules = solv->bestrules_end = solv->nrules;
3980 solver_freedupmaps(solv); /* no longer needed */
3982 if (solv->do_yum_obsoletes)
3983 solver_addyumobsrules(solv);
3985 solv->yumobsrules = solv->yumobsrules_end = solv->nrules;
3988 solver_addchoicerules(solv);
3990 solv->choicerules = solv->choicerules_end = solv->nrules;
3994 for (i = solv->featurerules; i < solv->nrules; i++)
3995 solver_printruleclass(solv, SOLV_DEBUG_RESULT, solv->rules + i);
3997 /* all rules created
3998 * --------------------------------------------------------------
3999 * prepare for solving
4002 /* free unneeded memory */
4003 map_free(&addedmap);
4004 map_free(&installcandidatemap);
4007 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);
4008 POOL_DEBUG(SOLV_DEBUG_STATS, "overall rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
4010 /* create weak map */
4011 if (solv->weakruleq.count)
4013 map_grow(&solv->weakrulemap, solv->nrules);
4014 for (i = 0; i < solv->weakruleq.count; i++)
4016 p = solv->weakruleq.elements[i];
4017 MAPSET(&solv->weakrulemap, p);
4021 /* enable cleandepsmap creation if we have updatepkgs */
4022 if (solv->cleandeps_updatepkgs && !solv->cleandepsmap.size)
4023 map_grow(&solv->cleandepsmap, installed->end - installed->start);
4025 if (solv->cleandeps_mistakes)
4027 queue_free(solv->cleandeps_mistakes);
4028 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
4031 /* all new rules are learnt after this point */
4032 solv->learntrules = solv->nrules;
4034 /* create watches chains */
4037 /* create assertion index. it is only used to speed up
4038 * makeruledecsions() a bit */
4039 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
4040 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
4041 queue_push(&solv->ruleassertions, i);
4043 /* disable update rules that conflict with our job */
4044 solver_disablepolicyrules(solv);
4046 /* break orphans if requested */
4047 if (solv->dupmap_all && solv->orphaned.count && solv->break_orphans)
4048 solver_breakorphans(solv);
4051 * ********************************************
4053 * ********************************************
4056 now = solv_timems(0);
4057 solver_run_sat(solv, 1, solv->dontinstallrecommended ? 0 : 1);
4058 POOL_DEBUG(SOLV_DEBUG_STATS, "solver took %d ms\n", solv_timems(now));
4061 * prepare solution queue if there were problems
4063 solver_prepare_solutions(solv);
4065 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);
4066 POOL_DEBUG(SOLV_DEBUG_STATS, "solver_solve took %d ms\n", solv_timems(solve_start));
4068 /* return number of problems */
4069 return solv->problems.count ? solv->problems.count / 2 : 0;
4073 solver_create_transaction(Solver *solv)
4075 return transaction_create_decisionq(solv->pool, &solv->decisionq, &solv->multiversion);
4078 void solver_get_orphaned(Solver *solv, Queue *orphanedq)
4080 queue_free(orphanedq);
4081 queue_init_clone(orphanedq, &solv->orphaned);
4084 void solver_get_recommendations(Solver *solv, Queue *recommendationsq, Queue *suggestionsq, int noselected)
4086 Pool *pool = solv->pool;
4087 Queue redoq, disabledq;
4093 if (!recommendationsq && !suggestionsq)
4096 map_init(&obsmap, pool->nsolvables);
4097 if (solv->installed)
4099 Id obs, *obsp, p, po, ppo;
4100 for (p = solv->installed->start; p < solv->installed->end; p++)
4102 s = pool->solvables + p;
4103 if (s->repo != solv->installed || !s->obsoletes)
4105 if (solv->decisionmap[p] <= 0)
4107 if (solv->multiversion.size && MAPTST(&solv->multiversion, p))
4109 obsp = s->repo->idarraydata + s->obsoletes;
4110 /* foreach obsoletes */
4111 while ((obs = *obsp++) != 0)
4112 FOR_PROVIDES(po, ppo, obs)
4113 MAPSET(&obsmap, po);
4118 queue_init(&disabledq);
4120 /* disable all erase jobs (including weak "keep uninstalled" rules) */
4121 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
4123 if (r->d < 0) /* disabled ? */
4125 if (r->p >= 0) /* install job? */
4127 queue_push(&disabledq, i);
4128 solver_disablerule(solv, r);
4134 enabledisablelearntrules(solv);
4135 removedisabledconflicts(solv, &redoq);
4139 * find recommended packages
4141 if (recommendationsq)
4143 Id rec, *recp, p, pp;
4145 queue_empty(recommendationsq);
4146 /* create map of all recommened packages */
4147 solv->recommends_index = -1;
4148 MAPZERO(&solv->recommendsmap);
4150 /* put all packages the solver already chose in the map */
4151 if (solv->decisioncnt_weak)
4153 for (i = solv->decisioncnt_weak; i < solv->decisioncnt_orphan; i++)
4156 why = solv->decisionq_why.elements[i];
4158 continue; /* forced by unit rule or dep resolving */
4159 p = solv->decisionq.elements[i];
4162 MAPSET(&solv->recommendsmap, p);
4166 for (i = 0; i < solv->decisionq.count; i++)
4168 p = solv->decisionq.elements[i];
4171 s = pool->solvables + p;
4174 recp = s->repo->idarraydata + s->recommends;
4175 while ((rec = *recp++) != 0)
4177 #ifdef ENABLE_COMPLEX_DEPS
4178 if (pool_is_complex_dep(pool, rec))
4180 do_complex_recommendations(solv, rec, &solv->recommendsmap, noselected);
4184 FOR_PROVIDES(p, pp, rec)
4185 if (solv->decisionmap[p] > 0)
4191 FOR_PROVIDES(p, pp, rec)
4192 if (solv->decisionmap[p] > 0)
4193 MAPSET(&solv->recommendsmap, p);
4195 continue; /* p != 0: already fulfilled */
4197 FOR_PROVIDES(p, pp, rec)
4198 MAPSET(&solv->recommendsmap, p);
4202 for (i = 1; i < pool->nsolvables; i++)
4204 if (solv->decisionmap[i] < 0)
4206 if (solv->decisionmap[i] > 0 && noselected)
4208 if (MAPTST(&obsmap, i))
4210 s = pool->solvables + i;
4211 if (!MAPTST(&solv->recommendsmap, i))
4213 if (!s->supplements)
4215 if (!pool_installable(pool, s))
4217 if (!solver_is_supplementing(solv, s))
4220 queue_push(recommendationsq, i);
4222 /* we use MODE_SUGGEST here so that repo prio is ignored */
4223 policy_filter_unwanted(solv, recommendationsq, POLICY_MODE_SUGGEST);
4227 * find suggested packages
4232 Id sug, *sugp, p, pp;
4234 queue_empty(suggestionsq);
4235 /* create map of all suggests that are still open */
4236 solv->recommends_index = -1;
4237 MAPZERO(&solv->suggestsmap);
4238 for (i = 0; i < solv->decisionq.count; i++)
4240 p = solv->decisionq.elements[i];
4243 s = pool->solvables + p;
4246 sugp = s->repo->idarraydata + s->suggests;
4247 while ((sug = *sugp++) != 0)
4249 #ifdef ENABLE_COMPLEX_DEPS
4250 if (pool_is_complex_dep(pool, sug))
4252 do_complex_recommendations(solv, sug, &solv->suggestsmap, noselected);
4256 FOR_PROVIDES(p, pp, sug)
4257 if (solv->decisionmap[p] > 0)
4263 FOR_PROVIDES(p, pp, sug)
4264 if (solv->decisionmap[p] > 0)
4265 MAPSET(&solv->suggestsmap, p);
4267 continue; /* already fulfilled */
4269 FOR_PROVIDES(p, pp, sug)
4270 MAPSET(&solv->suggestsmap, p);
4274 for (i = 1; i < pool->nsolvables; i++)
4276 if (solv->decisionmap[i] < 0)
4278 if (solv->decisionmap[i] > 0 && noselected)
4280 if (MAPTST(&obsmap, i))
4282 s = pool->solvables + i;
4283 if (!MAPTST(&solv->suggestsmap, i))
4287 if (!pool_installable(pool, s))
4289 if (!solver_is_enhancing(solv, s))
4292 queue_push(suggestionsq, i);
4294 policy_filter_unwanted(solv, suggestionsq, POLICY_MODE_SUGGEST);
4297 /* undo removedisabledconflicts */
4299 undo_removedisabledconflicts(solv, &redoq);
4302 /* undo job rule disabling */
4303 for (i = 0; i < disabledq.count; i++)
4304 solver_enablerule(solv, solv->rules + disabledq.elements[i]);
4305 queue_free(&disabledq);
4310 /***********************************************************************/
4311 /* disk usage computations */
4313 /*-------------------------------------------------------------------
4315 * calculate DU changes
4319 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
4323 solver_create_state_maps(solv, &installedmap, 0);
4324 pool_calc_duchanges(solv->pool, &installedmap, mps, nmps);
4325 map_free(&installedmap);
4329 /*-------------------------------------------------------------------
4331 * calculate changes in install size
4335 solver_calc_installsizechange(Solver *solv)
4340 solver_create_state_maps(solv, &installedmap, 0);
4341 change = pool_calc_installsizechange(solv->pool, &installedmap);
4342 map_free(&installedmap);
4347 solver_create_state_maps(Solver *solv, Map *installedmap, Map *conflictsmap)
4349 pool_create_state_maps(solv->pool, &solv->decisionq, installedmap, conflictsmap);
4353 solver_trivial_installable(Solver *solv, Queue *pkgs, Queue *res)
4355 Pool *pool = solv->pool;
4358 pool_create_state_maps(pool, &solv->decisionq, &installedmap, 0);
4359 pool_trivial_installable_multiversionmap(pool, &installedmap, pkgs, res, solv->multiversion.size ? &solv->multiversion : 0);
4360 for (i = 0; i < res->count; i++)
4361 if (res->elements[i] != -1)
4363 Solvable *s = pool->solvables + pkgs->elements[i];
4364 if (!strncmp("patch:", pool_id2str(pool, s->name), 6) && solvable_is_irrelevant_patch(s, &installedmap))
4365 res->elements[i] = -1;
4367 map_free(&installedmap);
4370 /*-------------------------------------------------------------------
4372 * decision introspection
4376 solver_get_decisionlevel(Solver *solv, Id p)
4378 return solv->decisionmap[p];
4382 solver_get_decisionqueue(Solver *solv, Queue *decisionq)
4384 queue_free(decisionq);
4385 queue_init_clone(decisionq, &solv->decisionq);
4389 solver_get_lastdecisionblocklevel(Solver *solv)
4392 if (solv->decisionq.count == 0)
4394 p = solv->decisionq.elements[solv->decisionq.count - 1];
4397 return solv->decisionmap[p] < 0 ? -solv->decisionmap[p] : solv->decisionmap[p];
4401 solver_get_decisionblock(Solver *solv, int level, Queue *decisionq)
4406 queue_empty(decisionq);
4407 for (i = 0; i < solv->decisionq.count; i++)
4409 p = solv->decisionq.elements[i];
4412 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
4415 if (i == solv->decisionq.count)
4417 for (i = 0; i < solv->decisionq.count; i++)
4419 p = solv->decisionq.elements[i];
4422 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
4423 queue_push(decisionq, p);
4430 solver_describe_decision(Solver *solv, Id p, Id *infop)
4437 if (!solv->decisionmap[p])
4438 return SOLVER_REASON_UNRELATED;
4439 pp = solv->decisionmap[p] < 0 ? -p : p;
4440 for (i = 0; i < solv->decisionq.count; i++)
4441 if (solv->decisionq.elements[i] == pp)
4443 if (i == solv->decisionq.count) /* just in case... */
4444 return SOLVER_REASON_UNRELATED;
4445 why = solv->decisionq_why.elements[i];
4447 *infop = why > 0 ? why : -why;
4449 return SOLVER_REASON_UNIT_RULE;
4452 return SOLVER_REASON_KEEP_INSTALLED; /* the systemsolvable */
4453 if (i < solv->decisioncnt_update)
4454 return SOLVER_REASON_RESOLVE_JOB;
4455 if (i < solv->decisioncnt_keep)
4457 if (why == 0 && pp < 0)
4458 return SOLVER_REASON_CLEANDEPS_ERASE;
4459 return SOLVER_REASON_UPDATE_INSTALLED;
4461 if (i < solv->decisioncnt_resolve)
4463 if (solv->focus_installed && i >= solv->decisioncnt_jobs)
4464 return SOLVER_REASON_RESOLVE_JOB;
4465 if (why == 0 && pp < 0)
4466 return SOLVER_REASON_CLEANDEPS_ERASE;
4467 return SOLVER_REASON_KEEP_INSTALLED;
4470 return SOLVER_REASON_RESOLVE;
4471 /* weak or orphaned */
4472 if (i < solv->decisioncnt_orphan)
4473 return SOLVER_REASON_WEAKDEP;
4474 return SOLVER_REASON_RESOLVE_ORPHAN;
4479 solver_describe_weakdep_decision(Solver *solv, Id p, Queue *whyq)
4481 Pool *pool = solv->pool;
4483 int level = solv->decisionmap[p];
4490 for (decisionno = 0; decisionno < solv->decisionq.count; decisionno++)
4491 if (solv->decisionq.elements[decisionno] == p)
4493 if (decisionno == solv->decisionq.count)
4495 if (decisionno < solv->decisioncnt_weak || decisionno >= solv->decisioncnt_orphan)
4498 /* 1) list all packages that recommend us */
4499 for (i = 1; i < pool->nsolvables; i++)
4501 Id *recp, rec, pp2, p2;
4502 if (solv->decisionmap[i] < 0 || solv->decisionmap[i] >= level)
4504 s = pool->solvables + i;
4507 if (!solv->addalreadyrecommended && s->repo == solv->installed)
4509 recp = s->repo->idarraydata + s->recommends;
4510 while ((rec = *recp++) != 0)
4513 FOR_PROVIDES(p2, pp2, rec)
4519 /* if p2 is already installed, this recommends is ignored */
4520 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4526 queue_push(whyq, SOLVER_REASON_RECOMMENDED);
4527 queue_push2(whyq, i, rec);
4531 /* 2) list all supplements */
4532 s = pool->solvables + p;
4533 if (s->supplements && level > 0)
4535 Id *supp, sup, pp2, p2;
4536 /* this is a hack. to use solver_dep_fulfilled we temporarily clear
4537 * everything above our level in the decisionmap */
4538 for (i = decisionno; i < solv->decisionq.count; i++ )
4540 p2 = solv->decisionq.elements[i];
4542 solv->decisionmap[p2] = -solv->decisionmap[p2];
4544 supp = s->repo->idarraydata + s->supplements;
4545 while ((sup = *supp++) != 0)
4546 if (solver_dep_fulfilled(solv, sup))
4549 /* let's see if this is an easy supp */
4550 FOR_PROVIDES(p2, pp2, sup)
4552 if (!solv->addalreadyrecommended && solv->installed)
4554 if (pool->solvables[p2].repo == solv->installed)
4557 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4559 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4560 queue_push2(whyq, p2, sup);
4566 /* hard case, just note dependency with no package */
4567 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4568 queue_push2(whyq, 0, sup);
4571 for (i = decisionno; i < solv->decisionq.count; i++)
4573 p2 = solv->decisionq.elements[i];
4575 solv->decisionmap[p2] = -solv->decisionmap[p2];
4581 pool_job2solvables(Pool *pool, Queue *pkgs, Id how, Id what)
4584 how &= SOLVER_SELECTMASK;
4586 if (how == SOLVER_SOLVABLE_ALL)
4588 FOR_POOL_SOLVABLES(p)
4589 queue_push(pkgs, p);
4591 else if (how == SOLVER_SOLVABLE_REPO)
4593 Repo *repo = pool_id2repo(pool, what);
4596 FOR_REPO_SOLVABLES(repo, p, s)
4597 queue_push(pkgs, p);
4601 FOR_JOB_SELECT(p, pp, how, what)
4602 queue_push(pkgs, p);
4607 pool_isemptyupdatejob(Pool *pool, Id how, Id what)
4610 Id select = how & SOLVER_SELECTMASK;
4611 if ((how & SOLVER_JOBMASK) != SOLVER_UPDATE)
4613 if (select == SOLVER_SOLVABLE_ALL || select == SOLVER_SOLVABLE_REPO)
4615 if (!pool->installed)
4617 FOR_JOB_SELECT(p, pp, select, what)
4618 if (pool->solvables[p].repo == pool->installed)
4621 FOR_JOB_SELECT(p, pp, select, what)
4623 Solvable *s = pool->solvables + p;
4624 FOR_PROVIDES(pi, pip, s->name)
4626 Solvable *si = pool->solvables + pi;
4627 if (si->repo != pool->installed || si->name != s->name)
4633 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
4634 while ((obs = *obsp++) != 0)
4636 FOR_PROVIDES(pi, pip, obs)
4638 Solvable *si = pool->solvables + pi;
4639 if (si->repo != pool->installed)
4641 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
4643 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
4654 get_userinstalled_cmp(const void *ap, const void *bp, void *dp)
4656 return *(Id *)ap - *(Id *)bp;
4660 get_userinstalled_cmp_names(const void *ap, const void *bp, void *dp)
4663 return strcmp(pool_id2str(pool, *(Id *)ap), pool_id2str(pool, *(Id *)bp));
4667 get_userinstalled_cmp_namearch(const void *ap, const void *bp, void *dp)
4671 r = strcmp(pool_id2str(pool, ((Id *)ap)[0]), pool_id2str(pool, ((Id *)bp)[0]));
4674 return strcmp(pool_id2str(pool, ((Id *)ap)[1]), pool_id2str(pool, ((Id *)bp)[1]));
4678 get_userinstalled_sort_uniq(Pool *pool, Queue *q, int flags)
4680 Id lastp = -1, lasta = -1;
4682 if (q->count < ((flags & GET_USERINSTALLED_NAMEARCH) ? 4 : 2))
4684 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4685 solv_sort(q->elements, q->count / 2, 2 * sizeof(Id), get_userinstalled_cmp_namearch, pool);
4686 else if ((flags & GET_USERINSTALLED_NAMES) != 0)
4687 solv_sort(q->elements, q->count, sizeof(Id), get_userinstalled_cmp_names, pool);
4689 solv_sort(q->elements, q->count, sizeof(Id), get_userinstalled_cmp, 0);
4690 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4692 for (i = j = 0; i < q->count; i += 2)
4693 if (q->elements[i] != lastp || q->elements[i + 1] != lasta)
4695 q->elements[j++] = lastp = q->elements[i];
4696 q->elements[j++] = lasta = q->elements[i + 1];
4701 for (i = j = 0; i < q->count; i++)
4702 if (q->elements[i] != lastp)
4703 q->elements[j++] = lastp = q->elements[i];
4705 queue_truncate(q, j);
4709 namearch2solvables(Pool *pool, Queue *q, Queue *qout, int job)
4712 if (!pool->installed)
4714 for (i = 0; i < q->count; i += 2)
4716 Id p, pp, name = q->elements[i], arch = q->elements[i + 1];
4717 FOR_PROVIDES(p, pp, name)
4719 Solvable *s = pool->solvables + p;
4720 if (s->repo != pool->installed || s->name != name || (arch && s->arch != arch))
4723 queue_push(qout, job);
4724 queue_push(qout, p);
4730 solver_get_userinstalled(Solver *solv, Queue *q, int flags)
4732 Pool *pool = solv->pool;
4735 Repo *installed = solv->installed;
4739 map_init(&userinstalled, 0);
4741 /* first process jobs */
4742 for (i = 0; i < solv->job.count; i += 2)
4744 Id how = solv->job.elements[i];
4746 if (installed && (how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
4748 if (!userinstalled.size)
4749 map_grow(&userinstalled, installed->end - installed->start);
4750 what = solv->job.elements[i + 1];
4751 select = how & SOLVER_SELECTMASK;
4752 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
4753 FOR_REPO_SOLVABLES(installed, p, s)
4754 MAPSET(&userinstalled, p - installed->start);
4755 FOR_JOB_SELECT(p, pp, select, what)
4756 if (pool->solvables[p].repo == installed)
4757 MAPSET(&userinstalled, p - installed->start);
4760 if ((how & SOLVER_JOBMASK) != SOLVER_INSTALL)
4762 if ((how & SOLVER_NOTBYUSER) != 0)
4764 what = solv->job.elements[i + 1];
4765 select = how & SOLVER_SELECTMASK;
4766 FOR_JOB_SELECT(p, pp, select, what)
4767 if (solv->decisionmap[p] > 0)
4770 #ifdef ENABLE_LINKED_PKGS
4771 if (has_package_link(pool, pool->solvables + p))
4776 find_package_link(pool, pool->solvables + p, 0, &lq, 0, 0);
4777 for (j = 0; j < lq.count; j++)
4778 if (solv->decisionmap[lq.elements[j]] > 0)
4779 queue_push(q, lq.elements[j]);
4784 /* now process updates of userinstalled packages */
4785 if (installed && userinstalled.size)
4787 for (i = 1; i < solv->decisionq.count; i++)
4789 p = solv->decisionq.elements[i];
4792 s = pool->solvables + p;
4795 if (s->repo == installed)
4797 if (MAPTST(&userinstalled, p - installed->start))
4801 /* new package, check if we replace a userinstalled one */
4802 FOR_PROVIDES(p2, pp, s->name)
4804 Solvable *ps = pool->solvables + p2;
4805 if (p2 == p || ps->repo != installed || !MAPTST(&userinstalled, p2 - installed->start))
4807 if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
4809 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, ps))
4814 if (!p2 && s->repo != installed && s->obsoletes)
4816 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
4817 while ((obs = *obsp++) != 0)
4819 FOR_PROVIDES(p2, pp, obs)
4821 Solvable *ps = pool->solvables + p2;
4822 if (p2 == p || ps->repo != installed || !MAPTST(&userinstalled, p2 - installed->start))
4824 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
4826 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
4837 map_free(&userinstalled);
4839 /* convert to desired output format */
4840 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4842 int qcount = q->count;
4843 queue_insertn(q, 0, qcount, 0);
4844 for (i = j = 0; i < qcount; i++)
4846 s = pool->solvables + q->elements[i + qcount];
4847 q->elements[j++] = s->name;
4848 q->elements[j++] = s->arch;
4851 else if ((flags & GET_USERINSTALLED_NAMES) != 0)
4853 for (i = 0; i < q->count; i++)
4855 s = pool->solvables + q->elements[i];
4856 q->elements[i] = s->name;
4859 /* sort and unify */
4860 get_userinstalled_sort_uniq(pool, q, flags);
4862 /* invert if asked for */
4863 if ((flags & GET_USERINSTALLED_INVERTED) != 0)
4865 /* first generate queue with all installed packages */
4868 for (i = 1; i < solv->decisionq.count; i++)
4870 p = solv->decisionq.elements[i];
4873 s = pool->solvables + p;
4876 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4877 queue_push2(&invq, s->name, s->arch);
4878 else if ((flags & GET_USERINSTALLED_NAMES) != 0)
4879 queue_push(&invq, s->name);
4881 queue_push(&invq, p);
4883 /* push q on invq, just in case... */
4884 queue_insertn(&invq, invq.count, q->count, q->elements);
4885 get_userinstalled_sort_uniq(pool, &invq, flags);
4886 /* subtract queues (easy as they are sorted and invq is a superset of q) */
4887 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4891 for (i = j = 0; i < invq.count; i += 2)
4892 if (invq.elements[i] == q->elements[j] && invq.elements[i + 1] == q->elements[j + 1])
4894 invq.elements[i] = invq.elements[i + 1] = 0;
4901 for (i = 0; i < invq.count; i += 2)
4902 if (invq.elements[i])
4903 queue_push2(q, invq.elements[i], invq.elements[i + 1]);
4909 for (i = j = 0; i < invq.count; i++)
4910 if (invq.elements[i] == q->elements[j])
4912 invq.elements[i] = 0;
4913 if (++j >= q->count)
4918 for (i = 0; i < invq.count; i++)
4919 if (invq.elements[i])
4920 queue_push(q, invq.elements[i]);
4927 pool_add_userinstalled_jobs(Pool *pool, Queue *q, Queue *job, int flags)
4931 if ((flags & GET_USERINSTALLED_INVERTED) != 0)
4937 if (!pool->installed)
4940 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4941 flags &= ~GET_USERINSTALLED_NAMES; /* just in case */
4942 FOR_REPO_SOLVABLES(pool->installed, p, s)
4943 queue_push(&invq, flags & GET_USERINSTALLED_NAMES ? s->name : p);
4944 if ((flags & GET_USERINSTALLED_NAMEARCH) != 0)
4946 /* for namearch we convert to packages */
4947 namearch2solvables(pool, q, &invq, 0);
4948 get_userinstalled_sort_uniq(pool, &invq, flags);
4949 namearch2solvables(pool, q, &invq, 0);
4954 queue_insertn(&invq, invq.count, q->count, q->elements);
4955 get_userinstalled_sort_uniq(pool, &invq, flags);
4956 /* now the fun part, add q again, sort, and remove all dups */
4957 queue_insertn(&invq, invq.count, q->count, q->elements);
4961 if ((flags & GET_USERINSTALLED_NAMES) != 0)
4962 solv_sort(invq.elements, invq.count, sizeof(Id), get_userinstalled_cmp_names, pool);
4964 solv_sort(invq.elements, invq.count, sizeof(Id), get_userinstalled_cmp, 0);
4968 for (i = 0; i < invq.count; i++)
4970 if (invq.elements[i] == lastid)
4976 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), lastid);
4978 lastid = invq.elements[i];
4981 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), lastid);
4986 if (flags & GET_USERINSTALLED_NAMEARCH)
4987 namearch2solvables(pool, q, job, SOLVER_USERINSTALLED | SOLVER_SOLVABLE);
4990 for (i = 0; i < q->count; i++)
4991 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), q->elements[i]);
4997 solver_alternatives_count(Solver *solv)
4999 Id *elements = solv->branches.elements;
5001 for (res = 0, count = solv->branches.count; count; res++)
5002 count -= elements[count - 2];
5007 solver_get_alternative(Solver *solv, Id alternative, Id *idp, Id *fromp, Id *chosenp, Queue *choices, int *levelp)
5009 int cnt = solver_alternatives_count(solv);
5010 int count = solv->branches.count;
5011 Id *elements = solv->branches.elements;
5013 queue_empty(choices);
5014 if (alternative <= 0 || alternative > cnt)
5017 for (; cnt > alternative; cnt--)
5018 elements -= elements[-2];
5020 *levelp = elements[-1];
5022 *fromp = elements[-4];
5024 *idp = elements[-3];
5029 for (i = elements[-2]; i > 4; i--)
5031 Id p = -elements[-i];
5032 if (p > 0 && solv->decisionmap[p] == elements[-1] + 1)
5040 queue_insertn(choices, 0, elements[-2] - 4, elements - elements[-2]);
5041 return elements[-4] ? SOLVER_ALTERNATIVE_TYPE_RECOMMENDS : SOLVER_ALTERNATIVE_TYPE_RULE;
5045 solver_select2str(Pool *pool, Id select, Id what)
5049 select &= SOLVER_SELECTMASK;
5050 if (select == SOLVER_SOLVABLE)
5051 return pool_solvid2str(pool, what);
5052 if (select == SOLVER_SOLVABLE_NAME)
5053 return pool_dep2str(pool, what);
5054 if (select == SOLVER_SOLVABLE_PROVIDES)
5056 s = pool_dep2str(pool, what);
5057 b = pool_alloctmpspace(pool, 11 + strlen(s));
5058 sprintf(b, "providing %s", s);
5061 if (select == SOLVER_SOLVABLE_ONE_OF)
5065 while ((p = pool->whatprovidesdata[what++]) != 0)
5067 s = pool_solvid2str(pool, p);
5069 b = pool_tmpappend(pool, b, ", ", s);
5071 b = pool_tmpjoin(pool, s, 0, 0);
5072 pool_freetmpspace(pool, s);
5074 return b ? b : "nothing";
5076 if (select == SOLVER_SOLVABLE_REPO)
5078 b = pool_alloctmpspace(pool, 20);
5079 sprintf(b, "repo #%d", what);
5082 if (select == SOLVER_SOLVABLE_ALL)
5083 return "all packages";
5084 return "unknown job select";
5088 pool_job2str(Pool *pool, Id how, Id what, Id flagmask)
5090 Id select = how & SOLVER_SELECTMASK;
5091 const char *strstart = 0, *strend = 0;
5095 switch (how & SOLVER_JOBMASK)
5098 return "do nothing";
5099 case SOLVER_INSTALL:
5100 if (select == SOLVER_SOLVABLE && pool->installed && pool->solvables[what].repo == pool->installed)
5101 strstart = "keep ", strend = " installed";
5102 else if (select == SOLVER_SOLVABLE || select == SOLVER_SOLVABLE_NAME)
5103 strstart = "install ";
5104 else if (select == SOLVER_SOLVABLE_PROVIDES)
5105 strstart = "install a package ";
5107 strstart = "install one of ";
5110 if (select == SOLVER_SOLVABLE && !(pool->installed && pool->solvables[what].repo == pool->installed))
5111 strstart = "keep ", strend = " uninstalled";
5112 else if (select == SOLVER_SOLVABLE_PROVIDES)
5113 strstart = "deinstall all packages ";
5115 strstart = "deinstall ";
5118 strstart = "update ";
5120 case SOLVER_WEAKENDEPS:
5121 strstart = "weaken deps of ";
5123 case SOLVER_MULTIVERSION:
5124 strstart = "multi version ";
5129 case SOLVER_DISTUPGRADE:
5130 strstart = "dist upgrade ";
5133 strstart = "verify ";
5135 case SOLVER_DROP_ORPHANED:
5136 strstart = "deinstall ", strend = " if orphaned";
5138 case SOLVER_USERINSTALLED:
5139 strstart = "regard ", strend = " as userinstalled";
5141 case SOLVER_ALLOWUNINSTALL:
5142 strstart = "allow deinstallation of ";
5145 strstart = "unknown job ";
5148 s = pool_tmpjoin(pool, strstart, solver_select2str(pool, select, what), strend);
5150 if ((how & ~(SOLVER_SELECTMASK|SOLVER_JOBMASK)) == 0)
5153 s = pool_tmpappend(pool, s, " ", 0);
5154 if (how & SOLVER_WEAK)
5155 s = pool_tmpappend(pool, s, ",weak", 0);
5156 if (how & SOLVER_ESSENTIAL)
5157 s = pool_tmpappend(pool, s, ",essential", 0);
5158 if (how & SOLVER_CLEANDEPS)
5159 s = pool_tmpappend(pool, s, ",cleandeps", 0);
5160 if (how & SOLVER_ORUPDATE)
5161 s = pool_tmpappend(pool, s, ",orupdate", 0);
5162 if (how & SOLVER_FORCEBEST)
5163 s = pool_tmpappend(pool, s, ",forcebest", 0);
5164 if (how & SOLVER_TARGETED)
5165 s = pool_tmpappend(pool, s, ",targeted", 0);
5166 if (how & SOLVER_SETEV)
5167 s = pool_tmpappend(pool, s, ",setev", 0);
5168 if (how & SOLVER_SETEVR)
5169 s = pool_tmpappend(pool, s, ",setevr", 0);
5170 if (how & SOLVER_SETARCH)
5171 s = pool_tmpappend(pool, s, ",setarch", 0);
5172 if (how & SOLVER_SETVENDOR)
5173 s = pool_tmpappend(pool, s, ",setvendor", 0);
5174 if (how & SOLVER_SETREPO)
5175 s = pool_tmpappend(pool, s, ",setrepo", 0);
5176 if (how & SOLVER_SETNAME)
5177 s = pool_tmpappend(pool, s, ",setname", 0);
5178 if (how & SOLVER_NOAUTOSET)
5179 s = pool_tmpappend(pool, s, ",noautoset", 0);
5180 if (s[o + 1] != ',')
5181 s = pool_tmpappend(pool, s, ",?", 0);
5183 return pool_tmpappend(pool, s, "]", 0);
5187 solver_alternative2str(Solver *solv, int type, Id id, Id from)
5189 Pool *pool = solv->pool;
5190 if (type == SOLVER_ALTERNATIVE_TYPE_RECOMMENDS)
5192 const char *s = pool_dep2str(pool, id);
5193 return pool_tmpappend(pool, s, ", recommended by ", pool_solvid2str(pool, from));
5195 if (type == SOLVER_ALTERNATIVE_TYPE_RULE)
5198 Id depfrom, depto, dep;
5200 if (solver_ruleclass(solv, id) == SOLVER_RULE_CHOICE)
5201 id = solver_rule2pkgrule(solv, id);
5202 rtype = solver_ruleinfo(solv, id, &depfrom, &depto, &dep);
5203 if ((rtype & SOLVER_RULE_TYPEMASK) == SOLVER_RULE_JOB)
5205 if ((depto & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_PROVIDES)
5206 return pool_dep2str(pool, dep);
5207 return solver_select2str(pool, depto & SOLVER_SELECTMASK, dep);
5209 if (rtype == SOLVER_RULE_PKG_REQUIRES)
5211 const char *s = pool_dep2str(pool, dep);
5212 return pool_tmpappend(pool, s, ", required by ", pool_solvid2str(pool, depfrom));
5214 sprintf(buf, "Rule #%d", id);
5215 return pool_tmpjoin(pool, buf, 0, 0);
5217 return "unknown alternative type";