2 * Copyright (c) 2007-2009, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
20 #include "solver_private.h"
25 #include "solverdebug.h"
28 /**********************************************************************************/
30 /* a problem is an item on the solver's problem list. It can either be >0, in that
31 * case it is a update/infarch/dup rule, or it can be <0, which makes it refer to a job
32 * consisting of multiple job rules.
36 solver_disableproblem(Solver *solv, Id v)
44 if (v >= solv->infarchrules && v < solv->infarchrules_end)
46 Pool *pool = solv->pool;
47 Id name = pool->solvables[-solv->rules[v].p].name;
48 while (v > solv->infarchrules && pool->solvables[-solv->rules[v - 1].p].name == name)
50 for (; v < solv->infarchrules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
51 solver_disablerule(solv, solv->rules + v);
54 if (v >= solv->duprules && v < solv->duprules_end)
56 Pool *pool = solv->pool;
57 Id name = pool->solvables[-solv->rules[v].p].name;
58 while (v > solv->duprules && pool->solvables[-solv->rules[v - 1].p].name == name)
60 for (; v < solv->duprules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
61 solver_disablerule(solv, solv->rules + v);
64 solver_disablerule(solv, solv->rules + v);
66 /* XXX: doesn't work */
67 if (v >= solv->updaterules && v < solv->updaterules_end)
69 /* enable feature rule if we disabled the update rule */
70 r = solv->rules + (v - solv->updaterules + solv->featurerules);
72 solver_enablerule(solv, r);
78 jp = solv->ruletojob.elements;
79 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
81 solver_disablerule(solv, r);
84 /*-------------------------------------------------------------------
89 solver_enableproblem(Solver *solv, Id v)
97 if (v >= solv->infarchrules && v < solv->infarchrules_end)
99 Pool *pool = solv->pool;
100 Id name = pool->solvables[-solv->rules[v].p].name;
101 while (v > solv->infarchrules && pool->solvables[-solv->rules[v - 1].p].name == name)
103 for (; v < solv->infarchrules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
104 solver_enablerule(solv, solv->rules + v);
107 if (v >= solv->duprules && v < solv->duprules_end)
109 Pool *pool = solv->pool;
110 Id name = pool->solvables[-solv->rules[v].p].name;
111 while (v > solv->duprules && pool->solvables[-solv->rules[v - 1].p].name == name)
113 for (; v < solv->duprules_end && pool->solvables[-solv->rules[v].p].name == name; v++)
114 solver_enablerule(solv, solv->rules + v);
117 if (v >= solv->featurerules && v < solv->featurerules_end)
119 /* do not enable feature rule if update rule is enabled */
120 r = solv->rules + (v - solv->featurerules + solv->updaterules);
124 solver_enablerule(solv, solv->rules + v);
125 if (v >= solv->updaterules && v < solv->updaterules_end)
127 /* disable feature rule when enabling update rule */
128 r = solv->rules + (v - solv->updaterules + solv->featurerules);
130 solver_disablerule(solv, r);
135 jp = solv->ruletojob.elements;
136 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
138 solver_enablerule(solv, r);
142 /*-------------------------------------------------------------------
145 * Reenable all disabled weak rules (marked in weakrulemap)
150 enableweakrules(Solver *solv)
155 for (i = 1, r = solv->rules + i; i < solv->learntrules; i++, r++)
157 if (r->d >= 0) /* already enabled? */
159 if (!MAPTST(&solv->weakrulemap, i))
161 solver_enablerule(solv, r);
163 /* make sure broken orphan rules stay disabled */
164 if (solv->brokenorphanrules)
165 for (i = 0; i < solv->brokenorphanrules->count; i++)
166 solver_disablerule(solv, solv->rules + solv->brokenorphanrules->elements[i]);
170 /*-------------------------------------------------------------------
174 * at this point, all rules that led to conflicts are disabled.
175 * we re-enable all rules of a problem set but rule "sug", then
176 * continue to disable more rules until there as again a solution.
179 /* FIXME: think about conflicting assertions */
182 refine_suggestion(Solver *solv, Id *problem, Id sug, Queue *refined, int essentialok)
184 Pool *pool = solv->pool;
190 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
192 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "refine_suggestion start\n");
193 for (i = 0; problem[i]; i++)
195 if (problem[i] == sug)
196 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "=> ");
197 solver_printproblem(solv, problem[i]);
200 queue_empty(refined);
201 if (!essentialok && sug < 0 && (solv->job.elements[-sug - 1] & SOLVER_ESSENTIAL) != 0)
203 queue_init(&disabled);
204 queue_push(refined, sug);
206 /* re-enable all problem rules with the exception of "sug"(gestion) */
209 for (i = 0; problem[i]; i++)
210 if (problem[i] != sug)
211 solver_enableproblem(solv, problem[i]);
214 solver_reenablepolicyrules(solv, -sug);
215 else if (sug >= solv->updaterules && sug < solv->updaterules_end)
217 /* enable feature rule */
218 Rule *r = solv->rules + solv->featurerules + (sug - solv->updaterules);
220 solver_enablerule(solv, r);
223 enableweakrules(solv);
227 int njob, nfeature, nupdate, pass;
228 queue_empty(&solv->problems);
231 if (!solv->problems.count)
232 solver_run_sat(solv, 0, 0);
234 if (!solv->problems.count)
236 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "no more problems!\n");
237 break; /* great, no more problems */
239 disabledcnt = disabled.count;
240 /* start with 1 to skip over proof index */
241 njob = nfeature = nupdate = 0;
242 for (pass = 0; pass < 2; pass++)
244 for (i = 1; i < solv->problems.count - 1; i++)
246 /* ignore solutions in refined */
247 v = solv->problems.elements[i];
249 break; /* end of problem reached */
252 /* check if v is in the given problems list
253 * we allow disabling all problem rules *after* sug in
254 * pass 2, to prevent getting the same solution twice */
255 for (j = 0; problem[j]; j++)
256 if (problem[j] == v || (pass && problem[j] == sug))
261 if (v >= solv->featurerules && v < solv->featurerules_end)
267 if (!essentialok && (solv->job.elements[-v - 1] & SOLVER_ESSENTIAL) != 0)
268 continue; /* not that one! */
271 queue_push(&disabled, v);
273 if (disabled.count != disabledcnt)
276 if (disabled.count == disabledcnt)
278 /* no solution found, this was an invalid suggestion! */
279 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "no solution found!\n");
283 if (!njob && nupdate && nfeature)
285 /* got only update rules, filter out feature rules */
286 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "throwing away feature rules\n");
287 for (i = j = disabledcnt; i < disabled.count; i++)
289 v = disabled.elements[i];
290 if (v < solv->featurerules || v >= solv->featurerules_end)
291 disabled.elements[j++] = v;
296 if (disabled.count == disabledcnt + 1)
298 /* just one suggestion, add it to refined list */
299 v = disabled.elements[disabledcnt];
300 if (!nfeature && v != sug)
301 queue_push(refined, v); /* do not record feature rules */
302 solver_disableproblem(solv, v);
303 if (v >= solv->updaterules && v < solv->updaterules_end)
305 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
307 solver_enablerule(solv, r); /* enable corresponding feature rule */
310 solver_reenablepolicyrules(solv, -v);
314 /* more than one solution, disable all */
315 /* do not push anything on refine list, as we do not know which solution to choose */
316 /* thus, the user will get another problem if he selects this solution, where he
317 * can choose the right one */
318 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
320 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "more than one solution found:\n");
321 for (i = disabledcnt; i < disabled.count; i++)
322 solver_printproblem(solv, disabled.elements[i]);
324 for (i = disabledcnt; i < disabled.count; i++)
326 v = disabled.elements[i];
327 solver_disableproblem(solv, v);
328 if (v >= solv->updaterules && v < solv->updaterules_end)
330 Rule *r = solv->rules + (v - solv->updaterules + solv->featurerules);
332 solver_enablerule(solv, r);
337 /* all done, get us back into the same state as before */
338 /* enable refined rules again */
339 for (i = 0; i < disabled.count; i++)
340 solver_enableproblem(solv, disabled.elements[i]);
341 queue_free(&disabled);
342 /* reset policy rules */
343 for (i = 0; problem[i]; i++)
344 solver_enableproblem(solv, problem[i]);
345 solver_disablepolicyrules(solv);
346 /* disable problem rules again */
347 for (i = 0; problem[i]; i++)
348 solver_disableproblem(solv, problem[i]);
349 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "refine_suggestion end\n");
353 /*-------------------------------------------------------------------
354 * sorting helper for problems
356 * bring update rules before job rules
357 * make essential job rules last
361 problems_sortcmp(const void *ap, const void *bp, void *dp)
364 Id a = *(Id *)ap, b = *(Id *)bp;
371 int af = job->elements[-a - 1] & SOLVER_ESSENTIAL;
372 int bf = job->elements[-b - 1] & SOLVER_ESSENTIAL;
381 * convert a solution rule into a job modifier
384 convertsolution(Solver *solv, Id why, Queue *solutionq)
386 Pool *pool = solv->pool;
390 if (why < solv->pooljobcnt)
392 queue_push(solutionq, SOLVER_SOLUTION_POOLJOB);
393 queue_push(solutionq, why);
397 queue_push(solutionq, SOLVER_SOLUTION_JOB);
398 queue_push(solutionq, why - solv->pooljobcnt);
402 if (why >= solv->infarchrules && why < solv->infarchrules_end)
405 /* infarch rule, find replacement */
406 assert(solv->rules[why].p < 0);
407 name = pool->solvables[-solv->rules[why].p].name;
408 while (why > solv->infarchrules && pool->solvables[-solv->rules[why - 1].p].name == name)
411 for (; why < solv->infarchrules_end && pool->solvables[-solv->rules[why].p].name == name; why++)
412 if (solv->decisionmap[-solv->rules[why].p] > 0)
414 p = -solv->rules[why].p;
418 return; /* false alarm */
419 queue_push(solutionq, SOLVER_SOLUTION_INFARCH);
420 queue_push(solutionq, p);
423 if (why >= solv->duprules && why < solv->duprules_end)
426 /* dist upgrade rule, find replacement */
427 assert(solv->rules[why].p < 0);
428 name = pool->solvables[-solv->rules[why].p].name;
429 while (why > solv->duprules && pool->solvables[-solv->rules[why - 1].p].name == name)
432 for (; why < solv->duprules_end && pool->solvables[-solv->rules[why].p].name == name; why++)
433 if (solv->decisionmap[-solv->rules[why].p] > 0)
435 p = -solv->rules[why].p;
439 return; /* false alarm */
440 queue_push(solutionq, SOLVER_SOLUTION_DISTUPGRADE);
441 queue_push(solutionq, p);
444 if (why >= solv->updaterules && why < solv->updaterules_end)
446 /* update rule, find replacement package */
450 /* check if this is a false positive, i.e. the update rule is fulfilled */
451 rr = solv->rules + why;
452 FOR_RULELITERALS(p, pp, rr)
453 if (p > 0 && solv->decisionmap[p] > 0)
454 return; /* false alarm */
456 p = solv->installed->start + (why - solv->updaterules);
457 if (solv->dupmap_all && solv->rules[why].p != p && solv->decisionmap[p] > 0)
459 /* distupgrade case, allow to keep old package */
460 queue_push(solutionq, SOLVER_SOLUTION_DISTUPGRADE);
461 queue_push(solutionq, p);
464 if (solv->decisionmap[p] > 0)
465 return; /* false alarm, turned out we can keep the package */
466 rr = solv->rules + solv->featurerules + (why - solv->updaterules);
468 rr = solv->rules + why;
471 int mvrp = 0; /* multi-version replacement */
472 FOR_RULELITERALS(rp, pp, rr)
474 if (rp > 0 && solv->decisionmap[rp] > 0 && pool->solvables[rp].repo != solv->installed)
477 if (!(solv->multiversion.size && MAPTST(&solv->multiversion, rp)))
483 /* found only multi-version replacements */
484 /* have to split solution into two parts */
485 queue_push(solutionq, p);
486 queue_push(solutionq, mvrp);
489 queue_push(solutionq, p);
490 queue_push(solutionq, rp);
493 if (why >= solv->bestrules && why < solv->bestrules_end)
498 /* check false positive */
499 rr = solv->rules + why;
500 FOR_RULELITERALS(p, pp, rr)
501 if (p > 0 && solv->decisionmap[p] > 0)
502 return; /* false alarm */
503 /* check update/feature rule */
504 p = solv->bestrules_pkg[why - solv->bestrules];
508 queue_push(solutionq, 0);
509 queue_push(solutionq, solv->ruletojob.elements[-p - solv->jobrules] + 1);
512 if (solv->decisionmap[p] > 0)
514 /* disable best rule by keeping the old package */
515 queue_push(solutionq, SOLVER_SOLUTION_BEST);
516 queue_push(solutionq, p);
519 rr = solv->rules + solv->featurerules + (p - solv->installed->start);
521 rr = solv->rules + solv->updaterules + (p - solv->installed->start);
522 mvrp = 0; /* multi-version replacement */
523 FOR_RULELITERALS(rp, pp, rr)
524 if (rp > 0 && solv->decisionmap[rp] > 0 && pool->solvables[rp].repo != solv->installed)
527 if (!(solv->multiversion.size && MAPTST(&solv->multiversion, rp)))
532 queue_push(solutionq, SOLVER_SOLUTION_BEST); /* split, see above */
533 queue_push(solutionq, mvrp);
534 queue_push(solutionq, p);
535 queue_push(solutionq, 0);
540 queue_push(solutionq, SOLVER_SOLUTION_BEST);
541 queue_push(solutionq, rp);
548 * convert problem data into a form usable for refining.
549 * Returns the number of problems.
552 solver_prepare_solutions(Solver *solv)
556 if (!solv->problems.count)
558 queue_empty(&solv->solutions);
559 queue_push(&solv->solutions, 0); /* dummy so idx is always nonzero */
560 idx = solv->solutions.count;
561 queue_push(&solv->solutions, -1); /* unrefined */
562 /* proofidx stays in position, thus we start with 1 */
563 for (i = 1; i < solv->problems.count; i++)
565 Id p = solv->problems.elements[i];
566 queue_push(&solv->solutions, p);
569 /* end of problem reached */
570 solv->problems.elements[j++] = idx;
571 if (i + 1 >= solv->problems.count)
573 /* start another problem */
574 solv->problems.elements[j++] = solv->problems.elements[++i]; /* copy proofidx */
575 idx = solv->solutions.count;
576 queue_push(&solv->solutions, -1); /* unrefined */
578 solv->problems.count = j;
583 * refine the simple solution rule list provided by
584 * the solver into multiple lists of job modifiers.
587 create_solutions(Solver *solv, int probnr, int solidx)
589 Pool *pool = solv->pool;
591 Queue problem, solution, problems_save;
595 int oldmistakes = solv->cleandeps_mistakes ? solv->cleandeps_mistakes->count : 0;
597 int decisioncnt_update;
598 int decisioncnt_keep;
599 int decisioncnt_resolve;
600 int decisioncnt_weak;
601 int decisioncnt_orphan;
603 now = solv_timems(0);
605 /* save decisionq, decisionq_why, decisionmap, and decisioncnt */
606 for (i = 0; i < solv->decisionq.count; i++)
608 Id p = solv->decisionq.elements[i];
609 queue_push(&redoq, p);
610 queue_push(&redoq, solv->decisionq_why.elements[i]);
611 queue_push(&redoq, solv->decisionmap[p > 0 ? p : -p]);
613 decisioncnt_update = solv->decisioncnt_update;
614 decisioncnt_keep = solv->decisioncnt_keep;
615 decisioncnt_resolve = solv->decisioncnt_resolve;
616 decisioncnt_weak = solv->decisioncnt_weak;
617 decisioncnt_orphan = solv->decisioncnt_orphan;
619 /* save problems queue */
620 problems_save = solv->problems;
621 memset(&solv->problems, 0, sizeof(solv->problems));
623 /* extract problem from queue */
624 queue_init(&problem);
625 for (i = solidx + 1; i < solv->solutions.count; i++)
627 Id v = solv->solutions.elements[i];
630 queue_push(&problem, v);
632 extraflags &= solv->job.elements[-v - 1];
634 if (extraflags == -1)
636 if (problem.count > 1)
637 solv_sort(problem.elements, problem.count, sizeof(Id), problems_sortcmp, &solv->job);
638 queue_push(&problem, 0); /* mark end for refine_suggestion */
641 for (i = 0; i < problem.count; i++)
642 printf("PP %d %d\n", i, problem.elements[i]);
645 /* refine each solution element */
648 queue_init(&solution);
649 for (i = 0; i < problem.count; i++)
651 int solstart = solv->solutions.count;
652 refine_suggestion(solv, problem.elements, problem.elements[i], &solution, essentialok);
653 queue_push(&solv->solutions, 0); /* reserve room for number of elements */
654 for (j = 0; j < solution.count; j++)
655 convertsolution(solv, solution.elements[j], &solv->solutions);
656 if (solv->solutions.count == solstart + 1)
658 solv->solutions.count--; /* this one did not work out */
659 if (nsol || i + 1 < problem.count)
660 continue; /* got one or still hope */
663 /* nothing found, start over */
664 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "nothing found, re-run with essentialok = 1\n");
669 /* this is bad, we found no solution */
670 /* for now just offer a rule */
671 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "nothing found, already did essentialok, fake it\n");
672 queue_push(&solv->solutions, 0);
673 for (j = 0; j < problem.count; j++)
675 convertsolution(solv, problem.elements[j], &solv->solutions);
676 if (solv->solutions.count > solstart + 1)
679 if (solv->solutions.count == solstart + 1)
681 solv->solutions.count--;
682 continue; /* sorry */
685 /* patch in number of solution elements */
686 solv->solutions.elements[solstart] = (solv->solutions.count - (solstart + 1)) / 2;
687 queue_push(&solv->solutions, 0); /* add end marker */
688 queue_push(&solv->solutions, 0); /* add end marker */
689 queue_push(&solv->solutions, problem.elements[i]); /* just for bookkeeping */
690 queue_push(&solv->solutions, extraflags & SOLVER_CLEANDEPS); /* our extraflags */
691 solv->solutions.elements[solidx + 1 + nsol++] = solstart;
693 solv->solutions.elements[solidx + 1 + nsol] = 0; /* end marker */
694 solv->solutions.elements[solidx] = nsol;
695 queue_free(&problem);
696 queue_free(&solution);
698 /* restore decisions */
699 memset(solv->decisionmap, 0, pool->nsolvables * sizeof(Id));
700 queue_empty(&solv->decisionq);
701 queue_empty(&solv->decisionq_why);
702 for (i = 0; i < redoq.count; i += 3)
704 Id p = redoq.elements[i];
705 queue_push(&solv->decisionq, p);
706 queue_push(&solv->decisionq_why, redoq.elements[i + 1]);
707 solv->decisionmap[p > 0 ? p : -p] = redoq.elements[i + 2];
710 solv->decisioncnt_update = decisioncnt_update;
711 solv->decisioncnt_keep = decisioncnt_keep;
712 solv->decisioncnt_resolve = decisioncnt_resolve;
713 solv->decisioncnt_weak = decisioncnt_weak;
714 solv->decisioncnt_orphan = decisioncnt_orphan;
716 /* restore problems */
717 queue_free(&solv->problems);
718 solv->problems = problems_save;
720 if (solv->cleandeps_mistakes)
723 queue_truncate(solv->cleandeps_mistakes, oldmistakes);
726 queue_free(solv->cleandeps_mistakes);
727 solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
731 POOL_DEBUG(SOLV_DEBUG_STATS, "create_solutions for problem #%d took %d ms\n", probnr, solv_timems(now));
735 /**************************************************************************/
738 solver_problem_count(Solver *solv)
740 return solv->problems.count / 2;
744 solver_next_problem(Solver *solv, Id problem)
747 return solv->problems.count ? 1 : 0;
748 return (problem + 1) * 2 - 1 < solv->problems.count ? problem + 1 : 0;
752 solver_solution_count(Solver *solv, Id problem)
754 Id solidx = solv->problems.elements[problem * 2 - 1];
755 if (solv->solutions.elements[solidx] < 0)
756 create_solutions(solv, problem, solidx);
757 return solv->solutions.elements[solidx];
761 solver_next_solution(Solver *solv, Id problem, Id solution)
763 Id solidx = solv->problems.elements[problem * 2 - 1];
764 if (solv->solutions.elements[solidx] < 0)
765 create_solutions(solv, problem, solidx);
766 return solv->solutions.elements[solidx + solution + 1] ? solution + 1 : 0;
770 solver_solutionelement_count(Solver *solv, Id problem, Id solution)
772 Id solidx = solv->problems.elements[problem * 2 - 1];
773 solidx = solv->solutions.elements[solidx + solution];
774 return solv->solutions.elements[solidx];
778 solver_solutionelement_internalid(Solver *solv, Id problem, Id solution)
780 Id solidx = solv->problems.elements[problem * 2 - 1];
781 solidx = solv->solutions.elements[solidx + solution];
782 return solv->solutions.elements[solidx + 2 * solv->solutions.elements[solidx] + 3];
786 solver_solutionelement_extrajobflags(Solver *solv, Id problem, Id solution)
788 Id solidx = solv->problems.elements[problem * 2 - 1];
789 solidx = solv->solutions.elements[solidx + solution];
790 return solv->solutions.elements[solidx + 2 * solv->solutions.elements[solidx] + 4];
795 * return the next item of the proposed solution
796 * here are the possibilities for p / rp and what
797 * the solver expects the application to do:
799 * -------------------------------------------------------
800 * SOLVER_SOLUTION_INFARCH pkgid
801 * -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
802 * SOLVER_SOLUTION_DISTUPGRADE pkgid
803 * -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
804 * SOLVER_SOLUTION_BEST pkgid
805 * -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
806 * SOLVER_SOLUTION_JOB jobidx
807 * -> remove job (jobidx - 1, jobidx) from job queue
808 * SOLVER_SOLUTION_POOLJOB jobidx
809 * -> remove job (jobidx - 1, jobidx) from pool job queue
811 * -> add (SOLVER_ERASE|SOLVER_SOLVABLE, p) to the job
812 * pkgid (> 0) pkgid (> 0)
813 * -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
814 * (this will replace package p)
816 * Thus, the solver will either ask the application to remove
817 * a specific job from the job queue, or ask to add an install/erase
823 solver_next_solutionelement(Solver *solv, Id problem, Id solution, Id element, Id *p, Id *rp)
825 Id solidx = solv->problems.elements[problem * 2 - 1];
826 solidx = solv->solutions.elements[solidx + solution];
829 solidx += 1 + element * 2;
830 if (!solv->solutions.elements[solidx] && !solv->solutions.elements[solidx + 1])
832 *p = solv->solutions.elements[solidx];
833 *rp = solv->solutions.elements[solidx + 1];
838 solver_take_solutionelement(Solver *solv, Id p, Id rp, Id extrajobflags, Queue *job)
842 if (p == SOLVER_SOLUTION_POOLJOB)
844 solv->pool->pooljobs.elements[rp - 1] = SOLVER_NOOP;
845 solv->pool->pooljobs.elements[rp] = 0;
848 if (p == SOLVER_SOLUTION_JOB)
850 job->elements[rp - 1] = SOLVER_NOOP;
851 job->elements[rp] = 0;
854 if (rp <= 0 && p <= 0)
855 return; /* just in case */
857 p = SOLVER_INSTALL|SOLVER_SOLVABLE|SOLVER_NOTBYUSER|extrajobflags;
861 p = SOLVER_ERASE|SOLVER_SOLVABLE|extrajobflags;
863 for (i = 0; i < job->count; i += 2)
864 if (job->elements[i] == p && job->elements[i + 1] == rp)
866 queue_push2(job, p, rp);
870 solver_take_solution(Solver *solv, Id problem, Id solution, Queue *job)
872 Id p, rp, element = 0;
873 Id extrajobflags = solver_solutionelement_extrajobflags(solv, problem, solution);
874 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
875 solver_take_solutionelement(solv, p, rp, extrajobflags, job);
879 /*-------------------------------------------------------------------
885 findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp, Map *rseen)
888 Id lreqr, lconr, lsysr, ljobr;
891 int i, reqset = 0; /* 0: unset, 1: installed, 2: jobassert, 3: assert */
892 int conset = 0; /* 0: unset, 1: installed */
894 /* find us a jobassert rule */
895 for (i = idx; (rid = solv->learnt_pool.elements[i]) != 0; i++)
897 if (rid < solv->jobrules || rid >= solv->jobrules_end)
899 r = solv->rules + rid;
900 d = r->d < 0 ? -r->d - 1 : r->d;
901 if (!d && r->w2 == 0 && r->p > 0)
908 /* the problem rules are somewhat ordered from "near to the problem" to
909 * "near to the job" */
910 lreqr = lconr = lsysr = ljobr = 0;
911 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
914 if (rid >= solv->learntrules)
916 if (MAPTST(rseen, rid - solv->learntrules))
918 MAPSET(rseen, rid - solv->learntrules);
919 findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr, rseen);
921 else if ((rid >= solv->jobrules && rid < solv->jobrules_end) || (rid >= solv->infarchrules && rid < solv->infarchrules_end) || (rid >= solv->duprules && rid < solv->duprules_end) || (rid >= solv->bestrules && rid < solv->bestrules_end) || (rid >= solv->yumobsrules && rid <= solv->yumobsrules_end))
926 else if (rid >= solv->updaterules && rid < solv->updaterules_end)
933 assert(rid < solv->rpmrules_end);
934 r = solv->rules + rid;
935 d = r->d < 0 ? -r->d - 1 : r->d;
938 /* prefer conflicts of installed packages */
939 if (solv->installed && !conset)
941 if (r->p < 0 && (solv->pool->solvables[-r->p].repo == solv->installed ||
942 solv->pool->solvables[-r->w2].repo == solv->installed))
953 if (!d && r->w2 == 0 && reqset < 3)
955 if (*reqrp > 0 && r->p < -1)
957 Id op = -solv->rules[*reqrp].p;
958 if (op > 1 && solv->pool->solvables[op].arch != solv->pool->solvables[-r->p].arch)
959 continue; /* different arch, skip */
961 /* prefer assertions */
965 else if (jobassert && r->p == -jobassert)
967 /* prefer rules of job assertions */
971 else if (solv->installed && r->p < 0 && solv->pool->solvables[-r->p].repo == solv->installed && reqset <= 1)
973 /* prefer rules of job installed package so that the user doesn't get confused by strange packages */
982 if (!*reqrp && lreqr)
984 if (!*conrp && lconr)
986 if (!*jobrp && ljobr)
988 if (!*sysrp && lsysr)
995 * search for a rule that describes the problem to the
996 * user. Actually a pretty hopeless task that may leave the user
997 * puzzled. To get all of the needed information use
998 * solver_findallproblemrules() instead.
1002 solver_findproblemrule(Solver *solv, Id problem)
1004 Id reqr, conr, sysr, jobr;
1005 Id idx = solv->problems.elements[2 * problem - 2];
1007 reqr = conr = sysr = jobr = 0;
1008 map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
1009 findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr, &rseen);
1011 /* check if the request is about a not-installed package requiring a installed
1012 * package conflicting with the non-installed package. In that case return the conflict */
1013 if (reqr && conr && solv->installed && solv->rules[reqr].p < 0 && solv->rules[conr].p < 0 && solv->rules[conr].w2 < 0)
1015 Pool *pool = solv->pool;
1016 Solvable *s = pool->solvables - solv->rules[reqr].p;
1017 Solvable *s1 = pool->solvables - solv->rules[conr].p;
1018 Solvable *s2 = pool->solvables - solv->rules[conr].w2;
1020 if (s == s1 && s2->repo == solv->installed)
1021 cp = -solv->rules[conr].w2;
1022 else if (s == s2 && s1->repo == solv->installed)
1023 cp = -solv->rules[conr].p;
1024 if (cp && s1->name != s2->name && s->repo != solv->installed)
1027 Rule *r = solv->rules + reqr;
1028 FOR_RULELITERALS(p, pp, r)
1034 return reqr; /* some requires */
1036 return conr; /* some conflict */
1038 return sysr; /* an update rule */
1040 return jobr; /* a user request */
1045 /*-------------------------------------------------------------------*/
1048 findallproblemrules_internal(Solver *solv, Id idx, Queue *rules, Map *rseen)
1051 while ((rid = solv->learnt_pool.elements[idx++]) != 0)
1053 if (rid >= solv->learntrules)
1055 if (MAPTST(rseen, rid - solv->learntrules))
1057 MAPSET(rseen, rid - solv->learntrules);
1058 findallproblemrules_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], rules, rseen);
1061 queue_pushunique(rules, rid);
1066 * find all problem rule
1068 * return all rules that lead to the problem. This gives the user
1069 * all of the information to understand the problem, but the result
1070 * can be a large number of rules.
1074 solver_findallproblemrules(Solver *solv, Id problem, Queue *rules)
1078 map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
1079 findallproblemrules_internal(solv, solv->problems.elements[2 * problem - 2], rules, &rseen);
1084 solver_problemruleinfo2str(Solver *solv, SolverRuleinfo type, Id source, Id target, Id dep)
1086 Pool *pool = solv->pool;
1090 case SOLVER_RULE_DISTUPGRADE:
1091 return pool_tmpjoin(pool, pool_solvid2str(pool, source), " does not belong to a distupgrade repository", 0);
1092 case SOLVER_RULE_INFARCH:
1093 return pool_tmpjoin(pool, pool_solvid2str(pool, source), " has inferior architecture", 0);
1094 case SOLVER_RULE_UPDATE:
1095 return pool_tmpjoin(pool, "problem with installed package ", pool_solvid2str(pool, source), 0);
1096 case SOLVER_RULE_JOB:
1097 return "conflicting requests";
1098 case SOLVER_RULE_JOB_UNSUPPORTED:
1099 return "unsupported request";
1100 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
1101 return pool_tmpjoin(pool, "nothing provides requested ", pool_dep2str(pool, dep), 0);
1102 case SOLVER_RULE_JOB_UNKNOWN_PACKAGE:
1103 return pool_tmpjoin(pool, "package ", pool_dep2str(pool, dep), " does not exist");
1104 case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM:
1105 return pool_tmpjoin(pool, pool_dep2str(pool, dep), " is provided by the system", 0);
1106 case SOLVER_RULE_RPM:
1107 return "some dependency problem";
1108 case SOLVER_RULE_BEST:
1110 return pool_tmpjoin(pool, "cannot install the best update candidate for package ", pool_solvid2str(pool, source), 0);
1111 return "cannot install the best candidate for the job";
1112 case SOLVER_RULE_RPM_NOT_INSTALLABLE:
1113 return pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), " is not installable");
1114 case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
1115 s = pool_tmpjoin(pool, "nothing provides ", pool_dep2str(pool, dep), 0);
1116 return pool_tmpappend(pool, s, " needed by ", pool_solvid2str(pool, source));
1117 case SOLVER_RULE_RPM_SAME_NAME:
1118 s = pool_tmpjoin(pool, "cannot install both ", pool_solvid2str(pool, source), 0);
1119 return pool_tmpappend(pool, s, " and ", pool_solvid2str(pool, target));
1120 case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
1121 s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), 0);
1122 s = pool_tmpappend(pool, s, " conflicts with ", pool_dep2str(pool, dep));
1123 return pool_tmpappend(pool, s, " provided by ", pool_solvid2str(pool, target));
1124 case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
1125 s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), 0);
1126 s = pool_tmpappend(pool, s, " obsoletes ", pool_dep2str(pool, dep));
1127 return pool_tmpappend(pool, s, " provided by ", pool_solvid2str(pool, target));
1128 case SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES:
1129 s = pool_tmpjoin(pool, "installed package ", pool_solvid2str(pool, source), 0);
1130 s = pool_tmpappend(pool, s, " obsoletes ", pool_dep2str(pool, dep));
1131 return pool_tmpappend(pool, s, " provided by ", pool_solvid2str(pool, target));
1132 case SOLVER_RULE_RPM_IMPLICIT_OBSOLETES:
1133 s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), 0);
1134 s = pool_tmpappend(pool, s, " implicitly obsoletes ", pool_dep2str(pool, dep));
1135 return pool_tmpappend(pool, s, " provided by ", pool_solvid2str(pool, target));
1136 case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
1137 s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), " requires ");
1138 return pool_tmpappend(pool, s, pool_dep2str(pool, dep), ", but none of the providers can be installed");
1139 case SOLVER_RULE_RPM_SELF_CONFLICT:
1140 s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), " conflicts with ");
1141 return pool_tmpappend(pool, s, pool_dep2str(pool, dep), " provided by itself");
1142 case SOLVER_RULE_YUMOBS:
1143 s = pool_tmpjoin(pool, "both package ", pool_solvid2str(pool, source), " and ");
1144 s = pool_tmpjoin(pool, s, pool_solvid2str(pool, target), " obsolete ");
1145 return pool_tmpappend(pool, s, pool_dep2str(pool, dep), 0);
1147 return "bad problem rule type";
1151 /* convenience function */
1153 solver_problem2str(Solver *solv, Id problem)
1155 Id type, source, target, dep;
1156 Id r = solver_findproblemrule(solv, problem);
1158 return "no problem rule?";
1159 type = solver_ruleinfo(solv, r, &source, &target, &dep);
1160 return solver_problemruleinfo2str(solv, type, source, target, dep);
1164 solver_solutionelement2str(Solver *solv, Id p, Id rp)
1166 Pool *pool = solv->pool;
1167 if (p == SOLVER_SOLUTION_JOB || p == SOLVER_SOLUTION_POOLJOB)
1170 if (p == SOLVER_SOLUTION_JOB)
1171 rp += solv->pooljobcnt;
1172 how = solv->job.elements[rp - 1];
1173 what = solv->job.elements[rp];
1174 return pool_tmpjoin(pool, "do not ask to ", pool_job2str(pool, how, what, 0), 0);
1176 else if (p == SOLVER_SOLUTION_INFARCH)
1178 Solvable *s = pool->solvables + rp;
1179 if (solv->installed && s->repo == solv->installed)
1180 return pool_tmpjoin(pool, "keep ", pool_solvable2str(pool, s), " despite the inferior architecture");
1182 return pool_tmpjoin(pool, "install ", pool_solvable2str(pool, s), " despite the inferior architecture");
1184 else if (p == SOLVER_SOLUTION_DISTUPGRADE)
1186 Solvable *s = pool->solvables + rp;
1187 if (solv->installed && s->repo == solv->installed)
1188 return pool_tmpjoin(pool, "keep obsolete ", pool_solvable2str(pool, s), 0);
1190 return pool_tmpjoin(pool, "install ", pool_solvable2str(pool, s), " from excluded repository");
1192 else if (p == SOLVER_SOLUTION_BEST)
1194 Solvable *s = pool->solvables + rp;
1195 if (solv->installed && s->repo == solv->installed)
1196 return pool_tmpjoin(pool, "keep old ", pool_solvable2str(pool, s), 0);
1198 return pool_tmpjoin(pool, "install ", pool_solvable2str(pool, s), " despite the old version");
1200 else if (p > 0 && rp == 0)
1201 return pool_tmpjoin(pool, "allow deinstallation of ", pool_solvid2str(pool, p), 0);
1202 else if (p > 0 && rp > 0)
1204 const char *sp = pool_solvid2str(pool, p);
1205 const char *srp = pool_solvid2str(pool, rp);
1206 const char *str = pool_tmpjoin(pool, "allow replacement of ", sp, 0);
1207 return pool_tmpappend(pool, str, " with ", srp);
1210 return "bad solution element";