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
41 dep_possible(Solver *solv, Id dep, Map *m)
43 Pool *pool = solv->pool;
48 Reldep *rd = GETRELDEP(pool, dep);
49 if (rd->flags == REL_AND)
51 if (!dep_possible(solv, rd->name, m))
53 return dep_possible(solv, rd->evr, m);
55 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
56 return solver_splitprovides(solv, rd->evr);
57 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
58 return solver_dep_installed(solv, rd->evr);
60 FOR_PROVIDES(p, pp, dep)
68 /********************************************************************
72 * - unify rules, remove duplicates
75 /*-------------------------------------------------------------------
77 * compare rules for unification sort
82 unifyrules_sortcmp(const void *ap, const void *bp, void *dp)
92 return x; /* p differs */
95 if (a->d == 0 && b->d == 0)
96 return a->w2 - b->w2; /* assertion: return w2 diff */
98 if (a->d == 0) /* a is assertion, b not */
100 x = a->w2 - pool->whatprovidesdata[b->d];
104 if (b->d == 0) /* b is assertion, a not */
106 x = pool->whatprovidesdata[a->d] - b->w2;
110 /* compare whatprovidesdata */
111 ad = pool->whatprovidesdata + a->d;
112 bd = pool->whatprovidesdata + b->d;
114 if ((x = *ad++ - *bd++) != 0)
120 solver_samerule(Solver *solv, Rule *r1, Rule *r2)
122 return unifyrules_sortcmp(r1, r2, solv->pool);
126 /*-------------------------------------------------------------------
129 * go over all rules and remove duplicates
133 solver_unifyrules(Solver *solv)
135 Pool *pool = solv->pool;
139 if (solv->nrules <= 1) /* nothing to unify */
142 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules -----\n");
144 /* sort rules first */
145 sat_sort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp, solv->pool);
152 for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
154 if (jr && !unifyrules_sortcmp(ir, jr, pool))
155 continue; /* prune! */
156 jr = solv->rules + j++; /* keep! */
161 /* reduced count from nrules to j rules */
162 POOL_DEBUG(SAT_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
164 /* adapt rule buffer */
166 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
169 * debug: log rule statistics
171 IF_POOLDEBUG (SAT_DEBUG_STATS)
178 for (i = 1; i < solv->nrules; i++)
185 dp = solv->pool->whatprovidesdata + r->d;
190 POOL_DEBUG(SAT_DEBUG_STATS, " binary: %d\n", binr);
191 POOL_DEBUG(SAT_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
193 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules end -----\n");
203 hashrule(Solver *solv, Id p, Id d, int n)
205 unsigned int x = (unsigned int)p;
209 return (x * 37) ^ (unsigned int)d;
210 dp = solv->pool->whatprovidesdata + d;
212 x = (x * 37) ^ (unsigned int)*dp++;
218 /*-------------------------------------------------------------------
224 * p = direct literal; always < 0 for installed rpm rules
225 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
228 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
230 * p < 0 : pkg id of A
231 * d > 0 : Offset in whatprovidesdata (list of providers of b)
233 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
234 * p < 0 : pkg id of A
235 * d < 0 : Id of solvable (e.g. B1)
237 * d == 0: unary rule, assertion => (A) or (-A)
239 * Install: p > 0, d = 0 (A) user requested install
240 * Remove: p < 0, d = 0 (-A) user requested remove (also: uninstallable)
241 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
242 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
243 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
244 * also used for obsoletes
245 * ?: p > 0, d < 0 (A|-B)
246 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
250 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
251 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
252 * every other : w1 = p, w2 = whatprovidesdata[d];
253 * Disabled rule: w1 = 0
255 * always returns a rule for non-rpm rules
259 solver_addrule(Solver *solv, Id p, Id d)
261 Pool *pool = solv->pool;
265 int n = 0; /* number of literals in rule - 1
266 0 = direct assertion (single literal)
271 /* it often happenes that requires lead to adding the same rpm rule
272 * multiple times, so we prune those duplicates right away to make
273 * the work for unifyrules a bit easier */
275 if (solv->nrules /* we already have rules */
276 && !solv->rpmrules_end) /* but are not done with rpm rules */
278 r = solv->rules + solv->nrules - 1; /* get the last added rule */
279 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
284 * compute number of literals (n) in rule
289 /* always a binary rule */
291 return 0; /* ignore self conflict */
296 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
298 return 0; /* rule is self-fulfilling */
300 if (n == 1) /* have single provider */
301 d = dp[-1]; /* take single literal */
304 if (n == 1 && p > d && !solv->rpmrules_end)
306 /* smallest literal first so we can find dups */
307 n = p; p = d; d = n; /* p <-> d */
308 n = 1; /* re-set n, was used as temp var */
312 * check for duplicate
315 /* check if the last added rule (r) is exactly the same as what we're looking for. */
316 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
317 return r; /* binary rule */
319 /* have n-ary rule with same first literal, check other literals */
320 if (r && n > 1 && r->d && r->p == p)
322 /* Rule where d is an offset in whatprovidesdata */
326 dp2 = pool->whatprovidesdata + r->d;
327 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
338 /* extend rule buffer */
339 solv->rules = sat_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
340 r = solv->rules + solv->nrules++; /* point to rule space */
349 /* direct assertion, no watch needed */
365 r->w2 = pool->whatprovidesdata[d];
370 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
372 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
373 solver_printrule(solv, SAT_DEBUG_RULE_CREATION, r);
380 /******************************************************************************
382 *** rpm rule part: create rules representing the package dependencies
387 * special multiversion patch conflict handling:
388 * a patch conflict is also satisfied if some other
389 * version with the same name/arch that doesn't conflict
390 * gets installed. The generated rule is thus:
391 * -patch|-cpack|opack1|opack2|...
394 makemultiversionconflict(Solver *solv, Id n, Id con)
396 Pool *pool = solv->pool;
401 sn = pool->solvables + n;
402 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
404 FOR_PROVIDES(p, pp, sn->name)
406 s = pool->solvables + p;
407 if (s->name != sn->name || s->arch != sn->arch)
409 if (!MAPTST(&solv->noobsoletes, p))
411 if (pool_match_nevr(pool, pool->solvables + p, con))
413 /* here we have a multiversion solvable that doesn't conflict */
414 /* thus we're not in conflict if it is installed */
418 return -n; /* no other package found, generate normal conflict */
419 return pool_queuetowhatprovides(pool, &q);
423 addrpmrule(Solver *solv, Id p, Id d, int type, Id dep)
425 if (!solv->ruleinfoq)
426 solver_addrule(solv, p, d);
428 addrpmruleinfo(solv, p, d, type, dep);
431 /*-------------------------------------------------------------------
433 * add (install) rules for solvable
435 * s: Solvable for which to add rules
436 * m: m[s] = 1 for solvables which have rules, prevent rule duplication
438 * Algorithm: 'visit all nodes of a graph'. The graph nodes are
439 * solvables, the edges their dependencies.
440 * Starting from an installed solvable, this will create all rules
441 * representing the graph created by the solvables dependencies.
443 * for unfulfilled requirements, conflicts, obsoletes,....
444 * add a negative assertion for solvables that are not installable
446 * It will also create rules for all solvables referenced by 's'
447 * i.e. descend to all providers of requirements of 's'
452 solver_addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
454 Pool *pool = solv->pool;
455 Repo *installed = solv->installed;
457 /* 'work' queue. keeps Ids of solvables we still have to work on.
458 And buffer for it. */
463 /* if to add rules for broken deps ('rpm -V' functionality)
467 /* Id var and pointer for each dependency
468 * (not used in parallel)
475 Id p, pp; /* whatprovides loops */
476 Id *dp; /* ptr to 'whatprovides' */
477 Id n; /* Id for current solvable 's' */
479 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
481 queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
482 queue_push(&workq, s - pool->solvables); /* push solvable Id to work queue */
484 /* loop until there's no more work left */
489 * s: Pointer to solvable
492 n = queue_shift(&workq); /* 'pop' next solvable to work on from queue */
495 if (MAPTST(m, n)) /* continue if already visited */
497 MAPSET(m, n); /* mark as visited */
500 s = pool->solvables + n; /* s = Solvable in question */
503 if (installed /* Installed system available */
504 && s->repo == installed /* solvable is installed */
505 && !solv->fixmap_all /* NOT repair errors in rpm dependency graph */
506 && !(solv->fixmap.size && MAPTST(&solv->fixmap, n - installed->start)))
508 dontfix = 1; /* dont care about broken rpm deps */
512 && s->arch != ARCH_SRC
513 && s->arch != ARCH_NOSRC
514 && !pool_installable(pool, s))
516 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
517 addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOT_INSTALLABLE, 0);
520 /* yet another SUSE hack, sigh */
521 if (pool->nscallback && !strncmp("product:", id2str(pool, s->name), 8))
523 Id buddy = pool->nscallback(pool, pool->nscallbackdata, NAMESPACE_PRODUCTBUDDY, n);
524 if (buddy > 0 && buddy != SYSTEMSOLVABLE && buddy != n && buddy < pool->nsolvables)
526 addrpmrule(solv, n, -buddy, SOLVER_RULE_RPM_PACKAGE_REQUIRES, solvable_selfprovidedep(pool->solvables + n));
527 addrpmrule(solv, buddy, -n, SOLVER_RULE_RPM_PACKAGE_REQUIRES, solvable_selfprovidedep(pool->solvables + buddy));
528 if (m && !MAPTST(m, buddy))
529 queue_push(&workq, buddy);
533 /*-----------------------------------------
534 * check requires of s
539 reqp = s->repo->idarraydata + s->requires;
540 while ((req = *reqp++) != 0) /* go through all requires */
542 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
545 /* find list of solvables providing 'req' */
546 dp = pool_whatprovides_ptr(pool, req);
548 if (*dp == SYSTEMSOLVABLE) /* always installed */
553 /* the strategy here is to not insist on dependencies
554 * that are already broken. so if we find one provider
555 * that was already installed, we know that the
556 * dependency was not broken before so we enforce it */
558 /* check if any of the providers for 'req' is installed */
559 for (i = 0; (p = dp[i]) != 0; i++)
561 if (pool->solvables[p].repo == installed)
562 break; /* provider was installed */
564 /* didn't find an installed provider: previously broken dependency */
567 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
574 /* nothing provides req! */
575 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
576 addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP, req);
580 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
582 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
583 for (i = 0; dp[i]; i++)
584 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvid2str(pool, dp[i]));
587 /* add 'requires' dependency */
588 /* rule: (-requestor|provider1|provider2|...|providerN) */
589 addrpmrule(solv, -n, dp - pool->whatprovidesdata, SOLVER_RULE_RPM_PACKAGE_REQUIRES, req);
591 /* descend the dependency tree
592 push all non-visited providers on the work queue */
598 queue_push(&workq, *dp);
602 } /* while, requirements of n */
604 } /* if, requirements */
606 /* that's all we check for src packages */
607 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
610 /*-----------------------------------------
611 * check conflicts of s
618 /* we treat conflicts in patches a bit differen:
620 * - multiversion handling
621 * XXX: we should really handle this different, looking
622 * at the name is a bad hack
624 if (!strncmp("patch:", id2str(pool, s->name), 6))
626 conp = s->repo->idarraydata + s->conflicts;
627 /* foreach conflicts of 's' */
628 while ((con = *conp++) != 0)
630 /* foreach providers of a conflict of 's' */
631 FOR_PROVIDES(p, pp, con)
633 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, con))
635 /* dontfix: dont care about conflicts with already installed packs */
636 if (dontfix && pool->solvables[p].repo == installed)
638 /* p == n: self conflict */
639 if (p == n && !pool->allowselfconflicts)
643 Reldep *rd = GETRELDEP(pool, con);
644 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
647 p = 0; /* make it a negative assertion, aka 'uninstallable' */
649 if (p && ispatch && solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p) && ISRELDEP(con))
651 /* our patch conflicts with a noobsoletes (aka multiversion) package */
652 p = -makemultiversionconflict(solv, p, con);
654 /* rule: -n|-p: either solvable _or_ provider of conflict */
655 addrpmrule(solv, -n, -p, p ? SOLVER_RULE_RPM_PACKAGE_CONFLICT : SOLVER_RULE_RPM_SELF_CONFLICT, con);
660 /*-----------------------------------------
661 * check obsoletes and implicit obsoletes of a package
662 * if ignoreinstalledsobsoletes is not set, we're also checking
663 * obsoletes of installed packages (like newer rpm versions)
665 if ((!installed || s->repo != installed) || !pool->noinstalledobsoletes)
667 int noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n);
668 int isinstalled = (installed && s->repo == installed);
669 if (s->obsoletes && !noobs)
671 obsp = s->repo->idarraydata + s->obsoletes;
672 /* foreach obsoletes */
673 while ((obs = *obsp++) != 0)
675 /* foreach provider of an obsoletes of 's' */
676 FOR_PROVIDES(p, pp, obs)
678 Solvable *ps = pool->solvables + p;
681 if (isinstalled && dontfix && ps->repo == installed)
682 continue; /* don't repair installed/installed problems */
683 if (!pool->obsoleteusesprovides /* obsoletes are matched names, not provides */
684 && !pool_match_nevr(pool, ps, obs))
686 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
689 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_PACKAGE_OBSOLETES, obs);
691 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES, obs);
695 /* check implicit obsoletes
696 * for installed packages we only need to check installed/installed problems (and
697 * only when dontfix is not set), as the others are picked up when looking at the
698 * uninstalled package.
700 if (!isinstalled || !dontfix)
702 FOR_PROVIDES(p, pp, s->name)
704 Solvable *ps = pool->solvables + p;
707 if (isinstalled && ps->repo != installed)
709 /* we still obsolete packages with same nevra, like rpm does */
710 /* (actually, rpm mixes those packages. yuck...) */
711 if (noobs && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
713 if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
715 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
717 if (s->name == ps->name)
718 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_SAME_NAME, 0);
720 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_IMPLICIT_OBSOLETES, s->name);
725 /*-----------------------------------------
726 * add recommends to the work queue
728 if (s->recommends && m)
730 recp = s->repo->idarraydata + s->recommends;
731 while ((rec = *recp++) != 0)
733 FOR_PROVIDES(p, pp, rec)
735 queue_push(&workq, p);
738 if (s->suggests && m)
740 sugp = s->repo->idarraydata + s->suggests;
741 while ((sug = *sugp++) != 0)
743 FOR_PROVIDES(p, pp, sug)
745 queue_push(&workq, p);
750 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
754 /*-------------------------------------------------------------------
756 * Add package rules for weak rules
758 * m: visited solvables
762 solver_addrpmrulesforweak(Solver *solv, Map *m)
764 Pool *pool = solv->pool;
769 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
770 /* foreach solvable in pool */
771 for (i = n = 1; n < pool->nsolvables; i++, n++)
773 if (i == pool->nsolvables) /* wrap i */
775 if (MAPTST(m, i)) /* been there */
778 s = pool->solvables + i;
779 if (!pool_installable(pool, s)) /* only look at installable ones */
785 /* find possible supplements */
786 supp = s->repo->idarraydata + s->supplements;
787 while ((sup = *supp++) != ID_NULL)
788 if (dep_possible(solv, sup, m))
792 /* if nothing found, check for enhances */
793 if (!sup && s->enhances)
795 supp = s->repo->idarraydata + s->enhances;
796 while ((sup = *supp++) != ID_NULL)
797 if (dep_possible(solv, sup, m))
800 /* if nothing found, goto next solvables */
803 solver_addrpmrulesforsolvable(solv, s, m);
804 n = 0; /* check all solvables again */
806 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
810 /*-------------------------------------------------------------------
812 * add package rules for possible updates
815 * m: map of already visited solvables
816 * allow_all: 0 = dont allow downgrades, 1 = allow all candidates
820 solver_addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
822 Pool *pool = solv->pool;
824 /* queue and buffer for it */
828 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
830 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
831 /* find update candidates for 's' */
832 policy_findupdatepackages(solv, s, &qs, allow_all);
833 /* add rule for 's' if not already done */
834 if (!MAPTST(m, s - pool->solvables))
835 solver_addrpmrulesforsolvable(solv, s, m);
836 /* foreach update candidate, add rule if not already done */
837 for (i = 0; i < qs.count; i++)
838 if (!MAPTST(m, qs.elements[i]))
839 solver_addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
842 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
846 /***********************************************************************
848 *** Update/Feature rule part
850 *** Those rules make sure an installed package isn't silently deleted
855 finddistupgradepackages(Solver *solv, Solvable *s, Queue *qs, int allow_all)
857 Pool *pool = solv->pool;
860 policy_findupdatepackages(solv, s, qs, allow_all);
864 return 0; /* orphaned, don't create feature rule */
865 /* check if this is an orphaned package */
866 policy_findupdatepackages(solv, s, qs, 1);
868 return 0; /* orphaned, don't create update rule */
870 return -SYSTEMSOLVABLE; /* supported but not installable */
873 return s - pool->solvables;
874 /* check if it is ok to keep the installed package */
875 for (i = 0; i < qs->count; i++)
877 Solvable *ns = pool->solvables + qs->elements[i];
878 if (s->evr == ns->evr && solvable_identical(s, ns))
879 return s - pool->solvables;
881 /* nope, it must be some other package */
882 return -SYSTEMSOLVABLE;
885 /* add packages from the dup repositories to the update candidates
886 * this isn't needed for the global dup mode as all packages are
887 * from dup repos in that case */
889 addduppackages(Solver *solv, Solvable *s, Queue *qs)
894 int oldnoupdateprovide = solv->noupdateprovide;
896 queue_init_buffer(&dupqs, dupqsbuf, sizeof(dupqsbuf)/sizeof(*dupqsbuf));
897 solv->noupdateprovide = 1;
898 policy_findupdatepackages(solv, s, &dupqs, 2);
899 solv->noupdateprovide = oldnoupdateprovide;
900 for (i = 0; i < dupqs.count; i++)
902 p = dupqs.elements[i];
903 if (MAPTST(&solv->dupmap, p))
904 queue_pushunique(qs, p);
909 /*-------------------------------------------------------------------
911 * add rule for update
912 * (A|A1|A2|A3...) An = update candidates for A
914 * s = (installed) solvable
918 solver_addupdaterule(Solver *solv, Solvable *s, int allow_all)
920 /* installed packages get a special upgrade allowed rule */
921 Pool *pool = solv->pool;
926 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
927 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
928 p = s - pool->solvables;
929 /* find update candidates for 's' */
930 if (solv->dupmap_all)
931 p = finddistupgradepackages(solv, s, &qs, allow_all);
933 policy_findupdatepackages(solv, s, &qs, allow_all);
934 if (!allow_all && !solv->dupmap_all && solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
935 addduppackages(solv, s, &qs);
937 if (!allow_all && qs.count && solv->noobsoletes.size)
941 d = pool_queuetowhatprovides(pool, &qs);
942 /* filter out all noobsoletes packages as they don't update */
943 for (i = j = 0; i < qs.count; i++)
945 if (MAPTST(&solv->noobsoletes, qs.elements[i]))
947 /* it's ok if they have same nevra */
948 Solvable *ps = pool->solvables + qs.elements[i];
949 if (ps->name != s->name || ps->evr != s->evr || ps->arch != s->arch)
952 qs.elements[j++] = qs.elements[i];
956 if (d && solv->installed && s->repo == solv->installed &&
957 (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, s - pool->solvables - solv->installed->start))))
959 if (!solv->multiversionupdaters)
960 solv->multiversionupdaters = sat_calloc(solv->installed->end - solv->installed->start, sizeof(Id));
961 solv->multiversionupdaters[s - pool->solvables - solv->installed->start] = d;
963 if (j == 0 && p == -SYSTEMSOLVABLE && solv->dupmap_all)
965 queue_push(&solv->orphaned, s - pool->solvables); /* treat as orphaned */
971 if (qs.count && p == -SYSTEMSOLVABLE)
972 p = queue_shift(&qs);
973 d = qs.count ? pool_queuetowhatprovides(pool, &qs) : 0;
975 solver_addrule(solv, p, d); /* allow update of s */
976 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
980 disableupdaterule(Solver *solv, Id p)
984 MAPSET(&solv->noupdate, p - solv->installed->start);
985 r = solv->rules + solv->updaterules + (p - solv->installed->start);
986 if (r->p && r->d >= 0)
987 solver_disablerule(solv, r);
988 r = solv->rules + solv->featurerules + (p - solv->installed->start);
989 if (r->p && r->d >= 0)
990 solver_disablerule(solv, r);
994 reenableupdaterule(Solver *solv, Id p)
996 Pool *pool = solv->pool;
999 MAPCLR(&solv->noupdate, p - solv->installed->start);
1000 r = solv->rules + solv->updaterules + (p - solv->installed->start);
1005 solver_enablerule(solv, r);
1006 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1008 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1009 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1013 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1014 if (r->p && r->d < 0)
1016 solver_enablerule(solv, r);
1017 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1019 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1020 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1026 /***********************************************************************
1028 *** Infarch rule part
1030 *** Infarch rules make sure the solver uses the best architecture of
1031 *** a package if multiple archetectures are available
1036 solver_addinfarchrules(Solver *solv, Map *addedmap)
1038 Pool *pool = solv->pool;
1040 Id p, pp, a, aa, bestarch;
1041 Solvable *s, *ps, *bests;
1042 Queue badq, allowedarchs;
1045 queue_init(&allowedarchs);
1046 solv->infarchrules = solv->nrules;
1047 for (i = 1; i < pool->nsolvables; i++)
1049 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1051 s = pool->solvables + i;
1055 queue_empty(&allowedarchs);
1056 FOR_PROVIDES(p, pp, s->name)
1058 ps = pool->solvables + p;
1059 if (ps->name != s->name || !MAPTST(addedmap, p))
1066 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1067 if (a != 1 && pool->installed && ps->repo == pool->installed)
1069 if (!solv->dupmap_all && !(solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
1070 queue_pushunique(&allowedarchs, ps->arch); /* also ok to keep this architecture */
1071 continue; /* ignore installed solvables when calculating the best arch */
1073 if (a && a != 1 && (!bestarch || a < bestarch))
1081 /* speed up common case where installed package already has best arch */
1082 if (allowedarchs.count == 1 && bests && allowedarchs.elements[0] == bests->arch)
1083 allowedarchs.count--; /* installed arch is best */
1085 FOR_PROVIDES(p, pp, s->name)
1087 ps = pool->solvables + p;
1088 if (ps->name != s->name || !MAPTST(addedmap, p))
1091 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1092 if (a != 1 && bestarch && ((a ^ bestarch) & 0xffff0000) != 0)
1094 if (pool->installed && ps->repo == pool->installed)
1095 continue; /* always ok to keep an installed package */
1096 for (j = 0; j < allowedarchs.count; j++)
1098 aa = allowedarchs.elements[j];
1101 aa = (aa <= pool->lastarch) ? pool->id2arch[aa] : 0;
1102 if (aa && ((a ^ aa) & 0xffff0000) == 0)
1103 break; /* compatible */
1105 if (j == allowedarchs.count)
1106 queue_push(&badq, p);
1111 /* block all solvables in the badq! */
1112 for (j = 0; j < badq.count; j++)
1114 p = badq.elements[j];
1115 solver_addrule(solv, -p, 0);
1119 queue_free(&allowedarchs);
1120 solv->infarchrules_end = solv->nrules;
1124 disableinfarchrule(Solver *solv, Id name)
1126 Pool *pool = solv->pool;
1129 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1131 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1132 solver_disablerule(solv, r);
1137 reenableinfarchrule(Solver *solv, Id name)
1139 Pool *pool = solv->pool;
1142 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1144 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1146 solver_enablerule(solv, r);
1147 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1149 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1150 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1157 /***********************************************************************
1161 *** Dup rules make sure a package is selected from the specified dup
1162 *** repositories if an update candidate is included in one of them.
1167 solver_createdupmaps(Solver *solv)
1169 Queue *job = &solv->job;
1170 Pool *pool = solv->pool;
1172 Id how, what, p, pi, pp, obs, *obsp;
1176 map_init(&solv->dupmap, pool->nsolvables);
1177 map_init(&solv->dupinvolvedmap, pool->nsolvables);
1178 for (i = 0; i < job->count; i += 2)
1180 how = job->elements[i];
1181 what = job->elements[i + 1];
1182 switch (how & SOLVER_JOBMASK)
1184 case SOLVER_DISTUPGRADE:
1185 if ((how & SOLVER_SELECTMASK) != SOLVER_SOLVABLE_REPO)
1187 if (what <= 0 || what > pool->nrepos)
1189 repo = pool_id2repo(pool, what);
1190 FOR_REPO_SOLVABLES(repo, p, s)
1192 MAPSET(&solv->dupmap, p);
1193 FOR_PROVIDES(pi, pp, s->name)
1195 ps = pool->solvables + pi;
1196 if (ps->name != s->name)
1198 MAPSET(&solv->dupinvolvedmap, pi);
1202 /* FIXME: check obsoletes/provides combination */
1203 obsp = s->repo->idarraydata + s->obsoletes;
1204 while ((obs = *obsp++) != 0)
1206 FOR_PROVIDES(pi, pp, obs)
1208 Solvable *pis = pool->solvables + pi;
1209 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pis, obs))
1211 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, pis))
1213 MAPSET(&solv->dupinvolvedmap, pi);
1223 MAPCLR(&solv->dupinvolvedmap, SYSTEMSOLVABLE);
1227 solver_freedupmaps(Solver *solv)
1229 map_free(&solv->dupmap);
1230 map_free(&solv->dupinvolvedmap);
1234 solver_addduprules(Solver *solv, Map *addedmap)
1236 Pool *pool = solv->pool;
1241 solv->duprules = solv->nrules;
1242 for (i = 1; i < pool->nsolvables; i++)
1244 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1246 s = pool->solvables + i;
1248 FOR_PROVIDES(p, pp, s->name)
1250 ps = pool->solvables + p;
1251 if (ps->name != s->name || !MAPTST(addedmap, p))
1257 if (!MAPTST(&solv->dupinvolvedmap, p))
1259 if (solv->installed && ps->repo == solv->installed)
1261 if (!solv->updatemap.size)
1262 map_grow(&solv->updatemap, solv->installed->end - solv->installed->start);
1263 MAPSET(&solv->updatemap, p - solv->installed->start);
1264 if (!MAPTST(&solv->dupmap, p))
1267 /* is installed identical to a good one? */
1268 FOR_PROVIDES(ip, ipp, ps->name)
1270 Solvable *is = pool->solvables + ip;
1271 if (!MAPTST(&solv->dupmap, ip))
1273 if (is->evr == ps->evr && solvable_identical(ps, is))
1277 solver_addrule(solv, -p, 0); /* no match, sorry */
1280 else if (!MAPTST(&solv->dupmap, p))
1281 solver_addrule(solv, -p, 0);
1284 solv->duprules_end = solv->nrules;
1289 disableduprule(Solver *solv, Id name)
1291 Pool *pool = solv->pool;
1294 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1296 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1297 solver_disablerule(solv, r);
1302 reenableduprule(Solver *solv, Id name)
1304 Pool *pool = solv->pool;
1307 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1309 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1311 solver_enablerule(solv, r);
1312 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1314 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1315 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1322 /***********************************************************************
1324 *** Policy rule disabling/reenabling
1326 *** Disable all policy rules that conflict with our jobs. If a job
1327 *** gets disabled later on, reenable the involved policy rules again.
1331 #define DISABLE_UPDATE 1
1332 #define DISABLE_INFARCH 2
1333 #define DISABLE_DUP 3
1336 jobtodisablelist(Solver *solv, Id how, Id what, Queue *q)
1338 Pool *pool = solv->pool;
1342 int i, j, set, qstart, pass;
1345 installed = solv->installed;
1346 select = how & SOLVER_SELECTMASK;
1347 switch (how & SOLVER_JOBMASK)
1349 case SOLVER_INSTALL:
1350 set = how & SOLVER_SETMASK;
1351 if (!(set & SOLVER_NOAUTOSET))
1353 /* automatically add set bits by analysing the job */
1354 if (select == SOLVER_SOLVABLE)
1355 set |= SOLVER_SETARCH | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_SETEVR;
1356 else if ((select == SOLVER_SOLVABLE_NAME || select == SOLVER_SOLVABLE_PROVIDES) && ISRELDEP(what))
1358 Reldep *rd = GETRELDEP(pool, what);
1359 if (rd->flags == REL_EQ && select == SOLVER_SOLVABLE_NAME)
1361 #if !defined(DEBIAN_SEMANTICS)
1362 const char *evr = id2str(pool, rd->evr);
1363 if (strchr(evr, '-'))
1364 set |= SOLVER_SETEVR;
1366 set |= SOLVER_SETEV;
1368 set |= SOLVER_SETEVR;
1371 if (rd->flags <= 7 && ISRELDEP(rd->name))
1372 rd = GETRELDEP(pool, rd->name);
1373 if (rd->flags == REL_ARCH)
1374 set |= SOLVER_SETARCH;
1378 set &= ~SOLVER_NOAUTOSET;
1381 if ((set & SOLVER_SETARCH) != 0 && solv->infarchrules != solv->infarchrules_end)
1383 if (select == SOLVER_SOLVABLE)
1384 queue_push2(q, DISABLE_INFARCH, pool->solvables[what].name);
1387 int qcnt = q->count;
1388 FOR_JOB_SELECT(p, pp, select, what)
1390 s = pool->solvables + p;
1392 for (i = qcnt; i < q->count; i += 2)
1393 if (q->elements[i + 1] == s->name)
1397 queue_push2(q, DISABLE_INFARCH, s->name);
1401 if ((set & SOLVER_SETREPO) != 0 && solv->duprules != solv->duprules_end)
1403 if (select == SOLVER_SOLVABLE)
1404 queue_push2(q, DISABLE_DUP, pool->solvables[what].name);
1407 int qcnt = q->count;
1408 FOR_JOB_SELECT(p, pp, select, what)
1410 s = pool->solvables + p;
1412 for (i = qcnt; i < q->count; i += 2)
1413 if (q->elements[i + 1] == s->name)
1417 queue_push2(q, DISABLE_DUP, s->name);
1423 /* now the hard part: disable some update rules */
1425 /* first check if we have noobs or installed packages in the job */
1426 FOR_JOB_SELECT(p, pp, select, what)
1428 if (pool->solvables[p].repo == installed)
1430 if (select == SOLVER_SOLVABLE)
1431 queue_push2(q, DISABLE_UPDATE, what);
1434 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p))
1438 /* all job packages obsolete */
1441 memset(&omap, 0, sizeof(omap));
1442 FOR_JOB_SELECT(p, pp, select, what)
1447 map_grow(&omap, installed->end - installed->start);
1448 s = pool->solvables + p;
1452 obsp = s->repo->idarraydata + s->obsoletes;
1453 while ((obs = *obsp++) != 0)
1454 FOR_PROVIDES(p2, pp2, obs)
1456 Solvable *ps = pool->solvables + p2;
1457 if (ps->repo != installed)
1459 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
1461 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1464 MAPSET(&omap, p2 - installed->start);
1466 queue_push2(q, DISABLE_UPDATE, p2);
1469 FOR_PROVIDES(p2, pp2, s->name)
1471 Solvable *ps = pool->solvables + p2;
1472 if (ps->repo != installed)
1474 if (!pool->implicitobsoleteusesprovides && ps->name != s->name)
1476 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1479 MAPSET(&omap, p2 - installed->start);
1481 queue_push2(q, DISABLE_UPDATE, p2);
1485 for (i = j = qstart; i < q->count; i += 2)
1487 if (MAPTST(&omap, q->elements[i + 1] - installed->start))
1489 MAPCLR(&omap, q->elements[i + 1] - installed->start);
1490 q->elements[j + 1] = q->elements[i + 1];
1494 queue_truncate(q, j);
1496 if (q->count == qstart)
1503 if (qstart == q->count)
1504 return; /* nothing to prune */
1505 if ((set & (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR)) == (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR))
1506 return; /* all is set */
1508 /* now that we know which installed packages are obsoleted check each of them */
1509 for (i = j = qstart; i < q->count; i += 2)
1511 Solvable *is = pool->solvables + q->elements[i + 1];
1512 FOR_JOB_SELECT(p, pp, select, what)
1515 s = pool->solvables + p;
1516 if ((set & SOLVER_SETEVR) != 0)
1517 illegal |= POLICY_ILLEGAL_DOWNGRADE; /* ignore */
1518 if ((set & SOLVER_SETARCH) != 0)
1519 illegal |= POLICY_ILLEGAL_ARCHCHANGE; /* ignore */
1520 if ((set & SOLVER_SETVENDOR) != 0)
1521 illegal |= POLICY_ILLEGAL_VENDORCHANGE; /* ignore */
1522 illegal = policy_is_illegal(solv, is, s, illegal);
1523 if (illegal && illegal == POLICY_ILLEGAL_DOWNGRADE && (set & SOLVER_SETEV) != 0)
1525 /* it's ok if the EV is different */
1526 if (evrcmp(pool, is->evr, s->evr, EVRCMP_COMPARE_EVONLY) != 0)
1534 /* no package conflicts with the update rule */
1535 /* thus keep the DISABLE_UPDATE */
1536 q->elements[j + 1] = q->elements[i + 1];
1540 queue_truncate(q, j);
1546 FOR_JOB_SELECT(p, pp, select, what)
1547 if (pool->solvables[p].repo == installed)
1548 queue_push2(q, DISABLE_UPDATE, p);
1555 /* disable all policy rules that are in conflict with our job list */
1557 solver_disablepolicyrules(Solver *solv)
1559 Queue *job = &solv->job;
1566 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
1568 for (i = solv->jobrules; i < solv->jobrules_end; i++)
1570 r = solv->rules + i;
1571 if (r->d < 0) /* disabled? */
1573 j = solv->ruletojob.elements[i - solv->jobrules];
1577 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
1579 if (solv->cleandepsmap.size)
1581 solver_createcleandepsmap(solv);
1582 for (i = solv->installed->start; i < solv->installed->end; i++)
1583 if (MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1584 queue_push2(&allq, DISABLE_UPDATE, i);
1586 MAPZERO(&solv->noupdate);
1587 for (i = 0; i < allq.count; i += 2)
1589 Id type = allq.elements[i], arg = allq.elements[i + 1];
1592 case DISABLE_UPDATE:
1593 disableupdaterule(solv, arg);
1595 case DISABLE_INFARCH:
1596 disableinfarchrule(solv, arg);
1599 disableduprule(solv, arg);
1608 /* we just disabled job #jobidx, now reenable all policy rules that were
1609 * disabled because of this job */
1611 solver_reenablepolicyrules(Solver *solv, int jobidx)
1613 Queue *job = &solv->job;
1618 Id qbuf[32], allqbuf[128];
1620 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1621 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
1622 jobtodisablelist(solv, job->elements[jobidx], job->elements[jobidx + 1], &q);
1625 for (i = solv->jobrules; i < solv->jobrules_end; i++)
1627 r = solv->rules + i;
1628 if (r->d < 0) /* disabled? */
1630 j = solv->ruletojob.elements[i - solv->jobrules];
1634 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
1636 if (solv->cleandepsmap.size)
1638 solver_createcleandepsmap(solv);
1639 for (i = solv->installed->start; i < solv->installed->end; i++)
1640 if (MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1641 queue_push2(&allq, DISABLE_UPDATE, i);
1643 for (j = 0; j < q.count; j += 2)
1645 Id type = q.elements[j], arg = q.elements[j + 1];
1646 for (i = 0; i < allq.count; i += 2)
1647 if (allq.elements[i] == type && allq.elements[i + 1] == arg)
1650 continue; /* still disabled */
1653 case DISABLE_UPDATE:
1654 reenableupdaterule(solv, arg);
1656 case DISABLE_INFARCH:
1657 reenableinfarchrule(solv, arg);
1660 reenableduprule(solv, arg);
1669 /***********************************************************************
1671 *** Rule info part, tell the user what the rule is about.
1676 addrpmruleinfo(Solver *solv, Id p, Id d, int type, Id dep)
1678 Pool *pool = solv->pool;
1682 /* check if this creates the rule we're searching for */
1683 r = solv->rules + solv->ruleinfoq->elements[0];
1685 od = r->d < 0 ? -r->d - 1 : r->d;
1690 if (p < 0 && d > 0 && (!pool->whatprovidesdata[d] || !pool->whatprovidesdata[d + 1]))
1692 w2 = pool->whatprovidesdata[d];
1696 if (p > 0 && d < 0) /* this hack is used for buddy deps */
1708 Id *dp = pool->whatprovidesdata + d;
1709 Id *odp = pool->whatprovidesdata + od;
1711 if (*dp++ != *odp++)
1717 /* handle multiversion conflict rules */
1718 if (p < 0 && pool->whatprovidesdata[d] < 0)
1720 w2 = pool->whatprovidesdata[d];
1721 /* XXX: free memory */
1731 if (w2 != op || p != ow2)
1736 if (p != op || w2 != ow2)
1740 /* yep, rule matches. record info */
1741 queue_push(solv->ruleinfoq, type);
1742 if (type == SOLVER_RULE_RPM_SAME_NAME)
1744 /* we normalize same name order */
1745 queue_push(solv->ruleinfoq, op < 0 ? -op : 0);
1746 queue_push(solv->ruleinfoq, ow2 < 0 ? -ow2 : 0);
1750 queue_push(solv->ruleinfoq, p < 0 ? -p : 0);
1751 queue_push(solv->ruleinfoq, w2 < 0 ? -w2 : 0);
1753 queue_push(solv->ruleinfoq, dep);
1757 solver_allruleinfos_cmp(const void *ap, const void *bp, void *dp)
1759 const Id *a = ap, *b = bp;
1778 solver_allruleinfos(Solver *solv, Id rid, Queue *rq)
1780 Pool *pool = solv->pool;
1781 Rule *r = solv->rules + rid;
1785 if (rid <= 0 || rid >= solv->rpmrules_end)
1787 Id type, from, to, dep;
1788 type = solver_ruleinfo(solv, rid, &from, &to, &dep);
1789 queue_push(rq, type);
1790 queue_push(rq, from);
1792 queue_push(rq, dep);
1797 queue_push(rq, rid);
1798 solv->ruleinfoq = rq;
1799 solver_addrpmrulesforsolvable(solv, pool->solvables - r->p, 0);
1800 /* also try reverse direction for conflicts */
1801 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
1802 solver_addrpmrulesforsolvable(solv, pool->solvables - r->w2, 0);
1803 solv->ruleinfoq = 0;
1805 /* now sort & unify em */
1808 sat_sort(rq->elements, rq->count / 4, 4 * sizeof(Id), solver_allruleinfos_cmp, 0);
1809 /* throw out identical entries */
1810 for (i = j = 0; i < rq->count; i += 4)
1814 if (rq->elements[i] == rq->elements[j - 4] &&
1815 rq->elements[i + 1] == rq->elements[j - 3] &&
1816 rq->elements[i + 2] == rq->elements[j - 2] &&
1817 rq->elements[i + 3] == rq->elements[j - 1])
1820 rq->elements[j++] = rq->elements[i];
1821 rq->elements[j++] = rq->elements[i + 1];
1822 rq->elements[j++] = rq->elements[i + 2];
1823 rq->elements[j++] = rq->elements[i + 3];
1830 solver_ruleinfo(Solver *solv, Id rid, Id *fromp, Id *top, Id *depp)
1832 Pool *pool = solv->pool;
1833 Rule *r = solv->rules + rid;
1834 SolverRuleinfo type = SOLVER_RULE_UNKNOWN;
1842 if (rid > 0 && rid < solv->rpmrules_end)
1848 return SOLVER_RULE_RPM;
1852 queue_push(&rq, rid);
1853 solv->ruleinfoq = &rq;
1854 solver_addrpmrulesforsolvable(solv, pool->solvables - r->p, 0);
1855 /* also try reverse direction for conflicts */
1856 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
1857 solver_addrpmrulesforsolvable(solv, pool->solvables - r->w2, 0);
1858 solv->ruleinfoq = 0;
1859 type = SOLVER_RULE_RPM;
1860 for (i = 1; i < rq.count; i += 4)
1863 qt = rq.elements[i];
1864 qp = rq.elements[i + 1];
1865 qo = rq.elements[i + 2];
1866 qd = rq.elements[i + 3];
1867 if (type == SOLVER_RULE_RPM || type > qt)
1881 if (rid >= solv->jobrules && rid < solv->jobrules_end)
1883 Id jidx = solv->ruletojob.elements[rid - solv->jobrules];
1887 *top = solv->job.elements[jidx];
1889 *depp = solv->job.elements[jidx + 1];
1890 if ((r->d == 0 || r->d == -1) && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && (solv->job.elements[jidx] & SOLVER_SELECTMASK) != SOLVER_SOLVABLE_ONE_OF)
1891 return SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP;
1892 return SOLVER_RULE_JOB;
1894 if (rid >= solv->updaterules && rid < solv->updaterules_end)
1897 *fromp = solv->installed->start + (rid - solv->updaterules);
1898 return SOLVER_RULE_UPDATE;
1900 if (rid >= solv->featurerules && rid < solv->featurerules_end)
1903 *fromp = solv->installed->start + (rid - solv->featurerules);
1904 return SOLVER_RULE_FEATURE;
1906 if (rid >= solv->duprules && rid < solv->duprules_end)
1911 *depp = pool->solvables[-r->p].name;
1912 return SOLVER_RULE_DISTUPGRADE;
1914 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
1919 *depp = pool->solvables[-r->p].name;
1920 return SOLVER_RULE_INFARCH;
1922 if (rid >= solv->choicerules && rid < solv->choicerules_end)
1924 return SOLVER_RULE_CHOICE;
1926 if (rid >= solv->learntrules)
1928 return SOLVER_RULE_LEARNT;
1930 return SOLVER_RULE_UNKNOWN;
1934 solver_addchoicerules(Solver *solv)
1936 Pool *pool = solv->pool;
1940 int i, j, rid, havechoice;
1945 solv->choicerules = solv->nrules;
1946 if (!pool->installed)
1948 solv->choicerules_end = solv->nrules;
1951 solv->choicerules_ref = sat_calloc(solv->rpmrules_end, sizeof(Id));
1954 map_init(&m, pool->nsolvables);
1955 map_init(&mneg, pool->nsolvables);
1956 /* set up negative assertion map from infarch and dup rules */
1957 for (rid = solv->infarchrules, r = solv->rules + rid; rid < solv->infarchrules_end; rid++, r++)
1958 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
1959 MAPSET(&mneg, -r->p);
1960 for (rid = solv->duprules, r = solv->rules + rid; rid < solv->duprules_end; rid++, r++)
1961 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
1962 MAPSET(&mneg, -r->p);
1963 for (rid = 1; rid < solv->rpmrules_end ; rid++)
1965 r = solv->rules + rid;
1966 if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 < 0))
1967 continue; /* only look at requires rules */
1968 // solver_printrule(solv, SAT_DEBUG_RESULT, r);
1972 FOR_RULELITERALS(p, pp, r)
1976 s = pool->solvables + p;
1979 if (s->repo == pool->installed)
1984 /* check if this package is "blocked" by a installed package */
1986 FOR_PROVIDES(p2, pp2, s->name)
1988 s2 = pool->solvables + p2;
1989 if (s2->repo != pool->installed)
1991 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
1993 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
1999 /* found installed package p2 that we can update to p */
2000 if (MAPTST(&mneg, p))
2002 if (policy_is_illegal(solv, s2, s, 0))
2004 queue_push(&qi, p2);
2010 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
2012 while ((obs = *obsp++) != 0)
2014 FOR_PROVIDES(p2, pp2, obs)
2016 s2 = pool->solvables + p2;
2017 if (s2->repo != pool->installed)
2019 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
2021 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
2030 /* found installed package p2 that we can update to p */
2031 if (MAPTST(&mneg, p))
2033 if (policy_is_illegal(solv, s2, s, 0))
2035 queue_push(&qi, p2);
2040 /* package p is independent of the installed ones */
2043 if (!havechoice || !q.count)
2044 continue; /* no choice */
2046 /* now check the update rules of the installed package.
2047 * if all packages of the update rules are contained in
2048 * the dependency rules, there's no need to set up the choice rule */
2050 FOR_RULELITERALS(p, pp, r)
2053 for (i = 0; i < qi.count; i++)
2055 if (!qi.elements[i])
2057 Rule *ur = solv->rules + solv->updaterules + (qi.elements[i] - pool->installed->start);
2059 ur = solv->rules + solv->featurerules + (qi.elements[i] - pool->installed->start);
2062 FOR_RULELITERALS(p, pp, ur)
2067 for (j = i + 1; j < qi.count; j++)
2068 if (qi.elements[i] == qi.elements[j])
2074 printf("skipping choice ");
2075 solver_printrule(solv, SAT_DEBUG_RESULT, solv->rules + rid);
2079 d = q.count ? pool_queuetowhatprovides(pool, &q) : 0;
2080 solver_addrule(solv, r->p, d);
2081 queue_push(&solv->weakruleq, solv->nrules - 1);
2082 solv->choicerules_ref[solv->nrules - 1 - solv->choicerules] = rid;
2085 solver_printrule(solv, SAT_DEBUG_RESULT, solv->rules + rid);
2086 printf("WEAK CHOICE ");
2087 solver_printrule(solv, SAT_DEBUG_RESULT, solv->rules + solv->nrules - 1);
2094 solv->choicerules_end = solv->nrules;
2097 /* called when a choice rule is disabled by analyze_unsolvable. We also
2098 * have to disable all other choice rules so that the best packages get
2101 solver_disablechoicerules(Solver *solv, Rule *r)
2104 Pool *pool = solv->pool;
2108 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
2109 map_init(&m, pool->nsolvables);
2110 FOR_RULELITERALS(p, pp, or)
2113 FOR_RULELITERALS(p, pp, r)
2116 for (rid = solv->choicerules; rid < solv->choicerules_end; rid++)
2118 r = solv->rules + rid;
2121 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
2122 FOR_RULELITERALS(p, pp, or)
2123 if (p > 0 && MAPTST(&m, p))
2126 solver_disablerule(solv, r);
2130 static void solver_createcleandepsmap(Solver *solv)
2132 Pool *pool = solv->pool;
2133 Repo *installed = solv->installed;
2134 Queue *job = &solv->job;
2139 Id rid, how, what, select;
2141 Id req, *reqp, sup, *supp;
2146 map_init(&userinstalled, installed->end - installed->start);
2147 map_init(&im, pool->nsolvables);
2148 map_init(&installedm, pool->nsolvables);
2149 map_empty(&solv->cleandepsmap);
2152 for (i = 0; i < job->count; i += 2)
2154 how = job->elements[i];
2155 if ((how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
2157 what = job->elements[i + 1];
2158 select = how & SOLVER_SELECTMASK;
2159 FOR_JOB_SELECT(p, pp, select, what)
2160 if (pool->solvables[p].repo == installed)
2161 MAPSET(&userinstalled, p - installed->start);
2164 /* add all positive elements (e.g. locks) to "userinstalled" */
2165 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2167 r = solv->rules + rid;
2170 FOR_RULELITERALS(p, jp, r)
2171 if (p > 0 && pool->solvables[p].repo == installed)
2172 MAPSET(&userinstalled, p - installed->start);
2174 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2176 r = solv->rules + rid;
2177 if (r->p >= 0 || r->d != 0)
2178 continue; /* disabled or not erase */
2180 if (pool->solvables[p].repo != installed)
2182 MAPCLR(&userinstalled, p - installed->start);
2183 i = solv->ruletojob.elements[rid - solv->jobrules];
2184 how = job->elements[i];
2185 if ((how & (SOLVER_JOBMASK|SOLVER_CLEANDEPS)) == (SOLVER_ERASE|SOLVER_CLEANDEPS))
2188 for (p = installed->start; p < installed->end; p++)
2190 if (pool->solvables[p].repo != installed)
2192 MAPSET(&installedm, p);
2198 ip = queue_shift(&iq);
2199 s = pool->solvables + ip;
2200 if (!MAPTST(&im, ip))
2202 if (!MAPTST(&installedm, ip))
2204 if (s->repo == installed && MAPTST(&userinstalled, ip - installed->start))
2207 #ifdef CLEANDEPSDEBUG
2208 printf("hello %s\n", solvable2str(pool, s));
2212 reqp = s->repo->idarraydata + s->requires;
2213 while ((req = *reqp++) != 0)
2215 if (req == SOLVABLE_PREREQMARKER)
2218 /* count number of installed packages that match */
2220 FOR_PROVIDES(p, pp, req)
2221 if (MAPTST(&installedm, p))
2226 FOR_PROVIDES(p, pp, req)
2230 #ifdef CLEANDEPSDEBUG
2231 printf("%s requires %s\n", solvid2str(pool, ip), solvid2str(pool, p));
2240 reqp = s->repo->idarraydata + s->recommends;
2241 while ((req = *reqp++) != 0)
2245 FOR_PROVIDES(p, pp, req)
2246 if (MAPTST(&installedm, p))
2251 FOR_PROVIDES(p, pp, req)
2255 #ifdef CLEANDEPSDEBUG
2256 printf("%s recommends %s\n", solvid2str(pool, ip), solvid2str(pool, p));
2265 /* supplements pass */
2266 for (ip = solv->installed->start; ip < solv->installed->end; ip++)
2268 if (!MAPTST(&installedm, ip))
2270 s = pool->solvables + ip;
2271 if (!s->supplements)
2273 if (!MAPTST(&im, ip))
2275 supp = s->repo->idarraydata + s->supplements;
2276 while ((sup = *supp++) != 0)
2277 if (!dep_possible(solv, sup, &im) && dep_possible(solv, sup, &installedm))
2279 /* no longer supplemented, also erase */
2282 #ifdef CLEANDEPSDEBUG
2283 printf("%s supplemented\n", solvid2str(pool, ip));
2285 queue_push(&iq, ip);
2291 /* turn userinstalled into remove set for pruning */
2292 map_empty(&userinstalled);
2293 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2295 r = solv->rules + rid;
2296 if (r->p >= 0 || r->d != 0)
2297 continue; /* disabled or not erase */
2300 if (pool->solvables[p].repo == installed)
2301 MAPSET(&userinstalled, p - installed->start);
2303 for (p = installed->start; p < installed->end; p++)
2306 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2308 r = solv->rules + rid;
2311 FOR_RULELITERALS(p, jp, r)
2315 /* also put directly addressed packages on the install queue
2316 * so we can mark patterns as installed */
2317 for (i = 0; i < job->count; i += 2)
2319 how = job->elements[i];
2320 if ((how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
2322 what = job->elements[i + 1];
2323 select = how & SOLVER_SELECTMASK;
2324 if (select == SOLVER_SOLVABLE && pool->solvables[what].repo != installed)
2325 queue_push(&iq, what);
2330 ip = queue_shift(&iq);
2331 s = pool->solvables + ip;
2332 #ifdef CLEANDEPSDEBUG
2333 printf("bye %s\n", solvable2str(pool, s));
2337 reqp = s->repo->idarraydata + s->requires;
2338 while ((req = *reqp++) != 0)
2340 FOR_PROVIDES(p, pp, req)
2342 if (!MAPTST(&im, p) && MAPTST(&installedm, p))
2346 if (MAPTST(&userinstalled, p - installed->start))
2348 #ifdef CLEANDEPSDEBUG
2349 printf("%s requires %s\n", solvid2str(pool, ip), solvid2str(pool, p));
2359 reqp = s->repo->idarraydata + s->recommends;
2360 while ((req = *reqp++) != 0)
2362 FOR_PROVIDES(p, pp, req)
2364 if (!MAPTST(&im, p) && MAPTST(&installedm, p))
2368 if (MAPTST(&userinstalled, p - installed->start))
2370 #ifdef CLEANDEPSDEBUG
2371 printf("%s recommends %s\n", solvid2str(pool, ip), solvid2str(pool, p));
2381 /* supplements pass */
2382 for (ip = installed->start; ip < installed->end; ip++)
2384 if (!MAPTST(&installedm, ip))
2386 if (MAPTST(&userinstalled, ip - installed->start))
2388 s = pool->solvables + ip;
2389 if (!s->supplements)
2391 if (MAPTST(&im, ip) || !MAPTST(&installedm, ip))
2393 supp = s->repo->idarraydata + s->supplements;
2394 while ((sup = *supp++) != 0)
2395 if (dep_possible(solv, sup, &im))
2399 #ifdef CLEANDEPSDEBUG
2400 printf("%s supplemented\n", solvid2str(pool, ip));
2403 queue_push(&iq, ip);
2410 for (p = installed->start; p < installed->end; p++)
2412 if (pool->solvables[p].repo != installed)
2414 if (!MAPTST(&im, p))
2415 MAPSET(&solv->cleandepsmap, p - installed->start);
2418 map_free(&installedm);
2419 map_free(&userinstalled);