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
26 #include "solverdebug.h"
28 #define RULES_BLOCK 63
30 static void addrpmruleinfo(Solver *solv, Id p, Id d, int type, Id dep);
31 static void solver_createcleandepsmap(Solver *solv);
33 /*-------------------------------------------------------------------
34 * Check if dependency is possible
36 * mirrors solver_dep_fulfilled but uses map m instead of the decisionmap
40 dep_possible(Solver *solv, Id dep, Map *m)
42 Pool *pool = solv->pool;
47 Reldep *rd = GETRELDEP(pool, dep);
48 if (rd->flags == REL_AND)
50 if (!dep_possible(solv, rd->name, m))
52 return dep_possible(solv, rd->evr, m);
54 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
55 return solver_splitprovides(solv, rd->evr);
56 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
57 return solver_dep_installed(solv, rd->evr);
59 FOR_PROVIDES(p, pp, dep)
67 /********************************************************************
71 * - unify rules, remove duplicates
74 /*-------------------------------------------------------------------
76 * compare rules for unification sort
81 unifyrules_sortcmp(const void *ap, const void *bp, void *dp)
91 return x; /* p differs */
94 if (a->d == 0 && b->d == 0)
95 return a->w2 - b->w2; /* assertion: return w2 diff */
97 if (a->d == 0) /* a is assertion, b not */
99 x = a->w2 - pool->whatprovidesdata[b->d];
103 if (b->d == 0) /* b is assertion, a not */
105 x = pool->whatprovidesdata[a->d] - b->w2;
109 /* compare whatprovidesdata */
110 ad = pool->whatprovidesdata + a->d;
111 bd = pool->whatprovidesdata + b->d;
113 if ((x = *ad++ - *bd++) != 0)
119 solver_samerule(Solver *solv, Rule *r1, Rule *r2)
121 return unifyrules_sortcmp(r1, r2, solv->pool);
125 /*-------------------------------------------------------------------
128 * go over all rules and remove duplicates
132 solver_unifyrules(Solver *solv)
134 Pool *pool = solv->pool;
138 if (solv->nrules <= 1) /* nothing to unify */
141 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules -----\n");
143 /* sort rules first */
144 sat_sort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp, solv->pool);
151 for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
153 if (jr && !unifyrules_sortcmp(ir, jr, pool))
154 continue; /* prune! */
155 jr = solv->rules + j++; /* keep! */
160 /* reduced count from nrules to j rules */
161 POOL_DEBUG(SAT_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
163 /* adapt rule buffer */
165 solv->rules = sat_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
168 * debug: log rule statistics
170 IF_POOLDEBUG (SAT_DEBUG_STATS)
177 for (i = 1; i < solv->nrules; i++)
184 dp = solv->pool->whatprovidesdata + r->d;
189 POOL_DEBUG(SAT_DEBUG_STATS, " binary: %d\n", binr);
190 POOL_DEBUG(SAT_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
192 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- unifyrules end -----\n");
202 hashrule(Solver *solv, Id p, Id d, int n)
204 unsigned int x = (unsigned int)p;
208 return (x * 37) ^ (unsigned int)d;
209 dp = solv->pool->whatprovidesdata + d;
211 x = (x * 37) ^ (unsigned int)*dp++;
217 /*-------------------------------------------------------------------
223 * p = direct literal; always < 0 for installed rpm rules
224 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
227 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
229 * p < 0 : pkg id of A
230 * d > 0 : Offset in whatprovidesdata (list of providers of b)
232 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
233 * p < 0 : pkg id of A
234 * d < 0 : Id of solvable (e.g. B1)
236 * d == 0: unary rule, assertion => (A) or (-A)
238 * Install: p > 0, d = 0 (A) user requested install
239 * Remove: p < 0, d = 0 (-A) user requested remove (also: uninstallable)
240 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
241 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
242 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
243 * also used for obsoletes
244 * ?: p > 0, d < 0 (A|-B)
245 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
249 * Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
250 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
251 * every other : w1 = p, w2 = whatprovidesdata[d];
252 * Disabled rule: w1 = 0
254 * always returns a rule for non-rpm rules
258 solver_addrule(Solver *solv, Id p, Id d)
260 Pool *pool = solv->pool;
264 int n = 0; /* number of literals in rule - 1
265 0 = direct assertion (single literal)
270 /* it often happenes that requires lead to adding the same rpm rule
271 * multiple times, so we prune those duplicates right away to make
272 * the work for unifyrules a bit easier */
274 if (solv->nrules /* we already have rules */
275 && !solv->rpmrules_end) /* but are not done with rpm rules */
277 r = solv->rules + solv->nrules - 1; /* get the last added rule */
278 if (r->p == p && r->d == d && d != 0) /* identical and not user requested */
283 * compute number of literals (n) in rule
288 /* always a binary rule */
290 return 0; /* ignore self conflict */
295 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
297 return 0; /* rule is self-fulfilling */
299 if (n == 1) /* have single provider */
300 d = dp[-1]; /* take single literal */
303 if (n == 1 && p > d && !solv->rpmrules_end)
305 /* smallest literal first so we can find dups */
306 n = p; p = d; d = n; /* p <-> d */
307 n = 1; /* re-set n, was used as temp var */
311 * check for duplicate
314 /* check if the last added rule (r) is exactly the same as what we're looking for. */
315 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
316 return r; /* binary rule */
318 /* have n-ary rule with same first literal, check other literals */
319 if (r && n > 1 && r->d && r->p == p)
321 /* Rule where d is an offset in whatprovidesdata */
325 dp2 = pool->whatprovidesdata + r->d;
326 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
337 /* extend rule buffer */
338 solv->rules = sat_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
339 r = solv->rules + solv->nrules++; /* point to rule space */
348 /* direct assertion, no watch needed */
364 r->w2 = pool->whatprovidesdata[d];
369 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
371 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " Add rule: ");
372 solver_printrule(solv, SAT_DEBUG_RULE_CREATION, r);
379 /******************************************************************************
381 *** rpm rule part: create rules representing the package dependencies
386 * special multiversion patch conflict handling:
387 * a patch conflict is also satisfied if some other
388 * version with the same name/arch that doesn't conflict
389 * gets installed. The generated rule is thus:
390 * -patch|-cpack|opack1|opack2|...
393 makemultiversionconflict(Solver *solv, Id n, Id con)
395 Pool *pool = solv->pool;
400 sn = pool->solvables + n;
401 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
403 FOR_PROVIDES(p, pp, sn->name)
405 s = pool->solvables + p;
406 if (s->name != sn->name || s->arch != sn->arch)
408 if (!MAPTST(&solv->noobsoletes, p))
410 if (pool_match_nevr(pool, pool->solvables + p, con))
412 /* here we have a multiversion solvable that doesn't conflict */
413 /* thus we're not in conflict if it is installed */
417 return -n; /* no other package found, generate normal conflict */
418 return pool_queuetowhatprovides(pool, &q);
422 addrpmrule(Solver *solv, Id p, Id d, int type, Id dep)
424 if (!solv->ruleinfoq)
425 solver_addrule(solv, p, d);
427 addrpmruleinfo(solv, p, d, type, dep);
430 /*-------------------------------------------------------------------
432 * add (install) rules for solvable
434 * s: Solvable for which to add rules
435 * m: m[s] = 1 for solvables which have rules, prevent rule duplication
437 * Algorithm: 'visit all nodes of a graph'. The graph nodes are
438 * solvables, the edges their dependencies.
439 * Starting from an installed solvable, this will create all rules
440 * representing the graph created by the solvables dependencies.
442 * for unfulfilled requirements, conflicts, obsoletes,....
443 * add a negative assertion for solvables that are not installable
445 * It will also create rules for all solvables referenced by 's'
446 * i.e. descend to all providers of requirements of 's'
451 solver_addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
453 Pool *pool = solv->pool;
454 Repo *installed = solv->installed;
456 /* 'work' queue. keeps Ids of solvables we still have to work on.
457 And buffer for it. */
462 /* if to add rules for broken deps ('rpm -V' functionality)
466 /* Id var and pointer for each dependency
467 * (not used in parallel)
474 Id p, pp; /* whatprovides loops */
475 Id *dp; /* ptr to 'whatprovides' */
476 Id n; /* Id for current solvable 's' */
478 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable -----\n");
480 queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
481 queue_push(&workq, s - pool->solvables); /* push solvable Id to work queue */
483 /* loop until there's no more work left */
488 * s: Pointer to solvable
491 n = queue_shift(&workq); /* 'pop' next solvable to work on from queue */
494 if (MAPTST(m, n)) /* continue if already visited */
496 MAPSET(m, n); /* mark as visited */
499 s = pool->solvables + n; /* s = Solvable in question */
502 if (installed /* Installed system available */
503 && s->repo == installed /* solvable is installed */
504 && !solv->fixmap_all /* NOT repair errors in rpm dependency graph */
505 && !(solv->fixmap.size && MAPTST(&solv->fixmap, n - installed->start)))
507 dontfix = 1; /* dont care about broken rpm deps */
511 && s->arch != ARCH_SRC
512 && s->arch != ARCH_NOSRC
513 && !pool_installable(pool, s))
515 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", solvable2str(pool, s), (Id)(s - pool->solvables));
516 addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOT_INSTALLABLE, 0);
519 /* yet another SUSE hack, sigh */
520 if (pool->nscallback && !strncmp("product:", id2str(pool, s->name), 8))
522 Id buddy = pool->nscallback(pool, pool->nscallbackdata, NAMESPACE_PRODUCTBUDDY, n);
523 if (buddy > 0 && buddy != SYSTEMSOLVABLE && buddy != n && buddy < pool->nsolvables)
525 addrpmrule(solv, n, -buddy, SOLVER_RULE_RPM_PACKAGE_REQUIRES, solvable_selfprovidedep(pool->solvables + n));
526 addrpmrule(solv, buddy, -n, SOLVER_RULE_RPM_PACKAGE_REQUIRES, solvable_selfprovidedep(pool->solvables + buddy));
527 if (m && !MAPTST(m, buddy))
528 queue_push(&workq, buddy);
532 /*-----------------------------------------
533 * check requires of s
538 reqp = s->repo->idarraydata + s->requires;
539 while ((req = *reqp++) != 0) /* go through all requires */
541 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
544 /* find list of solvables providing 'req' */
545 dp = pool_whatprovides_ptr(pool, req);
547 if (*dp == SYSTEMSOLVABLE) /* always installed */
552 /* the strategy here is to not insist on dependencies
553 * that are already broken. so if we find one provider
554 * that was already installed, we know that the
555 * dependency was not broken before so we enforce it */
557 /* check if any of the providers for 'req' is installed */
558 for (i = 0; (p = dp[i]) != 0; i++)
560 if (pool->solvables[p].repo == installed)
561 break; /* provider was installed */
563 /* didn't find an installed provider: previously broken dependency */
566 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", dep2str(pool, req), solvable2str(pool, s));
573 /* nothing provides req! */
574 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", solvable2str(pool, s), (Id)(s - pool->solvables), dep2str(pool, req));
575 addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP, req);
579 IF_POOLDEBUG (SAT_DEBUG_RULE_CREATION)
581 POOL_DEBUG(SAT_DEBUG_RULE_CREATION," %s requires %s\n", solvable2str(pool, s), dep2str(pool, req));
582 for (i = 0; dp[i]; i++)
583 POOL_DEBUG(SAT_DEBUG_RULE_CREATION, " provided by %s\n", solvid2str(pool, dp[i]));
586 /* add 'requires' dependency */
587 /* rule: (-requestor|provider1|provider2|...|providerN) */
588 addrpmrule(solv, -n, dp - pool->whatprovidesdata, SOLVER_RULE_RPM_PACKAGE_REQUIRES, req);
590 /* descend the dependency tree
591 push all non-visited providers on the work queue */
597 queue_push(&workq, *dp);
601 } /* while, requirements of n */
603 } /* if, requirements */
605 /* that's all we check for src packages */
606 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
609 /*-----------------------------------------
610 * check conflicts of s
617 /* we treat conflicts in patches a bit differen:
619 * - multiversion handling
620 * XXX: we should really handle this different, looking
621 * at the name is a bad hack
623 if (!strncmp("patch:", id2str(pool, s->name), 6))
625 conp = s->repo->idarraydata + s->conflicts;
626 /* foreach conflicts of 's' */
627 while ((con = *conp++) != 0)
629 /* foreach providers of a conflict of 's' */
630 FOR_PROVIDES(p, pp, con)
632 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, con))
634 /* dontfix: dont care about conflicts with already installed packs */
635 if (dontfix && pool->solvables[p].repo == installed)
637 /* p == n: self conflict */
638 if (p == n && !pool->allowselfconflicts)
642 Reldep *rd = GETRELDEP(pool, con);
643 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
646 p = 0; /* make it a negative assertion, aka 'uninstallable' */
648 if (p && ispatch && solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p) && ISRELDEP(con))
650 /* our patch conflicts with a noobsoletes (aka multiversion) package */
651 p = -makemultiversionconflict(solv, p, con);
653 /* rule: -n|-p: either solvable _or_ provider of conflict */
654 addrpmrule(solv, -n, -p, p ? SOLVER_RULE_RPM_PACKAGE_CONFLICT : SOLVER_RULE_RPM_SELF_CONFLICT, con);
659 /*-----------------------------------------
660 * check obsoletes and implicit obsoletes of a package
661 * if ignoreinstalledsobsoletes is not set, we're also checking
662 * obsoletes of installed packages (like newer rpm versions)
664 if ((!installed || s->repo != installed) || !pool->noinstalledobsoletes)
666 int noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n);
667 int isinstalled = (installed && s->repo == installed);
668 if (s->obsoletes && !noobs)
670 obsp = s->repo->idarraydata + s->obsoletes;
671 /* foreach obsoletes */
672 while ((obs = *obsp++) != 0)
674 /* foreach provider of an obsoletes of 's' */
675 FOR_PROVIDES(p, pp, obs)
677 Solvable *ps = pool->solvables + p;
680 if (isinstalled && dontfix && ps->repo == installed)
681 continue; /* don't repair installed/installed problems */
682 if (!pool->obsoleteusesprovides /* obsoletes are matched names, not provides */
683 && !pool_match_nevr(pool, ps, obs))
685 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
688 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_PACKAGE_OBSOLETES, obs);
690 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES, obs);
694 /* check implicit obsoletes
695 * for installed packages we only need to check installed/installed problems (and
696 * only when dontfix is not set), as the others are picked up when looking at the
697 * uninstalled package.
699 if (!isinstalled || !dontfix)
701 FOR_PROVIDES(p, pp, s->name)
703 Solvable *ps = pool->solvables + p;
706 if (isinstalled && ps->repo != installed)
708 /* we still obsolete packages with same nevra, like rpm does */
709 /* (actually, rpm mixes those packages. yuck...) */
710 if (noobs && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
712 if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
714 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
716 if (s->name == ps->name)
717 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_SAME_NAME, 0);
719 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_IMPLICIT_OBSOLETES, s->name);
724 /*-----------------------------------------
725 * add recommends to the work queue
727 if (s->recommends && m)
729 recp = s->repo->idarraydata + s->recommends;
730 while ((rec = *recp++) != 0)
732 FOR_PROVIDES(p, pp, rec)
734 queue_push(&workq, p);
737 if (s->suggests && m)
739 sugp = s->repo->idarraydata + s->suggests;
740 while ((sug = *sugp++) != 0)
742 FOR_PROVIDES(p, pp, sug)
744 queue_push(&workq, p);
749 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforsolvable end -----\n");
753 /*-------------------------------------------------------------------
755 * Add package rules for weak rules
757 * m: visited solvables
761 solver_addrpmrulesforweak(Solver *solv, Map *m)
763 Pool *pool = solv->pool;
768 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak -----\n");
769 /* foreach solvable in pool */
770 for (i = n = 1; n < pool->nsolvables; i++, n++)
772 if (i == pool->nsolvables) /* wrap i */
774 if (MAPTST(m, i)) /* been there */
777 s = pool->solvables + i;
778 if (!pool_installable(pool, s)) /* only look at installable ones */
784 /* find possible supplements */
785 supp = s->repo->idarraydata + s->supplements;
786 while ((sup = *supp++) != ID_NULL)
787 if (dep_possible(solv, sup, m))
791 /* if nothing found, check for enhances */
792 if (!sup && s->enhances)
794 supp = s->repo->idarraydata + s->enhances;
795 while ((sup = *supp++) != ID_NULL)
796 if (dep_possible(solv, sup, m))
799 /* if nothing found, goto next solvables */
802 solver_addrpmrulesforsolvable(solv, s, m);
803 n = 0; /* check all solvables again */
805 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforweak end -----\n");
809 /*-------------------------------------------------------------------
811 * add package rules for possible updates
814 * m: map of already visited solvables
815 * allow_all: 0 = dont allow downgrades, 1 = allow all candidates
819 solver_addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
821 Pool *pool = solv->pool;
823 /* queue and buffer for it */
827 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
829 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
830 /* find update candidates for 's' */
831 policy_findupdatepackages(solv, s, &qs, allow_all);
832 /* add rule for 's' if not already done */
833 if (!MAPTST(m, s - pool->solvables))
834 solver_addrpmrulesforsolvable(solv, s, m);
835 /* foreach update candidate, add rule if not already done */
836 for (i = 0; i < qs.count; i++)
837 if (!MAPTST(m, qs.elements[i]))
838 solver_addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
841 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addrpmrulesforupdaters -----\n");
845 /***********************************************************************
847 *** Update/Feature rule part
849 *** Those rules make sure an installed package isn't silently deleted
854 finddistupgradepackages(Solver *solv, Solvable *s, Queue *qs, int allow_all)
856 Pool *pool = solv->pool;
859 policy_findupdatepackages(solv, s, qs, allow_all);
863 return 0; /* orphaned, don't create feature rule */
864 /* check if this is an orphaned package */
865 policy_findupdatepackages(solv, s, qs, 1);
867 return 0; /* orphaned, don't create update rule */
869 return -SYSTEMSOLVABLE; /* supported but not installable */
872 return s - pool->solvables;
873 /* check if it is ok to keep the installed package */
874 for (i = 0; i < qs->count; i++)
876 Solvable *ns = pool->solvables + qs->elements[i];
877 if (s->evr == ns->evr && solvable_identical(s, ns))
878 return s - pool->solvables;
880 /* nope, it must be some other package */
881 return -SYSTEMSOLVABLE;
884 /* add packages from the dup repositories to the update candidates
885 * this isn't needed for the global dup mode as all packages are
886 * from dup repos in that case */
888 addduppackages(Solver *solv, Solvable *s, Queue *qs)
893 int oldnoupdateprovide = solv->noupdateprovide;
895 queue_init_buffer(&dupqs, dupqsbuf, sizeof(dupqsbuf)/sizeof(*dupqsbuf));
896 solv->noupdateprovide = 1;
897 policy_findupdatepackages(solv, s, &dupqs, 2);
898 solv->noupdateprovide = oldnoupdateprovide;
899 for (i = 0; i < dupqs.count; i++)
901 p = dupqs.elements[i];
902 if (MAPTST(&solv->dupmap, p))
903 queue_pushunique(qs, p);
908 /*-------------------------------------------------------------------
910 * add rule for update
911 * (A|A1|A2|A3...) An = update candidates for A
913 * s = (installed) solvable
917 solver_addupdaterule(Solver *solv, Solvable *s, int allow_all)
919 /* installed packages get a special upgrade allowed rule */
920 Pool *pool = solv->pool;
925 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule -----\n");
926 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
927 p = s - pool->solvables;
928 /* find update candidates for 's' */
929 if (solv->dupmap_all)
930 p = finddistupgradepackages(solv, s, &qs, allow_all);
932 policy_findupdatepackages(solv, s, &qs, allow_all);
933 if (!allow_all && !solv->dupmap_all && solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
934 addduppackages(solv, s, &qs);
936 if (!allow_all && qs.count && solv->noobsoletes.size)
940 d = pool_queuetowhatprovides(pool, &qs);
941 /* filter out all noobsoletes packages as they don't update */
942 for (i = j = 0; i < qs.count; i++)
944 if (MAPTST(&solv->noobsoletes, qs.elements[i]))
946 /* it's ok if they have same nevra */
947 Solvable *ps = pool->solvables + qs.elements[i];
948 if (ps->name != s->name || ps->evr != s->evr || ps->arch != s->arch)
951 qs.elements[j++] = qs.elements[i];
955 if (d && solv->installed && s->repo == solv->installed &&
956 (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, s - pool->solvables - solv->installed->start))))
958 if (!solv->multiversionupdaters)
959 solv->multiversionupdaters = sat_calloc(solv->installed->end - solv->installed->start, sizeof(Id));
960 solv->multiversionupdaters[s - pool->solvables - solv->installed->start] = d;
962 if (j == 0 && p == -SYSTEMSOLVABLE && solv->dupmap_all)
964 queue_push(&solv->orphaned, s - pool->solvables); /* treat as orphaned */
970 if (qs.count && p == -SYSTEMSOLVABLE)
971 p = queue_shift(&qs);
972 d = qs.count ? pool_queuetowhatprovides(pool, &qs) : 0;
974 solver_addrule(solv, p, d); /* allow update of s */
975 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
979 disableupdaterule(Solver *solv, Id p)
983 MAPSET(&solv->noupdate, p - solv->installed->start);
984 r = solv->rules + solv->updaterules + (p - solv->installed->start);
985 if (r->p && r->d >= 0)
986 solver_disablerule(solv, r);
987 r = solv->rules + solv->featurerules + (p - solv->installed->start);
988 if (r->p && r->d >= 0)
989 solver_disablerule(solv, r);
993 reenableupdaterule(Solver *solv, Id p)
995 Pool *pool = solv->pool;
998 MAPCLR(&solv->noupdate, p - solv->installed->start);
999 r = solv->rules + solv->updaterules + (p - solv->installed->start);
1004 solver_enablerule(solv, r);
1005 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1007 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1008 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1012 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1013 if (r->p && r->d < 0)
1015 solver_enablerule(solv, r);
1016 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1018 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1019 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1025 /***********************************************************************
1027 *** Infarch rule part
1029 *** Infarch rules make sure the solver uses the best architecture of
1030 *** a package if multiple archetectures are available
1035 solver_addinfarchrules(Solver *solv, Map *addedmap)
1037 Pool *pool = solv->pool;
1039 Id p, pp, a, aa, bestarch;
1040 Solvable *s, *ps, *bests;
1041 Queue badq, allowedarchs;
1044 queue_init(&allowedarchs);
1045 solv->infarchrules = solv->nrules;
1046 for (i = 1; i < pool->nsolvables; i++)
1048 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1050 s = pool->solvables + i;
1054 queue_empty(&allowedarchs);
1055 FOR_PROVIDES(p, pp, s->name)
1057 ps = pool->solvables + p;
1058 if (ps->name != s->name || !MAPTST(addedmap, p))
1065 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1066 if (a != 1 && pool->installed && ps->repo == pool->installed)
1068 if (!solv->dupmap_all && !(solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
1069 queue_pushunique(&allowedarchs, ps->arch); /* also ok to keep this architecture */
1070 continue; /* ignore installed solvables when calculating the best arch */
1072 if (a && a != 1 && (!bestarch || a < bestarch))
1080 /* speed up common case where installed package already has best arch */
1081 if (allowedarchs.count == 1 && bests && allowedarchs.elements[0] == bests->arch)
1082 allowedarchs.count--; /* installed arch is best */
1084 FOR_PROVIDES(p, pp, s->name)
1086 ps = pool->solvables + p;
1087 if (ps->name != s->name || !MAPTST(addedmap, p))
1090 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1091 if (a != 1 && bestarch && ((a ^ bestarch) & 0xffff0000) != 0)
1093 if (pool->installed && ps->repo == pool->installed)
1094 continue; /* always ok to keep an installed package */
1095 for (j = 0; j < allowedarchs.count; j++)
1097 aa = allowedarchs.elements[j];
1100 aa = (aa <= pool->lastarch) ? pool->id2arch[aa] : 0;
1101 if (aa && ((a ^ aa) & 0xffff0000) == 0)
1102 break; /* compatible */
1104 if (j == allowedarchs.count)
1105 queue_push(&badq, p);
1110 /* block all solvables in the badq! */
1111 for (j = 0; j < badq.count; j++)
1113 p = badq.elements[j];
1114 solver_addrule(solv, -p, 0);
1118 queue_free(&allowedarchs);
1119 solv->infarchrules_end = solv->nrules;
1123 disableinfarchrule(Solver *solv, Id name)
1125 Pool *pool = solv->pool;
1128 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1130 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1131 solver_disablerule(solv, r);
1136 reenableinfarchrule(Solver *solv, Id name)
1138 Pool *pool = solv->pool;
1141 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1143 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1145 solver_enablerule(solv, r);
1146 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1148 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1149 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1156 /***********************************************************************
1160 *** Dup rules make sure a package is selected from the specified dup
1161 *** repositories if an update candidate is included in one of them.
1166 solver_createdupmaps(Solver *solv)
1168 Queue *job = &solv->job;
1169 Pool *pool = solv->pool;
1171 Id how, what, p, pi, pp, obs, *obsp;
1175 map_init(&solv->dupmap, pool->nsolvables);
1176 map_init(&solv->dupinvolvedmap, pool->nsolvables);
1177 for (i = 0; i < job->count; i += 2)
1179 how = job->elements[i];
1180 what = job->elements[i + 1];
1181 switch (how & SOLVER_JOBMASK)
1183 case SOLVER_DISTUPGRADE:
1184 if ((how & SOLVER_SELECTMASK) != SOLVER_SOLVABLE_REPO)
1186 if (what <= 0 || what > pool->nrepos)
1188 repo = pool_id2repo(pool, what);
1189 FOR_REPO_SOLVABLES(repo, p, s)
1191 MAPSET(&solv->dupmap, p);
1192 FOR_PROVIDES(pi, pp, s->name)
1194 ps = pool->solvables + pi;
1195 if (ps->name != s->name)
1197 MAPSET(&solv->dupinvolvedmap, pi);
1201 /* FIXME: check obsoletes/provides combination */
1202 obsp = s->repo->idarraydata + s->obsoletes;
1203 while ((obs = *obsp++) != 0)
1205 FOR_PROVIDES(pi, pp, obs)
1207 Solvable *pis = pool->solvables + pi;
1208 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pis, obs))
1210 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, pis))
1212 MAPSET(&solv->dupinvolvedmap, pi);
1222 MAPCLR(&solv->dupinvolvedmap, SYSTEMSOLVABLE);
1226 solver_freedupmaps(Solver *solv)
1228 map_free(&solv->dupmap);
1229 map_free(&solv->dupinvolvedmap);
1233 solver_addduprules(Solver *solv, Map *addedmap)
1235 Pool *pool = solv->pool;
1240 solv->duprules = solv->nrules;
1241 for (i = 1; i < pool->nsolvables; i++)
1243 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1245 s = pool->solvables + i;
1247 FOR_PROVIDES(p, pp, s->name)
1249 ps = pool->solvables + p;
1250 if (ps->name != s->name || !MAPTST(addedmap, p))
1256 if (!MAPTST(&solv->dupinvolvedmap, p))
1258 if (solv->installed && ps->repo == solv->installed)
1260 if (!solv->updatemap.size)
1261 map_grow(&solv->updatemap, solv->installed->end - solv->installed->start);
1262 MAPSET(&solv->updatemap, p - solv->installed->start);
1263 if (!MAPTST(&solv->dupmap, p))
1266 /* is installed identical to a good one? */
1267 FOR_PROVIDES(ip, ipp, ps->name)
1269 Solvable *is = pool->solvables + ip;
1270 if (!MAPTST(&solv->dupmap, ip))
1272 if (is->evr == ps->evr && solvable_identical(ps, is))
1276 solver_addrule(solv, -p, 0); /* no match, sorry */
1279 else if (!MAPTST(&solv->dupmap, p))
1280 solver_addrule(solv, -p, 0);
1283 solv->duprules_end = solv->nrules;
1288 disableduprule(Solver *solv, Id name)
1290 Pool *pool = solv->pool;
1293 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1295 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1296 solver_disablerule(solv, r);
1301 reenableduprule(Solver *solv, Id name)
1303 Pool *pool = solv->pool;
1306 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1308 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1310 solver_enablerule(solv, r);
1311 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1313 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1314 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1321 /***********************************************************************
1323 *** Policy rule disabling/reenabling
1325 *** Disable all policy rules that conflict with our jobs. If a job
1326 *** gets disabled later on, reenable the involved policy rules again.
1330 #define DISABLE_UPDATE 1
1331 #define DISABLE_INFARCH 2
1332 #define DISABLE_DUP 3
1335 jobtodisablelist(Solver *solv, Id how, Id what, Queue *q)
1337 Pool *pool = solv->pool;
1343 installed = solv->installed;
1344 select = how & SOLVER_SELECTMASK;
1345 switch (how & SOLVER_JOBMASK)
1347 case SOLVER_INSTALL:
1348 if ((select == SOLVER_SOLVABLE_NAME || select == SOLVER_SOLVABLE_PROVIDES) && solv->infarchrules != solv->infarchrules_end && ISRELDEP(what))
1350 Reldep *rd = GETRELDEP(pool, what);
1351 if (rd->flags == REL_ARCH)
1353 int qcnt = q->count;
1354 FOR_JOB_SELECT(p, pp, select, what)
1356 s = pool->solvables + p;
1358 for (i = qcnt; i < q->count; i += 2)
1359 if (q->elements[i + 1] == s->name)
1363 queue_push2(q, DISABLE_INFARCH, s->name);
1367 if (select != SOLVER_SOLVABLE)
1369 s = pool->solvables + what;
1370 if (solv->infarchrules != solv->infarchrules_end)
1371 queue_push2(q, DISABLE_INFARCH, s->name);
1372 if (solv->duprules != solv->duprules_end)
1373 queue_push2(q, DISABLE_DUP, s->name);
1376 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, what))
1378 /* XXX: remove if we always do distupgrade with DUP rules */
1379 if (solv->dupmap_all && s->repo == installed)
1380 queue_push2(q, DISABLE_UPDATE, what);
1383 if (s->repo == installed)
1385 queue_push2(q, DISABLE_UPDATE, what);
1391 obsp = s->repo->idarraydata + s->obsoletes;
1392 while ((obs = *obsp++) != 0)
1393 FOR_PROVIDES(p, pp, obs)
1395 Solvable *ps = pool->solvables + p;
1396 if (ps->repo != installed)
1398 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
1400 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1402 queue_push2(q, DISABLE_UPDATE, p);
1405 FOR_PROVIDES(p, pp, s->name)
1407 Solvable *ps = pool->solvables + p;
1408 if (ps->repo != installed)
1410 if (!pool->implicitobsoleteusesprovides && ps->name != s->name)
1412 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1414 queue_push2(q, DISABLE_UPDATE, p);
1420 FOR_JOB_SELECT(p, pp, select, what)
1421 if (pool->solvables[p].repo == installed)
1422 queue_push2(q, DISABLE_UPDATE, p);
1429 /* disable all policy rules that are in conflict with our job list */
1431 solver_disablepolicyrules(Solver *solv)
1433 Queue *job = &solv->job;
1440 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
1442 for (i = solv->jobrules; i < solv->jobrules_end; i++)
1444 r = solv->rules + i;
1445 if (r->d < 0) /* disabled? */
1447 j = solv->ruletojob.elements[i - solv->jobrules];
1451 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
1453 if (solv->cleandepsmap.size)
1455 solver_createcleandepsmap(solv);
1456 for (i = solv->installed->start; i < solv->installed->end; i++)
1457 if (MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1458 queue_push2(&allq, DISABLE_UPDATE, i);
1460 MAPZERO(&solv->noupdate);
1461 for (i = 0; i < allq.count; i += 2)
1463 Id type = allq.elements[i], arg = allq.elements[i + 1];
1466 case DISABLE_UPDATE:
1467 disableupdaterule(solv, arg);
1469 case DISABLE_INFARCH:
1470 disableinfarchrule(solv, arg);
1473 disableduprule(solv, arg);
1482 /* we just disabled job #jobidx, now reenable all policy rules that were
1483 * disabled because of this job */
1485 solver_reenablepolicyrules(Solver *solv, int jobidx)
1487 Queue *job = &solv->job;
1492 Id qbuf[32], allqbuf[128];
1494 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1495 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
1496 jobtodisablelist(solv, job->elements[jobidx], job->elements[jobidx + 1], &q);
1499 for (i = solv->jobrules; i < solv->jobrules_end; i++)
1501 r = solv->rules + i;
1502 if (r->d < 0) /* disabled? */
1504 j = solv->ruletojob.elements[i - solv->jobrules];
1508 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
1510 if (solv->cleandepsmap.size)
1512 solver_createcleandepsmap(solv);
1513 for (i = solv->installed->start; i < solv->installed->end; i++)
1514 if (MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1515 queue_push2(&allq, DISABLE_UPDATE, i);
1517 for (j = 0; j < q.count; j += 2)
1519 Id type = q.elements[j], arg = q.elements[j + 1];
1520 for (i = 0; i < allq.count; i += 2)
1521 if (allq.elements[i] == type && allq.elements[i + 1] == arg)
1524 continue; /* still disabled */
1527 case DISABLE_UPDATE:
1528 reenableupdaterule(solv, arg);
1530 case DISABLE_INFARCH:
1531 reenableinfarchrule(solv, arg);
1534 reenableduprule(solv, arg);
1543 /***********************************************************************
1545 *** Rule info part, tell the user what the rule is about.
1550 addrpmruleinfo(Solver *solv, Id p, Id d, int type, Id dep)
1552 Pool *pool = solv->pool;
1556 /* check if this creates the rule we're searching for */
1557 r = solv->rules + solv->ruleinfoq->elements[0];
1559 od = r->d < 0 ? -r->d - 1 : r->d;
1564 if (p < 0 && d > 0 && (!pool->whatprovidesdata[d] || !pool->whatprovidesdata[d + 1]))
1566 w2 = pool->whatprovidesdata[d];
1570 if (p > 0 && d < 0) /* this hack is used for buddy deps */
1582 Id *dp = pool->whatprovidesdata + d;
1583 Id *odp = pool->whatprovidesdata + od;
1585 if (*dp++ != *odp++)
1591 /* handle multiversion conflict rules */
1592 if (p < 0 && pool->whatprovidesdata[d] < 0)
1594 w2 = pool->whatprovidesdata[d];
1595 /* XXX: free memory */
1605 if (w2 != op || p != ow2)
1610 if (p != op || w2 != ow2)
1614 /* yep, rule matches. record info */
1615 queue_push(solv->ruleinfoq, type);
1616 if (type == SOLVER_RULE_RPM_SAME_NAME)
1618 /* we normalize same name order */
1619 queue_push(solv->ruleinfoq, op < 0 ? -op : 0);
1620 queue_push(solv->ruleinfoq, ow2 < 0 ? -ow2 : 0);
1624 queue_push(solv->ruleinfoq, p < 0 ? -p : 0);
1625 queue_push(solv->ruleinfoq, w2 < 0 ? -w2 : 0);
1627 queue_push(solv->ruleinfoq, dep);
1631 solver_allruleinfos_cmp(const void *ap, const void *bp, void *dp)
1633 const Id *a = ap, *b = bp;
1652 solver_allruleinfos(Solver *solv, Id rid, Queue *rq)
1654 Pool *pool = solv->pool;
1655 Rule *r = solv->rules + rid;
1659 if (rid <= 0 || rid >= solv->rpmrules_end)
1661 Id type, from, to, dep;
1662 type = solver_ruleinfo(solv, rid, &from, &to, &dep);
1663 queue_push(rq, type);
1664 queue_push(rq, from);
1666 queue_push(rq, dep);
1671 queue_push(rq, rid);
1672 solv->ruleinfoq = rq;
1673 solver_addrpmrulesforsolvable(solv, pool->solvables - r->p, 0);
1674 /* also try reverse direction for conflicts */
1675 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
1676 solver_addrpmrulesforsolvable(solv, pool->solvables - r->w2, 0);
1677 solv->ruleinfoq = 0;
1679 /* now sort & unify em */
1682 sat_sort(rq->elements, rq->count / 4, 4 * sizeof(Id), solver_allruleinfos_cmp, 0);
1683 /* throw out identical entries */
1684 for (i = j = 0; i < rq->count; i += 4)
1688 if (rq->elements[i] == rq->elements[j - 4] &&
1689 rq->elements[i + 1] == rq->elements[j - 3] &&
1690 rq->elements[i + 2] == rq->elements[j - 2] &&
1691 rq->elements[i + 3] == rq->elements[j - 1])
1694 rq->elements[j++] = rq->elements[i];
1695 rq->elements[j++] = rq->elements[i + 1];
1696 rq->elements[j++] = rq->elements[i + 2];
1697 rq->elements[j++] = rq->elements[i + 3];
1704 solver_ruleinfo(Solver *solv, Id rid, Id *fromp, Id *top, Id *depp)
1706 Pool *pool = solv->pool;
1707 Rule *r = solv->rules + rid;
1708 SolverRuleinfo type = SOLVER_RULE_UNKNOWN;
1716 if (rid > 0 && rid < solv->rpmrules_end)
1722 return SOLVER_RULE_RPM;
1726 queue_push(&rq, rid);
1727 solv->ruleinfoq = &rq;
1728 solver_addrpmrulesforsolvable(solv, pool->solvables - r->p, 0);
1729 /* also try reverse direction for conflicts */
1730 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
1731 solver_addrpmrulesforsolvable(solv, pool->solvables - r->w2, 0);
1732 solv->ruleinfoq = 0;
1733 type = SOLVER_RULE_RPM;
1734 for (i = 1; i < rq.count; i += 4)
1737 qt = rq.elements[i];
1738 qp = rq.elements[i + 1];
1739 qo = rq.elements[i + 2];
1740 qd = rq.elements[i + 3];
1741 if (type == SOLVER_RULE_RPM || type > qt)
1755 if (rid >= solv->jobrules && rid < solv->jobrules_end)
1757 Id jidx = solv->ruletojob.elements[rid - solv->jobrules];
1761 *top = solv->job.elements[jidx];
1763 *depp = solv->job.elements[jidx + 1];
1764 if ((r->d == 0 || r->d == -1) && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && (solv->job.elements[jidx] & SOLVER_SELECTMASK) != SOLVER_SOLVABLE_ONE_OF)
1765 return SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP;
1766 return SOLVER_RULE_JOB;
1768 if (rid >= solv->updaterules && rid < solv->updaterules_end)
1771 *fromp = solv->installed->start + (rid - solv->updaterules);
1772 return SOLVER_RULE_UPDATE;
1774 if (rid >= solv->featurerules && rid < solv->featurerules_end)
1777 *fromp = solv->installed->start + (rid - solv->featurerules);
1778 return SOLVER_RULE_FEATURE;
1780 if (rid >= solv->duprules && rid < solv->duprules_end)
1785 *depp = pool->solvables[-r->p].name;
1786 return SOLVER_RULE_DISTUPGRADE;
1788 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
1793 *depp = pool->solvables[-r->p].name;
1794 return SOLVER_RULE_INFARCH;
1796 if (rid >= solv->choicerules && rid < solv->choicerules_end)
1798 return SOLVER_RULE_CHOICE;
1800 if (rid >= solv->learntrules)
1802 return SOLVER_RULE_LEARNT;
1804 return SOLVER_RULE_UNKNOWN;
1808 solver_addchoicerules(Solver *solv)
1810 Pool *pool = solv->pool;
1814 int i, j, rid, havechoice;
1819 solv->choicerules = solv->nrules;
1820 if (!pool->installed)
1822 solv->choicerules_end = solv->nrules;
1825 solv->choicerules_ref = sat_calloc(solv->rpmrules_end, sizeof(Id));
1828 map_init(&m, pool->nsolvables);
1829 map_init(&mneg, pool->nsolvables);
1830 /* set up negative assertion map from infarch and dup rules */
1831 for (rid = solv->infarchrules, r = solv->rules + rid; rid < solv->infarchrules_end; rid++, r++)
1832 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
1833 MAPSET(&mneg, -r->p);
1834 for (rid = solv->duprules, r = solv->rules + rid; rid < solv->duprules_end; rid++, r++)
1835 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
1836 MAPSET(&mneg, -r->p);
1837 for (rid = 1; rid < solv->rpmrules_end ; rid++)
1839 r = solv->rules + rid;
1840 if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 < 0))
1841 continue; /* only look at requires rules */
1842 // solver_printrule(solv, SAT_DEBUG_RESULT, r);
1846 FOR_RULELITERALS(p, pp, r)
1850 s = pool->solvables + p;
1853 if (s->repo == pool->installed)
1858 /* check if this package is "blocked" by a installed package */
1860 FOR_PROVIDES(p2, pp2, s->name)
1862 s2 = pool->solvables + p2;
1863 if (s2->repo != pool->installed)
1865 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
1867 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
1873 /* found installed package p2 that we can update to p */
1874 if (!solv->allowarchchange && s->arch != s2->arch && policy_illegal_archchange(solv, s, s2))
1876 if (!solv->allowvendorchange && s->vendor != s2->vendor && policy_illegal_vendorchange(solv, s, s2))
1878 if (MAPTST(&mneg, p))
1880 queue_push(&qi, p2);
1886 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1888 while ((obs = *obsp++) != 0)
1890 FOR_PROVIDES(p2, pp2, obs)
1892 s2 = pool->solvables + p2;
1893 if (s2->repo != pool->installed)
1895 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
1897 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
1906 /* found installed package p2 that we can update to p */
1907 if (!solv->allowarchchange && s->arch != s2->arch && policy_illegal_archchange(solv, s, s2))
1909 if (!solv->allowvendorchange && s->vendor != s2->vendor && policy_illegal_vendorchange(solv, s, s2))
1911 if (MAPTST(&mneg, p))
1913 queue_push(&qi, p2);
1918 /* package p is independent of the installed ones */
1921 if (!havechoice || !q.count)
1922 continue; /* no choice */
1924 /* now check the update rules of the installed package.
1925 * if all packages of the update rules are contained in
1926 * the dependency rules, there's no need to set up the choice rule */
1928 FOR_RULELITERALS(p, pp, r)
1931 for (i = 0; i < qi.count; i++)
1933 if (!qi.elements[i])
1935 Rule *ur = solv->rules + solv->updaterules + (qi.elements[i] - pool->installed->start);
1937 ur = solv->rules + solv->featurerules + (qi.elements[i] - pool->installed->start);
1940 FOR_RULELITERALS(p, pp, ur)
1945 for (j = i + 1; j < qi.count; j++)
1946 if (qi.elements[i] == qi.elements[j])
1952 printf("skipping choice ");
1953 solver_printrule(solv, SAT_DEBUG_RESULT, solv->rules + rid);
1957 d = q.count ? pool_queuetowhatprovides(pool, &q) : 0;
1958 solver_addrule(solv, r->p, d);
1959 queue_push(&solv->weakruleq, solv->nrules - 1);
1960 solv->choicerules_ref[solv->nrules - 1 - solv->choicerules] = rid;
1963 solver_printrule(solv, SAT_DEBUG_RESULT, solv->rules + rid);
1964 printf("WEAK CHOICE ");
1965 solver_printrule(solv, SAT_DEBUG_RESULT, solv->rules + solv->nrules - 1);
1972 solv->choicerules_end = solv->nrules;
1975 /* called when a choice rule is disabled by analyze_unsolvable. We also
1976 * have to disable all other choice rules so that the best packages get
1979 solver_disablechoicerules(Solver *solv, Rule *r)
1982 Pool *pool = solv->pool;
1986 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
1987 map_init(&m, pool->nsolvables);
1988 FOR_RULELITERALS(p, pp, or)
1991 FOR_RULELITERALS(p, pp, r)
1994 for (rid = solv->choicerules; rid < solv->choicerules_end; rid++)
1996 r = solv->rules + rid;
1999 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
2000 FOR_RULELITERALS(p, pp, or)
2001 if (p > 0 && MAPTST(&m, p))
2004 solver_disablerule(solv, r);
2008 static void solver_createcleandepsmap(Solver *solv)
2010 Pool *pool = solv->pool;
2011 Repo *installed = solv->installed;
2012 Queue *job = &solv->job;
2017 Id rid, how, what, select;
2019 Id req, *reqp, sup, *supp;
2024 map_init(&userinstalled, installed->end - installed->start);
2025 map_init(&im, pool->nsolvables);
2026 map_init(&installedm, pool->nsolvables);
2027 map_empty(&solv->cleandepsmap);
2030 for (i = 0; i < job->count; i += 2)
2032 how = job->elements[i];
2033 if ((how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
2035 what = job->elements[i + 1];
2036 select = how & SOLVER_SELECTMASK;
2037 FOR_JOB_SELECT(p, pp, select, what)
2038 if (pool->solvables[p].repo == installed)
2039 MAPSET(&userinstalled, p - installed->start);
2042 /* add all positive elements (e.g. locks) to "userinstalled" */
2043 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2045 r = solv->rules + rid;
2048 FOR_RULELITERALS(p, jp, r)
2049 if (p > 0 && pool->solvables[p].repo == installed)
2050 MAPSET(&userinstalled, p - installed->start);
2052 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2054 r = solv->rules + rid;
2055 if (r->p >= 0 || r->d != 0)
2056 continue; /* disabled or not erase */
2058 if (pool->solvables[p].repo != installed)
2060 MAPCLR(&userinstalled, p - installed->start);
2061 i = solv->ruletojob.elements[rid - solv->jobrules];
2062 how = job->elements[i];
2063 if ((how & (SOLVER_JOBMASK|SOLVER_CLEANDEPS)) == (SOLVER_ERASE|SOLVER_CLEANDEPS))
2066 for (p = installed->start; p < installed->end; p++)
2068 if (pool->solvables[p].repo != installed)
2070 MAPSET(&installedm, p);
2076 ip = queue_shift(&iq);
2077 s = pool->solvables + ip;
2078 if (!MAPTST(&im, ip))
2080 if (!MAPTST(&installedm, ip))
2082 if (s->repo == installed && MAPTST(&userinstalled, ip - installed->start))
2085 #ifdef CLEANDEPSDEBUG
2086 printf("hello %s\n", solvable2str(pool, s));
2090 reqp = s->repo->idarraydata + s->requires;
2091 while ((req = *reqp++) != 0)
2093 if (req == SOLVABLE_PREREQMARKER)
2096 /* count number of installed packages that match */
2098 FOR_PROVIDES(p, pp, req)
2099 if (MAPTST(&installedm, p))
2104 FOR_PROVIDES(p, pp, req)
2108 #ifdef CLEANDEPSDEBUG
2109 printf("%s requires %s\n", solvid2str(pool, ip), solvid2str(pool, p));
2118 reqp = s->repo->idarraydata + s->recommends;
2119 while ((req = *reqp++) != 0)
2123 FOR_PROVIDES(p, pp, req)
2124 if (MAPTST(&installedm, p))
2129 FOR_PROVIDES(p, pp, req)
2133 #ifdef CLEANDEPSDEBUG
2134 printf("%s recommends %s\n", solvid2str(pool, ip), solvid2str(pool, p));
2143 /* supplements pass */
2144 for (ip = solv->installed->start; ip < solv->installed->end; ip++)
2146 if (!MAPTST(&installedm, ip))
2148 s = pool->solvables + ip;
2149 if (!s->supplements)
2151 if (!MAPTST(&im, ip))
2153 supp = s->repo->idarraydata + s->supplements;
2154 while ((sup = *supp++) != 0)
2155 if (!dep_possible(solv, sup, &im) && dep_possible(solv, sup, &installedm))
2157 /* no longer supplemented, also erase */
2160 #ifdef CLEANDEPSDEBUG
2161 printf("%s supplemented\n", solvid2str(pool, ip));
2163 queue_push(&iq, ip);
2169 /* turn userinstalled into remove set for pruning */
2170 map_empty(&userinstalled);
2171 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2173 r = solv->rules + rid;
2174 if (r->p >= 0 || r->d != 0)
2175 continue; /* disabled or not erase */
2178 if (pool->solvables[p].repo == installed)
2179 MAPSET(&userinstalled, p - installed->start);
2181 for (p = installed->start; p < installed->end; p++)
2184 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2186 r = solv->rules + rid;
2189 FOR_RULELITERALS(p, jp, r)
2193 /* also put directly addressed packages on the install queue
2194 * so we can mark patterns as installed */
2195 for (i = 0; i < job->count; i += 2)
2197 how = job->elements[i];
2198 if ((how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
2200 what = job->elements[i + 1];
2201 select = how & SOLVER_SELECTMASK;
2202 if (select == SOLVER_SOLVABLE && pool->solvables[what].repo != installed)
2203 queue_push(&iq, what);
2208 ip = queue_shift(&iq);
2209 s = pool->solvables + ip;
2210 #ifdef CLEANDEPSDEBUG
2211 printf("bye %s\n", solvable2str(pool, s));
2215 reqp = s->repo->idarraydata + s->requires;
2216 while ((req = *reqp++) != 0)
2218 FOR_PROVIDES(p, pp, req)
2220 if (!MAPTST(&im, p) && MAPTST(&installedm, p))
2224 if (MAPTST(&userinstalled, p - installed->start))
2226 #ifdef CLEANDEPSDEBUG
2227 printf("%s requires %s\n", solvid2str(pool, ip), solvid2str(pool, p));
2237 reqp = s->repo->idarraydata + s->recommends;
2238 while ((req = *reqp++) != 0)
2240 FOR_PROVIDES(p, pp, req)
2242 if (!MAPTST(&im, p) && MAPTST(&installedm, p))
2246 if (MAPTST(&userinstalled, p - installed->start))
2248 #ifdef CLEANDEPSDEBUG
2249 printf("%s recommends %s\n", solvid2str(pool, ip), solvid2str(pool, p));
2259 /* supplements pass */
2260 for (ip = installed->start; ip < installed->end; ip++)
2262 if (!MAPTST(&installedm, ip))
2264 if (MAPTST(&userinstalled, ip - installed->start))
2266 s = pool->solvables + ip;
2267 if (!s->supplements)
2269 if (MAPTST(&im, ip) || !MAPTST(&installedm, ip))
2271 supp = s->repo->idarraydata + s->supplements;
2272 while ((sup = *supp++) != 0)
2273 if (dep_possible(solv, sup, &im))
2277 #ifdef CLEANDEPSDEBUG
2278 printf("%s supplemented\n", solvid2str(pool, ip));
2281 queue_push(&iq, ip);
2288 for (p = installed->start; p < installed->end; p++)
2290 if (pool->solvables[p].repo != installed)
2292 if (!MAPTST(&im, p))
2293 MAPSET(&solv->cleandepsmap, p - installed->start);
2296 map_free(&installedm);
2297 map_free(&userinstalled);