revert pyhton3 part that was commit by mistake in #ab8b3ded
[platform/upstream/libsolv.git] / src / problems.c
index 1be6577..75aaa88 100644 (file)
@@ -141,9 +141,9 @@ solver_enableproblem(Solver *solv, Id v)
 
 /*-------------------------------------------------------------------
  * enable weak rules
- * 
+ *
  * Reenable all disabled weak rules (marked in weakrulemap)
- * 
+ *
  */
 
 static void
@@ -164,9 +164,9 @@ enableweakrules(Solver *solv)
 
 
 /*-------------------------------------------------------------------
- * 
+ *
  * 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.
@@ -556,14 +556,14 @@ solver_prepare_solutions(Solver *solv)
   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++) 
-    {   
+  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;
       /* end of problem reached */
-      solv->problems.elements[j++] = idx; 
+      solv->problems.elements[j++] = idx;
       if (i + 1 >= solv->problems.count)
         break;
       /* start another problem */
@@ -571,7 +571,7 @@ solver_prepare_solutions(Solver *solv)
       idx = solv->solutions.count;
       queue_push(&solv->solutions, -1);        /* unrefined */
     }
-  solv->problems.count = j;  
+  solv->problems.count = j;
   return j / 2;
 }
 
@@ -590,10 +590,15 @@ create_solutions(Solver *solv, int probnr, int solidx)
   unsigned int now;
   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];
@@ -601,6 +606,12 @@ create_solutions(Solver *solv, int probnr, int solidx)
       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));
@@ -692,6 +703,12 @@ create_solutions(Solver *solv, int probnr, int solidx)
       solv->decisionmap[p > 0 ? p : -p] = redoq.elements[i + 2];
     }
   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;
@@ -706,7 +723,7 @@ create_solutions(Solver *solv, int probnr, int solidx)
          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));
 }
 
@@ -791,7 +808,7 @@ solver_solutionelement_extrajobflags(Solver *solv, Id problem, Id solution)
  *    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.
@@ -856,7 +873,7 @@ solver_take_solution(Solver *solv, Id problem, Id solution, Queue *job)
 
 
 /*-------------------------------------------------------------------
- * 
+ *
  * find problem rule
  */
 
@@ -868,6 +885,7 @@ findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp,
   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++)
@@ -913,6 +931,16 @@ findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp,
          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;
            }
@@ -957,7 +985,7 @@ findproblemrule_internal(Solver *solv, Id idx, Id *reqrp, Id *conrp, Id *sysrp,
     *sysrp = lsysr;
 }
 
-/* 
+/*
  * find problem rule
  *
  * search for a rule that describes the problem to the
@@ -976,6 +1004,28 @@ solver_findproblemrule(Solver *solv, Id problem)
   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)
@@ -1041,8 +1091,12 @@ solver_problemruleinfo2str(Solver *solv, SolverRuleinfo type, Id source, Id targ
       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:
@@ -1082,6 +1136,18 @@ solver_problemruleinfo2str(Solver *solv, SolverRuleinfo type, Id source, Id targ
     }
 }
 
+/* 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);
+}
+
 const char *
 solver_solutionelement2str(Solver *solv, Id p, Id rp)
 {