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
33 /********************************************************************
35 * dependency check helpers
39 /*-------------------------------------------------------------------
40 * handle split provides
42 * a splitprovides dep looks like
43 * namespace:splitprovides(pkg REL_WITH path)
44 * and is only true if pkg is installed and contains the specified path.
45 * we also make sure that pkg is selected for an update, otherwise the
46 * update would always be forced onto the user.
49 solver_splitprovides(Solver *solv, Id dep)
51 Pool *pool = solv->pool;
56 if (!solv->dosplitprovides || !solv->installed || (!solv->updatemap_all && !solv->updatemap.size))
60 rd = GETRELDEP(pool, dep);
61 if (rd->flags != REL_WITH)
64 * things are a bit tricky here if pool->addedprovides == 1, because most split-provides are in
65 * a non-standard location. If we simply call pool_whatprovides, we'll drag in the complete
66 * file list. Instead we rely on pool_addfileprovides ignoring the addfileprovidesfiltered flag
67 * for installed packages and check the lazywhatprovidesq (ignoring the REL_WITH part, but
68 * we filter the package name further down anyway).
70 if (pool->addedfileprovides == 1 && !ISRELDEP(rd->evr) && !pool->whatprovides[rd->evr])
71 pp = pool_searchlazywhatprovidesq(pool, rd->evr);
73 pp = pool_whatprovides(pool, dep);
74 while ((p = pool->whatprovidesdata[pp++]) != 0)
76 /* here we have packages that provide the correct name and contain the path,
77 * now do extra filtering */
78 s = pool->solvables + p;
79 if (s->repo == solv->installed && s->name == rd->name &&
80 (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, p - solv->installed->start))))
87 /*-------------------------------------------------------------------
88 * solver_dep_installed
92 solver_dep_installed(Solver *solv, Id dep)
95 Pool *pool = solv->pool;
100 Reldep *rd = GETRELDEP(pool, dep);
101 if (rd->flags == REL_AND)
103 if (!solver_dep_installed(solv, rd->name))
105 return solver_dep_installed(solv, rd->evr);
107 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
108 return solver_dep_installed(solv, rd->evr);
110 FOR_PROVIDES(p, pp, dep)
112 if (p == SYSTEMSOLVABLE || (solv->installed && pool->solvables[p].repo == solv->installed))
119 /* mirrors solver_dep_installed, but returns 2 if a
120 * dependency listed in solv->installsuppdepq was involved */
122 solver_check_installsuppdepq_dep(Solver *solv, Id dep)
124 Pool *pool = solv->pool;
130 Reldep *rd = GETRELDEP(pool, dep);
131 if (rd->flags == REL_AND)
133 int r2, r1 = solver_check_installsuppdepq_dep(solv, rd->name);
136 r2 = solver_check_installsuppdepq_dep(solv, rd->evr);
139 return r1 == 2 || r2 == 2 ? 2 : 1;
141 if (rd->flags == REL_OR)
143 int r2, r1 = solver_check_installsuppdepq_dep(solv, rd->name);
144 r2 = solver_check_installsuppdepq_dep(solv, rd->evr);
147 return r1 == 2 || r2 == 2 ? 2 : 1;
149 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
150 return solver_splitprovides(solv, rd->evr);
151 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
152 return solver_dep_installed(solv, rd->evr);
153 if (rd->flags == REL_NAMESPACE && (q = solv->installsuppdepq) != 0)
156 for (i = 0; i < q->count; i++)
157 if (q->elements[i] == dep || q->elements[i] == rd->name)
161 FOR_PROVIDES(p, pp, dep)
162 if (solv->decisionmap[p] > 0)
168 solver_check_installsuppdepq(Solver *solv, Solvable *s)
171 supp = s->repo->idarraydata + s->supplements;
172 while ((sup = *supp++) != 0)
173 if (solver_check_installsuppdepq_dep(solv, sup) == 2)
179 autouninstall(Solver *solv, Id *problem)
181 Pool *pool = solv->pool;
183 int lastfeature = 0, lastupdate = 0;
187 for (i = 0; (v = problem[i]) != 0; i++)
190 extraflags &= solv->job.elements[-v - 1];
191 if (v >= solv->featurerules && v < solv->featurerules_end)
194 if (v >= solv->updaterules && v < solv->updaterules_end)
196 /* check if identical to feature rule */
197 Id p = solv->rules[v].p;
201 r = solv->rules + solv->featurerules + (p - solv->installed->start);
204 /* update rule == feature rule */
213 if (!lastupdate && !lastfeature)
215 v = lastupdate ? lastupdate : lastfeature;
216 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "allowuninstall disabling ");
217 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + v);
218 solver_disableproblem(solv, v);
219 if (extraflags != -1 && (extraflags & SOLVER_CLEANDEPS) != 0 && solv->cleandepsmap.size)
221 /* add the package to the updatepkgs list, this will automatically turn
222 * on cleandeps mode */
223 Id p = solv->rules[v].p;
224 if (!solv->cleandeps_updatepkgs)
226 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
227 queue_init(solv->cleandeps_updatepkgs);
231 int oldupdatepkgscnt = solv->cleandeps_updatepkgs->count;
232 queue_pushunique(solv->cleandeps_updatepkgs, p);
233 if (solv->cleandeps_updatepkgs->count != oldupdatepkgscnt)
234 solver_disablepolicyrules(solv);
240 /************************************************************************/
243 * enable/disable learnt rules
245 * we have enabled or disabled some of our rules. We now reenable all
246 * of our learnt rules except the ones that were learnt from rules that
250 enabledisablelearntrules(Solver *solv)
252 Pool *pool = solv->pool;
257 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "enabledisablelearntrules called\n");
258 for (i = solv->learntrules, r = solv->rules + i; i < solv->nrules; i++, r++)
260 whyp = solv->learnt_pool.elements + solv->learnt_why.elements[i - solv->learntrules];
261 while ((why = *whyp++) != 0)
263 assert(why > 0 && why < i);
264 if (solv->rules[why].d < 0)
267 /* why != 0: we found a disabled rule, disable the learnt rule */
268 if (why && r->d >= 0)
270 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
272 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "disabling ");
273 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
275 solver_disablerule(solv, r);
277 else if (!why && r->d < 0)
279 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
281 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "re-enabling ");
282 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
284 solver_enablerule(solv, r);
291 * make assertion rules into decisions
293 * Go through rules and add direct assertions to the decisionqueue.
294 * If we find a conflict, disable rules and add them to problem queue.
298 makeruledecisions(Solver *solv)
300 Pool *pool = solv->pool;
305 int record_proof = 1;
307 int havedisabled = 0;
309 /* The system solvable is always installed first */
310 assert(solv->decisionq.count == 0);
311 queue_push(&solv->decisionq, SYSTEMSOLVABLE);
312 queue_push(&solv->decisionq_why, 0);
313 solv->decisionmap[SYSTEMSOLVABLE] = 1; /* installed at level '1' */
315 decisionstart = solv->decisionq.count;
318 /* if we needed to re-run, back up decisions to decisionstart */
319 while (solv->decisionq.count > decisionstart)
321 v = solv->decisionq.elements[--solv->decisionq.count];
322 --solv->decisionq_why.count;
324 solv->decisionmap[vv] = 0;
327 /* note that the ruleassertions queue is ordered */
328 for (ii = 0; ii < solv->ruleassertions.count; ii++)
330 ri = solv->ruleassertions.elements[ii];
331 r = solv->rules + ri;
333 if (havedisabled && ri >= solv->learntrules)
335 /* just started with learnt rule assertions. If we have disabled
336 * some rules, adapt the learnt rule status */
337 enabledisablelearntrules(solv);
341 if (r->d < 0 || !r->p || r->w2) /* disabled, dummy or no assertion */
344 /* do weak rules in phase 2 */
345 if (ri < solv->learntrules && MAPTST(&solv->weakrulemap, ri))
351 if (!solv->decisionmap[vv]) /* if not yet decided */
353 queue_push(&solv->decisionq, v);
354 queue_push(&solv->decisionq_why, r - solv->rules);
355 solv->decisionmap[vv] = v > 0 ? 1 : -1;
356 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
358 Solvable *s = solv->pool->solvables + vv;
360 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (assertion)\n", pool_solvable2str(solv->pool, s));
362 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (assertion)\n", pool_solvable2str(solv->pool, s));
367 /* check against previous decision: is there a conflict? */
368 if (v > 0 && solv->decisionmap[vv] > 0) /* ok to install */
370 if (v < 0 && solv->decisionmap[vv] < 0) /* ok to remove */
376 * The rule (r) we're currently processing says something
377 * different (v = r->p) than a previous decision (decisionmap[abs(v)])
381 if (ri >= solv->learntrules)
383 /* conflict with a learnt rule */
384 /* can happen when packages cannot be installed for multiple reasons. */
385 /* we disable the learnt rule in this case */
386 /* (XXX: we should really call analyze_unsolvable_rule here!) */
387 solver_disablerule(solv, r);
392 * find the decision which is the "opposite" of the rule
394 for (i = 0; i < solv->decisionq.count; i++)
395 if (solv->decisionq.elements[i] == -v)
397 assert(i < solv->decisionq.count); /* assert that we found it */
398 oldproblemcount = solv->problems.count;
401 * conflict with system solvable ?
403 if (v == -SYSTEMSOLVABLE)
407 queue_push(&solv->problems, solv->learnt_pool.count);
408 queue_push(&solv->learnt_pool, ri);
409 queue_push(&solv->learnt_pool, 0);
412 queue_push(&solv->problems, 0);
413 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with system solvable, disabling rule #%d\n", ri);
414 if (ri >= solv->jobrules && ri < solv->jobrules_end)
415 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
418 queue_push(&solv->problems, v);
419 queue_push(&solv->problems, 0);
420 if (solv->allowuninstall && v >= solv->featurerules && v < solv->updaterules_end)
421 solv->problems.count = oldproblemcount;
422 solver_disableproblem(solv, v);
424 break; /* start over */
427 assert(solv->decisionq_why.elements[i] > 0);
430 * conflict with an rpm rule ?
432 if (solv->decisionq_why.elements[i] < solv->rpmrules_end)
436 queue_push(&solv->problems, solv->learnt_pool.count);
437 queue_push(&solv->learnt_pool, ri);
438 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
439 queue_push(&solv->learnt_pool, 0);
442 queue_push(&solv->problems, 0);
443 assert(v > 0 || v == -SYSTEMSOLVABLE);
444 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflict with rpm rule, disabling rule #%d\n", ri);
445 if (ri >= solv->jobrules && ri < solv->jobrules_end)
446 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
449 queue_push(&solv->problems, v);
450 queue_push(&solv->problems, 0);
451 if (solv->allowuninstall && v >= solv->featurerules && v < solv->updaterules_end)
452 solv->problems.count = oldproblemcount;
453 solver_disableproblem(solv, v);
455 break; /* start over */
459 * conflict with another job or update/feature rule
465 queue_push(&solv->problems, solv->learnt_pool.count);
466 queue_push(&solv->learnt_pool, ri);
467 queue_push(&solv->learnt_pool, solv->decisionq_why.elements[i]);
468 queue_push(&solv->learnt_pool, 0);
471 queue_push(&solv->problems, 0);
473 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "conflicting update/job assertions over literal %d\n", vv);
476 * push all of our rules (can only be feature or job rules)
477 * asserting this literal on the problem stack
479 for (i = solv->featurerules, rr = solv->rules + i; i < solv->learntrules; i++, rr++)
481 if (rr->d < 0 /* disabled */
482 || rr->w2) /* or no assertion */
484 if (rr->p != vv /* not affecting the literal */
487 if (MAPTST(&solv->weakrulemap, i)) /* weak: silently ignore */
490 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, " - disabling rule #%d\n", i);
491 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + i);
494 if (i >= solv->jobrules && i < solv->jobrules_end)
495 v = -(solv->ruletojob.elements[i - solv->jobrules] + 1);
496 queue_push(&solv->problems, v);
498 queue_push(&solv->problems, 0);
500 if (solv->allowuninstall && (v = autouninstall(solv, solv->problems.elements + oldproblemcount + 1)) != 0)
501 solv->problems.count = oldproblemcount;
503 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
504 solver_disableproblem(solv, solv->problems.elements[i]);
506 break; /* start over */
508 if (ii < solv->ruleassertions.count)
512 * phase 2: now do the weak assertions
514 for (ii = 0; ii < solv->ruleassertions.count; ii++)
516 ri = solv->ruleassertions.elements[ii];
517 r = solv->rules + ri;
518 if (r->d < 0 || r->w2) /* disabled or no assertion */
520 if (ri >= solv->learntrules || !MAPTST(&solv->weakrulemap, ri)) /* skip non-weak */
525 if (!solv->decisionmap[vv]) /* if not yet decided */
527 queue_push(&solv->decisionq, v);
528 queue_push(&solv->decisionq_why, r - solv->rules);
529 solv->decisionmap[vv] = v > 0 ? 1 : -1;
530 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
532 Solvable *s = solv->pool->solvables + vv;
534 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "conflicting %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
536 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "installing %s (weak assertion)\n", pool_solvable2str(solv->pool, s));
540 /* check against previous decision: is there a conflict? */
541 if (v > 0 && solv->decisionmap[vv] > 0)
543 if (v < 0 && solv->decisionmap[vv] < 0)
546 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "assertion conflict, but I am weak, disabling ");
547 solver_printrule(solv, SOLV_DEBUG_UNSOLVABLE, r);
549 if (ri >= solv->jobrules && ri < solv->jobrules_end)
550 v = -(solv->ruletojob.elements[ri - solv->jobrules] + 1);
553 solver_disableproblem(solv, v);
555 solver_reenablepolicyrules(solv, -v);
557 break; /* start over */
559 if (ii == solv->ruleassertions.count)
560 break; /* finished! */
565 /********************************************************************/
569 /*-------------------------------------------------------------------
572 * initial setup for all watches
576 makewatches(Solver *solv)
580 int nsolvables = solv->pool->nsolvables;
582 solv_free(solv->watches);
583 /* lower half for removals, upper half for installs */
584 solv->watches = solv_calloc(2 * nsolvables, sizeof(Id));
586 /* do it reverse so rpm rules get triggered first (XXX: obsolete?) */
587 for (i = 1, r = solv->rules + solv->nrules - 1; i < solv->nrules; i++, r--)
589 for (i = 1, r = solv->rules + 1; i < solv->nrules; i++, r++)
592 if (!r->w2) /* assertions do not need watches */
595 /* see addwatches_rule(solv, r) */
596 r->n1 = solv->watches[nsolvables + r->w1];
597 solv->watches[nsolvables + r->w1] = r - solv->rules;
599 r->n2 = solv->watches[nsolvables + r->w2];
600 solv->watches[nsolvables + r->w2] = r - solv->rules;
605 /*-------------------------------------------------------------------
607 * add watches (for a new learned rule)
608 * sets up watches for a single rule
610 * see also makewatches() above.
614 addwatches_rule(Solver *solv, Rule *r)
616 int nsolvables = solv->pool->nsolvables;
618 r->n1 = solv->watches[nsolvables + r->w1];
619 solv->watches[nsolvables + r->w1] = r - solv->rules;
621 r->n2 = solv->watches[nsolvables + r->w2];
622 solv->watches[nsolvables + r->w2] = r - solv->rules;
626 /********************************************************************/
632 /* shortcuts to check if a literal (positive or negative) assignment
633 * evaluates to 'true' or 'false'
635 #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0))
636 #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0))
637 #define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0)
639 /*-------------------------------------------------------------------
643 * make decision and propagate to all rules
645 * Evaluate each term affected by the decision (linked through watches).
646 * If we find unit rules we make new decisions based on them.
648 * return : 0 = everything is OK
649 * rule = conflict found in this rule
653 propagate(Solver *solv, int level)
655 Pool *pool = solv->pool;
656 Id *rp, *next_rp; /* rule pointer, next rule pointer in linked list */
658 Id p, pkg, other_watch;
660 Id *decisionmap = solv->decisionmap;
662 Id *watches = solv->watches + pool->nsolvables; /* place ptr in middle */
664 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate -----\n");
666 /* foreach non-propagated decision */
667 while (solv->propagate_index < solv->decisionq.count)
670 * 'pkg' was just decided
671 * negate because our watches trigger if literal goes FALSE
673 pkg = -solv->decisionq.elements[solv->propagate_index++];
675 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
677 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagate for decision %d level %d\n", -pkg, level);
678 solver_printruleelement(solv, SOLV_DEBUG_PROPAGATE, 0, -pkg);
681 /* foreach rule where 'pkg' is now FALSE */
682 for (rp = watches + pkg; *rp; rp = next_rp)
684 r = solv->rules + *rp;
687 /* rule is disabled, goto next */
695 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
697 POOL_DEBUG(SOLV_DEBUG_PROPAGATE," watch triggered ");
698 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
701 /* 'pkg' was just decided (was set to FALSE)
703 * now find other literal watch, check clause
704 * and advance on linked list
718 * This term is already true (through the other literal)
719 * so we have nothing to do
721 if (DECISIONMAP_TRUE(other_watch))
725 * The other literal is FALSE or UNDEF
731 /* Not a binary clause, try to move our watch.
733 * Go over all literals and find one that is
737 * (TRUE is also ok, in that case the rule is fulfilled)
739 if (r->p /* we have a 'p' */
740 && r->p != other_watch /* which is not watched */
741 && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */
745 else /* go find a 'd' to make 'true' */
748 we just iterate sequentially, doing it in another order just changes the order of decisions, not the decisions itself
750 for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;)
752 if (p != other_watch /* which is not watched */
753 && !DECISIONMAP_FALSE(p)) /* and not FALSE */
761 * if we found some p that is UNDEF or TRUE, move
764 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
767 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> move w%d to %s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, p));
769 POOL_DEBUG(SOLV_DEBUG_PROPAGATE," -> move w%d to !%s\n", (pkg == r->w1 ? 1 : 2), pool_solvid2str(pool, -p));
785 watches[p] = r - solv->rules;
788 /* search failed, thus all unwatched literals are FALSE */
793 * unit clause found, set literal other_watch to TRUE
796 if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */
797 return r; /* eek, a conflict! */
799 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
801 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " unit ");
802 solver_printrule(solv, SOLV_DEBUG_PROPAGATE, r);
806 decisionmap[other_watch] = level; /* install! */
808 decisionmap[-other_watch] = -level; /* remove! */
810 queue_push(&solv->decisionq, other_watch);
811 queue_push(&solv->decisionq_why, r - solv->rules);
813 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
816 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to install %s\n", pool_solvid2str(pool, other_watch));
818 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, " -> decided to conflict %s\n", pool_solvid2str(pool, -other_watch));
821 } /* foreach rule involving 'pkg' */
823 } /* while we have non-decided decisions */
825 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "----- propagate end-----\n");
827 return 0; /* all is well */
831 /********************************************************************/
834 /*-------------------------------------------------------------------
841 analyze(Solver *solv, int level, Rule *c, int *pr, int *dr, int *whyp)
843 Pool *pool = solv->pool;
847 Map seen; /* global? */
848 Id d, v, vv, *dp, why;
850 int num = 0, l1num = 0;
851 int learnt_why = solv->learnt_pool.count;
852 Id *decisionmap = solv->decisionmap;
854 queue_init_buffer(&r, r_buf, sizeof(r_buf)/sizeof(*r_buf));
856 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "ANALYZE at %d ----------------------\n", level);
857 map_init(&seen, pool->nsolvables);
858 idx = solv->decisionq.count;
861 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
862 solver_printruleclass(solv, SOLV_DEBUG_ANALYZE, c);
863 queue_push(&solv->learnt_pool, c - solv->rules);
864 d = c->d < 0 ? -c->d - 1 : c->d;
865 dp = d ? pool->whatprovidesdata + d : 0;
866 /* go through all literals of the rule */
878 if (DECISIONMAP_TRUE(v)) /* the one true literal */
881 if (MAPTST(&seen, vv))
883 l = solv->decisionmap[vv];
886 MAPSET(&seen, vv); /* mark that we also need to look at this literal */
888 l1num++; /* need to do this one in level1 pass */
890 num++; /* need to do this one as well */
893 queue_push(&r, v); /* not level1 or conflict level, add to new rule */
899 if (!num && !--l1num)
900 break; /* all level 1 literals done */
902 /* find the next literal to investigate */
903 /* (as num + l1num > 0, we know that we'll always find one) */
907 v = solv->decisionq.elements[--idx];
909 if (MAPTST(&seen, vv))
914 if (num && --num == 0)
916 *pr = -v; /* so that v doesn't get lost */
919 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "got %d involved level 1 decisions\n", l1num);
920 /* clear non-l1 bits from seen map */
921 for (i = 0; i < r.count; i++)
924 MAPCLR(&seen, v > 0 ? v : -v);
926 /* only level 1 marks left in seen map */
927 l1num++; /* as l1retry decrements it */
931 why = solv->decisionq_why.elements[idx];
932 if (why <= 0) /* just in case, maybe for SYSTEMSOLVABLE */
934 c = solv->rules + why;
940 else if (r.count == 1 && r.elements[0] < 0)
943 *dr = pool_queuetowhatprovides(pool, &r);
944 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
946 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "learned rule for level %d (am %d)\n", rlevel, level);
947 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, *pr);
948 for (i = 0; i < r.count; i++)
949 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, r.elements[i]);
951 /* push end marker on learnt reasons stack */
952 queue_push(&solv->learnt_pool, 0);
956 solv->stats_learned++;
961 /*-------------------------------------------------------------------
965 * reset all solver decisions
966 * called after rules have been enabled/disabled
970 solver_reset(Solver *solv)
972 Pool *pool = solv->pool;
976 /* rewind all decisions */
977 for (i = solv->decisionq.count - 1; i >= 0; i--)
979 v = solv->decisionq.elements[i];
980 solv->decisionmap[v > 0 ? v : -v] = 0;
982 queue_empty(&solv->decisionq_why);
983 queue_empty(&solv->decisionq);
984 solv->recommends_index = -1;
985 solv->propagate_index = 0;
986 solv->decisioncnt_update = solv->decisioncnt_keep = solv->decisioncnt_resolve = solv->decisioncnt_weak = solv->decisioncnt_orphan = 0;
987 queue_empty(&solv->branches);
989 /* adapt learnt rule status to new set of enabled/disabled rules */
990 enabledisablelearntrules(solv);
992 /* redo all assertion rule decisions */
993 makeruledecisions(solv);
994 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "decisions so far: %d\n", solv->decisionq.count);
998 /*-------------------------------------------------------------------
1000 * analyze_unsolvable_rule
1002 * recursion helper used by analyze_unsolvable
1006 analyze_unsolvable_rule(Solver *solv, Rule *r, Id *lastweakp, Map *rseen)
1008 Pool *pool = solv->pool;
1010 Id why = r - solv->rules;
1012 IF_POOLDEBUG (SOLV_DEBUG_UNSOLVABLE)
1013 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, r);
1014 if (solv->learntrules && why >= solv->learntrules)
1016 if (MAPTST(rseen, why - solv->learntrules))
1018 MAPSET(rseen, why - solv->learntrules);
1019 for (i = solv->learnt_why.elements[why - solv->learntrules]; solv->learnt_pool.elements[i]; i++)
1020 if (solv->learnt_pool.elements[i] > 0)
1021 analyze_unsolvable_rule(solv, solv->rules + solv->learnt_pool.elements[i], lastweakp, rseen);
1024 if (MAPTST(&solv->weakrulemap, why))
1025 if (!*lastweakp || why > *lastweakp)
1027 /* do not add rpm rules to problem */
1028 if (why < solv->rpmrules_end)
1030 /* turn rule into problem */
1031 if (why >= solv->jobrules && why < solv->jobrules_end)
1032 why = -(solv->ruletojob.elements[why - solv->jobrules] + 1);
1033 /* normalize dup/infarch rules */
1034 if (why > solv->infarchrules && why < solv->infarchrules_end)
1036 Id name = pool->solvables[-solv->rules[why].p].name;
1037 while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
1040 if (why > solv->duprules && why < solv->duprules_end)
1042 Id name = pool->solvables[-solv->rules[why].p].name;
1043 while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
1047 /* return if problem already countains our rule */
1048 if (solv->problems.count)
1050 for (i = solv->problems.count - 1; i >= 0; i--)
1051 if (solv->problems.elements[i] == 0) /* end of last problem reached? */
1053 else if (solv->problems.elements[i] == why)
1056 queue_push(&solv->problems, why);
1060 /*-------------------------------------------------------------------
1062 * analyze_unsolvable
1064 * We know that the problem is not solvable. Record all involved
1065 * rules (i.e. the "proof") into solv->learnt_pool.
1066 * Record the learnt pool index and all non-rpm rules into
1067 * solv->problems. (Our solutions to fix the problems are to
1068 * disable those rules.)
1070 * If the proof contains at least one weak rule, we disable the
1073 * Otherwise we return 0 if disablerules is not set or disable
1074 * _all_ of the problem rules and return 1.
1076 * return: 1 - disabled some rules, try again
1081 analyze_unsolvable(Solver *solv, Rule *cr, int disablerules)
1083 Pool *pool = solv->pool;
1085 Map seen; /* global to speed things up? */
1087 Id d, v, vv, *dp, why;
1089 Id *decisionmap = solv->decisionmap;
1090 int oldproblemcount;
1091 int oldlearntpoolcount;
1093 int record_proof = 1;
1095 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "ANALYZE UNSOLVABLE ----------------------\n");
1096 solv->stats_unsolvable++;
1097 oldproblemcount = solv->problems.count;
1098 oldlearntpoolcount = solv->learnt_pool.count;
1100 /* make room for proof index */
1101 /* must update it later, as analyze_unsolvable_rule would confuse
1102 * it with a rule index if we put the real value in already */
1103 queue_push(&solv->problems, 0);
1106 map_init(&seen, pool->nsolvables);
1107 map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
1109 queue_push(&solv->learnt_pool, r - solv->rules);
1111 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1112 d = r->d < 0 ? -r->d - 1 : r->d;
1113 dp = d ? pool->whatprovidesdata + d : 0;
1124 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1126 vv = v > 0 ? v : -v;
1127 l = solv->decisionmap[vv];
1132 idx = solv->decisionq.count;
1135 v = solv->decisionq.elements[--idx];
1136 vv = v > 0 ? v : -v;
1137 if (!MAPTST(&seen, vv) || vv == SYSTEMSOLVABLE)
1139 why = solv->decisionq_why.elements[idx];
1142 queue_push(&solv->learnt_pool, why);
1143 r = solv->rules + why;
1144 analyze_unsolvable_rule(solv, r, &lastweak, &rseen);
1145 d = r->d < 0 ? -r->d - 1 : r->d;
1146 dp = d ? pool->whatprovidesdata + d : 0;
1157 if (DECISIONMAP_TRUE(v)) /* the one true literal */
1159 vv = v > 0 ? v : -v;
1160 l = solv->decisionmap[vv];
1168 queue_push(&solv->problems, 0); /* mark end of this problem */
1172 /* disable last weak rule */
1173 solv->problems.count = oldproblemcount;
1174 solv->learnt_pool.count = oldlearntpoolcount;
1175 if (lastweak >= solv->jobrules && lastweak < solv->jobrules_end)
1176 v = -(solv->ruletojob.elements[lastweak - solv->jobrules] + 1);
1179 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "disabling ");
1180 solver_printruleclass(solv, SOLV_DEBUG_UNSOLVABLE, solv->rules + lastweak);
1181 if (lastweak >= solv->choicerules && lastweak < solv->choicerules_end)
1182 solver_disablechoicerules(solv, solv->rules + lastweak);
1183 solver_disableproblem(solv, v);
1185 solver_reenablepolicyrules(solv, -v);
1190 if (solv->allowuninstall && (v = autouninstall(solv, solv->problems.elements + oldproblemcount + 1)) != 0)
1192 solv->problems.count = oldproblemcount;
1193 solv->learnt_pool.count = oldlearntpoolcount;
1201 queue_push(&solv->learnt_pool, 0);
1202 solv->problems.elements[oldproblemcount] = oldlearntpoolcount;
1205 /* + 2: index + trailing zero */
1206 if (disablerules && oldproblemcount + 2 < solv->problems.count)
1208 for (i = oldproblemcount + 1; i < solv->problems.count - 1; i++)
1209 solver_disableproblem(solv, solv->problems.elements[i]);
1210 /* XXX: might want to enable all weak rules again */
1214 POOL_DEBUG(SOLV_DEBUG_UNSOLVABLE, "UNSOLVABLE\n");
1219 /********************************************************************/
1220 /* Decision revert */
1222 /*-------------------------------------------------------------------
1225 * revert decisionq to a level
1229 revert(Solver *solv, int level)
1231 Pool *pool = solv->pool;
1233 while (solv->decisionq.count)
1235 v = solv->decisionq.elements[solv->decisionq.count - 1];
1236 vv = v > 0 ? v : -v;
1237 if (solv->decisionmap[vv] <= level && solv->decisionmap[vv] >= -level)
1239 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "reverting decision %d at %d\n", v, solv->decisionmap[vv]);
1240 solv->decisionmap[vv] = 0;
1241 solv->decisionq.count--;
1242 solv->decisionq_why.count--;
1243 solv->propagate_index = solv->decisionq.count;
1245 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] <= -level)
1247 solv->branches.count--;
1248 while (solv->branches.count && solv->branches.elements[solv->branches.count - 1] >= 0)
1249 solv->branches.count--;
1251 if (solv->recommends_index > solv->decisionq.count)
1252 solv->recommends_index = -1; /* rebuild recommends/suggests maps */
1253 if (solv->decisionq.count < solv->decisioncnt_jobs)
1254 solv->decisioncnt_jobs = 0;
1255 if (solv->decisionq.count < solv->decisioncnt_update)
1256 solv->decisioncnt_update = 0;
1257 if (solv->decisionq.count < solv->decisioncnt_keep)
1258 solv->decisioncnt_keep = 0;
1259 if (solv->decisionq.count < solv->decisioncnt_resolve)
1260 solv->decisioncnt_resolve = 0;
1261 if (solv->decisionq.count < solv->decisioncnt_weak)
1262 solv->decisioncnt_weak= 0;
1263 if (solv->decisionq.count < solv->decisioncnt_orphan)
1264 solv->decisioncnt_orphan = 0;
1268 /*-------------------------------------------------------------------
1270 * watch2onhighest - put watch2 on literal with highest level
1274 watch2onhighest(Solver *solv, Rule *r)
1279 d = r->d < 0 ? -r->d - 1 : r->d;
1281 return; /* binary rule, both watches are set */
1282 dp = solv->pool->whatprovidesdata + d;
1283 while ((v = *dp++) != 0)
1285 l = solv->decisionmap[v < 0 ? -v : v];
1297 /*-------------------------------------------------------------------
1301 * add free decision (solvable to install) to decisionq
1302 * increase level and propagate decision
1303 * return if no conflict.
1305 * in conflict case, analyze conflict rule, add resulting
1306 * rule to learnt rule set, make decision from learnt
1307 * rule (always unit) and re-propagate.
1309 * returns the new solver level or 0 if unsolvable
1314 setpropagatelearn(Solver *solv, int level, Id decision, int disablerules, Id ruleid)
1316 Pool *pool = solv->pool;
1321 assert(ruleid >= 0);
1326 solv->decisionmap[decision] = level;
1328 solv->decisionmap[-decision] = -level;
1329 queue_push(&solv->decisionq, decision);
1330 queue_push(&solv->decisionq_why, -ruleid); /* <= 0 -> free decision */
1334 r = propagate(solv, level);
1338 return analyze_unsolvable(solv, r, disablerules);
1339 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "conflict with rule #%d\n", (int)(r - solv->rules));
1340 l = analyze(solv, level, r, &p, &d, &why); /* learnt rule in p and d */
1341 assert(l > 0 && l < level);
1342 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "reverting decisions (level %d -> %d)\n", level, l);
1344 revert(solv, level);
1345 r = solver_addrule(solv, p, d);
1347 assert(solv->learnt_why.count == (r - solv->rules) - solv->learntrules);
1348 queue_push(&solv->learnt_why, why);
1351 /* at least 2 literals, needs watches */
1352 watch2onhighest(solv, r);
1353 addwatches_rule(solv, r);
1357 /* learnt rule is an assertion */
1358 queue_push(&solv->ruleassertions, r - solv->rules);
1360 /* the new rule is unit by design */
1361 solv->decisionmap[p > 0 ? p : -p] = p > 0 ? level : -level;
1362 queue_push(&solv->decisionq, p);
1363 queue_push(&solv->decisionq_why, r - solv->rules);
1364 IF_POOLDEBUG (SOLV_DEBUG_ANALYZE)
1366 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "decision: ");
1367 solver_printruleelement(solv, SOLV_DEBUG_ANALYZE, 0, p);
1368 POOL_DEBUG(SOLV_DEBUG_ANALYZE, "new rule: ");
1369 solver_printrule(solv, SOLV_DEBUG_ANALYZE, r);
1376 reorder_dq_for_jobrules(Solver *solv, int level, Queue *dq)
1378 Pool *pool = solv->pool;
1379 int i, j, haveone = 0, dqcount = dq->count;
1383 /* at the time we process jobrules the installed packages are not kept yet */
1384 /* reorder so that "future-supplemented" packages come first */
1385 FOR_REPO_SOLVABLES(solv->installed, p, s)
1387 if (MAPTST(&solv->noupdate, p - solv->installed->start))
1389 if (solv->decisionmap[p] == 0)
1391 solv->decisionmap[p] = level;
1397 for (i = 0; i < dqcount; i++)
1398 if (!solver_is_enhancing(solv, pool->solvables + dq->elements[i]))
1400 queue_push(dq, dq->elements[i]);
1401 dq->elements[i] = 0;
1403 dqcount = dq->count;
1404 for (i = 0; i < dqcount; i++)
1405 if (dq->elements[i] && !solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1407 queue_push(dq, dq->elements[i]);
1408 dq->elements[i] = 0;
1410 for (i = j = 0; i < dq->count; i++)
1411 if (dq->elements[i])
1412 dq->elements[j++] = dq->elements[i];
1413 queue_truncate(dq, j);
1414 FOR_REPO_SOLVABLES(solv->installed, p, s)
1415 if (solv->decisionmap[p] == level)
1416 solv->decisionmap[p] = 0;
1419 /*-------------------------------------------------------------------
1421 * select and install
1423 * install best package from the queue. We add an extra package, inst, if
1424 * provided. See comment in weak install section.
1426 * returns the new solver level or 0 if unsolvable
1431 selectandinstall(Solver *solv, int level, Queue *dq, int disablerules, Id ruleid)
1433 Pool *pool = solv->pool;
1438 policy_filter_unwanted(solv, dq, POLICY_MODE_CHOOSE);
1441 /* XXX: didn't we already do that? */
1442 /* XXX: shouldn't we prefer installed packages? */
1443 /* XXX: move to policy.c? */
1444 /* choose the supplemented one */
1445 for (i = 0; i < dq->count; i++)
1446 if (solver_is_supplementing(solv, pool->solvables + dq->elements[i]))
1448 dq->elements[0] = dq->elements[i];
1453 /* if we're resolving job rules and didn't resolve the installed packages yet,
1454 * do some special supplements ordering */
1455 if (dq->count > 1 && ruleid >= solv->jobrules && ruleid < solv->jobrules_end && solv->installed && !solv->focus_installed)
1456 reorder_dq_for_jobrules(solv, level, dq);
1459 /* multiple candidates, open a branch */
1460 for (i = 1; i < dq->count; i++)
1461 queue_push(&solv->branches, dq->elements[i]);
1462 queue_push(&solv->branches, -level);
1464 p = dq->elements[0];
1466 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing %s\n", pool_solvid2str(pool, p));
1468 return setpropagatelearn(solv, level, p, disablerules, ruleid);
1472 /********************************************************************/
1473 /* Main solver interface */
1476 /*-------------------------------------------------------------------
1479 * create solver structure
1481 * pool: all available solvables
1482 * installed: installed Solvables
1485 * Upon solving, rules are created to flag the Solvables
1486 * of the 'installed' Repo as installed.
1490 solver_create(Pool *pool)
1493 solv = (Solver *)solv_calloc(1, sizeof(Solver));
1495 solv->installed = pool->installed;
1497 solv->allownamechange = 1;
1499 solv->dup_allowdowngrade = 1;
1500 solv->dup_allownamechange = 1;
1501 solv->dup_allowarchchange = 1;
1502 solv->dup_allowvendorchange = 1;
1504 solv->keepexplicitobsoletes = pool->noobsoletesmultiversion ? 0 : 1;
1506 queue_init(&solv->ruletojob);
1507 queue_init(&solv->decisionq);
1508 queue_init(&solv->decisionq_why);
1509 queue_init(&solv->problems);
1510 queue_init(&solv->orphaned);
1511 queue_init(&solv->learnt_why);
1512 queue_init(&solv->learnt_pool);
1513 queue_init(&solv->branches);
1514 queue_init(&solv->weakruleq);
1515 queue_init(&solv->ruleassertions);
1516 queue_init(&solv->addedmap_deduceq);
1518 queue_push(&solv->learnt_pool, 0); /* so that 0 does not describe a proof */
1520 map_init(&solv->recommendsmap, pool->nsolvables);
1521 map_init(&solv->suggestsmap, pool->nsolvables);
1522 map_init(&solv->noupdate, solv->installed ? solv->installed->end - solv->installed->start : 0);
1523 solv->recommends_index = 0;
1525 solv->decisionmap = (Id *)solv_calloc(pool->nsolvables, sizeof(Id));
1527 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
1528 memset(solv->rules, 0, sizeof(Rule));
1535 resolve_jobrules(Solver *solv, int level, int disablerules, Queue *dq)
1537 Pool *pool = solv->pool;
1538 int oldlevel = level;
1542 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving job rules\n");
1543 if (!solv->decisioncnt_jobs)
1544 solv->decisioncnt_jobs = solv->decisionq.count;
1545 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
1548 if (r->d < 0) /* ignore disabled rules */
1551 FOR_RULELITERALS(l, pp, r)
1555 if (solv->decisionmap[-l] <= 0)
1560 if (solv->decisionmap[l] > 0)
1562 if (solv->decisionmap[l] == 0)
1566 if (l || !dq->count)
1568 /* prune to installed if not updating */
1569 if (dq->count > 1 && solv->installed && !solv->updatemap_all &&
1570 !(solv->job.elements[solv->ruletojob.elements[i - solv->jobrules]] & SOLVER_ORUPDATE))
1573 for (j = k = 0; j < dq->count; j++)
1575 Solvable *s = pool->solvables + dq->elements[j];
1576 if (s->repo == solv->installed)
1578 dq->elements[k++] = dq->elements[j];
1579 if (solv->updatemap.size && MAPTST(&solv->updatemap, dq->elements[j] - solv->installed->start))
1581 k = 0; /* package wants to be updated, do not prune */
1590 level = selectandinstall(solv, level, dq, disablerules, i);
1591 if (level <= olevel)
1594 return 0; /* unsolvable */
1595 if (level == olevel)
1599 continue; /* try something else */
1601 if (level < oldlevel)
1603 /* redo from start of jobrules */
1604 i = solv->jobrules - 1;
1605 r = solv->rules + i;
1611 /*-------------------------------------------------------------------
1617 queuep_free(Queue **qp)
1622 *qp = solv_free(*qp);
1626 map_zerosize(Map *m)
1636 solver_free(Solver *solv)
1638 queue_free(&solv->job);
1639 queue_free(&solv->ruletojob);
1640 queue_free(&solv->decisionq);
1641 queue_free(&solv->decisionq_why);
1642 queue_free(&solv->learnt_why);
1643 queue_free(&solv->learnt_pool);
1644 queue_free(&solv->problems);
1645 queue_free(&solv->solutions);
1646 queue_free(&solv->orphaned);
1647 queue_free(&solv->branches);
1648 queue_free(&solv->weakruleq);
1649 queue_free(&solv->ruleassertions);
1650 queue_free(&solv->addedmap_deduceq);
1651 queuep_free(&solv->cleandeps_updatepkgs);
1652 queuep_free(&solv->cleandeps_mistakes);
1653 queuep_free(&solv->update_targets);
1654 queuep_free(&solv->installsuppdepq);
1655 queuep_free(&solv->recommendscplxq);
1656 queuep_free(&solv->suggestscplxq);
1657 queuep_free(&solv->brokenorphanrules);
1659 map_free(&solv->recommendsmap);
1660 map_free(&solv->suggestsmap);
1661 map_free(&solv->noupdate);
1662 map_free(&solv->weakrulemap);
1663 map_free(&solv->multiversion);
1665 map_free(&solv->updatemap);
1666 map_free(&solv->bestupdatemap);
1667 map_free(&solv->fixmap);
1668 map_free(&solv->dupmap);
1669 map_free(&solv->dupinvolvedmap);
1670 map_free(&solv->droporphanedmap);
1671 map_free(&solv->cleandepsmap);
1673 solv_free(solv->decisionmap);
1674 solv_free(solv->rules);
1675 solv_free(solv->watches);
1676 solv_free(solv->obsoletes);
1677 solv_free(solv->obsoletes_data);
1678 solv_free(solv->specialupdaters);
1679 solv_free(solv->choicerules_ref);
1680 solv_free(solv->bestrules_pkg);
1681 solv_free(solv->instbuddy);
1686 solver_get_flag(Solver *solv, int flag)
1690 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1691 return solv->allowdowngrade;
1692 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1693 return solv->allownamechange;
1694 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1695 return solv->allowarchchange;
1696 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1697 return solv->allowvendorchange;
1698 case SOLVER_FLAG_ALLOW_UNINSTALL:
1699 return solv->allowuninstall;
1700 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1701 return solv->noupdateprovide;
1702 case SOLVER_FLAG_SPLITPROVIDES:
1703 return solv->dosplitprovides;
1704 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1705 return solv->dontinstallrecommended;
1706 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1707 return solv->addalreadyrecommended;
1708 case SOLVER_FLAG_NO_INFARCHCHECK:
1709 return solv->noinfarchcheck;
1710 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1711 return solv->keepexplicitobsoletes;
1712 case SOLVER_FLAG_BEST_OBEY_POLICY:
1713 return solv->bestobeypolicy;
1714 case SOLVER_FLAG_NO_AUTOTARGET:
1715 return solv->noautotarget;
1716 case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
1717 return solv->dup_allowdowngrade;
1718 case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
1719 return solv->dup_allownamechange;
1720 case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
1721 return solv->dup_allowarchchange;
1722 case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
1723 return solv->dup_allowvendorchange;
1724 case SOLVER_FLAG_KEEP_ORPHANS:
1725 return solv->keep_orphans;
1726 case SOLVER_FLAG_BREAK_ORPHANS:
1727 return solv->break_orphans;
1728 case SOLVER_FLAG_FOCUS_INSTALLED:
1729 return solv->focus_installed;
1737 solver_set_flag(Solver *solv, int flag, int value)
1739 int old = solver_get_flag(solv, flag);
1742 case SOLVER_FLAG_ALLOW_DOWNGRADE:
1743 solv->allowdowngrade = value;
1745 case SOLVER_FLAG_ALLOW_NAMECHANGE:
1746 solv->allownamechange = value;
1748 case SOLVER_FLAG_ALLOW_ARCHCHANGE:
1749 solv->allowarchchange = value;
1751 case SOLVER_FLAG_ALLOW_VENDORCHANGE:
1752 solv->allowvendorchange = value;
1754 case SOLVER_FLAG_ALLOW_UNINSTALL:
1755 solv->allowuninstall = value;
1757 case SOLVER_FLAG_NO_UPDATEPROVIDE:
1758 solv->noupdateprovide = value;
1760 case SOLVER_FLAG_SPLITPROVIDES:
1761 solv->dosplitprovides = value;
1763 case SOLVER_FLAG_IGNORE_RECOMMENDED:
1764 solv->dontinstallrecommended = value;
1766 case SOLVER_FLAG_ADD_ALREADY_RECOMMENDED:
1767 solv->addalreadyrecommended = value;
1769 case SOLVER_FLAG_NO_INFARCHCHECK:
1770 solv->noinfarchcheck = value;
1772 case SOLVER_FLAG_KEEP_EXPLICIT_OBSOLETES:
1773 solv->keepexplicitobsoletes = value;
1775 case SOLVER_FLAG_BEST_OBEY_POLICY:
1776 solv->bestobeypolicy = value;
1778 case SOLVER_FLAG_NO_AUTOTARGET:
1779 solv->noautotarget = value;
1781 case SOLVER_FLAG_DUP_ALLOW_DOWNGRADE:
1782 solv->dup_allowdowngrade = value;
1784 case SOLVER_FLAG_DUP_ALLOW_NAMECHANGE:
1785 solv->dup_allownamechange = value;
1787 case SOLVER_FLAG_DUP_ALLOW_ARCHCHANGE:
1788 solv->dup_allowarchchange = value;
1790 case SOLVER_FLAG_DUP_ALLOW_VENDORCHANGE:
1791 solv->dup_allowvendorchange = value;
1793 case SOLVER_FLAG_KEEP_ORPHANS:
1794 solv->keep_orphans = value;
1796 case SOLVER_FLAG_BREAK_ORPHANS:
1797 solv->break_orphans = value;
1799 case SOLVER_FLAG_FOCUS_INSTALLED:
1800 solv->focus_installed = value;
1809 cleandeps_check_mistakes(Solver *solv, int level)
1811 Pool *pool = solv->pool;
1815 int mademistake = 0;
1817 if (!solv->cleandepsmap.size)
1819 /* check for mistakes */
1820 for (i = solv->installed->start; i < solv->installed->end; i++)
1822 if (!MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1824 r = solv->rules + solv->featurerules + (i - solv->installed->start);
1825 /* a mistake is when the featurerule is true but the updaterule is false */
1828 FOR_RULELITERALS(p, pp, r)
1829 if (p > 0 && solv->decisionmap[p] > 0)
1832 continue; /* feature rule is not true */
1833 r = solv->rules + solv->updaterules + (i - solv->installed->start);
1836 FOR_RULELITERALS(p, pp, r)
1837 if (p > 0 && solv->decisionmap[p] > 0)
1840 continue; /* update rule is true */
1841 POOL_DEBUG(SOLV_DEBUG_SOLVER, "cleandeps mistake: ");
1842 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, r);
1843 POOL_DEBUG(SOLV_DEBUG_SOLVER, "feature rule: ");
1844 solver_printruleclass(solv, SOLV_DEBUG_SOLVER, solv->rules + solv->featurerules + (i - solv->installed->start));
1845 if (!solv->cleandeps_mistakes)
1847 solv->cleandeps_mistakes = solv_calloc(1, sizeof(Queue));
1848 queue_init(solv->cleandeps_mistakes);
1850 queue_push(solv->cleandeps_mistakes, i);
1851 MAPCLR(&solv->cleandepsmap, i - solv->installed->start);
1852 solver_reenablepolicyrules_cleandeps(solv, i);
1861 prune_to_update_targets(Solver *solv, Id *cp, Queue *q)
1865 for (i = j = 0; i < q->count; i++)
1868 for (cp2 = cp; *cp2; cp2++)
1871 q->elements[j++] = p;
1875 queue_truncate(q, j);
1878 #ifdef ENABLE_COMPLEX_DEPS
1881 add_complex_recommends(Solver *solv, Id rec, Queue *dq, Map *dqmap)
1883 Pool *pool = solv->pool;
1884 int oldcnt = dq->count;
1890 printf("ADD_COMPLEX_RECOMMENDS %s\n", pool_dep2str(pool, rec));
1892 i = pool_normalize_complex_dep(pool, rec, dq, CPLXDEPS_EXPAND);
1893 if (i == 0 || i == 1)
1896 for (i = oldcnt; i < cutcnt; i++)
1899 for (; (p = dq->elements[i]) != 0; i++)
1903 if (solv->decisionmap[-p] <= 0)
1907 if (solv->decisionmap[p] > 0)
1909 queue_truncate(dq, blkcnt);
1914 if (!MAPTST(dqmap, p))
1919 if (solv->decisionmap[p] < 0)
1921 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))))
1926 while (dq->elements[i])
1929 queue_deleten(dq, oldcnt, cutcnt - oldcnt);
1931 if (dq->count != oldcnt)
1933 for (j = oldcnt; j < dq->count; j++)
1935 p = dq->elements[j];
1936 for (i = 0; i < j; i++)
1937 if (dq->elements[i] == p)
1939 dq->elements[j] = 0;
1943 for (i = j = oldcnt; j < dq->count; j++)
1944 if (dq->elements[j])
1945 dq->elements[i++] = dq->elements[j];
1946 queue_truncate(dq, i);
1949 printf("RETURN:\n");
1950 for (i = oldcnt; i < dq->count; i++)
1951 printf(" - %s\n", pool_solvid2str(pool, dq->elements[i]));
1956 do_complex_recommendations(Solver *solv, Id rec, Map *m, int noselected)
1958 Pool *pool = solv->pool;
1964 printf("DO_COMPLEX_RECOMMENDATIONS %s\n", pool_dep2str(pool, rec));
1967 i = pool_normalize_complex_dep(pool, rec, &dq, CPLXDEPS_EXPAND);
1968 if (i == 0 || i == 1)
1973 for (i = 0; i < dq.count; i++)
1976 for (; (p = dq.elements[i]) != 0; i++)
1980 if (solv->decisionmap[-p] <= 0)
1984 if (solv->decisionmap[p] > 0)
1989 for (i++; (p = dq.elements[i]) != 0; i++)
1990 if (p > 0 && solv->decisionmap[p] > 0)
1998 for (i = blk; (p = dq.elements[i]) != 0; i++)
2002 while (dq.elements[i])
2010 /*-------------------------------------------------------------------
2014 * all rules have been set up, now actually run the solver
2019 solver_run_sat(Solver *solv, int disablerules, int doweak)
2021 Queue dq; /* local decisionqueue */
2022 Queue dqs; /* local decisionqueue for supplements */
2028 Pool *pool = solv->pool;
2030 int minimizationsteps;
2031 int installedpos = solv->installed ? solv->installed->start : 0;
2033 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
2035 POOL_DEBUG (SOLV_DEBUG_RULE_CREATION, "number of rules: %d\n", solv->nrules);
2036 for (i = 1; i < solv->nrules; i++)
2037 solver_printruleclass(solv, SOLV_DEBUG_RULE_CREATION, solv->rules + i);
2040 POOL_DEBUG(SOLV_DEBUG_SOLVER, "initial decisions: %d\n", solv->decisionq.count);
2042 /* start SAT algorithm */
2044 systemlevel = level + 1;
2045 POOL_DEBUG(SOLV_DEBUG_SOLVER, "solving...\n");
2051 * here's the main loop:
2052 * 1) propagate new decisions (only needed once)
2054 * 3) try to keep installed packages
2055 * 4) fulfill all unresolved rules
2056 * 5) install recommended packages
2057 * 6) minimalize solution if we had choices
2058 * if we encounter a problem, we rewind to a safe level and restart
2062 minimizationsteps = 0;
2066 * initial propagation of the assertions
2070 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "propagating (propagate_index: %d; size decisionq: %d)...\n", solv->propagate_index, solv->decisionq.count);
2071 if ((r = propagate(solv, level)) != 0)
2073 if (analyze_unsolvable(solv, r, disablerules))
2076 break; /* unsolvable */
2081 * resolve jobs first (unless focus_installed is set)
2083 if (level < systemlevel && !solv->focus_installed)
2086 level = resolve_jobrules(solv, level, disablerules, &dq);
2090 break; /* unsolvable */
2093 systemlevel = level + 1;
2098 * installed packages
2100 if (!solv->decisioncnt_update)
2101 solv->decisioncnt_update = solv->decisionq.count;
2102 if (level < systemlevel && solv->installed && solv->installed->nsolvables && !solv->installed->disabled)
2104 Repo *installed = solv->installed;
2107 POOL_DEBUG(SOLV_DEBUG_SOLVER, "resolving installed packages\n");
2108 /* we use two passes if we need to update packages
2109 * to create a better user experience */
2110 for (pass = solv->updatemap.size ? 0 : 1; pass < 2; pass++)
2112 int passlevel = level;
2113 Id *specialupdaters = solv->specialupdaters;
2114 if (pass == 1 && !solv->decisioncnt_keep)
2115 solv->decisioncnt_keep = solv->decisionq.count;
2116 /* start with installedpos, the position that gave us problems the last time */
2117 for (i = installedpos, n = installed->start; n < installed->end; i++, n++)
2122 if (i == installed->end)
2123 i = installed->start;
2124 s = pool->solvables + i;
2125 if (s->repo != installed)
2128 if (solv->decisionmap[i] > 0 && (!specialupdaters || !specialupdaters[i - installed->start]))
2129 continue; /* already decided */
2130 if (!pass && solv->updatemap.size && !MAPTST(&solv->updatemap, i - installed->start))
2131 continue; /* updates first */
2132 r = solv->rules + solv->updaterules + (i - installed->start);
2134 if (!rr->p || rr->d < 0) /* disabled -> look at feature rule */
2135 rr -= solv->installed->end - solv->installed->start;
2136 if (!rr->p) /* identical to update rule? */
2138 if (!rr->p && !(specialupdaters && specialupdaters[i - installed->start]))
2139 continue; /* orpaned package */
2141 /* check if we should update this package to the latest version
2142 * noupdate is set for erase jobs, in that case we want to deinstall
2143 * the installed package and not replace it with a newer version
2144 * rr->p != i is for dup jobs where the installed package cannot be kept */
2146 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)))
2150 /* specialupdater with no update/feature rule */
2151 for (d = specialupdaters[i - installed->start]; (p = pool->whatprovidesdata[d++]) != 0; )
2153 if (solv->decisionmap[p] > 0)
2158 if (!solv->decisionmap[p])
2162 else if (specialupdaters && (d = specialupdaters[i - installed->start]) != 0)
2164 /* special multiversion handling, make sure best version is chosen */
2165 if (rr->p == i && solv->decisionmap[i] >= 0)
2167 while ((p = pool->whatprovidesdata[d++]) != 0)
2168 if (solv->decisionmap[p] >= 0)
2170 if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
2171 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
2174 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2176 if (p != i && solv->decisionmap[p] == 0)
2178 rr = solv->rules + solv->featurerules + (i - solv->installed->start);
2179 if (!rr->p) /* update rule == feature rule? */
2180 rr = rr - solv->featurerules + solv->updaterules;
2189 /* update to best package of the update rule */
2190 FOR_RULELITERALS(p, pp, rr)
2192 if (solv->decisionmap[p] > 0)
2194 dq.count = 0; /* already fulfilled */
2197 if (!solv->decisionmap[p])
2202 if (dq.count && solv->update_targets && solv->update_targets->elements[i - installed->start])
2203 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[i - installed->start], &dq);
2204 /* install best version */
2208 level = selectandinstall(solv, level, &dq, disablerules, rr - solv->rules);
2215 if (level <= olevel)
2217 if (level == 1 || level < passlevel)
2218 break; /* trouble */
2220 n = installed->start; /* redo all */
2226 /* if still undecided keep package */
2227 if (solv->decisionmap[i] == 0)
2230 if (solv->cleandepsmap.size && MAPTST(&solv->cleandepsmap, i - installed->start))
2233 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, i));
2234 level = setpropagatelearn(solv, level, -i, disablerules, 0);
2241 POOL_DEBUG(SOLV_DEBUG_POLICY, "keeping %s\n", pool_solvid2str(pool, i));
2242 level = setpropagatelearn(solv, level, i, disablerules, r - solv->rules);
2246 if (level <= olevel)
2248 if (level == 1 || level < passlevel)
2249 break; /* trouble */
2251 n = installed->start; /* redo all */
2254 continue; /* retry with learnt rule */
2258 if (n < installed->end)
2260 installedpos = i; /* retry problem solvable next time */
2261 break; /* ran into trouble */
2263 installedpos = installed->start; /* reset installedpos */
2266 break; /* unsolvable */
2267 systemlevel = level + 1;
2269 continue; /* had trouble, retry */
2271 if (!solv->decisioncnt_keep)
2272 solv->decisioncnt_keep = solv->decisionq.count;
2274 if (level < systemlevel && solv->focus_installed)
2277 level = resolve_jobrules(solv, level, disablerules, &dq);
2281 break; /* unsolvable */
2284 systemlevel = level + 1;
2287 if (level < systemlevel)
2288 systemlevel = level;
2293 if (!solv->decisioncnt_resolve)
2294 solv->decisioncnt_resolve = solv->decisionq.count;
2295 POOL_DEBUG(SOLV_DEBUG_POLICY, "deciding unresolved rules\n");
2296 for (i = 1, n = 1; n < solv->nrules; i++, n++)
2298 if (i == solv->nrules)
2300 r = solv->rules + i;
2301 if (r->d < 0) /* ignore disabled rules */
2303 if (r->p < 0) /* most common cases first */
2305 if (r->d == 0 || solv->decisionmap[-r->p] <= 0)
2312 /* binary or unary rule */
2313 /* need two positive undecided literals, r->p already checked above */
2316 if (solv->decisionmap[r->p] || solv->decisionmap[r->w2])
2318 queue_push(&dq, r->p);
2319 queue_push(&dq, r->w2);
2324 * all negative literals are installed
2325 * no positive literal is installed
2326 * i.e. the rule is not fulfilled and we
2327 * just need to decide on the positive literals
2328 * (decisionmap[-r->p] for the r->p < 0 case is already checked above)
2332 if (solv->decisionmap[r->p] > 0)
2334 if (solv->decisionmap[r->p] == 0)
2335 queue_push(&dq, r->p);
2337 dp = pool->whatprovidesdata + r->d;
2338 while ((p = *dp++) != 0)
2342 if (solv->decisionmap[-p] <= 0)
2347 if (solv->decisionmap[p] > 0)
2349 if (solv->decisionmap[p] == 0)
2356 IF_POOLDEBUG (SOLV_DEBUG_PROPAGATE)
2358 POOL_DEBUG(SOLV_DEBUG_PROPAGATE, "unfulfilled ");
2359 solver_printruleclass(solv, SOLV_DEBUG_PROPAGATE, r);
2361 /* dq.count < 2 cannot happen as this means that
2362 * the rule is unit */
2363 assert(dq.count > 1);
2365 /* prune to cleandeps packages */
2366 if (solv->cleandepsmap.size && solv->installed)
2368 Repo *installed = solv->installed;
2369 for (j = 0; j < dq.count; j++)
2370 if (pool->solvables[dq.elements[j]].repo == installed && MAPTST(&solv->cleandepsmap, dq.elements[j] - installed->start))
2374 dq.elements[0] = dq.elements[j];
2375 queue_truncate(&dq, 1);
2380 level = selectandinstall(solv, level, &dq, disablerules, r - solv->rules);
2382 break; /* unsolvable */
2383 if (level < systemlevel || level == 1)
2384 break; /* trouble */
2385 /* something changed, so look at all rules again */
2389 if (n != solv->nrules) /* ran into trouble? */
2392 break; /* unsolvable */
2393 continue; /* start over */
2396 /* decide leftover cleandeps packages */
2397 if (solv->cleandepsmap.size && solv->installed)
2399 for (p = solv->installed->start; p < solv->installed->end; p++)
2401 s = pool->solvables + p;
2402 if (s->repo != solv->installed)
2404 if (solv->decisionmap[p] == 0 && MAPTST(&solv->cleandepsmap, p - solv->installed->start))
2406 POOL_DEBUG(SOLV_DEBUG_POLICY, "cleandeps erasing %s\n", pool_solvid2str(pool, p));
2408 level = setpropagatelearn(solv, level, -p, 0, 0);
2413 if (p < solv->installed->end)
2417 /* at this point we have a consistent system. now do the extras... */
2419 if (!solv->decisioncnt_weak)
2420 solv->decisioncnt_weak = solv->decisionq.count;
2425 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended packages\n");
2426 queue_empty(&dq); /* recommended packages */
2427 queue_empty(&dqs); /* supplemented packages */
2428 for (i = 1; i < pool->nsolvables; i++)
2430 if (solv->decisionmap[i] < 0)
2432 if (solv->decisionmap[i] > 0)
2434 /* installed, check for recommends */
2435 Id *recp, rec, pp, p;
2436 s = pool->solvables + i;
2437 if (!solv->addalreadyrecommended && s->repo == solv->installed)
2439 /* XXX need to special case AND ? */
2442 recp = s->repo->idarraydata + s->recommends;
2443 while ((rec = *recp++) != 0)
2445 #ifdef ENABLE_COMPLEX_DEPS
2446 if (pool_is_complex_dep(pool, rec))
2448 add_complex_recommends(solv, rec, &dq, 0);
2453 FOR_PROVIDES(p, pp, rec)
2455 if (solv->decisionmap[p] > 0)
2460 else if (solv->decisionmap[p] == 0)
2462 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))))
2464 queue_pushunique(&dq, p);
2472 s = pool->solvables + i;
2473 if (!s->supplements)
2475 if (!pool_installable(pool, s))
2477 if (!solver_is_supplementing(solv, s))
2479 if (solv->dupmap_all && solv->installed && s->repo == solv->installed && (solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, i - solv->installed->start))))
2481 queue_push(&dqs, i);
2485 /* filter out all packages obsoleted by installed packages */
2486 /* this is no longer needed if we have reverse obsoletes */
2487 if ((dqs.count || dq.count) && solv->installed)
2490 Id obs, *obsp, po, ppo;
2492 map_init(&obsmap, pool->nsolvables);
2493 for (p = solv->installed->start; p < solv->installed->end; p++)
2495 s = pool->solvables + p;
2496 if (s->repo != solv->installed || !s->obsoletes)
2498 if (solv->decisionmap[p] <= 0)
2500 if (solv->multiversion.size && MAPTST(&solv->multiversion, p))
2502 obsp = s->repo->idarraydata + s->obsoletes;
2503 /* foreach obsoletes */
2504 while ((obs = *obsp++) != 0)
2505 FOR_PROVIDES(po, ppo, obs)
2506 MAPSET(&obsmap, po);
2508 for (i = j = 0; i < dqs.count; i++)
2509 if (!MAPTST(&obsmap, dqs.elements[i]))
2510 dqs.elements[j++] = dqs.elements[i];
2512 for (i = j = 0; i < dq.count; i++)
2513 if (!MAPTST(&obsmap, dq.elements[i]))
2514 dq.elements[j++] = dq.elements[i];
2519 /* filter out all already supplemented packages if requested */
2520 if (!solv->addalreadyrecommended && dqs.count)
2522 int dosplitprovides_old = solv->dosplitprovides;
2523 /* turn off all new packages */
2524 for (i = 0; i < solv->decisionq.count; i++)
2526 p = solv->decisionq.elements[i];
2529 s = pool->solvables + p;
2530 if (s->repo && s->repo != solv->installed)
2531 solv->decisionmap[p] = -solv->decisionmap[p];
2533 solv->dosplitprovides = 0;
2534 /* filter out old supplements */
2535 for (i = j = 0; i < dqs.count; i++)
2537 p = dqs.elements[i];
2538 s = pool->solvables + p;
2539 if (!s->supplements)
2541 if (!solver_is_supplementing(solv, s))
2542 dqs.elements[j++] = p;
2543 else if (solv->installsuppdepq && solver_check_installsuppdepq(solv, s))
2544 dqs.elements[j++] = p;
2547 /* undo turning off */
2548 for (i = 0; i < solv->decisionq.count; i++)
2550 p = solv->decisionq.elements[i];
2553 s = pool->solvables + p;
2554 if (s->repo && s->repo != solv->installed)
2555 solv->decisionmap[p] = -solv->decisionmap[p];
2557 solv->dosplitprovides = dosplitprovides_old;
2560 /* multiversion doesn't mix well with supplements.
2561 * filter supplemented packages where we already decided
2562 * to install a different version (see bnc#501088) */
2563 if (dqs.count && solv->multiversion.size)
2565 for (i = j = 0; i < dqs.count; i++)
2567 p = dqs.elements[i];
2568 if (MAPTST(&solv->multiversion, p))
2571 s = pool->solvables + p;
2572 FOR_PROVIDES(p2, pp2, s->name)
2573 if (solv->decisionmap[p2] > 0 && pool->solvables[p2].name == s->name)
2576 continue; /* ignore this package */
2578 dqs.elements[j++] = p;
2583 /* make dq contain both recommended and supplemented pkgs */
2586 for (i = 0; i < dqs.count; i++)
2587 queue_pushunique(&dq, dqs.elements[i]);
2593 int decisioncount = solv->decisionq.count;
2597 /* simple case, just one package. no need to choose to best version */
2600 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2602 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2603 level = setpropagatelearn(solv, level, p, 0, 0);
2606 continue; /* back to main loop */
2609 /* filter packages, this gives us the best versions */
2610 policy_filter_unwanted(solv, &dq, POLICY_MODE_RECOMMEND);
2612 /* create map of result */
2613 map_init(&dqmap, pool->nsolvables);
2614 for (i = 0; i < dq.count; i++)
2615 MAPSET(&dqmap, dq.elements[i]);
2617 /* install all supplemented packages */
2618 for (i = 0; i < dqs.count; i++)
2620 p = dqs.elements[i];
2621 if (solv->decisionmap[p] || !MAPTST(&dqmap, p))
2623 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing supplemented %s\n", pool_solvid2str(pool, p));
2625 level = setpropagatelearn(solv, level, p, 0, 0);
2626 if (level <= olevel)
2629 if (i < dqs.count || solv->decisionq.count < decisioncount)
2637 /* install all recommended packages */
2638 /* more work as we want to created branches if multiple
2639 * choices are valid */
2640 for (i = 0; i < decisioncount; i++)
2643 p = solv->decisionq.elements[i];
2646 s = pool->solvables + p;
2647 if (!s->repo || (!solv->addalreadyrecommended && s->repo == solv->installed))
2651 recp = s->repo->idarraydata + s->recommends;
2652 while ((rec = *recp++) != 0)
2655 #ifdef ENABLE_COMPLEX_DEPS
2656 if (pool_is_complex_dep(pool, rec))
2657 add_complex_recommends(solv, rec, &dq, &dqmap);
2660 FOR_PROVIDES(p, pp, rec)
2662 if (solv->decisionmap[p] > 0)
2667 else if (solv->decisionmap[p] == 0 && MAPTST(&dqmap, p))
2674 /* multiple candidates, open a branch */
2675 for (i = 1; i < dq.count; i++)
2676 queue_push(&solv->branches, dq.elements[i]);
2677 queue_push(&solv->branches, -level);
2680 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing recommended %s\n", pool_solvid2str(pool, p));
2682 level = setpropagatelearn(solv, level, p, 0, 0);
2683 if (level <= olevel || solv->decisionq.count < decisioncount)
2684 break; /* we had to revert some decisions */
2687 break; /* had a problem above, quit loop */
2692 continue; /* back to main loop so that all deps are checked */
2696 if (!solv->decisioncnt_orphan)
2697 solv->decisioncnt_orphan = solv->decisionq.count;
2698 if (solv->dupmap_all && solv->installed)
2700 int installedone = 0;
2702 /* let's see if we can install some unsupported package */
2703 POOL_DEBUG(SOLV_DEBUG_SOLVER, "deciding orphaned packages\n");
2704 for (i = 0; i < solv->orphaned.count; i++)
2706 p = solv->orphaned.elements[i];
2707 if (solv->decisionmap[p])
2708 continue; /* already decided */
2709 if (solv->droporphanedmap_all)
2711 if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))
2713 POOL_DEBUG(SOLV_DEBUG_SOLVER, "keeping orphaned %s\n", pool_solvid2str(pool, p));
2715 level = setpropagatelearn(solv, level, p, 0, 0);
2720 if (installedone || i < solv->orphaned.count)
2724 continue; /* back to main loop */
2726 for (i = 0; i < solv->orphaned.count; i++)
2728 p = solv->orphaned.elements[i];
2729 if (solv->decisionmap[p])
2730 continue; /* already decided */
2731 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing orphaned %s\n", pool_solvid2str(pool, p));
2733 level = setpropagatelearn(solv, level, -p, 0, 0);
2737 if (i < solv->orphaned.count)
2741 continue; /* back to main loop */
2743 if (solv->brokenorphanrules)
2745 solver_check_brokenorphanrules(solv, &dq);
2748 policy_filter_unwanted(solv, &dq, POLICY_MODE_CHOOSE);
2749 for (i = 0; i < dq.count; i++)
2752 POOL_DEBUG(SOLV_DEBUG_POLICY, "installing orphaned dep %s\n", pool_solvid2str(pool, p));
2754 level = setpropagatelearn(solv, level, p, 0, 0);
2765 /* one final pass to make sure we decided all installed packages */
2766 if (solv->installed)
2768 for (p = solv->installed->start; p < solv->installed->end; p++)
2770 if (solv->decisionmap[p])
2771 continue; /* already decided */
2772 s = pool->solvables + p;
2773 if (s->repo != solv->installed)
2775 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing unwanted %s\n", pool_solvid2str(pool, p));
2777 level = setpropagatelearn(solv, level, -p, 0, 0);
2781 if (p < solv->installed->end)
2785 continue; /* back to main loop */
2789 if (solv->installed && solv->cleandepsmap.size)
2791 if (cleandeps_check_mistakes(solv, level))
2793 level = 1; /* restart from scratch */
2794 systemlevel = level + 1;
2799 if (solv->solution_callback)
2801 solv->solution_callback(solv, solv->solution_callback_data);
2802 if (solv->branches.count)
2804 int i = solv->branches.count - 1;
2805 int l = -solv->branches.elements[i];
2809 if (solv->branches.elements[i - 1] < 0)
2811 p = solv->branches.elements[i];
2812 POOL_DEBUG(SOLV_DEBUG_SOLVER, "branching with %s\n", pool_solvid2str(pool, p));
2814 for (j = i + 1; j < solv->branches.count; j++)
2815 queue_push(&dq, solv->branches.elements[j]);
2816 solv->branches.count = i;
2818 revert(solv, level);
2820 for (j = 0; j < dq.count; j++)
2821 queue_push(&solv->branches, dq.elements[j]);
2823 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
2825 level = setpropagatelearn(solv, level, p, disablerules, why);
2830 /* all branches done, we're finally finished */
2834 /* auto-minimization step */
2835 if (solv->branches.count)
2837 int l = 0, lasti = -1, lastl = -1;
2841 for (i = solv->branches.count - 1; i >= 0; i--)
2843 p = solv->branches.elements[i];
2846 else if (p > 0 && solv->decisionmap[p] > l + 1)
2854 /* kill old solvable so that we do not loop */
2855 p = solv->branches.elements[lasti];
2856 solv->branches.elements[lasti] = 0;
2857 POOL_DEBUG(SOLV_DEBUG_SOLVER, "minimizing %d -> %d with %s\n", solv->decisionmap[p], lastl, pool_solvid2str(pool, p));
2858 minimizationsteps++;
2861 revert(solv, level);
2862 why = -solv->decisionq_why.elements[solv->decisionq_why.count];
2865 level = setpropagatelearn(solv, level, p, disablerules, why);
2868 continue; /* back to main loop */
2871 /* no minimization found, we're finally finished! */
2875 POOL_DEBUG(SOLV_DEBUG_STATS, "solver statistics: %d learned rules, %d unsolvable, %d minimization steps\n", solv->stats_learned, solv->stats_unsolvable, minimizationsteps);
2877 POOL_DEBUG(SOLV_DEBUG_STATS, "done solving.\n\n");
2883 solv->decisioncnt_jobs = solv->decisionq.count;
2884 solv->decisioncnt_update = solv->decisionq.count;
2885 solv->decisioncnt_keep = solv->decisionq.count;
2886 solv->decisioncnt_resolve = solv->decisionq.count;
2887 solv->decisioncnt_weak = solv->decisionq.count;
2888 solv->decisioncnt_orphan = solv->decisionq.count;
2891 solver_printdecisionq(solv, SOLV_DEBUG_RESULT);
2896 /*-------------------------------------------------------------------
2898 * remove disabled conflicts
2900 * purpose: update the decisionmap after some rules were disabled.
2901 * this is used to calculate the suggested/recommended package list.
2902 * Also returns a "removed" list to undo the discisionmap changes.
2906 removedisabledconflicts(Solver *solv, Queue *removed)
2908 Pool *pool = solv->pool;
2913 Id *decisionmap = solv->decisionmap;
2915 queue_empty(removed);
2916 for (i = 0; i < solv->decisionq.count; i++)
2918 p = solv->decisionq.elements[i];
2920 continue; /* conflicts only, please */
2921 why = solv->decisionq_why.elements[i];
2924 /* no rule involved, must be a orphan package drop */
2927 /* we never do conflicts on free decisions, so there
2928 * must have been an unit rule */
2930 r = solv->rules + why;
2931 if (r->d < 0 && decisionmap[-p])
2933 /* rule is now disabled, remove from decisionmap */
2934 POOL_DEBUG(SOLV_DEBUG_SOLVER, "removing conflict for package %s[%d]\n", pool_solvid2str(pool, -p), -p);
2935 queue_push(removed, -p);
2936 queue_push(removed, decisionmap[-p]);
2937 decisionmap[-p] = 0;
2940 if (!removed->count)
2942 /* we removed some confliced packages. some of them might still
2943 * be in conflict, so search for unit rules and re-conflict */
2945 for (i = n = 1, r = solv->rules + i; n < solv->nrules; i++, r++, n++)
2947 if (i == solv->nrules)
2950 r = solv->rules + i;
2956 if (r->p < 0 && !decisionmap[-r->p])
2962 if (r->p < 0 && decisionmap[-r->p] == 0 && DECISIONMAP_FALSE(r->w2))
2964 else if (r->w2 < 0 && decisionmap[-r->w2] == 0 && DECISIONMAP_FALSE(r->p))
2969 if (r->p < 0 && decisionmap[-r->p] == 0)
2971 if (new || DECISIONMAP_FALSE(r->p))
2973 dp = pool->whatprovidesdata + r->d;
2974 while ((p = *dp++) != 0)
2976 if (new && p == new)
2978 if (p < 0 && decisionmap[-p] == 0)
2987 else if (!DECISIONMAP_FALSE(p))
2997 POOL_DEBUG(SOLV_DEBUG_SOLVER, "re-conflicting package %s[%d]\n", pool_solvid2str(pool, -new), -new);
2998 decisionmap[-new] = -1;
3000 n = 0; /* redo all rules */
3006 undo_removedisabledconflicts(Solver *solv, Queue *removed)
3009 for (i = 0; i < removed->count; i += 2)
3010 solv->decisionmap[removed->elements[i]] = removed->elements[i + 1];
3014 /*-------------------------------------------------------------------
3016 * weaken solvable dependencies
3020 weaken_solvable_deps(Solver *solv, Id p)
3025 for (i = 1, r = solv->rules + i; i < solv->rpmrules_end; i++, r++)
3029 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3030 continue; /* conflict */
3031 queue_push(&solv->weakruleq, i);
3036 /********************************************************************/
3041 solver_calculate_multiversionmap(Pool *pool, Queue *job, Map *multiversionmap)
3044 Id how, what, select;
3046 for (i = 0; i < job->count; i += 2)
3048 how = job->elements[i];
3049 if ((how & SOLVER_JOBMASK) != SOLVER_MULTIVERSION)
3051 what = job->elements[i + 1];
3052 select = how & SOLVER_SELECTMASK;
3053 if (!multiversionmap->size)
3054 map_grow(multiversionmap, pool->nsolvables);
3055 if (select == SOLVER_SOLVABLE_ALL)
3057 FOR_POOL_SOLVABLES(p)
3058 MAPSET(multiversionmap, p);
3060 else if (select == SOLVER_SOLVABLE_REPO)
3063 Repo *repo = pool_id2repo(pool, what);
3065 FOR_REPO_SOLVABLES(repo, p, s)
3066 MAPSET(multiversionmap, p);
3068 FOR_JOB_SELECT(p, pp, select, what)
3069 MAPSET(multiversionmap, p);
3074 solver_calculate_noobsmap(Pool *pool, Queue *job, Map *multiversionmap)
3076 solver_calculate_multiversionmap(pool, job, multiversionmap);
3080 * add a rule created by a job, record job number and weak flag
3083 solver_addjobrule(Solver *solv, Id p, Id d, Id job, int weak)
3085 solver_addrule(solv, p, d);
3086 queue_push(&solv->ruletojob, job);
3088 queue_push(&solv->weakruleq, solv->nrules - 1);
3092 add_cleandeps_package(Solver *solv, Id p)
3094 if (!solv->cleandeps_updatepkgs)
3096 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
3097 queue_init(solv->cleandeps_updatepkgs);
3099 queue_pushunique(solv->cleandeps_updatepkgs, p);
3103 add_update_target(Solver *solv, Id p, Id how)
3105 Pool *pool = solv->pool;
3106 Solvable *s = pool->solvables + p;
3107 Repo *installed = solv->installed;
3109 if (!solv->update_targets)
3111 solv->update_targets = solv_calloc(1, sizeof(Queue));
3112 queue_init(solv->update_targets);
3114 if (s->repo == installed)
3116 queue_push2(solv->update_targets, p, p);
3119 FOR_PROVIDES(pi, pip, s->name)
3121 Solvable *si = pool->solvables + pi;
3122 if (si->repo != installed || si->name != s->name)
3124 if (how & SOLVER_FORCEBEST)
3126 if (!solv->bestupdatemap.size)
3127 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3128 MAPSET(&solv->bestupdatemap, pi - installed->start);
3130 if (how & SOLVER_CLEANDEPS)
3131 add_cleandeps_package(solv, pi);
3132 queue_push2(solv->update_targets, pi, p);
3133 /* check if it's ok to keep the installed package */
3134 if (s->evr == si->evr && solvable_identical(s, si))
3135 queue_push2(solv->update_targets, pi, pi);
3139 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
3140 while ((obs = *obsp++) != 0)
3142 FOR_PROVIDES(pi, pip, obs)
3144 Solvable *si = pool->solvables + pi;
3145 if (si->repo != installed)
3147 if (si->name == s->name)
3148 continue; /* already handled above */
3149 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
3151 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
3153 if (how & SOLVER_FORCEBEST)
3155 if (!solv->bestupdatemap.size)
3156 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3157 MAPSET(&solv->bestupdatemap, pi - installed->start);
3159 if (how & SOLVER_CLEANDEPS)
3160 add_cleandeps_package(solv, pi);
3161 queue_push2(solv->update_targets, pi, p);
3168 transform_update_targets_sortfn(const void *ap, const void *bp, void *dp)
3178 transform_update_targets(Solver *solv)
3180 Repo *installed = solv->installed;
3181 Queue *update_targets = solv->update_targets;
3183 Id p, q, lastp, lastq;
3185 if (!update_targets->count)
3187 queue_free(update_targets);
3188 solv->update_targets = solv_free(update_targets);
3191 if (update_targets->count > 2)
3192 solv_sort(update_targets->elements, update_targets->count >> 1, 2 * sizeof(Id), transform_update_targets_sortfn, solv);
3193 queue_insertn(update_targets, 0, installed->end - installed->start, 0);
3195 for (i = j = installed->end - installed->start; i < update_targets->count; i += 2)
3197 if ((p = update_targets->elements[i]) != lastp)
3199 if (!solv->updatemap.size)
3200 map_grow(&solv->updatemap, installed->end - installed->start);
3201 MAPSET(&solv->updatemap, p - installed->start);
3202 update_targets->elements[j++] = 0; /* finish old set */
3203 update_targets->elements[p - installed->start] = j; /* start new set */
3207 if ((q = update_targets->elements[i + 1]) != lastq)
3209 update_targets->elements[j++] = q;
3213 queue_truncate(update_targets, j);
3214 queue_push(update_targets, 0); /* finish last set */
3219 addedmap2deduceq(Solver *solv, Map *addedmap)
3221 Pool *pool = solv->pool;
3226 queue_empty(&solv->addedmap_deduceq);
3227 for (i = 2, j = solv->rpmrules_end - 1; i < pool->nsolvables && j > 0; j--)
3229 r = solv->rules + j;
3232 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3235 if (!MAPTST(addedmap, p))
3237 /* should never happen, but... */
3238 if (!solv->addedmap_deduceq.count || solv->addedmap_deduceq.elements[solv->addedmap_deduceq.count - 1] != -p)
3239 queue_push(&solv->addedmap_deduceq, -p);
3243 if (MAPTST(addedmap, i))
3244 queue_push(&solv->addedmap_deduceq, i);
3248 for (; i < pool->nsolvables; i++)
3249 if (MAPTST(addedmap, i))
3250 queue_push(&solv->addedmap_deduceq, i);
3252 for (i = 2; i < pool->nsolvables; i++)
3253 if (MAPTST(addedmap, i))
3258 deduceq2addedmap(Solver *solv, Map *addedmap)
3263 for (j = solv->rpmrules_end - 1; j > 0; j--)
3265 r = solv->rules + j;
3266 if (r->d < 0 && r->p)
3267 solver_enablerule(solv, r);
3270 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
3273 MAPSET(addedmap, p);
3275 for (j = 0; j < solv->addedmap_deduceq.count; j++)
3277 p = solv->addedmap_deduceq.elements[j];
3279 MAPSET(addedmap, p);
3281 MAPCLR(addedmap, p);
3293 solver_solve(Solver *solv, Queue *job)
3295 Pool *pool = solv->pool;
3296 Repo *installed = solv->installed;
3298 int oldnrules, initialnrules;
3299 Map addedmap; /* '1' == have rpm-rules for solvable */
3300 Map installcandidatemap;
3301 Id how, what, select, name, weak, p, pp, d;
3305 int now, solve_start;
3307 int hasbestinstalljob = 0;
3309 solve_start = solv_timems(0);
3311 /* log solver options */
3312 POOL_DEBUG(SOLV_DEBUG_STATS, "solver started\n");
3313 POOL_DEBUG(SOLV_DEBUG_STATS, "dosplitprovides=%d, noupdateprovide=%d, noinfarchcheck=%d\n", solv->dosplitprovides, solv->noupdateprovide, solv->noinfarchcheck);
3314 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);
3315 POOL_DEBUG(SOLV_DEBUG_STATS, "promoteepoch=%d, forbidselfconflicts=%d\n", pool->promoteepoch, pool->forbidselfconflicts);
3316 POOL_DEBUG(SOLV_DEBUG_STATS, "obsoleteusesprovides=%d, implicitobsoleteusesprovides=%d, obsoleteusescolors=%d, implicitobsoleteusescolors=%d\n", pool->obsoleteusesprovides, pool->implicitobsoleteusesprovides, pool->obsoleteusescolors, pool->implicitobsoleteusescolors);
3317 POOL_DEBUG(SOLV_DEBUG_STATS, "dontinstallrecommended=%d, addalreadyrecommended=%d\n", solv->dontinstallrecommended, solv->addalreadyrecommended);
3319 /* create whatprovides if not already there */
3320 if (!pool->whatprovides)
3321 pool_createwhatprovides(pool);
3323 /* create obsolete index */
3324 policy_create_obsolete_index(solv);
3327 queue_free(&solv->job);
3328 queue_init_clone(&solv->job, job);
3329 solv->pooljobcnt = pool->pooljobs.count;
3330 if (pool->pooljobs.count)
3331 queue_insertn(&solv->job, 0, pool->pooljobs.count, pool->pooljobs.elements);
3334 /* free old stuff in jase we re-run a solver */
3335 queuep_free(&solv->update_targets);
3336 queuep_free(&solv->cleandeps_updatepkgs);
3337 queue_empty(&solv->ruleassertions);
3338 solv->bestrules_pkg = solv_free(solv->bestrules_pkg);
3339 solv->choicerules_ref = solv_free(solv->choicerules_ref);
3340 if (solv->noupdate.size)
3341 map_empty(&solv->noupdate);
3342 map_zerosize(&solv->multiversion);
3343 solv->updatemap_all = 0;
3344 map_zerosize(&solv->updatemap);
3345 solv->bestupdatemap_all = 0;
3346 map_zerosize(&solv->bestupdatemap);
3347 solv->fixmap_all = 0;
3348 map_zerosize(&solv->fixmap);
3349 solv->dupmap_all = 0;
3350 map_zerosize(&solv->dupmap);
3351 map_zerosize(&solv->dupinvolvedmap);
3352 solv->droporphanedmap_all = 0;
3353 map_zerosize(&solv->droporphanedmap);
3354 map_zerosize(&solv->cleandepsmap);
3355 map_zerosize(&solv->weakrulemap);
3356 queue_empty(&solv->weakruleq);
3357 solv->watches = solv_free(solv->watches);
3358 queue_empty(&solv->ruletojob);
3359 if (solv->decisionq.count)
3360 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
3361 queue_empty(&solv->decisionq);
3362 queue_empty(&solv->decisionq_why);
3363 solv->decisioncnt_jobs = solv->decisioncnt_update = solv->decisioncnt_keep = solv->decisioncnt_resolve = solv->decisioncnt_weak = solv->decisioncnt_orphan = 0;
3364 queue_empty(&solv->learnt_why);
3365 queue_empty(&solv->learnt_pool);
3366 queue_empty(&solv->branches);
3367 solv->propagate_index = 0;
3368 queue_empty(&solv->problems);
3369 queue_empty(&solv->solutions);
3370 queue_empty(&solv->orphaned);
3371 solv->stats_learned = solv->stats_unsolvable = 0;
3372 if (solv->recommends_index)
3374 map_empty(&solv->recommendsmap);
3375 map_empty(&solv->suggestsmap);
3376 queuep_free(&solv->recommendscplxq);
3377 queuep_free(&solv->suggestscplxq);
3378 solv->recommends_index = 0;
3380 queuep_free(&solv->brokenorphanrules);
3381 solv->specialupdaters = solv_free(solv->specialupdaters);
3385 * create basic rule set of all involved packages
3386 * use addedmap bitmap to make sure we don't create rules twice
3389 /* create multiversion map if needed */
3390 solver_calculate_multiversionmap(pool, job, &solv->multiversion);
3392 map_init(&addedmap, pool->nsolvables);
3393 MAPSET(&addedmap, SYSTEMSOLVABLE);
3395 map_init(&installcandidatemap, pool->nsolvables);
3398 now = solv_timems(0);
3400 * create rules for all package that could be involved with the solving
3401 * so called: rpm rules
3404 initialnrules = solv->rpmrules_end ? solv->rpmrules_end : 1;
3405 if (initialnrules > 1)
3406 deduceq2addedmap(solv, &addedmap);
3407 if (solv->nrules != initialnrules)
3408 solver_shrinkrules(solv, initialnrules);
3409 solv->nrules = initialnrules;
3410 solv->rpmrules_end = 0;
3414 /* check for update/verify jobs as they need to be known early */
3415 /* also setup the droporphaned map, we need it when creating update rules */
3416 for (i = 0; i < job->count; i += 2)
3418 how = job->elements[i];
3419 what = job->elements[i + 1];
3420 select = how & SOLVER_SELECTMASK;
3421 switch (how & SOLVER_JOBMASK)
3424 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && installed && what == installed->repoid))
3425 solv->fixmap_all = 1;
3426 FOR_JOB_SELECT(p, pp, select, what)
3428 s = pool->solvables + p;
3429 if (s->repo != installed)
3431 if (!solv->fixmap.size)
3432 map_grow(&solv->fixmap, installed->end - installed->start);
3433 MAPSET(&solv->fixmap, p - installed->start);
3437 if (select == SOLVER_SOLVABLE_ALL)
3439 solv->updatemap_all = 1;
3440 if (how & SOLVER_FORCEBEST)
3441 solv->bestupdatemap_all = 1;
3442 if (how & SOLVER_CLEANDEPS)
3444 FOR_REPO_SOLVABLES(installed, p, s)
3445 add_cleandeps_package(solv, p);
3448 else if (select == SOLVER_SOLVABLE_REPO)
3450 Repo *repo = pool_id2repo(pool, what);
3453 if (repo == installed && !(how & SOLVER_TARGETED))
3455 solv->updatemap_all = 1;
3456 if (how & SOLVER_FORCEBEST)
3457 solv->bestupdatemap_all = 1;
3458 if (how & SOLVER_CLEANDEPS)
3460 FOR_REPO_SOLVABLES(installed, p, s)
3461 add_cleandeps_package(solv, p);
3465 if (solv->noautotarget && !(how & SOLVER_TARGETED))
3467 /* targeted update */
3468 FOR_REPO_SOLVABLES(repo, p, s)
3469 add_update_target(solv, p, how);
3473 if (!(how & SOLVER_TARGETED))
3476 FOR_JOB_SELECT(p, pp, select, what)
3478 s = pool->solvables + p;
3479 if (s->repo != installed)
3481 if (!solv->updatemap.size)
3482 map_grow(&solv->updatemap, installed->end - installed->start);
3483 MAPSET(&solv->updatemap, p - installed->start);
3484 if (how & SOLVER_FORCEBEST)
3486 if (!solv->bestupdatemap.size)
3487 map_grow(&solv->bestupdatemap, installed->end - installed->start);
3488 MAPSET(&solv->bestupdatemap, p - installed->start);
3490 if (how & SOLVER_CLEANDEPS)
3491 add_cleandeps_package(solv, p);
3494 if (!targeted || solv->noautotarget)
3497 FOR_JOB_SELECT(p, pp, select, what)
3498 add_update_target(solv, p, how);
3501 case SOLVER_DROP_ORPHANED:
3502 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
3503 solv->droporphanedmap_all = 1;
3504 FOR_JOB_SELECT(p, pp, select, what)
3506 s = pool->solvables + p;
3507 if (s->repo != installed)
3509 if (!solv->droporphanedmap.size)
3510 map_grow(&solv->droporphanedmap, installed->end - installed->start);
3511 MAPSET(&solv->droporphanedmap, p - installed->start);
3519 if (solv->update_targets)
3520 transform_update_targets(solv);
3522 oldnrules = solv->nrules;
3523 FOR_REPO_SOLVABLES(installed, p, s)
3524 solver_addrpmrulesforsolvable(solv, s, &addedmap);
3525 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for installed solvables\n", solv->nrules - oldnrules);
3526 oldnrules = solv->nrules;
3527 FOR_REPO_SOLVABLES(installed, p, s)
3528 solver_addrpmrulesforupdaters(solv, s, &addedmap, 1);
3529 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules);
3533 * create rules for all packages involved in the job
3534 * (to be installed or removed)
3537 oldnrules = solv->nrules;
3538 for (i = 0; i < job->count; i += 2)
3540 how = job->elements[i];
3541 what = job->elements[i + 1];
3542 select = how & SOLVER_SELECTMASK;
3544 switch (how & SOLVER_JOBMASK)
3546 case SOLVER_INSTALL:
3547 FOR_JOB_SELECT(p, pp, select, what)
3549 MAPSET(&installcandidatemap, p);
3550 solver_addrpmrulesforsolvable(solv, pool->solvables + p, &addedmap);
3553 case SOLVER_DISTUPGRADE:
3554 if (select == SOLVER_SOLVABLE_ALL)
3556 solv->dupmap_all = 1;
3557 solv->updatemap_all = 1;
3558 if (how & SOLVER_FORCEBEST)
3559 solv->bestupdatemap_all = 1;
3561 if (!solv->dupmap_all)
3568 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules for packages involved in a job\n", solv->nrules - oldnrules);
3572 * add rules for suggests, enhances
3574 oldnrules = solv->nrules;
3575 solver_addrpmrulesforweak(solv, &addedmap);
3576 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules because of weak dependencies\n", solv->nrules - oldnrules);
3578 #ifdef ENABLE_LINKED_PKGS
3579 oldnrules = solv->nrules;
3580 solver_addrpmrulesforlinked(solv, &addedmap);
3581 POOL_DEBUG(SOLV_DEBUG_STATS, "added %d rpm rules because of linked packages\n", solv->nrules - oldnrules);
3585 * first pass done, we now have all the rpm rules we need.
3586 * unify existing rules before going over all job rules and
3588 * at this point the system is always solvable,
3589 * as an empty system (remove all packages) is a valid solution
3592 IF_POOLDEBUG (SOLV_DEBUG_STATS)
3594 int possible = 0, installable = 0;
3595 for (i = 1; i < pool->nsolvables; i++)
3597 if (pool_installable(pool, pool->solvables + i))
3599 if (MAPTST(&addedmap, i))
3602 POOL_DEBUG(SOLV_DEBUG_STATS, "%d of %d installable solvables considered for solving\n", possible, installable);
3605 if (solv->nrules > initialnrules)
3606 solver_unifyrules(solv); /* remove duplicate rpm rules */
3607 solv->rpmrules_end = solv->nrules; /* mark end of rpm rules */
3609 if (solv->nrules > initialnrules)
3610 addedmap2deduceq(solv, &addedmap); /* so that we can recreate the addedmap */
3612 POOL_DEBUG(SOLV_DEBUG_STATS, "rpm rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
3613 POOL_DEBUG(SOLV_DEBUG_STATS, "rpm rule creation took %d ms\n", solv_timems(now));
3615 /* create dup maps if needed. We need the maps early to create our
3618 solver_createdupmaps(solv);
3621 * create feature rules
3623 * foreach installed:
3624 * create assertion (keep installed, if no update available)
3626 * create update rule (A|update1(A)|update2(A)|...)
3628 * those are used later on to keep a version of the installed packages in
3632 solv->featurerules = solv->nrules; /* mark start of feature rules */
3635 /* foreach possibly installed solvable */
3636 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3638 if (s->repo != installed)
3640 solver_addrule(solv, 0, 0); /* create dummy rule */
3643 solver_addupdaterule(solv, s, 1); /* allow s to be updated */
3645 /* make sure we accounted for all rules */
3646 assert(solv->nrules - solv->featurerules == installed->end - installed->start);
3648 solv->featurerules_end = solv->nrules;
3651 * Add update rules for installed solvables
3653 * almost identical to feature rules
3654 * except that downgrades/archchanges/vendorchanges are not allowed
3657 solv->updaterules = solv->nrules;
3660 { /* foreach installed solvables */
3661 /* we create all update rules, but disable some later on depending on the job */
3662 for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++)
3666 if (s->repo != installed)
3668 solver_addrule(solv, 0, 0); /* create dummy rule */
3671 solver_addupdaterule(solv, s, 0); /* allowall = 0: downgrades not allowed */
3673 * check for and remove duplicate
3675 r = solv->rules + solv->nrules - 1; /* r: update rule */
3678 sr = r - (installed->end - installed->start); /* sr: feature rule */
3679 /* it's also orphaned if the feature rule consists just of the installed package */
3680 if (!solv->dupmap_all && sr->p == i && !sr->d && !sr->w2)
3681 queue_push(&solv->orphaned, i);
3682 if (!solver_rulecmp(solv, r, sr))
3683 memset(sr, 0, sizeof(*sr)); /* delete unneeded feature rule */
3685 solver_disablerule(solv, sr); /* disable feature rule for now */
3687 /* consistency check: we added a rule for _every_ installed solvable */
3688 assert(solv->nrules - solv->updaterules == installed->end - installed->start);
3690 solv->updaterules_end = solv->nrules;
3694 * now add all job rules
3697 solv->jobrules = solv->nrules;
3698 for (i = 0; i < job->count; i += 2)
3700 oldnrules = solv->nrules;
3702 if (i && i == solv->pooljobcnt)
3703 POOL_DEBUG(SOLV_DEBUG_JOB, "end of pool jobs\n");
3704 how = job->elements[i];
3705 what = job->elements[i + 1];
3706 weak = how & SOLVER_WEAK;
3707 select = how & SOLVER_SELECTMASK;
3708 switch (how & SOLVER_JOBMASK)
3710 case SOLVER_INSTALL:
3711 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sinstall %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3712 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
3713 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3714 if (select == SOLVER_SOLVABLE)
3722 FOR_JOB_SELECT(p, pp, select, what)
3726 if (select == SOLVER_SOLVABLE_ONE_OF)
3727 break; /* ignore empty installs */
3728 /* no candidate found or unsupported, make this an impossible rule */
3729 queue_push(&q, -SYSTEMSOLVABLE);
3731 p = queue_shift(&q); /* get first candidate */
3732 d = !q.count ? 0 : pool_queuetowhatprovides(pool, &q); /* internalize */
3734 /* force install of namespace supplements hack */
3735 if (select == SOLVER_SOLVABLE_PROVIDES && !d && (p == SYSTEMSOLVABLE || p == -SYSTEMSOLVABLE) && ISRELDEP(what))
3737 Reldep *rd = GETRELDEP(pool, what);
3738 if (rd->flags == REL_NAMESPACE)
3741 if (!solv->installsuppdepq)
3743 solv->installsuppdepq = solv_calloc(1, sizeof(Queue));
3744 queue_init(solv->installsuppdepq);
3746 queue_pushunique(solv->installsuppdepq, rd->evr == 0 ? rd->name : what);
3749 solver_addjobrule(solv, p, d, i, weak);
3750 if (how & SOLVER_FORCEBEST)
3751 hasbestinstalljob = 1;
3754 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %s%serase %s\n", weak ? "weak " : "", how & SOLVER_CLEANDEPS ? "clean deps " : "", solver_select2str(pool, select, what));
3755 if ((how & SOLVER_CLEANDEPS) != 0 && !solv->cleandepsmap.size && installed)
3756 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3757 /* specific solvable: by id or by nevra */
3758 name = (select == SOLVER_SOLVABLE || (select == SOLVER_SOLVABLE_NAME && ISRELDEP(what))) ? 0 : -1;
3759 if (select == SOLVER_SOLVABLE_ALL) /* hmmm ;) */
3761 FOR_POOL_SOLVABLES(p)
3762 solver_addjobrule(solv, -p, 0, i, weak);
3764 else if (select == SOLVER_SOLVABLE_REPO)
3766 Repo *repo = pool_id2repo(pool, what);
3768 FOR_REPO_SOLVABLES(repo, p, s)
3769 solver_addjobrule(solv, -p, 0, i, weak);
3771 FOR_JOB_SELECT(p, pp, select, what)
3773 s = pool->solvables + p;
3774 if (installed && s->repo == installed)
3775 name = !name ? s->name : -1;
3776 solver_addjobrule(solv, -p, 0, i, weak);
3778 /* special case for "erase a specific solvable": we also
3779 * erase all other solvables with that name, so that they
3780 * don't get picked up as replacement.
3781 * name is > 0 if exactly one installed solvable matched.
3783 /* XXX: look also at packages that obsolete this package? */
3788 FOR_PROVIDES(p, pp, name)
3790 s = pool->solvables + p;
3791 if (s->name != name)
3793 /* keep other versions installed */
3794 if (s->repo == installed)
3796 /* keep installcandidates of other jobs */
3797 if (MAPTST(&installcandidatemap, p))
3799 /* don't add the same rule twice */
3800 for (j = oldnrules; j < k; j++)
3801 if (solv->rules[j].p == -p)
3804 solver_addjobrule(solv, -p, 0, i, weak); /* remove by id */
3810 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %supdate %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3813 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sverify %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3815 case SOLVER_WEAKENDEPS:
3816 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %sweaken deps %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3817 if (select != SOLVER_SOLVABLE)
3819 s = pool->solvables + what;
3820 weaken_solvable_deps(solv, what);
3822 case SOLVER_MULTIVERSION:
3823 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %smultiversion %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3826 POOL_DEBUG(SOLV_DEBUG_JOB, "job: %slock %s\n", weak ? "weak " : "", solver_select2str(pool, select, what));
3827 if (select == SOLVER_SOLVABLE_ALL)
3829 FOR_POOL_SOLVABLES(p)
3830 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
3832 else if (select == SOLVER_SOLVABLE_REPO)
3834 Repo *repo = pool_id2repo(pool, what);
3836 FOR_REPO_SOLVABLES(repo, p, s)
3837 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
3839 FOR_JOB_SELECT(p, pp, select, what)
3840 solver_addjobrule(solv, installed && pool->solvables[p].repo == installed ? p : -p, 0, i, weak);
3842 case SOLVER_DISTUPGRADE:
3843 POOL_DEBUG(SOLV_DEBUG_JOB, "job: distupgrade %s\n", solver_select2str(pool, select, what));
3845 case SOLVER_DROP_ORPHANED:
3846 POOL_DEBUG(SOLV_DEBUG_JOB, "job: drop orphaned %s\n", solver_select2str(pool, select, what));
3848 case SOLVER_USERINSTALLED:
3849 POOL_DEBUG(SOLV_DEBUG_JOB, "job: user installed %s\n", solver_select2str(pool, select, what));
3852 POOL_DEBUG(SOLV_DEBUG_JOB, "job: unknown job\n");
3856 IF_POOLDEBUG (SOLV_DEBUG_JOB)
3859 if (solv->nrules == oldnrules)
3860 POOL_DEBUG(SOLV_DEBUG_JOB, " - no rule created\n");
3861 for (j = oldnrules; j < solv->nrules; j++)
3863 POOL_DEBUG(SOLV_DEBUG_JOB, " - job ");
3864 solver_printrule(solv, SOLV_DEBUG_JOB, solv->rules + j);
3868 assert(solv->ruletojob.count == solv->nrules - solv->jobrules);
3869 solv->jobrules_end = solv->nrules;
3871 /* now create infarch and dup rules */
3872 if (!solv->noinfarchcheck)
3874 solver_addinfarchrules(solv, &addedmap);
3876 if (pool->implicitobsoleteusescolors)
3878 /* currently doesn't work well with infarch rules, so make
3880 for (i = solv->infarchrules; i < solv->infarchrules_end; i++)
3881 queue_push(&solv->weakruleq, i);
3886 solv->infarchrules = solv->infarchrules_end = solv->nrules;
3889 solver_addduprules(solv, &addedmap);
3891 solv->duprules = solv->duprules_end = solv->nrules;
3893 if (solv->bestupdatemap_all || solv->bestupdatemap.size || hasbestinstalljob)
3894 solver_addbestrules(solv, hasbestinstalljob);
3896 solv->bestrules = solv->bestrules_end = solv->nrules;
3899 solver_freedupmaps(solv); /* no longer needed */
3902 solver_addchoicerules(solv);
3904 solv->choicerules = solv->choicerules_end = solv->nrules;
3908 for (i = solv->featurerules; i < solv->nrules; i++)
3909 solver_printruleclass(solv, SOLV_DEBUG_RESULT, solv->rules + i);
3911 /* all rules created
3912 * --------------------------------------------------------------
3913 * prepare for solving
3916 /* free unneeded memory */
3917 map_free(&addedmap);
3918 map_free(&installcandidatemap);
3921 POOL_DEBUG(SOLV_DEBUG_STATS, "%d rpm rules, 2 * %d update rules, %d job rules, %d infarch rules, %d dup rules, %d choice rules, %d best rules\n", solv->rpmrules_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);
3922 POOL_DEBUG(SOLV_DEBUG_STATS, "overall rule memory used: %d K\n", solv->nrules * (int)sizeof(Rule) / 1024);
3924 /* create weak map */
3925 map_init(&solv->weakrulemap, solv->nrules);
3926 for (i = 0; i < solv->weakruleq.count; i++)
3928 p = solv->weakruleq.elements[i];
3929 MAPSET(&solv->weakrulemap, p);
3932 /* enable cleandepsmap creation if we have updatepkgs */
3933 if (solv->cleandeps_updatepkgs && !solv->cleandepsmap.size)
3934 map_grow(&solv->cleandepsmap, installed->end - installed->start);
3936 if (solv->cleandeps_mistakes)
3938 queue_free(solv->cleandeps_mistakes);
3939 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
3942 /* all new rules are learnt after this point */
3943 solv->learntrules = solv->nrules;
3945 /* create watches chains */
3948 /* create assertion index. it is only used to speed up
3949 * makeruledecsions() a bit */
3950 for (i = 1, r = solv->rules + i; i < solv->nrules; i++, r++)
3951 if (r->p && !r->w2 && (r->d == 0 || r->d == -1))
3952 queue_push(&solv->ruleassertions, i);
3954 /* disable update rules that conflict with our job */
3955 solver_disablepolicyrules(solv);
3957 /* break orphans if requested */
3958 if (solv->dupmap_all && solv->orphaned.count && solv->break_orphans)
3959 solver_breakorphans(solv);
3961 /* make initial decisions based on assertion rules */
3962 makeruledecisions(solv);
3963 POOL_DEBUG(SOLV_DEBUG_SOLVER, "problems so far: %d\n", solv->problems.count);
3966 * ********************************************
3968 * ********************************************
3971 now = solv_timems(0);
3972 solver_run_sat(solv, 1, solv->dontinstallrecommended ? 0 : 1);
3973 POOL_DEBUG(SOLV_DEBUG_STATS, "solver took %d ms\n", solv_timems(now));
3976 * prepare solution queue if there were problems
3978 solver_prepare_solutions(solv);
3980 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);
3981 POOL_DEBUG(SOLV_DEBUG_STATS, "solver_solve took %d ms\n", solv_timems(solve_start));
3983 /* return number of problems */
3984 return solv->problems.count ? solv->problems.count / 2 : 0;
3988 solver_create_transaction(Solver *solv)
3990 return transaction_create_decisionq(solv->pool, &solv->decisionq, &solv->multiversion);
3993 void solver_get_orphaned(Solver *solv, Queue *orphanedq)
3995 queue_free(orphanedq);
3996 queue_init_clone(orphanedq, &solv->orphaned);
3999 void solver_get_recommendations(Solver *solv, Queue *recommendationsq, Queue *suggestionsq, int noselected)
4001 Pool *pool = solv->pool;
4002 Queue redoq, disabledq;
4008 if (!recommendationsq && !suggestionsq)
4011 map_init(&obsmap, pool->nsolvables);
4012 if (solv->installed)
4014 Id obs, *obsp, p, po, ppo;
4015 for (p = solv->installed->start; p < solv->installed->end; p++)
4017 s = pool->solvables + p;
4018 if (s->repo != solv->installed || !s->obsoletes)
4020 if (solv->decisionmap[p] <= 0)
4022 if (solv->multiversion.size && MAPTST(&solv->multiversion, p))
4024 obsp = s->repo->idarraydata + s->obsoletes;
4025 /* foreach obsoletes */
4026 while ((obs = *obsp++) != 0)
4027 FOR_PROVIDES(po, ppo, obs)
4028 MAPSET(&obsmap, po);
4033 queue_init(&disabledq);
4035 /* disable all erase jobs (including weak "keep uninstalled" rules) */
4036 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++)
4038 if (r->d < 0) /* disabled ? */
4040 if (r->p >= 0) /* install job? */
4042 queue_push(&disabledq, i);
4043 solver_disablerule(solv, r);
4049 enabledisablelearntrules(solv);
4050 removedisabledconflicts(solv, &redoq);
4054 * find recommended packages
4056 if (recommendationsq)
4058 Id rec, *recp, p, pp;
4060 queue_empty(recommendationsq);
4061 /* create map of all recommened packages */
4062 solv->recommends_index = -1;
4063 MAPZERO(&solv->recommendsmap);
4065 /* put all packages the solver already chose in the map */
4066 if (solv->decisioncnt_weak)
4068 for (i = solv->decisioncnt_weak; i < solv->decisioncnt_orphan; i++)
4071 why = solv->decisionq_why.elements[i];
4073 continue; /* forced by unit rule or dep resolving */
4074 p = solv->decisionq.elements[i];
4077 MAPSET(&solv->recommendsmap, p);
4081 for (i = 0; i < solv->decisionq.count; i++)
4083 p = solv->decisionq.elements[i];
4086 s = pool->solvables + p;
4089 recp = s->repo->idarraydata + s->recommends;
4090 while ((rec = *recp++) != 0)
4092 #ifdef ENABLE_COMPLEX_DEPS
4093 if (pool_is_complex_dep(pool, rec))
4095 do_complex_recommendations(solv, rec, &solv->recommendsmap, noselected);
4099 FOR_PROVIDES(p, pp, rec)
4100 if (solv->decisionmap[p] > 0)
4106 FOR_PROVIDES(p, pp, rec)
4107 if (solv->decisionmap[p] > 0)
4108 MAPSET(&solv->recommendsmap, p);
4110 continue; /* p != 0: already fulfilled */
4112 FOR_PROVIDES(p, pp, rec)
4113 MAPSET(&solv->recommendsmap, p);
4117 for (i = 1; i < pool->nsolvables; i++)
4119 if (solv->decisionmap[i] < 0)
4121 if (solv->decisionmap[i] > 0 && noselected)
4123 if (MAPTST(&obsmap, i))
4125 s = pool->solvables + i;
4126 if (!MAPTST(&solv->recommendsmap, i))
4128 if (!s->supplements)
4130 if (!pool_installable(pool, s))
4132 if (!solver_is_supplementing(solv, s))
4135 queue_push(recommendationsq, i);
4137 /* we use MODE_SUGGEST here so that repo prio is ignored */
4138 policy_filter_unwanted(solv, recommendationsq, POLICY_MODE_SUGGEST);
4142 * find suggested packages
4147 Id sug, *sugp, p, pp;
4149 queue_empty(suggestionsq);
4150 /* create map of all suggests that are still open */
4151 solv->recommends_index = -1;
4152 MAPZERO(&solv->suggestsmap);
4153 for (i = 0; i < solv->decisionq.count; i++)
4155 p = solv->decisionq.elements[i];
4158 s = pool->solvables + p;
4161 sugp = s->repo->idarraydata + s->suggests;
4162 while ((sug = *sugp++) != 0)
4164 #ifdef ENABLE_COMPLEX_DEPS
4165 if (pool_is_complex_dep(pool, sug))
4167 do_complex_recommendations(solv, sug, &solv->suggestsmap, noselected);
4171 FOR_PROVIDES(p, pp, sug)
4172 if (solv->decisionmap[p] > 0)
4178 FOR_PROVIDES(p, pp, sug)
4179 if (solv->decisionmap[p] > 0)
4180 MAPSET(&solv->suggestsmap, p);
4182 continue; /* already fulfilled */
4184 FOR_PROVIDES(p, pp, sug)
4185 MAPSET(&solv->suggestsmap, p);
4189 for (i = 1; i < pool->nsolvables; i++)
4191 if (solv->decisionmap[i] < 0)
4193 if (solv->decisionmap[i] > 0 && noselected)
4195 if (MAPTST(&obsmap, i))
4197 s = pool->solvables + i;
4198 if (!MAPTST(&solv->suggestsmap, i))
4202 if (!pool_installable(pool, s))
4204 if (!solver_is_enhancing(solv, s))
4207 queue_push(suggestionsq, i);
4209 policy_filter_unwanted(solv, suggestionsq, POLICY_MODE_SUGGEST);
4212 /* undo removedisabledconflicts */
4214 undo_removedisabledconflicts(solv, &redoq);
4217 /* undo job rule disabling */
4218 for (i = 0; i < disabledq.count; i++)
4219 solver_enablerule(solv, solv->rules + disabledq.elements[i]);
4220 queue_free(&disabledq);
4225 /***********************************************************************/
4226 /* disk usage computations */
4228 /*-------------------------------------------------------------------
4230 * calculate DU changes
4234 solver_calc_duchanges(Solver *solv, DUChanges *mps, int nmps)
4238 solver_create_state_maps(solv, &installedmap, 0);
4239 pool_calc_duchanges(solv->pool, &installedmap, mps, nmps);
4240 map_free(&installedmap);
4244 /*-------------------------------------------------------------------
4246 * calculate changes in install size
4250 solver_calc_installsizechange(Solver *solv)
4255 solver_create_state_maps(solv, &installedmap, 0);
4256 change = pool_calc_installsizechange(solv->pool, &installedmap);
4257 map_free(&installedmap);
4262 solver_create_state_maps(Solver *solv, Map *installedmap, Map *conflictsmap)
4264 pool_create_state_maps(solv->pool, &solv->decisionq, installedmap, conflictsmap);
4268 solver_trivial_installable(Solver *solv, Queue *pkgs, Queue *res)
4270 Pool *pool = solv->pool;
4273 pool_create_state_maps(pool, &solv->decisionq, &installedmap, 0);
4274 pool_trivial_installable_multiversionmap(pool, &installedmap, pkgs, res, solv->multiversion.size ? &solv->multiversion : 0);
4275 for (i = 0; i < res->count; i++)
4276 if (res->elements[i] != -1)
4278 Solvable *s = pool->solvables + pkgs->elements[i];
4279 if (!strncmp("patch:", pool_id2str(pool, s->name), 6) && solvable_is_irrelevant_patch(s, &installedmap))
4280 res->elements[i] = -1;
4282 map_free(&installedmap);
4285 /*-------------------------------------------------------------------
4287 * decision introspection
4291 solver_get_decisionlevel(Solver *solv, Id p)
4293 return solv->decisionmap[p];
4297 solver_get_decisionqueue(Solver *solv, Queue *decisionq)
4299 queue_free(decisionq);
4300 queue_init_clone(decisionq, &solv->decisionq);
4304 solver_get_lastdecisionblocklevel(Solver *solv)
4307 if (solv->decisionq.count == 0)
4309 p = solv->decisionq.elements[solv->decisionq.count - 1];
4312 return solv->decisionmap[p] < 0 ? -solv->decisionmap[p] : solv->decisionmap[p];
4316 solver_get_decisionblock(Solver *solv, int level, Queue *decisionq)
4321 queue_empty(decisionq);
4322 for (i = 0; i < solv->decisionq.count; i++)
4324 p = solv->decisionq.elements[i];
4327 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
4330 if (i == solv->decisionq.count)
4332 for (i = 0; i < solv->decisionq.count; i++)
4334 p = solv->decisionq.elements[i];
4337 if (solv->decisionmap[p] == level || solv->decisionmap[p] == -level)
4338 queue_push(decisionq, p);
4345 solver_describe_decision(Solver *solv, Id p, Id *infop)
4352 if (!solv->decisionmap[p])
4353 return SOLVER_REASON_UNRELATED;
4354 pp = solv->decisionmap[p] < 0 ? -p : p;
4355 for (i = 0; i < solv->decisionq.count; i++)
4356 if (solv->decisionq.elements[i] == pp)
4358 if (i == solv->decisionq.count) /* just in case... */
4359 return SOLVER_REASON_UNRELATED;
4360 why = solv->decisionq_why.elements[i];
4362 *infop = why > 0 ? why : -why;
4364 return SOLVER_REASON_UNIT_RULE;
4367 return SOLVER_REASON_KEEP_INSTALLED; /* the systemsolvable */
4368 if (i < solv->decisioncnt_update)
4369 return SOLVER_REASON_RESOLVE_JOB;
4370 if (i < solv->decisioncnt_keep)
4372 if (why == 0 && pp < 0)
4373 return SOLVER_REASON_CLEANDEPS_ERASE;
4374 return SOLVER_REASON_UPDATE_INSTALLED;
4376 if (i < solv->decisioncnt_resolve)
4378 if (solv->focus_installed && i >= solv->decisioncnt_jobs)
4379 return SOLVER_REASON_RESOLVE_JOB;
4380 if (why == 0 && pp < 0)
4381 return SOLVER_REASON_CLEANDEPS_ERASE;
4382 return SOLVER_REASON_KEEP_INSTALLED;
4385 return SOLVER_REASON_RESOLVE;
4386 /* weak or orphaned */
4387 if (i < solv->decisioncnt_orphan)
4388 return SOLVER_REASON_WEAKDEP;
4389 return SOLVER_REASON_RESOLVE_ORPHAN;
4394 solver_describe_weakdep_decision(Solver *solv, Id p, Queue *whyq)
4396 Pool *pool = solv->pool;
4398 int level = solv->decisionmap[p];
4405 for (decisionno = 0; decisionno < solv->decisionq.count; decisionno++)
4406 if (solv->decisionq.elements[decisionno] == p)
4408 if (decisionno == solv->decisionq.count)
4410 if (decisionno < solv->decisioncnt_weak || decisionno >= solv->decisioncnt_orphan)
4413 /* 1) list all packages that recommend us */
4414 for (i = 1; i < pool->nsolvables; i++)
4416 Id *recp, rec, pp2, p2;
4417 if (solv->decisionmap[i] < 0 || solv->decisionmap[i] >= level)
4419 s = pool->solvables + i;
4422 if (!solv->addalreadyrecommended && s->repo == solv->installed)
4424 recp = s->repo->idarraydata + s->recommends;
4425 while ((rec = *recp++) != 0)
4428 FOR_PROVIDES(p2, pp2, rec)
4434 /* if p2 is already installed, this recommends is ignored */
4435 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4441 queue_push(whyq, SOLVER_REASON_RECOMMENDED);
4442 queue_push2(whyq, i, rec);
4446 /* 2) list all supplements */
4447 s = pool->solvables + p;
4448 if (s->supplements && level > 0)
4450 Id *supp, sup, pp2, p2;
4451 /* this is a hack. to use solver_dep_fulfilled we temporarily clear
4452 * everything above our level in the decisionmap */
4453 for (i = decisionno; i < solv->decisionq.count; i++ )
4455 p2 = solv->decisionq.elements[i];
4457 solv->decisionmap[p2] = -solv->decisionmap[p2];
4459 supp = s->repo->idarraydata + s->supplements;
4460 while ((sup = *supp++) != 0)
4461 if (solver_dep_fulfilled(solv, sup))
4464 /* let's see if this is an easy supp */
4465 FOR_PROVIDES(p2, pp2, sup)
4467 if (!solv->addalreadyrecommended && solv->installed)
4469 if (pool->solvables[p2].repo == solv->installed)
4472 if (solv->decisionmap[p2] > 0 && solv->decisionmap[p2] < level)
4474 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4475 queue_push2(whyq, p2, sup);
4481 /* hard case, just note dependency with no package */
4482 queue_push(whyq, SOLVER_REASON_SUPPLEMENTED);
4483 queue_push2(whyq, 0, sup);
4486 for (i = decisionno; i < solv->decisionq.count; i++)
4488 p2 = solv->decisionq.elements[i];
4490 solv->decisionmap[p2] = -solv->decisionmap[p2];
4496 pool_job2solvables(Pool *pool, Queue *pkgs, Id how, Id what)
4499 how &= SOLVER_SELECTMASK;
4501 if (how == SOLVER_SOLVABLE_ALL)
4503 FOR_POOL_SOLVABLES(p)
4504 queue_push(pkgs, p);
4506 else if (how == SOLVER_SOLVABLE_REPO)
4508 Repo *repo = pool_id2repo(pool, what);
4511 FOR_REPO_SOLVABLES(repo, p, s)
4512 queue_push(pkgs, p);
4516 FOR_JOB_SELECT(p, pp, how, what)
4517 queue_push(pkgs, p);
4522 pool_isemptyupdatejob(Pool *pool, Id how, Id what)
4525 Id select = how & SOLVER_SELECTMASK;
4526 if ((how & SOLVER_JOBMASK) != SOLVER_UPDATE)
4528 if (select == SOLVER_SOLVABLE_ALL || select == SOLVER_SOLVABLE_REPO)
4530 if (!pool->installed)
4532 FOR_JOB_SELECT(p, pp, select, what)
4533 if (pool->solvables[p].repo == pool->installed)
4536 FOR_JOB_SELECT(p, pp, select, what)
4538 Solvable *s = pool->solvables + p;
4539 FOR_PROVIDES(pi, pip, s->name)
4541 Solvable *si = pool->solvables + pi;
4542 if (si->repo != pool->installed || si->name != s->name)
4548 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
4549 while ((obs = *obsp++) != 0)
4551 FOR_PROVIDES(pi, pip, obs)
4553 Solvable *si = pool->solvables + pi;
4554 if (si->repo != pool->installed)
4556 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, si, obs))
4558 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, si))
4569 get_userinstalled_cmp(const void *ap, const void *bp, void *dp)
4571 return *(Id *)ap - *(Id *)bp;
4575 get_userinstalled_cmp_names(const void *ap, const void *bp, void *dp)
4578 return strcmp(pool_id2str(pool, *(Id *)ap), pool_id2str(pool, *(Id *)bp));
4582 get_userinstalled_sort_uniq(Pool *pool, Queue *q, int flags)
4586 if ((flags & GET_USERINSTALLED_NAMES) != 0)
4587 solv_sort(q->elements, q->count, sizeof(Id), get_userinstalled_cmp_names, pool);
4589 solv_sort(q->elements, q->count, sizeof(Id), get_userinstalled_cmp, 0);
4590 for (i = j = 0; i < q->count; i++)
4591 if (q->elements[i] != lastp)
4592 q->elements[j++] = lastp = q->elements[i];
4593 queue_truncate(q, j);
4597 solver_get_userinstalled(Solver *solv, Queue *q, int flags)
4599 Pool *pool = solv->pool;
4602 Repo *installed = solv->installed;
4606 map_init(&userinstalled, 0);
4608 /* first process jobs */
4609 for (i = 0; i < solv->job.count; i += 2)
4611 Id how = solv->job.elements[i];
4613 if (installed && (how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
4615 if (!userinstalled.size)
4616 map_grow(&userinstalled, installed->end - installed->start);
4617 what = solv->job.elements[i + 1];
4618 select = how & SOLVER_SELECTMASK;
4619 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
4620 FOR_REPO_SOLVABLES(installed, p, s)
4621 MAPSET(&userinstalled, p - installed->start);
4622 FOR_JOB_SELECT(p, pp, select, what)
4623 if (pool->solvables[p].repo == installed)
4624 MAPSET(&userinstalled, p - installed->start);
4627 if ((how & SOLVER_JOBMASK) != SOLVER_INSTALL)
4629 if ((how & SOLVER_NOTBYUSER) != 0)
4631 what = solv->job.elements[i + 1];
4632 select = how & SOLVER_SELECTMASK;
4633 FOR_JOB_SELECT(p, pp, select, what)
4634 if (solv->decisionmap[p] > 0)
4637 #ifdef ENABLE_LINKED_PKGS
4638 if (has_package_link(pool, pool->solvables + p))
4643 find_package_link(pool, pool->solvables + p, 0, &lq, 0, 0);
4644 for (j = 0; j < lq.count; j++)
4645 if (solv->decisionmap[lq.elements[j]] > 0)
4646 queue_push(q, lq.elements[j]);
4651 /* now process updates of userinstalled packages */
4652 if (installed && userinstalled.size)
4654 for (i = 1; i < solv->decisionq.count; i++)
4656 p = solv->decisionq.elements[i];
4659 s = pool->solvables + p;
4662 if (s->repo == installed)
4664 if (MAPTST(&userinstalled, p - installed->start))
4668 /* new package, check if we replace a userinstalled one */
4669 FOR_PROVIDES(p2, pp, s->name)
4671 Solvable *ps = pool->solvables + p2;
4672 if (p2 == p || ps->repo != installed || !MAPTST(&userinstalled, p2 - installed->start))
4674 if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
4676 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, ps))
4681 if (!p2 && s->repo != installed && s->obsoletes)
4683 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
4684 while ((obs = *obsp++) != 0)
4686 FOR_PROVIDES(p2, pp, obs)
4688 Solvable *ps = pool->solvables + p2;
4689 if (p2 == p || ps->repo != installed || !MAPTST(&userinstalled, p2 - installed->start))
4691 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
4693 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
4704 map_free(&userinstalled);
4705 /* convert to names if asked */
4706 if ((flags & GET_USERINSTALLED_NAMES) != 0)
4708 for (i = 0; i < q->count; i++)
4710 s = pool->solvables + q->elements[i];
4711 q->elements[i] = s->name;
4714 /* sort and unify */
4716 get_userinstalled_sort_uniq(pool, q, flags);
4717 /* invert if asked */
4718 if ((flags & GET_USERINSTALLED_INVERTED) != 0)
4720 /* first generate queue with all installed packages */
4723 for (i = 1; i < solv->decisionq.count; i++)
4725 p = solv->decisionq.elements[i];
4728 s = pool->solvables + p;
4731 if ((flags & GET_USERINSTALLED_NAMES) != 0)
4732 queue_push(&invq, s->name);
4734 queue_push(&invq, p);
4736 /* push q on invq, just in case... */
4737 queue_insertn(&invq, invq.count, q->count, q->elements);
4739 get_userinstalled_sort_uniq(pool, &invq, flags);
4740 /* subtract queues (easy as they are sorted and invq is a superset of q) */
4743 for (i = j = 0; i < invq.count; i++)
4744 if (invq.elements[i] == q->elements[j])
4746 invq.elements[i] = 0;
4747 if (++j >= q->count)
4752 for (i = j = 0; i < invq.count; i++)
4753 if (invq.elements[i])
4754 queue_push(q, invq.elements[i]);
4760 pool_add_userinstalled_jobs(Pool *pool, Queue *q, Queue *job, int flags)
4764 if (flags & GET_USERINSTALLED_INVERTED)
4770 if (!pool->installed)
4773 FOR_REPO_SOLVABLES(pool->installed, p, s)
4774 queue_push(&invq, flags & GET_USERINSTALLED_NAMES ? s->name : p);
4775 queue_insertn(&invq, invq.count, q->count, q->elements);
4777 get_userinstalled_sort_uniq(pool, &invq, flags);
4778 /* now the fun part, add q again, sort, and remove all dups */
4779 queue_insertn(&invq, invq.count, q->count, q->elements);
4782 if ((flags & GET_USERINSTALLED_NAMES) != 0)
4783 solv_sort(invq.elements, invq.count, sizeof(Id), get_userinstalled_cmp_names, pool);
4785 solv_sort(invq.elements, invq.count, sizeof(Id), get_userinstalled_cmp, 0);
4789 for (i = 0; i < invq.count; i++)
4791 if (invq.elements[i] == lastid)
4797 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), lastid);
4799 lastid = invq.elements[i];
4802 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), lastid);
4807 for (i = 0; i < q->count; i++)
4808 queue_push2(job, SOLVER_USERINSTALLED | (flags & GET_USERINSTALLED_NAMES ? SOLVER_SOLVABLE_NAME : SOLVER_SOLVABLE), q->elements[i]);
4813 solver_select2str(Pool *pool, Id select, Id what)
4817 select &= SOLVER_SELECTMASK;
4818 if (select == SOLVER_SOLVABLE)
4819 return pool_solvid2str(pool, what);
4820 if (select == SOLVER_SOLVABLE_NAME)
4821 return pool_dep2str(pool, what);
4822 if (select == SOLVER_SOLVABLE_PROVIDES)
4824 s = pool_dep2str(pool, what);
4825 b = pool_alloctmpspace(pool, 11 + strlen(s));
4826 sprintf(b, "providing %s", s);
4829 if (select == SOLVER_SOLVABLE_ONE_OF)
4833 while ((p = pool->whatprovidesdata[what++]) != 0)
4835 s = pool_solvid2str(pool, p);
4837 b = pool_tmpappend(pool, b, ", ", s);
4839 b = pool_tmpjoin(pool, s, 0, 0);
4840 pool_freetmpspace(pool, s);
4842 return b ? b : "nothing";
4844 if (select == SOLVER_SOLVABLE_REPO)
4846 b = pool_alloctmpspace(pool, 20);
4847 sprintf(b, "repo #%d", what);
4850 if (select == SOLVER_SOLVABLE_ALL)
4851 return "all packages";
4852 return "unknown job select";
4856 pool_job2str(Pool *pool, Id how, Id what, Id flagmask)
4858 Id select = how & SOLVER_SELECTMASK;
4859 const char *strstart = 0, *strend = 0;
4863 switch (how & SOLVER_JOBMASK)
4866 return "do nothing";
4867 case SOLVER_INSTALL:
4868 if (select == SOLVER_SOLVABLE && pool->installed && pool->solvables[what].repo == pool->installed)
4869 strstart = "keep ", strend = " installed";
4870 else if (select == SOLVER_SOLVABLE || select == SOLVER_SOLVABLE_NAME)
4871 strstart = "install ";
4872 else if (select == SOLVER_SOLVABLE_PROVIDES)
4873 strstart = "install a package ";
4875 strstart = "install one of ";
4878 if (select == SOLVER_SOLVABLE && !(pool->installed && pool->solvables[what].repo == pool->installed))
4879 strstart = "keep ", strend = " uninstalled";
4880 else if (select == SOLVER_SOLVABLE_PROVIDES)
4881 strstart = "deinstall all packages ";
4883 strstart = "deinstall ";
4886 strstart = "update ";
4888 case SOLVER_WEAKENDEPS:
4889 strstart = "weaken deps of ";
4891 case SOLVER_MULTIVERSION:
4892 strstart = "multi version ";
4897 case SOLVER_DISTUPGRADE:
4898 strstart = "dist upgrade ";
4901 strstart = "verify ";
4903 case SOLVER_DROP_ORPHANED:
4904 strstart = "deinstall ", strend = " if orphaned";
4906 case SOLVER_USERINSTALLED:
4907 strstart = "regard ", strend = " as userinstalled";
4910 strstart = "unknown job ";
4913 s = pool_tmpjoin(pool, strstart, solver_select2str(pool, select, what), strend);
4915 if ((how & ~(SOLVER_SELECTMASK|SOLVER_JOBMASK)) == 0)
4918 s = pool_tmpappend(pool, s, " ", 0);
4919 if (how & SOLVER_WEAK)
4920 s = pool_tmpappend(pool, s, ",weak", 0);
4921 if (how & SOLVER_ESSENTIAL)
4922 s = pool_tmpappend(pool, s, ",essential", 0);
4923 if (how & SOLVER_CLEANDEPS)
4924 s = pool_tmpappend(pool, s, ",cleandeps", 0);
4925 if (how & SOLVER_ORUPDATE)
4926 s = pool_tmpappend(pool, s, ",orupdate", 0);
4927 if (how & SOLVER_FORCEBEST)
4928 s = pool_tmpappend(pool, s, ",forcebest", 0);
4929 if (how & SOLVER_TARGETED)
4930 s = pool_tmpappend(pool, s, ",targeted", 0);
4931 if (how & SOLVER_SETEV)
4932 s = pool_tmpappend(pool, s, ",setev", 0);
4933 if (how & SOLVER_SETEVR)
4934 s = pool_tmpappend(pool, s, ",setevr", 0);
4935 if (how & SOLVER_SETARCH)
4936 s = pool_tmpappend(pool, s, ",setarch", 0);
4937 if (how & SOLVER_SETVENDOR)
4938 s = pool_tmpappend(pool, s, ",setvendor", 0);
4939 if (how & SOLVER_SETREPO)
4940 s = pool_tmpappend(pool, s, ",setrepo", 0);
4941 if (how & SOLVER_SETNAME)
4942 s = pool_tmpappend(pool, s, ",setname", 0);
4943 if (how & SOLVER_NOAUTOSET)
4944 s = pool_tmpappend(pool, s, ",noautoset", 0);
4945 if (s[o + 1] != ',')
4946 s = pool_tmpappend(pool, s, ",?", 0);
4948 return pool_tmpappend(pool, s, "]", 0);