2 * Copyright (c) 2007-2009, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * SAT based dependency solver
27 #include "solverdebug.h"
29 #define RULES_BLOCK 63
31 static void addrpmruleinfo(Solver *solv, Id p, Id d, int type, Id dep);
32 static void solver_createcleandepsmap(Solver *solv);
34 /*-------------------------------------------------------------------
35 * Check if dependency is possible
37 * mirrors solver_dep_fulfilled but uses map m instead of the decisionmap
38 * used in solver_addrpmrulesforweak and solver_createcleandepsmap
42 dep_possible(Solver *solv, Id dep, Map *m)
44 Pool *pool = solv->pool;
49 Reldep *rd = GETRELDEP(pool, dep);
52 if (rd->flags == REL_AND)
54 if (!dep_possible(solv, rd->name, m))
56 return dep_possible(solv, rd->evr, m);
58 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
59 return solver_splitprovides(solv, rd->evr);
60 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
61 return solver_dep_installed(solv, rd->evr);
64 FOR_PROVIDES(p, pp, dep)
72 /********************************************************************
76 * - unify rules, remove duplicates
79 /*-------------------------------------------------------------------
81 * compare rules for unification sort
86 unifyrules_sortcmp(const void *ap, const void *bp, void *dp)
96 return x; /* p differs */
99 if (a->d == 0 && b->d == 0)
100 return a->w2 - b->w2; /* assertion: return w2 diff */
102 if (a->d == 0) /* a is assertion, b not */
104 x = a->w2 - pool->whatprovidesdata[b->d];
108 if (b->d == 0) /* b is assertion, a not */
110 x = pool->whatprovidesdata[a->d] - b->w2;
114 /* compare whatprovidesdata */
115 ad = pool->whatprovidesdata + a->d;
116 bd = pool->whatprovidesdata + b->d;
118 if ((x = *ad++ - *bd++) != 0)
124 solver_samerule(Solver *solv, Rule *r1, Rule *r2)
126 return unifyrules_sortcmp(r1, r2, solv->pool);
130 /*-------------------------------------------------------------------
133 * go over all rules and remove duplicates
137 solver_unifyrules(Solver *solv)
139 Pool *pool = solv->pool;
143 if (solv->nrules <= 2) /* nothing to unify */
146 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules -----\n");
148 /* sort rules first */
149 sat_sort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp, solv->pool);
156 for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
158 if (jr && !unifyrules_sortcmp(ir, jr, pool))
159 continue; /* prune! */
160 jr = solv->rules + j++; /* keep! */
165 /* reduced count from nrules to j rules */
166 POOL_DEBUG(SAT_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
168 /* adapt rule buffer */
170 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
173 * debug: log rule statistics
175 IF_POOLDEBUG (SAT_DEBUG_STATS)
182 for (i = 1; i < solv->nrules; i++)
189 dp = solv->pool->whatprovidesdata + r->d;
194 POOL_DEBUG(SAT_DEBUG_STATS, " binary: %d\n", binr);
195 POOL_DEBUG(SAT_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
197 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules end -----\n");
207 hashrule(Solver *solv, Id p, Id d, int n)
209 unsigned int x = (unsigned int)p;
213 return (x * 37) ^ (unsigned int)d;
214 dp = solv->pool->whatprovidesdata + d;
216 x = (x * 37) ^ (unsigned int)*dp++;
222 /*-------------------------------------------------------------------
228 * p = direct literal; always < 0 for installed rpm rules
229 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
232 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
234 * p < 0 : pkg id of A
235 * d > 0 : Offset in whatprovidesdata (list of providers of b)
237 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
238 * p < 0 : pkg id of A
239 * d < 0 : Id of solvable (e.g. B1)
241 * d == 0: unary rule, assertion => (A) or (-A)
243 * Install: p > 0, d = 0 (A) user requested install
244 * Remove: p < 0, d = 0 (-A) user requested remove (also: uninstallable)
245 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
246 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
247 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
248 * also used for obsoletes
249 * ?: p > 0, d < 0 (A|-B)
250 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
254 * Direct assertion (no watch needed) --> d = 0, w1 = p, w2 = 0
255 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
256 * every other : w1 = p, w2 = whatprovidesdata[d];
257 * Disabled rule: w1 = 0
259 * always returns a rule for non-rpm rules
263 solver_addrule(Solver *solv, Id p, Id d)
265 Pool *pool = solv->pool;
269 int n = 0; /* number of literals in rule - 1
270 0 = direct assertion (single literal)
275 /* it often happenes that requires lead to adding the same rpm rule
276 * multiple times, so we prune those duplicates right away to make
277 * the work for unifyrules a bit easier */
279 if (!solv->rpmrules_end) /* we add rpm rules */
281 r = solv->rules + solv->nrules - 1; /* get the last added rule */
282 if (r->p == p && r->d == d && (d != 0 || !r->w2))
287 * compute number of literals (n) in rule
292 /* always a binary rule */
294 return 0; /* ignore self conflict */
299 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
301 return 0; /* rule is self-fulfilling */
303 if (n == 1) /* convert to binary rule */
307 if (n == 1 && p > d && !solv->rpmrules_end)
309 /* smallest literal first so we can find dups */
310 n = p; p = d; d = n; /* p <-> d */
311 n = 1; /* re-set n, was used as temp var */
315 * check for duplicate
318 /* check if the last added rule (r) is exactly the same as what we're looking for. */
319 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
320 return r; /* binary rule */
322 /* have n-ary rule with same first literal, check other literals */
323 if (r && n > 1 && r->d && r->p == p)
325 /* Rule where d is an offset in whatprovidesdata */
329 dp2 = pool->whatprovidesdata + r->d;
330 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
341 /* extend rule buffer */
342 solv->rules = sat_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
343 r = solv->rules + solv->nrules++; /* point to rule space */
352 /* direct assertion, no watch needed */
368 r->w2 = pool->whatprovidesdata[d];
373 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
375 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
376 solver_printrule(solv, SAT_DEBUG_RULE_CREATION, r);
383 /******************************************************************************
385 *** rpm rule part: create rules representing the package dependencies
390 * special multiversion patch conflict handling:
391 * a patch conflict is also satisfied if some other
392 * version with the same name/arch that doesn't conflict
393 * gets installed. The generated rule is thus:
394 * -patch|-cpack|opack1|opack2|...
397 makemultiversionconflict(Solver *solv, Id n, Id con)
399 Pool *pool = solv->pool;
404 sn = pool->solvables + n;
405 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
407 FOR_PROVIDES(p, pp, sn->name)
409 s = pool->solvables + p;
410 if (s->name != sn->name || s->arch != sn->arch)
412 if (!MAPTST(&solv->noobsoletes, p))
414 if (pool_match_nevr(pool, pool->solvables + p, con))
416 /* here we have a multiversion solvable that doesn't conflict */
417 /* thus we're not in conflict if it is installed */
421 return -n; /* no other package found, generate normal conflict */
422 return pool_queuetowhatprovides(pool, &q);
426 addrpmrule(Solver *solv, Id p, Id d, int type, Id dep)
428 if (!solv->ruleinfoq)
429 solver_addrule(solv, p, d);
431 addrpmruleinfo(solv, p, d, type, dep);
434 /*-------------------------------------------------------------------
436 * add (install) rules for solvable
438 * s: Solvable for which to add rules
439 * m: m[s] = 1 for solvables which have rules, prevent rule duplication
441 * Algorithm: 'visit all nodes of a graph'. The graph nodes are
442 * solvables, the edges their dependencies.
443 * Starting from an installed solvable, this will create all rules
444 * representing the graph created by the solvables dependencies.
446 * for unfulfilled requirements, conflicts, obsoletes,....
447 * add a negative assertion for solvables that are not installable
449 * It will also create rules for all solvables referenced by 's'
450 * i.e. descend to all providers of requirements of 's'
455 solver_addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
457 Pool *pool = solv->pool;
458 Repo *installed = solv->installed;
460 /* 'work' queue. keeps Ids of solvables we still have to work on.
461 And buffer for it. */
466 /* if to add rules for broken deps ('rpm -V' functionality)
470 /* Id var and pointer for each dependency
471 * (not used in parallel)
478 Id p, pp; /* whatprovides loops */
479 Id *dp; /* ptr to 'whatprovides' */
480 Id n; /* Id for current solvable 's' */
482 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
484 queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
485 queue_push(&workq, s - pool->solvables); /* push solvable Id to work queue */
487 /* loop until there's no more work left */
492 * s: Pointer to solvable
495 n = queue_shift(&workq); /* 'pop' next solvable to work on from queue */
498 if (MAPTST(m, n)) /* continue if already visited */
500 MAPSET(m, n); /* mark as visited */
503 s = pool->solvables + n; /* s = Solvable in question */
506 if (installed /* Installed system available */
507 && s->repo == installed /* solvable is installed */
508 && !solv->fixmap_all /* NOT repair errors in rpm dependency graph */
509 && !(solv->fixmap.size && MAPTST(&solv->fixmap, n - installed->start)))
511 dontfix = 1; /* dont care about broken rpm deps */
515 && s->arch != ARCH_SRC
516 && s->arch != ARCH_NOSRC
517 && !pool_installable(pool, s))
519 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", pool_solvable2str(pool, s), (Id)(s - pool->solvables));
520 addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOT_INSTALLABLE, 0);
523 /* yet another SUSE hack, sigh */
524 if (pool->nscallback && !strncmp("product:", pool_id2str(pool, s->name), 8))
526 Id buddy = pool->nscallback(pool, pool->nscallbackdata, NAMESPACE_PRODUCTBUDDY, n);
527 if (buddy > 0 && buddy != SYSTEMSOLVABLE && buddy != n && buddy < pool->nsolvables)
529 addrpmrule(solv, n, -buddy, SOLVER_RULE_RPM_PACKAGE_REQUIRES, solvable_selfprovidedep(pool->solvables + n));
530 addrpmrule(solv, buddy, -n, SOLVER_RULE_RPM_PACKAGE_REQUIRES, solvable_selfprovidedep(pool->solvables + buddy));
531 if (m && !MAPTST(m, buddy))
532 queue_push(&workq, buddy);
536 /*-----------------------------------------
537 * check requires of s
542 reqp = s->repo->idarraydata + s->requires;
543 while ((req = *reqp++) != 0) /* go through all requires */
545 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
548 /* find list of solvables providing 'req' */
549 dp = pool_whatprovides_ptr(pool, req);
551 if (*dp == SYSTEMSOLVABLE) /* always installed */
556 /* the strategy here is to not insist on dependencies
557 * that are already broken. so if we find one provider
558 * that was already installed, we know that the
559 * dependency was not broken before so we enforce it */
561 /* check if any of the providers for 'req' is installed */
562 for (i = 0; (p = dp[i]) != 0; i++)
564 if (pool->solvables[p].repo == installed)
565 break; /* provider was installed */
567 /* didn't find an installed provider: previously broken dependency */
570 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", pool_dep2str(pool, req), pool_solvable2str(pool, s));
577 /* nothing provides req! */
578 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", pool_solvable2str(pool, s), (Id)(s - pool->solvables), pool_dep2str(pool, req));
579 addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP, req);
583 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
585 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, req));
586 for (i = 0; dp[i]; i++)
587 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", pool_solvid2str(pool, dp[i]));
590 /* add 'requires' dependency */
591 /* rule: (-requestor|provider1|provider2|...|providerN) */
592 addrpmrule(solv, -n, dp - pool->whatprovidesdata, SOLVER_RULE_RPM_PACKAGE_REQUIRES, req);
594 /* descend the dependency tree
595 push all non-visited providers on the work queue */
601 queue_push(&workq, *dp);
605 } /* while, requirements of n */
607 } /* if, requirements */
609 /* that's all we check for src packages */
610 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
613 /*-----------------------------------------
614 * check conflicts of s
621 /* we treat conflicts in patches a bit differen:
623 * - multiversion handling
624 * XXX: we should really handle this different, looking
625 * at the name is a bad hack
627 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
629 conp = s->repo->idarraydata + s->conflicts;
630 /* foreach conflicts of 's' */
631 while ((con = *conp++) != 0)
633 /* foreach providers of a conflict of 's' */
634 FOR_PROVIDES(p, pp, con)
636 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, con))
638 /* dontfix: dont care about conflicts with already installed packs */
639 if (dontfix && pool->solvables[p].repo == installed)
641 /* p == n: self conflict */
642 if (p == n && !pool->allowselfconflicts)
646 Reldep *rd = GETRELDEP(pool, con);
647 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
650 p = 0; /* make it a negative assertion, aka 'uninstallable' */
652 if (p && ispatch && solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p) && ISRELDEP(con))
654 /* our patch conflicts with a noobsoletes (aka multiversion) package */
655 p = -makemultiversionconflict(solv, p, con);
657 /* rule: -n|-p: either solvable _or_ provider of conflict */
658 addrpmrule(solv, -n, -p, p ? SOLVER_RULE_RPM_PACKAGE_CONFLICT : SOLVER_RULE_RPM_SELF_CONFLICT, con);
663 /*-----------------------------------------
664 * check obsoletes and implicit obsoletes of a package
665 * if ignoreinstalledsobsoletes is not set, we're also checking
666 * obsoletes of installed packages (like newer rpm versions)
668 if ((!installed || s->repo != installed) || !pool->noinstalledobsoletes)
670 int noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n);
671 int isinstalled = (installed && s->repo == installed);
672 if (s->obsoletes && !noobs)
674 obsp = s->repo->idarraydata + s->obsoletes;
675 /* foreach obsoletes */
676 while ((obs = *obsp++) != 0)
678 /* foreach provider of an obsoletes of 's' */
679 FOR_PROVIDES(p, pp, obs)
681 Solvable *ps = pool->solvables + p;
684 if (isinstalled && dontfix && ps->repo == installed)
685 continue; /* don't repair installed/installed problems */
686 if (!pool->obsoleteusesprovides /* obsoletes are matched names, not provides */
687 && !pool_match_nevr(pool, ps, obs))
689 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
692 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_PACKAGE_OBSOLETES, obs);
694 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES, obs);
698 /* check implicit obsoletes
699 * for installed packages we only need to check installed/installed problems (and
700 * only when dontfix is not set), as the others are picked up when looking at the
701 * uninstalled package.
703 if (!isinstalled || !dontfix)
705 FOR_PROVIDES(p, pp, s->name)
707 Solvable *ps = pool->solvables + p;
710 if (isinstalled && ps->repo != installed)
712 /* we still obsolete packages with same nevra, like rpm does */
713 /* (actually, rpm mixes those packages. yuck...) */
714 if (noobs && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
716 if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
718 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
720 if (s->name == ps->name)
721 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_SAME_NAME, 0);
723 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_IMPLICIT_OBSOLETES, s->name);
728 /*-----------------------------------------
729 * add recommends to the work queue
731 if (s->recommends && m)
733 recp = s->repo->idarraydata + s->recommends;
734 while ((rec = *recp++) != 0)
736 FOR_PROVIDES(p, pp, rec)
738 queue_push(&workq, p);
741 if (s->suggests && m)
743 sugp = s->repo->idarraydata + s->suggests;
744 while ((sug = *sugp++) != 0)
746 FOR_PROVIDES(p, pp, sug)
748 queue_push(&workq, p);
753 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
757 /*-------------------------------------------------------------------
759 * Add rules for packages possibly selected in by weak dependencies
761 * m: already added solvables
765 solver_addrpmrulesforweak(Solver *solv, Map *m)
767 Pool *pool = solv->pool;
772 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
773 /* foreach solvable in pool */
774 for (i = n = 1; n < pool->nsolvables; i++, n++)
776 if (i == pool->nsolvables) /* wrap i */
778 if (MAPTST(m, i)) /* already added that one */
781 s = pool->solvables + i;
782 if (!pool_installable(pool, s)) /* only look at installable ones */
788 /* find possible supplements */
789 supp = s->repo->idarraydata + s->supplements;
790 while ((sup = *supp++) != 0)
791 if (dep_possible(solv, sup, m))
795 /* if nothing found, check for enhances */
796 if (!sup && s->enhances)
798 supp = s->repo->idarraydata + s->enhances;
799 while ((sup = *supp++) != 0)
800 if (dep_possible(solv, sup, m))
803 /* if nothing found, goto next solvables */
806 solver_addrpmrulesforsolvable(solv, s, m);
807 n = 0; /* check all solvables again because we added solvables to m */
809 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
813 /*-------------------------------------------------------------------
815 * add package rules for possible updates
818 * m: map of already visited solvables
819 * allow_all: 0 = dont allow downgrades, 1 = allow all candidates
823 solver_addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
825 Pool *pool = solv->pool;
827 /* queue and buffer for it */
831 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
833 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
834 /* find update candidates for 's' */
835 policy_findupdatepackages(solv, s, &qs, allow_all);
836 /* add rule for 's' if not already done */
837 if (!MAPTST(m, s - pool->solvables))
838 solver_addrpmrulesforsolvable(solv, s, m);
839 /* foreach update candidate, add rule if not already done */
840 for (i = 0; i < qs.count; i++)
841 if (!MAPTST(m, qs.elements[i]))
842 solver_addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
845 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
849 /***********************************************************************
851 *** Update/Feature rule part
853 *** Those rules make sure an installed package isn't silently deleted
858 finddistupgradepackages(Solver *solv, Solvable *s, Queue *qs, int allow_all)
860 Pool *pool = solv->pool;
863 policy_findupdatepackages(solv, s, qs, allow_all);
867 return 0; /* orphaned, don't create feature rule */
868 /* check if this is an orphaned package */
869 policy_findupdatepackages(solv, s, qs, 1);
871 return 0; /* orphaned, don't create update rule */
873 return -SYSTEMSOLVABLE; /* supported but not installable */
876 return s - pool->solvables;
877 /* check if it is ok to keep the installed package */
878 for (i = 0; i < qs->count; i++)
880 Solvable *ns = pool->solvables + qs->elements[i];
881 if (s->evr == ns->evr && solvable_identical(s, ns))
882 return s - pool->solvables;
884 /* nope, it must be some other package */
885 return -SYSTEMSOLVABLE;
888 /* add packages from the dup repositories to the update candidates
889 * this isn't needed for the global dup mode as all packages are
890 * from dup repos in that case */
892 addduppackages(Solver *solv, Solvable *s, Queue *qs)
897 int oldnoupdateprovide = solv->noupdateprovide;
899 queue_init_buffer(&dupqs, dupqsbuf, sizeof(dupqsbuf)/sizeof(*dupqsbuf));
900 solv->noupdateprovide = 1;
901 policy_findupdatepackages(solv, s, &dupqs, 2);
902 solv->noupdateprovide = oldnoupdateprovide;
903 for (i = 0; i < dupqs.count; i++)
905 p = dupqs.elements[i];
906 if (MAPTST(&solv->dupmap, p))
907 queue_pushunique(qs, p);
912 /*-------------------------------------------------------------------
914 * add rule for update
915 * (A|A1|A2|A3...) An = update candidates for A
917 * s = (installed) solvable
921 solver_addupdaterule(Solver *solv, Solvable *s, int allow_all)
923 /* installed packages get a special upgrade allowed rule */
924 Pool *pool = solv->pool;
929 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
930 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
931 p = s - pool->solvables;
932 /* find update candidates for 's' */
933 if (solv->dupmap_all)
934 p = finddistupgradepackages(solv, s, &qs, allow_all);
936 policy_findupdatepackages(solv, s, &qs, allow_all);
937 if (!allow_all && !solv->dupmap_all && solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
938 addduppackages(solv, s, &qs);
940 if (!allow_all && qs.count && solv->noobsoletes.size)
944 d = pool_queuetowhatprovides(pool, &qs);
945 /* filter out all noobsoletes packages as they don't update */
946 for (i = j = 0; i < qs.count; i++)
948 if (MAPTST(&solv->noobsoletes, qs.elements[i]))
950 /* it's ok if they have same nevra */
951 Solvable *ps = pool->solvables + qs.elements[i];
952 if (ps->name != s->name || ps->evr != s->evr || ps->arch != s->arch)
955 qs.elements[j++] = qs.elements[i];
959 if (d && solv->installed && s->repo == solv->installed &&
960 (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, s - pool->solvables - solv->installed->start))))
962 if (!solv->multiversionupdaters)
963 solv->multiversionupdaters = sat_calloc(solv->installed->end - solv->installed->start, sizeof(Id));
964 solv->multiversionupdaters[s - pool->solvables - solv->installed->start] = d;
966 if (j == 0 && p == -SYSTEMSOLVABLE && solv->dupmap_all)
968 queue_push(&solv->orphaned, s - pool->solvables); /* treat as orphaned */
974 if (qs.count && p == -SYSTEMSOLVABLE)
975 p = queue_shift(&qs);
976 d = qs.count ? pool_queuetowhatprovides(pool, &qs) : 0;
978 solver_addrule(solv, p, d); /* allow update of s */
979 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
983 disableupdaterule(Solver *solv, Id p)
987 MAPSET(&solv->noupdate, p - solv->installed->start);
988 r = solv->rules + solv->updaterules + (p - solv->installed->start);
989 if (r->p && r->d >= 0)
990 solver_disablerule(solv, r);
991 r = solv->rules + solv->featurerules + (p - solv->installed->start);
992 if (r->p && r->d >= 0)
993 solver_disablerule(solv, r);
997 reenableupdaterule(Solver *solv, Id p)
999 Pool *pool = solv->pool;
1002 MAPCLR(&solv->noupdate, p - solv->installed->start);
1003 r = solv->rules + solv->updaterules + (p - solv->installed->start);
1008 solver_enablerule(solv, r);
1009 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1011 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1012 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1016 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1017 if (r->p && r->d < 0)
1019 solver_enablerule(solv, r);
1020 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1022 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1023 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1029 /***********************************************************************
1031 *** Infarch rule part
1033 *** Infarch rules make sure the solver uses the best architecture of
1034 *** a package if multiple archetectures are available
1039 solver_addinfarchrules(Solver *solv, Map *addedmap)
1041 Pool *pool = solv->pool;
1043 Id p, pp, a, aa, bestarch;
1044 Solvable *s, *ps, *bests;
1045 Queue badq, allowedarchs;
1048 queue_init(&allowedarchs);
1049 solv->infarchrules = solv->nrules;
1050 for (i = 1; i < pool->nsolvables; i++)
1052 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1054 s = pool->solvables + i;
1058 queue_empty(&allowedarchs);
1059 FOR_PROVIDES(p, pp, s->name)
1061 ps = pool->solvables + p;
1062 if (ps->name != s->name || !MAPTST(addedmap, p))
1069 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1070 if (a != 1 && pool->installed && ps->repo == pool->installed)
1072 if (!solv->dupmap_all && !(solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
1073 queue_pushunique(&allowedarchs, ps->arch); /* also ok to keep this architecture */
1074 continue; /* ignore installed solvables when calculating the best arch */
1076 if (a && a != 1 && (!bestarch || a < bestarch))
1084 /* speed up common case where installed package already has best arch */
1085 if (allowedarchs.count == 1 && bests && allowedarchs.elements[0] == bests->arch)
1086 allowedarchs.count--; /* installed arch is best */
1088 FOR_PROVIDES(p, pp, s->name)
1090 ps = pool->solvables + p;
1091 if (ps->name != s->name || !MAPTST(addedmap, p))
1094 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1095 if (a != 1 && bestarch && ((a ^ bestarch) & 0xffff0000) != 0)
1097 if (pool->installed && ps->repo == pool->installed)
1098 continue; /* always ok to keep an installed package */
1099 for (j = 0; j < allowedarchs.count; j++)
1101 aa = allowedarchs.elements[j];
1104 aa = (aa <= pool->lastarch) ? pool->id2arch[aa] : 0;
1105 if (aa && ((a ^ aa) & 0xffff0000) == 0)
1106 break; /* compatible */
1108 if (j == allowedarchs.count)
1109 queue_push(&badq, p);
1114 /* block all solvables in the badq! */
1115 for (j = 0; j < badq.count; j++)
1117 p = badq.elements[j];
1118 solver_addrule(solv, -p, 0);
1122 queue_free(&allowedarchs);
1123 solv->infarchrules_end = solv->nrules;
1127 disableinfarchrule(Solver *solv, Id name)
1129 Pool *pool = solv->pool;
1132 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1134 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1135 solver_disablerule(solv, r);
1140 reenableinfarchrule(Solver *solv, Id name)
1142 Pool *pool = solv->pool;
1145 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1147 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1149 solver_enablerule(solv, r);
1150 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1152 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1153 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1160 /***********************************************************************
1164 *** Dup rules make sure a package is selected from the specified dup
1165 *** repositories if an update candidate is included in one of them.
1170 solver_createdupmaps(Solver *solv)
1172 Queue *job = &solv->job;
1173 Pool *pool = solv->pool;
1175 Id how, what, p, pi, pp, obs, *obsp;
1179 map_init(&solv->dupmap, pool->nsolvables);
1180 map_init(&solv->dupinvolvedmap, pool->nsolvables);
1181 for (i = 0; i < job->count; i += 2)
1183 how = job->elements[i];
1184 what = job->elements[i + 1];
1185 switch (how & SOLVER_JOBMASK)
1187 case SOLVER_DISTUPGRADE:
1188 if ((how & SOLVER_SELECTMASK) != SOLVER_SOLVABLE_REPO)
1190 if (what <= 0 || what > pool->nrepos)
1192 repo = pool_id2repo(pool, what);
1193 FOR_REPO_SOLVABLES(repo, p, s)
1195 MAPSET(&solv->dupmap, p);
1196 FOR_PROVIDES(pi, pp, s->name)
1198 ps = pool->solvables + pi;
1199 if (ps->name != s->name)
1201 MAPSET(&solv->dupinvolvedmap, pi);
1205 /* FIXME: check obsoletes/provides combination */
1206 obsp = s->repo->idarraydata + s->obsoletes;
1207 while ((obs = *obsp++) != 0)
1209 FOR_PROVIDES(pi, pp, obs)
1211 Solvable *pis = pool->solvables + pi;
1212 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pis, obs))
1214 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, pis))
1216 MAPSET(&solv->dupinvolvedmap, pi);
1226 MAPCLR(&solv->dupinvolvedmap, SYSTEMSOLVABLE);
1230 solver_freedupmaps(Solver *solv)
1232 map_free(&solv->dupmap);
1233 /* we no longer free solv->dupinvolvedmap as we need it in
1234 * policy's priority pruning code. sigh. */
1238 solver_addduprules(Solver *solv, Map *addedmap)
1240 Pool *pool = solv->pool;
1245 solv->duprules = solv->nrules;
1246 for (i = 1; i < pool->nsolvables; i++)
1248 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1250 s = pool->solvables + i;
1252 FOR_PROVIDES(p, pp, s->name)
1254 ps = pool->solvables + p;
1255 if (ps->name != s->name || !MAPTST(addedmap, p))
1261 if (!MAPTST(&solv->dupinvolvedmap, p))
1263 if (solv->installed && ps->repo == solv->installed)
1265 if (!solv->updatemap.size)
1266 map_grow(&solv->updatemap, solv->installed->end - solv->installed->start);
1267 MAPSET(&solv->updatemap, p - solv->installed->start);
1268 if (!MAPTST(&solv->dupmap, p))
1271 /* is installed identical to a good one? */
1272 FOR_PROVIDES(ip, ipp, ps->name)
1274 Solvable *is = pool->solvables + ip;
1275 if (!MAPTST(&solv->dupmap, ip))
1277 if (is->evr == ps->evr && solvable_identical(ps, is))
1281 solver_addrule(solv, -p, 0); /* no match, sorry */
1284 else if (!MAPTST(&solv->dupmap, p))
1285 solver_addrule(solv, -p, 0);
1288 solv->duprules_end = solv->nrules;
1293 disableduprule(Solver *solv, Id name)
1295 Pool *pool = solv->pool;
1298 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1300 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1301 solver_disablerule(solv, r);
1306 reenableduprule(Solver *solv, Id name)
1308 Pool *pool = solv->pool;
1311 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1313 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1315 solver_enablerule(solv, r);
1316 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1318 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1319 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1326 /***********************************************************************
1328 *** Policy rule disabling/reenabling
1330 *** Disable all policy rules that conflict with our jobs. If a job
1331 *** gets disabled later on, reenable the involved policy rules again.
1335 #define DISABLE_UPDATE 1
1336 #define DISABLE_INFARCH 2
1337 #define DISABLE_DUP 3
1340 jobtodisablelist(Solver *solv, Id how, Id what, Queue *q)
1342 Pool *pool = solv->pool;
1346 int i, j, set, qstart, pass;
1349 installed = solv->installed;
1350 select = how & SOLVER_SELECTMASK;
1351 switch (how & SOLVER_JOBMASK)
1353 case SOLVER_INSTALL:
1354 set = how & SOLVER_SETMASK;
1355 if (!(set & SOLVER_NOAUTOSET))
1357 /* automatically add set bits by analysing the job */
1358 if (select == SOLVER_SOLVABLE)
1359 set |= SOLVER_SETARCH | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_SETEVR;
1360 else if ((select == SOLVER_SOLVABLE_NAME || select == SOLVER_SOLVABLE_PROVIDES) && ISRELDEP(what))
1362 Reldep *rd = GETRELDEP(pool, what);
1363 if (rd->flags == REL_EQ && select == SOLVER_SOLVABLE_NAME)
1365 #if !defined(DEBIAN_SEMANTICS)
1366 const char *evr = pool_id2str(pool, rd->evr);
1367 if (strchr(evr, '-'))
1368 set |= SOLVER_SETEVR;
1370 set |= SOLVER_SETEV;
1372 set |= SOLVER_SETEVR;
1375 if (rd->flags <= 7 && ISRELDEP(rd->name))
1376 rd = GETRELDEP(pool, rd->name);
1377 if (rd->flags == REL_ARCH)
1378 set |= SOLVER_SETARCH;
1382 set &= ~SOLVER_NOAUTOSET;
1385 if ((set & SOLVER_SETARCH) != 0 && solv->infarchrules != solv->infarchrules_end)
1387 if (select == SOLVER_SOLVABLE)
1388 queue_push2(q, DISABLE_INFARCH, pool->solvables[what].name);
1391 int qcnt = q->count;
1392 FOR_JOB_SELECT(p, pp, select, what)
1394 s = pool->solvables + p;
1396 for (i = qcnt; i < q->count; i += 2)
1397 if (q->elements[i + 1] == s->name)
1401 queue_push2(q, DISABLE_INFARCH, s->name);
1405 if ((set & SOLVER_SETREPO) != 0 && solv->duprules != solv->duprules_end)
1407 if (select == SOLVER_SOLVABLE)
1408 queue_push2(q, DISABLE_DUP, pool->solvables[what].name);
1411 int qcnt = q->count;
1412 FOR_JOB_SELECT(p, pp, select, what)
1414 s = pool->solvables + p;
1416 for (i = qcnt; i < q->count; i += 2)
1417 if (q->elements[i + 1] == s->name)
1421 queue_push2(q, DISABLE_DUP, s->name);
1427 /* now the hard part: disable some update rules */
1429 /* first check if we have noobs or installed packages in the job */
1430 FOR_JOB_SELECT(p, pp, select, what)
1432 if (pool->solvables[p].repo == installed)
1434 if (select == SOLVER_SOLVABLE)
1435 queue_push2(q, DISABLE_UPDATE, what);
1438 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p))
1442 /* all job packages obsolete */
1445 memset(&omap, 0, sizeof(omap));
1446 FOR_JOB_SELECT(p, pp, select, what)
1451 map_grow(&omap, installed->end - installed->start);
1452 s = pool->solvables + p;
1456 obsp = s->repo->idarraydata + s->obsoletes;
1457 while ((obs = *obsp++) != 0)
1458 FOR_PROVIDES(p2, pp2, obs)
1460 Solvable *ps = pool->solvables + p2;
1461 if (ps->repo != installed)
1463 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
1465 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1468 MAPSET(&omap, p2 - installed->start);
1470 queue_push2(q, DISABLE_UPDATE, p2);
1473 FOR_PROVIDES(p2, pp2, s->name)
1475 Solvable *ps = pool->solvables + p2;
1476 if (ps->repo != installed)
1478 if (!pool->implicitobsoleteusesprovides && ps->name != s->name)
1480 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1483 MAPSET(&omap, p2 - installed->start);
1485 queue_push2(q, DISABLE_UPDATE, p2);
1489 for (i = j = qstart; i < q->count; i += 2)
1491 if (MAPTST(&omap, q->elements[i + 1] - installed->start))
1493 MAPCLR(&omap, q->elements[i + 1] - installed->start);
1494 q->elements[j + 1] = q->elements[i + 1];
1498 queue_truncate(q, j);
1500 if (q->count == qstart)
1507 if (qstart == q->count)
1508 return; /* nothing to prune */
1509 if ((set & (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR)) == (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR))
1510 return; /* all is set */
1512 /* now that we know which installed packages are obsoleted check each of them */
1513 for (i = j = qstart; i < q->count; i += 2)
1515 Solvable *is = pool->solvables + q->elements[i + 1];
1516 FOR_JOB_SELECT(p, pp, select, what)
1519 s = pool->solvables + p;
1520 if ((set & SOLVER_SETEVR) != 0)
1521 illegal |= POLICY_ILLEGAL_DOWNGRADE; /* ignore */
1522 if ((set & SOLVER_SETARCH) != 0)
1523 illegal |= POLICY_ILLEGAL_ARCHCHANGE; /* ignore */
1524 if ((set & SOLVER_SETVENDOR) != 0)
1525 illegal |= POLICY_ILLEGAL_VENDORCHANGE; /* ignore */
1526 illegal = policy_is_illegal(solv, is, s, illegal);
1527 if (illegal && illegal == POLICY_ILLEGAL_DOWNGRADE && (set & SOLVER_SETEV) != 0)
1529 /* it's ok if the EV is different */
1530 if (pool_evrcmp(pool, is->evr, s->evr, EVRCMP_COMPARE_EVONLY) != 0)
1538 /* no package conflicts with the update rule */
1539 /* thus keep the DISABLE_UPDATE */
1540 q->elements[j + 1] = q->elements[i + 1];
1544 queue_truncate(q, j);
1550 FOR_JOB_SELECT(p, pp, select, what)
1551 if (pool->solvables[p].repo == installed)
1552 queue_push2(q, DISABLE_UPDATE, p);
1559 /* disable all policy rules that are in conflict with our job list */
1561 solver_disablepolicyrules(Solver *solv)
1563 Queue *job = &solv->job;
1570 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
1572 for (i = solv->jobrules; i < solv->jobrules_end; i++)
1574 r = solv->rules + i;
1575 if (r->d < 0) /* disabled? */
1577 j = solv->ruletojob.elements[i - solv->jobrules];
1581 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
1583 if (solv->cleandepsmap.size)
1585 solver_createcleandepsmap(solv);
1586 for (i = solv->installed->start; i < solv->installed->end; i++)
1587 if (MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1588 queue_push2(&allq, DISABLE_UPDATE, i);
1590 MAPZERO(&solv->noupdate);
1591 for (i = 0; i < allq.count; i += 2)
1593 Id type = allq.elements[i], arg = allq.elements[i + 1];
1596 case DISABLE_UPDATE:
1597 disableupdaterule(solv, arg);
1599 case DISABLE_INFARCH:
1600 disableinfarchrule(solv, arg);
1603 disableduprule(solv, arg);
1612 /* we just disabled job #jobidx, now reenable all policy rules that were
1613 * disabled because of this job */
1615 solver_reenablepolicyrules(Solver *solv, int jobidx)
1617 Queue *job = &solv->job;
1622 Id qbuf[32], allqbuf[128];
1624 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1625 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
1626 jobtodisablelist(solv, job->elements[jobidx], job->elements[jobidx + 1], &q);
1629 for (i = solv->jobrules; i < solv->jobrules_end; i++)
1631 r = solv->rules + i;
1632 if (r->d < 0) /* disabled? */
1634 j = solv->ruletojob.elements[i - solv->jobrules];
1638 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
1640 if (solv->cleandepsmap.size)
1642 solver_createcleandepsmap(solv);
1643 for (i = solv->installed->start; i < solv->installed->end; i++)
1644 if (MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1645 queue_push2(&allq, DISABLE_UPDATE, i);
1647 for (j = 0; j < q.count; j += 2)
1649 Id type = q.elements[j], arg = q.elements[j + 1];
1650 for (i = 0; i < allq.count; i += 2)
1651 if (allq.elements[i] == type && allq.elements[i + 1] == arg)
1654 continue; /* still disabled */
1657 case DISABLE_UPDATE:
1658 reenableupdaterule(solv, arg);
1660 case DISABLE_INFARCH:
1661 reenableinfarchrule(solv, arg);
1664 reenableduprule(solv, arg);
1673 /***********************************************************************
1675 *** Rule info part, tell the user what the rule is about.
1680 addrpmruleinfo(Solver *solv, Id p, Id d, int type, Id dep)
1682 Pool *pool = solv->pool;
1686 /* check if this creates the rule we're searching for */
1687 r = solv->rules + solv->ruleinfoq->elements[0];
1689 od = r->d < 0 ? -r->d - 1 : r->d;
1694 if (p < 0 && d > 0 && (!pool->whatprovidesdata[d] || !pool->whatprovidesdata[d + 1]))
1696 w2 = pool->whatprovidesdata[d];
1700 if (p > 0 && d < 0) /* this hack is used for buddy deps */
1712 Id *dp = pool->whatprovidesdata + d;
1713 Id *odp = pool->whatprovidesdata + od;
1715 if (*dp++ != *odp++)
1721 /* handle multiversion conflict rules */
1722 if (p < 0 && pool->whatprovidesdata[d] < 0)
1724 w2 = pool->whatprovidesdata[d];
1725 /* XXX: free memory */
1735 if (w2 != op || p != ow2)
1740 if (p != op || w2 != ow2)
1744 /* yep, rule matches. record info */
1745 queue_push(solv->ruleinfoq, type);
1746 if (type == SOLVER_RULE_RPM_SAME_NAME)
1748 /* we normalize same name order */
1749 queue_push(solv->ruleinfoq, op < 0 ? -op : 0);
1750 queue_push(solv->ruleinfoq, ow2 < 0 ? -ow2 : 0);
1754 queue_push(solv->ruleinfoq, p < 0 ? -p : 0);
1755 queue_push(solv->ruleinfoq, w2 < 0 ? -w2 : 0);
1757 queue_push(solv->ruleinfoq, dep);
1761 solver_allruleinfos_cmp(const void *ap, const void *bp, void *dp)
1763 const Id *a = ap, *b = bp;
1782 solver_allruleinfos(Solver *solv, Id rid, Queue *rq)
1784 Pool *pool = solv->pool;
1785 Rule *r = solv->rules + rid;
1789 if (rid <= 0 || rid >= solv->rpmrules_end)
1791 Id type, from, to, dep;
1792 type = solver_ruleinfo(solv, rid, &from, &to, &dep);
1793 queue_push(rq, type);
1794 queue_push(rq, from);
1796 queue_push(rq, dep);
1801 queue_push(rq, rid);
1802 solv->ruleinfoq = rq;
1803 solver_addrpmrulesforsolvable(solv, pool->solvables - r->p, 0);
1804 /* also try reverse direction for conflicts */
1805 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
1806 solver_addrpmrulesforsolvable(solv, pool->solvables - r->w2, 0);
1807 solv->ruleinfoq = 0;
1809 /* now sort & unify em */
1812 sat_sort(rq->elements, rq->count / 4, 4 * sizeof(Id), solver_allruleinfos_cmp, 0);
1813 /* throw out identical entries */
1814 for (i = j = 0; i < rq->count; i += 4)
1818 if (rq->elements[i] == rq->elements[j - 4] &&
1819 rq->elements[i + 1] == rq->elements[j - 3] &&
1820 rq->elements[i + 2] == rq->elements[j - 2] &&
1821 rq->elements[i + 3] == rq->elements[j - 1])
1824 rq->elements[j++] = rq->elements[i];
1825 rq->elements[j++] = rq->elements[i + 1];
1826 rq->elements[j++] = rq->elements[i + 2];
1827 rq->elements[j++] = rq->elements[i + 3];
1834 solver_ruleinfo(Solver *solv, Id rid, Id *fromp, Id *top, Id *depp)
1836 Pool *pool = solv->pool;
1837 Rule *r = solv->rules + rid;
1838 SolverRuleinfo type = SOLVER_RULE_UNKNOWN;
1846 if (rid > 0 && rid < solv->rpmrules_end)
1852 return SOLVER_RULE_RPM;
1856 queue_push(&rq, rid);
1857 solv->ruleinfoq = &rq;
1858 solver_addrpmrulesforsolvable(solv, pool->solvables - r->p, 0);
1859 /* also try reverse direction for conflicts */
1860 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
1861 solver_addrpmrulesforsolvable(solv, pool->solvables - r->w2, 0);
1862 solv->ruleinfoq = 0;
1863 type = SOLVER_RULE_RPM;
1864 for (i = 1; i < rq.count; i += 4)
1867 qt = rq.elements[i];
1868 qp = rq.elements[i + 1];
1869 qo = rq.elements[i + 2];
1870 qd = rq.elements[i + 3];
1871 if (type == SOLVER_RULE_RPM || type > qt)
1885 if (rid >= solv->jobrules && rid < solv->jobrules_end)
1887 Id jidx = solv->ruletojob.elements[rid - solv->jobrules];
1891 *top = solv->job.elements[jidx];
1893 *depp = solv->job.elements[jidx + 1];
1894 if ((r->d == 0 || r->d == -1) && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && (solv->job.elements[jidx] & SOLVER_SELECTMASK) != SOLVER_SOLVABLE_ONE_OF)
1895 return SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP;
1896 return SOLVER_RULE_JOB;
1898 if (rid >= solv->updaterules && rid < solv->updaterules_end)
1901 *fromp = solv->installed->start + (rid - solv->updaterules);
1902 return SOLVER_RULE_UPDATE;
1904 if (rid >= solv->featurerules && rid < solv->featurerules_end)
1907 *fromp = solv->installed->start + (rid - solv->featurerules);
1908 return SOLVER_RULE_FEATURE;
1910 if (rid >= solv->duprules && rid < solv->duprules_end)
1915 *depp = pool->solvables[-r->p].name;
1916 return SOLVER_RULE_DISTUPGRADE;
1918 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
1923 *depp = pool->solvables[-r->p].name;
1924 return SOLVER_RULE_INFARCH;
1926 if (rid >= solv->choicerules && rid < solv->choicerules_end)
1928 return SOLVER_RULE_CHOICE;
1930 if (rid >= solv->learntrules)
1932 return SOLVER_RULE_LEARNT;
1934 return SOLVER_RULE_UNKNOWN;
1938 solver_addchoicerules(Solver *solv)
1940 Pool *pool = solv->pool;
1944 int i, j, rid, havechoice;
1949 solv->choicerules = solv->nrules;
1950 if (!pool->installed)
1952 solv->choicerules_end = solv->nrules;
1955 solv->choicerules_ref = sat_calloc(solv->rpmrules_end, sizeof(Id));
1958 map_init(&m, pool->nsolvables);
1959 map_init(&mneg, pool->nsolvables);
1960 /* set up negative assertion map from infarch and dup rules */
1961 for (rid = solv->infarchrules, r = solv->rules + rid; rid < solv->infarchrules_end; rid++, r++)
1962 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
1963 MAPSET(&mneg, -r->p);
1964 for (rid = solv->duprules, r = solv->rules + rid; rid < solv->duprules_end; rid++, r++)
1965 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
1966 MAPSET(&mneg, -r->p);
1967 for (rid = 1; rid < solv->rpmrules_end ; rid++)
1969 r = solv->rules + rid;
1970 if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 < 0))
1971 continue; /* only look at requires rules */
1972 // solver_printrule(solv, SAT_DEBUG_RESULT, r);
1976 FOR_RULELITERALS(p, pp, r)
1980 s = pool->solvables + p;
1983 if (s->repo == pool->installed)
1988 /* check if this package is "blocked" by a installed package */
1990 FOR_PROVIDES(p2, pp2, s->name)
1992 s2 = pool->solvables + p2;
1993 if (s2->repo != pool->installed)
1995 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
1997 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
2003 /* found installed package p2 that we can update to p */
2004 if (MAPTST(&mneg, p))
2006 if (policy_is_illegal(solv, s2, s, 0))
2008 queue_push(&qi, p2);
2014 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
2016 while ((obs = *obsp++) != 0)
2018 FOR_PROVIDES(p2, pp2, obs)
2020 s2 = pool->solvables + p2;
2021 if (s2->repo != pool->installed)
2023 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
2025 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
2034 /* found installed package p2 that we can update to p */
2035 if (MAPTST(&mneg, p))
2037 if (policy_is_illegal(solv, s2, s, 0))
2039 queue_push(&qi, p2);
2044 /* package p is independent of the installed ones */
2047 if (!havechoice || !q.count)
2048 continue; /* no choice */
2050 /* now check the update rules of the installed package.
2051 * if all packages of the update rules are contained in
2052 * the dependency rules, there's no need to set up the choice rule */
2054 FOR_RULELITERALS(p, pp, r)
2057 for (i = 0; i < qi.count; i++)
2059 if (!qi.elements[i])
2061 Rule *ur = solv->rules + solv->updaterules + (qi.elements[i] - pool->installed->start);
2063 ur = solv->rules + solv->featurerules + (qi.elements[i] - pool->installed->start);
2066 FOR_RULELITERALS(p, pp, ur)
2071 for (j = i + 1; j < qi.count; j++)
2072 if (qi.elements[i] == qi.elements[j])
2078 printf("skipping choice ");
2079 solver_printrule(solv, SAT_DEBUG_RESULT, solv->rules + rid);
2083 d = q.count ? pool_queuetowhatprovides(pool, &q) : 0;
2084 solver_addrule(solv, r->p, d);
2085 queue_push(&solv->weakruleq, solv->nrules - 1);
2086 solv->choicerules_ref[solv->nrules - 1 - solv->choicerules] = rid;
2089 solver_printrule(solv, SAT_DEBUG_RESULT, solv->rules + rid);
2090 printf("WEAK CHOICE ");
2091 solver_printrule(solv, SAT_DEBUG_RESULT, solv->rules + solv->nrules - 1);
2098 solv->choicerules_end = solv->nrules;
2101 /* called when a choice rule is disabled by analyze_unsolvable. We also
2102 * have to disable all other choice rules so that the best packages get
2105 solver_disablechoicerules(Solver *solv, Rule *r)
2108 Pool *pool = solv->pool;
2112 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
2113 map_init(&m, pool->nsolvables);
2114 FOR_RULELITERALS(p, pp, or)
2117 FOR_RULELITERALS(p, pp, r)
2120 for (rid = solv->choicerules; rid < solv->choicerules_end; rid++)
2122 r = solv->rules + rid;
2125 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
2126 FOR_RULELITERALS(p, pp, or)
2127 if (p > 0 && MAPTST(&m, p))
2130 solver_disablerule(solv, r);
2134 static void solver_createcleandepsmap(Solver *solv)
2136 Pool *pool = solv->pool;
2137 Repo *installed = solv->installed;
2138 Queue *job = &solv->job;
2143 Id rid, how, what, select;
2145 Id req, *reqp, sup, *supp;
2150 map_init(&userinstalled, installed->end - installed->start);
2151 map_init(&im, pool->nsolvables);
2152 map_init(&installedm, pool->nsolvables);
2153 map_empty(&solv->cleandepsmap);
2156 for (i = 0; i < job->count; i += 2)
2158 how = job->elements[i];
2159 if ((how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
2161 what = job->elements[i + 1];
2162 select = how & SOLVER_SELECTMASK;
2163 FOR_JOB_SELECT(p, pp, select, what)
2164 if (pool->solvables[p].repo == installed)
2165 MAPSET(&userinstalled, p - installed->start);
2168 /* add all positive elements (e.g. locks) to "userinstalled" */
2169 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2171 r = solv->rules + rid;
2174 FOR_RULELITERALS(p, jp, r)
2175 if (p > 0 && pool->solvables[p].repo == installed)
2176 MAPSET(&userinstalled, p - installed->start);
2178 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2180 r = solv->rules + rid;
2181 if (r->p >= 0 || r->d != 0)
2182 continue; /* disabled or not erase */
2184 if (pool->solvables[p].repo != installed)
2186 MAPCLR(&userinstalled, p - installed->start);
2187 i = solv->ruletojob.elements[rid - solv->jobrules];
2188 how = job->elements[i];
2189 if ((how & (SOLVER_JOBMASK|SOLVER_CLEANDEPS)) == (SOLVER_ERASE|SOLVER_CLEANDEPS))
2192 for (p = installed->start; p < installed->end; p++)
2194 if (pool->solvables[p].repo != installed)
2196 MAPSET(&installedm, p);
2202 ip = queue_shift(&iq);
2203 s = pool->solvables + ip;
2204 if (!MAPTST(&im, ip))
2206 if (!MAPTST(&installedm, ip))
2208 if (s->repo == installed && MAPTST(&userinstalled, ip - installed->start))
2211 #ifdef CLEANDEPSDEBUG
2212 printf("hello %s\n", pool_solvable2str(pool, s));
2216 reqp = s->repo->idarraydata + s->requires;
2217 while ((req = *reqp++) != 0)
2219 if (req == SOLVABLE_PREREQMARKER)
2222 /* count number of installed packages that match */
2224 FOR_PROVIDES(p, pp, req)
2225 if (MAPTST(&installedm, p))
2230 FOR_PROVIDES(p, pp, req)
2234 #ifdef CLEANDEPSDEBUG
2235 printf("%s requires %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
2244 reqp = s->repo->idarraydata + s->recommends;
2245 while ((req = *reqp++) != 0)
2249 FOR_PROVIDES(p, pp, req)
2250 if (MAPTST(&installedm, p))
2255 FOR_PROVIDES(p, pp, req)
2259 #ifdef CLEANDEPSDEBUG
2260 printf("%s recommends %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
2269 /* supplements pass */
2270 for (ip = solv->installed->start; ip < solv->installed->end; ip++)
2272 if (!MAPTST(&installedm, ip))
2274 s = pool->solvables + ip;
2275 if (!s->supplements)
2277 if (!MAPTST(&im, ip))
2279 supp = s->repo->idarraydata + s->supplements;
2280 while ((sup = *supp++) != 0)
2281 if (!dep_possible(solv, sup, &im) && dep_possible(solv, sup, &installedm))
2283 /* no longer supplemented, also erase */
2286 #ifdef CLEANDEPSDEBUG
2287 printf("%s supplemented\n", pool_solvid2str(pool, ip));
2289 queue_push(&iq, ip);
2295 /* turn userinstalled into remove set for pruning */
2296 map_empty(&userinstalled);
2297 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2299 r = solv->rules + rid;
2300 if (r->p >= 0 || r->d != 0)
2301 continue; /* disabled or not erase */
2304 if (pool->solvables[p].repo == installed)
2305 MAPSET(&userinstalled, p - installed->start);
2307 for (p = installed->start; p < installed->end; p++)
2310 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2312 r = solv->rules + rid;
2315 FOR_RULELITERALS(p, jp, r)
2319 /* also put directly addressed packages on the install queue
2320 * so we can mark patterns as installed */
2321 for (i = 0; i < job->count; i += 2)
2323 how = job->elements[i];
2324 if ((how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
2326 what = job->elements[i + 1];
2327 select = how & SOLVER_SELECTMASK;
2328 if (select == SOLVER_SOLVABLE && pool->solvables[what].repo != installed)
2329 queue_push(&iq, what);
2334 ip = queue_shift(&iq);
2335 s = pool->solvables + ip;
2336 #ifdef CLEANDEPSDEBUG
2337 printf("bye %s\n", pool_solvable2str(pool, s));
2341 reqp = s->repo->idarraydata + s->requires;
2342 while ((req = *reqp++) != 0)
2344 FOR_PROVIDES(p, pp, req)
2346 if (!MAPTST(&im, p) && MAPTST(&installedm, p))
2350 if (MAPTST(&userinstalled, p - installed->start))
2352 #ifdef CLEANDEPSDEBUG
2353 printf("%s requires %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
2363 reqp = s->repo->idarraydata + s->recommends;
2364 while ((req = *reqp++) != 0)
2366 FOR_PROVIDES(p, pp, req)
2368 if (!MAPTST(&im, p) && MAPTST(&installedm, p))
2372 if (MAPTST(&userinstalled, p - installed->start))
2374 #ifdef CLEANDEPSDEBUG
2375 printf("%s recommends %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
2385 /* supplements pass */
2386 for (ip = installed->start; ip < installed->end; ip++)
2388 if (!MAPTST(&installedm, ip))
2390 if (MAPTST(&userinstalled, ip - installed->start))
2392 s = pool->solvables + ip;
2393 if (!s->supplements)
2395 if (MAPTST(&im, ip) || !MAPTST(&installedm, ip))
2397 supp = s->repo->idarraydata + s->supplements;
2398 while ((sup = *supp++) != 0)
2399 if (dep_possible(solv, sup, &im))
2403 #ifdef CLEANDEPSDEBUG
2404 printf("%s supplemented\n", pool_solvid2str(pool, ip));
2407 queue_push(&iq, ip);
2414 for (p = installed->start; p < installed->end; p++)
2416 if (pool->solvables[p].repo != installed)
2418 if (!MAPTST(&im, p))
2419 MAPSET(&solv->cleandepsmap, p - installed->start);
2422 map_free(&installedm);
2423 map_free(&userinstalled);