#include <assert.h>
#include "solver.h"
+#include "solver_private.h"
#include "bitmap.h"
#include "pool.h"
#include "util.h"
/*-------------------------------------------------------------------
* enable weak rules
- *
+ *
* Reenable all disabled weak rules (marked in weakrulemap)
- *
+ *
*/
static void
continue;
solver_enablerule(solv, r);
}
+ /* make sure broken orphan rules stay disabled */
+ if (solv->brokenorphanrules)
+ for (i = 0; i < solv->brokenorphanrules->count; i++)
+ solver_disablerule(solv, solv->rules + solv->brokenorphanrules->elements[i]);
}
/*-------------------------------------------------------------------
- *
+ *
* refine_suggestion
- *
+ *
* at this point, all rules that led to conflicts are disabled.
* we re-enable all rules of a problem set but rule "sug", then
* continue to disable more rules until there as again a solution.
Queue disabled;
int disabledcnt;
- IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
+ IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
{
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion start\n");
+ POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "refine_suggestion start\n");
for (i = 0; problem[i]; i++)
{
if (problem[i] == sug)
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "=> ");
+ POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "=> ");
solver_printproblem(solv, problem[i]);
}
}
solver_enableproblem(solv, problem[i]);
if (sug < 0)
- solver_reenablepolicyrules(solv, -(sug + 1));
+ solver_reenablepolicyrules(solv, -sug);
else if (sug >= solv->updaterules && sug < solv->updaterules_end)
{
/* enable feature rule */
for (;;)
{
- int njob, nfeature, nupdate;
+ int njob, nfeature, nupdate, pass;
queue_empty(&solv->problems);
solver_reset(solv);
if (!solv->problems.count)
{
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no more problems!\n");
- IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
- solver_printdecisions(solv);
+ POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "no more problems!\n");
break; /* great, no more problems */
}
disabledcnt = disabled.count;
/* start with 1 to skip over proof index */
njob = nfeature = nupdate = 0;
- for (i = 1; i < solv->problems.count - 1; i++)
+ for (pass = 0; pass < 2; pass++)
{
- /* ignore solutions in refined */
- v = solv->problems.elements[i];
- if (v == 0)
- break; /* end of problem reached */
- for (j = 0; problem[j]; j++)
- if (problem[j] != sug && problem[j] == v)
- break;
- if (problem[j])
- continue;
- if (v >= solv->featurerules && v < solv->featurerules_end)
- nfeature++;
- else if (v > 0)
- nupdate++;
- else
+ for (i = 1; i < solv->problems.count - 1; i++)
{
- if (!essentialok && (solv->job.elements[-v -1] & SOLVER_ESSENTIAL) != 0)
- continue; /* not that one! */
- njob++;
+ /* ignore solutions in refined */
+ v = solv->problems.elements[i];
+ if (v == 0)
+ break; /* end of problem reached */
+ if (sug != v)
+ {
+ /* check if v is in the given problems list
+ * we allow disabling all problem rules *after* sug in
+ * pass 2, to prevent getting the same solution twice */
+ for (j = 0; problem[j]; j++)
+ if (problem[j] == v || (pass && problem[j] == sug))
+ break;
+ if (problem[j] == v)
+ continue;
+ }
+ if (v >= solv->featurerules && v < solv->featurerules_end)
+ nfeature++;
+ else if (v > 0)
+ nupdate++;
+ else
+ {
+ if (!essentialok && (solv->job.elements[-v - 1] & SOLVER_ESSENTIAL) != 0)
+ continue; /* not that one! */
+ njob++;
+ }
+ queue_push(&disabled, v);
}
- queue_push(&disabled, v);
+ if (disabled.count != disabledcnt)
+ break;
}
if (disabled.count == disabledcnt)
{
/* no solution found, this was an invalid suggestion! */
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "no solution found!\n");
+ POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "no solution found!\n");
refined->count = 0;
break;
}
if (!njob && nupdate && nfeature)
{
/* got only update rules, filter out feature rules */
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "throwing away feature rules\n");
+ POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "throwing away feature rules\n");
for (i = j = disabledcnt; i < disabled.count; i++)
{
v = disabled.elements[i];
{
/* just one suggestion, add it to refined list */
v = disabled.elements[disabledcnt];
- if (!nfeature)
+ if (!nfeature && v != sug)
queue_push(refined, v); /* do not record feature rules */
solver_disableproblem(solv, v);
if (v >= solv->updaterules && v < solv->updaterules_end)
solver_enablerule(solv, r); /* enable corresponding feature rule */
}
if (v < 0)
- solver_reenablepolicyrules(solv, -(v + 1));
+ solver_reenablepolicyrules(solv, -v);
}
else
{
/* do not push anything on refine list, as we do not know which solution to choose */
/* thus, the user will get another problem if he selects this solution, where he
* can choose the right one */
- IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
+ IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
{
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "more than one solution found:\n");
+ POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "more than one solution found:\n");
for (i = disabledcnt; i < disabled.count; i++)
solver_printproblem(solv, disabled.elements[i]);
}
/* disable problem rules again */
for (i = 0; problem[i]; i++)
solver_disableproblem(solv, problem[i]);
- POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "refine_suggestion end\n");
+ POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "refine_suggestion end\n");
}
Pool *pool = solv->pool;
if (why < 0)
{
- queue_push(solutionq, 0);
- queue_push(solutionq, -why);
+ why = -why;
+ if (why < solv->pooljobcnt)
+ {
+ queue_push(solutionq, SOLVER_SOLUTION_POOLJOB);
+ queue_push(solutionq, why);
+ }
+ else
+ {
+ queue_push(solutionq, SOLVER_SOLUTION_JOB);
+ queue_push(solutionq, why - solv->pooljobcnt);
+ }
return;
}
if (why >= solv->infarchrules && why < solv->infarchrules_end)
if (why >= solv->updaterules && why < solv->updaterules_end)
{
/* update rule, find replacement package */
- Id p, *dp, rp = 0;
+ Id p, pp, rp = 0;
Rule *rr;
- assert(why >= solv->updaterules && why < solv->updaterules_end);
/* check if this is a false positive, i.e. the update rule is fulfilled */
rr = solv->rules + why;
- FOR_RULELITERALS(p, dp, rr)
+ FOR_RULELITERALS(p, pp, rr)
if (p > 0 && solv->decisionmap[p] > 0)
- break;
- if (p)
- return; /* false alarm */
+ return; /* false alarm */
p = solv->installed->start + (why - solv->updaterules);
- rr = solv->rules + solv->featurerules + (why - solv->updaterules);
- if (!rr->p)
- rr = solv->rules + why;
- if (solv->distupgrade && solv->rules[why].p != p && solv->decisionmap[p] > 0)
+ if (solv->dupmap_all && solv->rules[why].p != p && solv->decisionmap[p] > 0)
{
/* distupgrade case, allow to keep old package */
- queue_push(solutionq, p);
+ queue_push(solutionq, SOLVER_SOLUTION_DISTUPGRADE);
queue_push(solutionq, p);
return;
}
if (solv->decisionmap[p] > 0)
return; /* false alarm, turned out we can keep the package */
+ rr = solv->rules + solv->featurerules + (why - solv->updaterules);
+ if (!rr->p)
+ rr = solv->rules + why;
if (rr->w2)
{
int mvrp = 0; /* multi-version replacement */
- FOR_RULELITERALS(rp, dp, rr)
+ FOR_RULELITERALS(rp, pp, rr)
{
if (rp > 0 && solv->decisionmap[rp] > 0 && pool->solvables[rp].repo != solv->installed)
{
mvrp = rp;
- if (!(solv->noobsoletes.size && MAPTST(&solv->noobsoletes, rp)))
+ if (!(solv->multiversion.size && MAPTST(&solv->multiversion, rp)))
break;
}
}
queue_push(solutionq, rp);
return;
}
+ if (why >= solv->bestrules && why < solv->bestrules_end)
+ {
+ int mvrp;
+ Id p, pp, rp = 0;
+ Rule *rr;
+ /* check false positive */
+ rr = solv->rules + why;
+ FOR_RULELITERALS(p, pp, rr)
+ if (p > 0 && solv->decisionmap[p] > 0)
+ return; /* false alarm */
+ /* check update/feature rule */
+ p = solv->bestrules_pkg[why - solv->bestrules];
+ if (p < 0)
+ {
+ /* install job */
+ queue_push(solutionq, 0);
+ queue_push(solutionq, solv->ruletojob.elements[-p - solv->jobrules] + 1);
+ return;
+ }
+ if (solv->decisionmap[p] > 0)
+ {
+ /* disable best rule by keeping the old package */
+ queue_push(solutionq, SOLVER_SOLUTION_BEST);
+ queue_push(solutionq, p);
+ return;
+ }
+ rr = solv->rules + solv->featurerules + (p - solv->installed->start);
+ if (!rr->p)
+ rr = solv->rules + solv->updaterules + (p - solv->installed->start);
+ mvrp = 0; /* multi-version replacement */
+ FOR_RULELITERALS(rp, pp, rr)
+ if (rp > 0 && solv->decisionmap[rp] > 0 && pool->solvables[rp].repo != solv->installed)
+ {
+ mvrp = rp;
+ if (!(solv->multiversion.size && MAPTST(&solv->multiversion, rp)))
+ break;
+ }
+ if (!rp && mvrp)
+ {
+ queue_push(solutionq, SOLVER_SOLUTION_BEST); /* split, see above */
+ queue_push(solutionq, mvrp);
+ queue_push(solutionq, p);
+ queue_push(solutionq, 0);
+ return;
+ }
+ if (rp)
+ {
+ queue_push(solutionq, SOLVER_SOLUTION_BEST);
+ queue_push(solutionq, rp);
+ }
+ return;
+ }
}
/*
int
solver_prepare_solutions(Solver *solv)
{
- int i, j = 1, idx = 1;
+ int i, j = 1, idx;
if (!solv->problems.count)
return 0;
- queue_push(&solv->solutions, 0);
- queue_push(&solv->solutions, -1); /* unrefined */
- for (i = 1; i < solv->problems.count; i++)
- {
+ queue_empty(&solv->solutions);
+ queue_push(&solv->solutions, 0); /* dummy so idx is always nonzero */
+ idx = solv->solutions.count;
+ queue_push(&solv->solutions, -1); /* unrefined */
+ /* proofidx stays in position, thus we start with 1 */
+ for (i = 1; i < solv->problems.count; i++)
+ {
Id p = solv->problems.elements[i];
- queue_push(&solv->solutions, p);
- if (p)
+ queue_push(&solv->solutions, p);
+ if (p)
continue;
- solv->problems.elements[j++] = idx;
+ /* end of problem reached */
+ solv->problems.elements[j++] = idx;
if (i + 1 >= solv->problems.count)
break;
+ /* start another problem */
solv->problems.elements[j++] = solv->problems.elements[++i]; /* copy proofidx */
idx = solv->solutions.count;
- queue_push(&solv->solutions, -1);
- }
- solv->problems.count = j;
+ queue_push(&solv->solutions, -1); /* unrefined */
+ }
+ solv->problems.count = j;
return j / 2;
}
Queue problem, solution, problems_save;
int i, j, nsol;
int essentialok;
- int recocount;
unsigned int now;
-
- now = sat_timems(0);
- recocount = solv->recommendations.count;
- solv->recommendations.count = 0; /* so that revert() doesn't mess with it later */
+ int oldmistakes = solv->cleandeps_mistakes ? solv->cleandeps_mistakes->count : 0;
+ Id extraflags = -1;
+ int decisioncnt_update;
+ int decisioncnt_keep;
+ int decisioncnt_resolve;
+ int decisioncnt_weak;
+ int decisioncnt_orphan;
+
+ now = solv_timems(0);
queue_init(&redoq);
- /* save decisionq, decisionq_why, decisionmap */
+ /* save decisionq, decisionq_why, decisionmap, and decisioncnt */
for (i = 0; i < solv->decisionq.count; i++)
{
Id p = solv->decisionq.elements[i];
queue_push(&redoq, solv->decisionq_why.elements[i]);
queue_push(&redoq, solv->decisionmap[p > 0 ? p : -p]);
}
+ decisioncnt_update = solv->decisioncnt_update;
+ decisioncnt_keep = solv->decisioncnt_keep;
+ decisioncnt_resolve = solv->decisioncnt_resolve;
+ decisioncnt_weak = solv->decisioncnt_weak;
+ decisioncnt_orphan = solv->decisioncnt_orphan;
+
/* save problems queue */
problems_save = solv->problems;
memset(&solv->problems, 0, sizeof(solv->problems));
if (!v)
break;
queue_push(&problem, v);
+ if (v < 0)
+ extraflags &= solv->job.elements[-v - 1];
}
+ if (extraflags == -1)
+ extraflags = 0;
if (problem.count > 1)
- sat_sort(problem.elements, problem.count, sizeof(Id), problems_sortcmp, &solv->job);
+ solv_sort(problem.elements, problem.count, sizeof(Id), problems_sortcmp, &solv->job);
queue_push(&problem, 0); /* mark end for refine_suggestion */
problem.count--;
#if 0
convertsolution(solv, solution.elements[j], &solv->solutions);
if (solv->solutions.count == solstart + 1)
{
- solv->solutions.count--;
- if (!essentialok && i + 1 == problem.count && !nsol)
+ solv->solutions.count--; /* this one did not work out */
+ if (nsol || i + 1 < problem.count)
+ continue; /* got one or still hope */
+ if (!essentialok)
{
/* nothing found, start over */
+ POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "nothing found, re-run with essentialok = 1\n");
essentialok = 1;
i = -1;
+ continue;
+ }
+ /* this is bad, we found no solution */
+ /* for now just offer a rule */
+ POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "nothing found, already did essentialok, fake it\n");
+ queue_push(&solv->solutions, 0);
+ for (j = 0; j < problem.count; j++)
+ {
+ convertsolution(solv, problem.elements[j], &solv->solutions);
+ if (solv->solutions.count > solstart + 1)
+ break;
+ }
+ if (solv->solutions.count == solstart + 1)
+ {
+ solv->solutions.count--;
+ continue; /* sorry */
}
- continue;
}
/* patch in number of solution elements */
solv->solutions.elements[solstart] = (solv->solutions.count - (solstart + 1)) / 2;
queue_push(&solv->solutions, 0); /* add end marker */
queue_push(&solv->solutions, 0); /* add end marker */
+ queue_push(&solv->solutions, problem.elements[i]); /* just for bookkeeping */
+ queue_push(&solv->solutions, extraflags & SOLVER_CLEANDEPS); /* our extraflags */
solv->solutions.elements[solidx + 1 + nsol++] = solstart;
}
solv->solutions.elements[solidx + 1 + nsol] = 0; /* end marker */
queue_push(&solv->decisionq_why, redoq.elements[i + 1]);
solv->decisionmap[p > 0 ? p : -p] = redoq.elements[i + 2];
}
- solv->recommendations.count = recocount;
queue_free(&redoq);
+ solv->decisioncnt_update = decisioncnt_update;
+ solv->decisioncnt_keep = decisioncnt_keep;
+ solv->decisioncnt_resolve = decisioncnt_resolve;
+ solv->decisioncnt_weak = decisioncnt_weak;
+ solv->decisioncnt_orphan = decisioncnt_orphan;
+
/* restore problems */
queue_free(&solv->problems);
solv->problems = problems_save;
- POOL_DEBUG(SAT_DEBUG_STATS, "create_solutions for problem #%d took %d ms\n", probnr, sat_timems(now));
+
+ if (solv->cleandeps_mistakes)
+ {
+ if (oldmistakes)
+ queue_truncate(solv->cleandeps_mistakes, oldmistakes);
+ else
+ {
+ queue_free(solv->cleandeps_mistakes);
+ solv->cleandeps_mistakes = solv_free(solv->cleandeps_mistakes);
+ }
+ }
+
+ POOL_DEBUG(SOLV_DEBUG_STATS, "create_solutions for problem #%d took %d ms\n", probnr, solv_timems(now));
}
return solv->solutions.elements[solidx];
}
+Id
+solver_solutionelement_internalid(Solver *solv, Id problem, Id solution)
+{
+ Id solidx = solv->problems.elements[problem * 2 - 1];
+ solidx = solv->solutions.elements[solidx + solution];
+ return solv->solutions.elements[solidx + 2 * solv->solutions.elements[solidx] + 3];
+}
+
+Id
+solver_solutionelement_extrajobflags(Solver *solv, Id problem, Id solution)
+{
+ Id solidx = solv->problems.elements[problem * 2 - 1];
+ solidx = solv->solutions.elements[solidx + solution];
+ return solv->solutions.elements[solidx + 2 * solv->solutions.elements[solidx] + 4];
+}
+
/*
* return the next item of the proposed solution
* -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
* SOLVER_SOLUTION_DISTUPGRADE pkgid
* -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
+ * SOLVER_SOLUTION_BEST pkgid
+ * -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
* SOLVER_SOLUTION_JOB jobidx
* -> remove job (jobidx - 1, jobidx) from job queue
+ * SOLVER_SOLUTION_POOLJOB jobidx
+ * -> remove job (jobidx - 1, jobidx) from pool job queue
* pkgid (> 0) 0
* -> add (SOLVER_ERASE|SOLVER_SOLVABLE, p) to the job
* pkgid (> 0) pkgid (> 0)
* -> add (SOLVER_INSTALL|SOLVER_SOLVABLE, rp) to the job
* (this will replace package p)
- *
+ *
* Thus, the solver will either ask the application to remove
* a specific job from the job queue, or ask to add an install/erase
* job to it.
}
void
-solver_take_solutionelement(Solver *solv, Id p, Id rp, Queue *job)
+solver_take_solutionelement(Solver *solv, Id p, Id rp, Id extrajobflags, Queue *job)
{
int i;
+ if (p == SOLVER_SOLUTION_POOLJOB)
+ {
+ solv->pool->pooljobs.elements[rp - 1] = SOLVER_NOOP;
+ solv->pool->pooljobs.elements[rp] = 0;
+ return;
+ }
if (p == SOLVER_SOLUTION_JOB)
{
job->elements[rp - 1] = SOLVER_NOOP;
if (rp <= 0 && p <= 0)
return; /* just in case */
if (rp > 0)
- p = SOLVER_INSTALL|SOLVER_SOLVABLE;
+ p = SOLVER_INSTALL|SOLVER_SOLVABLE|SOLVER_NOTBYUSER|extrajobflags;
else
{
rp = p;
- p = SOLVER_ERASE|SOLVER_SOLVABLE;
+ p = SOLVER_ERASE|SOLVER_SOLVABLE|extrajobflags;
}
for (i = 0; i < job->count; i += 2)
if (job->elements[i] == p && job->elements[i + 1] == rp)
solver_take_solution(Solver *solv, Id problem, Id solution, Queue *job)
{
Id p, rp, element = 0;
+ Id extrajobflags = solver_solutionelement_extrajobflags(solv, problem, solution);
while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
- solver_take_solutionelement(solv, p, rp, job);
+ solver_take_solutionelement(solv, p, rp, extrajobflags, job);
}
/*-------------------------------------------------------------------
- *
+ *
* find problem rule
*/
static void
-findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp)
+findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp, Id *jobrp, Map *rseen)
{
Id rid, d;
Id lreqr, lconr, lsysr, ljobr;
Rule *r;
Id jobassert = 0;
int i, reqset = 0; /* 0: unset, 1: installed, 2: jobassert, 3: assert */
+ int conset = 0; /* 0: unset, 1: installed */
/* find us a jobassert rule */
for (i = idx; (rid = solv->learnt_pool.elements[i]) != 0; i++)
{
assert(rid > 0);
if (rid >= solv->learntrules)
- findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr);
- else if ((rid >= solv->jobrules && rid < solv->jobrules_end) || (rid >= solv->infarchrules && rid < solv->infarchrules_end) || (rid >= solv->duprules && rid < solv->duprules_end))
+ {
+ if (MAPTST(rseen, rid - solv->learntrules))
+ continue;
+ MAPSET(rseen, rid - solv->learntrules);
+ findproblemrule_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], &lreqr, &lconr, &lsysr, &ljobr, rseen);
+ }
+ 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))
{
if (!*jobrp)
*jobrp = rid;
d = r->d < 0 ? -r->d - 1 : r->d;
if (!d && r->w2 < 0)
{
+ /* prefer conflicts of installed packages */
+ if (solv->installed && !conset)
+ {
+ if (r->p < 0 && (solv->pool->solvables[-r->p].repo == solv->installed ||
+ solv->pool->solvables[-r->w2].repo == solv->installed))
+ {
+ *conrp = rid;
+ conset = 1;
+ }
+ }
if (!*conrp)
*conrp = rid;
}
*sysrp = lsysr;
}
-/*
+/*
* find problem rule
*
* search for a rule that describes the problem to the
{
Id reqr, conr, sysr, jobr;
Id idx = solv->problems.elements[2 * problem - 2];
+ Map rseen;
reqr = conr = sysr = jobr = 0;
- findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr);
+ map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
+ findproblemrule_internal(solv, idx, &reqr, &conr, &sysr, &jobr, &rseen);
+ map_free(&rseen);
+ /* check if the request is about a not-installed package requiring a installed
+ * package conflicting with the non-installed package. In that case return the conflict */
+ if (reqr && conr && solv->installed && solv->rules[reqr].p < 0 && solv->rules[conr].p < 0 && solv->rules[conr].w2 < 0)
+ {
+ Pool *pool = solv->pool;
+ Solvable *s = pool->solvables - solv->rules[reqr].p;
+ Solvable *s1 = pool->solvables - solv->rules[conr].p;
+ Solvable *s2 = pool->solvables - solv->rules[conr].w2;
+ Id cp = 0;
+ if (s == s1 && s2->repo == solv->installed)
+ cp = -solv->rules[conr].w2;
+ else if (s == s2 && s1->repo == solv->installed)
+ cp = -solv->rules[conr].p;
+ if (cp && s1->name != s2->name && s->repo != solv->installed)
+ {
+ Id p, pp;
+ Rule *r = solv->rules + reqr;
+ FOR_RULELITERALS(p, pp, r)
+ if (p == cp)
+ return conr;
+ }
+ }
if (reqr)
return reqr; /* some requires */
if (conr)
if (jobr)
return jobr; /* a user request */
assert(0);
+ return 0;
}
/*-------------------------------------------------------------------*/
static void
-findallproblemrules_internal(Solver *solv, Id idx, Queue *rules)
+findallproblemrules_internal(Solver *solv, Id idx, Queue *rules, Map *rseen)
{
Id rid;
while ((rid = solv->learnt_pool.elements[idx++]) != 0)
{
if (rid >= solv->learntrules)
{
- findallproblemrules_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], rules);
+ if (MAPTST(rseen, rid - solv->learntrules))
+ continue;
+ MAPSET(rseen, rid - solv->learntrules);
+ findallproblemrules_internal(solv, solv->learnt_why.elements[rid - solv->learntrules], rules, rseen);
continue;
}
queue_pushunique(rules, rid);
void
solver_findallproblemrules(Solver *solv, Id problem, Queue *rules)
{
+ Map rseen;
queue_empty(rules);
- findallproblemrules_internal(solv, solv->problems.elements[2 * problem - 2], rules);
+ map_init(&rseen, solv->learntrules ? solv->nrules - solv->learntrules : 0);
+ findallproblemrules_internal(solv, solv->problems.elements[2 * problem - 2], rules, &rseen);
+ map_free(&rseen);
+}
+
+const char *
+solver_problemruleinfo2str(Solver *solv, SolverRuleinfo type, Id source, Id target, Id dep)
+{
+ Pool *pool = solv->pool;
+ char *s;
+ switch (type)
+ {
+ case SOLVER_RULE_DISTUPGRADE:
+ return pool_tmpjoin(pool, pool_solvid2str(pool, source), " does not belong to a distupgrade repository", 0);
+ case SOLVER_RULE_INFARCH:
+ return pool_tmpjoin(pool, pool_solvid2str(pool, source), " has inferior architecture", 0);
+ case SOLVER_RULE_UPDATE:
+ return pool_tmpjoin(pool, "problem with installed package ", pool_solvid2str(pool, source), 0);
+ case SOLVER_RULE_JOB:
+ return "conflicting requests";
+ case SOLVER_RULE_JOB_UNSUPPORTED:
+ return "unsupported request";
+ case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
+ return pool_tmpjoin(pool, "nothing provides requested ", pool_dep2str(pool, dep), 0);
+ case SOLVER_RULE_JOB_UNKNOWN_PACKAGE:
+ return pool_tmpjoin(pool, "package ", pool_dep2str(pool, dep), " does not exist");
+ case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM:
+ return pool_tmpjoin(pool, pool_dep2str(pool, dep), " is provided by the system", 0);
+ case SOLVER_RULE_RPM:
+ return "some dependency problem";
+ case SOLVER_RULE_RPM_NOT_INSTALLABLE:
+ return pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), " is not installable");
+ case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
+ s = pool_tmpjoin(pool, "nothing provides ", pool_dep2str(pool, dep), 0);
+ return pool_tmpappend(pool, s, " needed by ", pool_solvid2str(pool, source));
+ case SOLVER_RULE_RPM_SAME_NAME:
+ s = pool_tmpjoin(pool, "cannot install both ", pool_solvid2str(pool, source), 0);
+ return pool_tmpappend(pool, s, " and ", pool_solvid2str(pool, target));
+ case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
+ s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), 0);
+ s = pool_tmpappend(pool, s, " conflicts with ", pool_dep2str(pool, dep));
+ return pool_tmpappend(pool, s, " provided by ", pool_solvid2str(pool, target));
+ case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
+ s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), 0);
+ s = pool_tmpappend(pool, s, " obsoletes ", pool_dep2str(pool, dep));
+ return pool_tmpappend(pool, s, " provided by ", pool_solvid2str(pool, target));
+ case SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES:
+ s = pool_tmpjoin(pool, "installed package ", pool_solvid2str(pool, source), 0);
+ s = pool_tmpappend(pool, s, " obsoletes ", pool_dep2str(pool, dep));
+ return pool_tmpappend(pool, s, " provided by ", pool_solvid2str(pool, target));
+ case SOLVER_RULE_RPM_IMPLICIT_OBSOLETES:
+ s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), 0);
+ s = pool_tmpappend(pool, s, " implicitly obsoletes ", pool_dep2str(pool, dep));
+ return pool_tmpappend(pool, s, " provided by ", pool_solvid2str(pool, target));
+ case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
+ s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), " requires ");
+ return pool_tmpappend(pool, s, pool_dep2str(pool, dep), ", but none of the providers can be installed");
+ case SOLVER_RULE_RPM_SELF_CONFLICT:
+ s = pool_tmpjoin(pool, "package ", pool_solvid2str(pool, source), " conflicts with ");
+ return pool_tmpappend(pool, s, pool_dep2str(pool, dep), " provided by itself");
+ default:
+ return "bad problem rule type";
+ }
+}
+
+/* convenience function */
+const char *
+solver_problem2str(Solver *solv, Id problem)
+{
+ Id type, source, target, dep;
+ Id r = solver_findproblemrule(solv, problem);
+ if (!r)
+ return "no problem rule?";
+ type = solver_ruleinfo(solv, r, &source, &target, &dep);
+ return solver_problemruleinfo2str(solv, type, source, target, dep);
}
-/* obsolete function */
-SolverRuleinfo
-solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp)
+const char *
+solver_solutionelement2str(Solver *solv, Id p, Id rp)
{
- return solver_ruleinfo(solv, rid, sourcep, targetp, depp);
+ Pool *pool = solv->pool;
+ if (p == SOLVER_SOLUTION_JOB || p == SOLVER_SOLUTION_POOLJOB)
+ {
+ Id how, what;
+ if (p == SOLVER_SOLUTION_JOB)
+ rp += solv->pooljobcnt;
+ how = solv->job.elements[rp - 1];
+ what = solv->job.elements[rp];
+ return pool_tmpjoin(pool, "do not ask to ", pool_job2str(pool, how, what, 0), 0);
+ }
+ else if (p == SOLVER_SOLUTION_INFARCH)
+ {
+ Solvable *s = pool->solvables + rp;
+ if (solv->installed && s->repo == solv->installed)
+ return pool_tmpjoin(pool, "keep ", pool_solvable2str(pool, s), " despite the inferior architecture");
+ else
+ return pool_tmpjoin(pool, "install ", pool_solvable2str(pool, s), " despite the inferior architecture");
+ }
+ else if (p == SOLVER_SOLUTION_DISTUPGRADE)
+ {
+ Solvable *s = pool->solvables + rp;
+ if (solv->installed && s->repo == solv->installed)
+ return pool_tmpjoin(pool, "keep obsolete ", pool_solvable2str(pool, s), 0);
+ else
+ return pool_tmpjoin(pool, "install ", pool_solvable2str(pool, s), " from excluded repository");
+ }
+ else if (p == SOLVER_SOLUTION_BEST)
+ {
+ Solvable *s = pool->solvables + rp;
+ if (solv->installed && s->repo == solv->installed)
+ return pool_tmpjoin(pool, "keep old ", pool_solvable2str(pool, s), 0);
+ else
+ return pool_tmpjoin(pool, "install ", pool_solvable2str(pool, s), " despite the old version");
+ }
+ else if (p > 0 && rp == 0)
+ return pool_tmpjoin(pool, "allow deinstallation of ", pool_solvid2str(pool, p), 0);
+ else if (p > 0 && rp > 0)
+ {
+ const char *sp = pool_solvid2str(pool, p);
+ const char *srp = pool_solvid2str(pool, rp);
+ const char *str = pool_tmpjoin(pool, "allow replacement of ", sp, 0);
+ return pool_tmpappend(pool, str, " with ", srp);
+ }
+ else
+ return "bad solution element";
}
-/* EOF */