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 && !solv->fixsystem /* NOT repair errors in rpm dependency graph */
504 && s->repo == installed /* solvable is installed */
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->distupgrade)
930 p = finddistupgradepackages(solv, s, &qs, allow_all);
932 policy_findupdatepackages(solv, s, &qs, allow_all);
933 if (!allow_all && !solv->distupgrade && 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->updatesystem && solv->installed && s->repo == solv->installed)
957 if (!solv->multiversionupdaters)
958 solv->multiversionupdaters = sat_calloc(solv->installed->end - solv->installed->start, sizeof(Id));
959 solv->multiversionupdaters[s - pool->solvables - solv->installed->start] = d;
961 if (j == 0 && p == -SYSTEMSOLVABLE && solv->distupgrade)
963 queue_push(&solv->orphaned, s - pool->solvables); /* treat as orphaned */
969 if (qs.count && p == -SYSTEMSOLVABLE)
970 p = queue_shift(&qs);
971 d = qs.count ? pool_queuetowhatprovides(pool, &qs) : 0;
973 solver_addrule(solv, p, d); /* allow update of s */
974 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- addupdaterule end -----\n");
978 disableupdaterule(Solver *solv, Id p)
982 MAPSET(&solv->noupdate, p - solv->installed->start);
983 r = solv->rules + solv->updaterules + (p - solv->installed->start);
984 if (r->p && r->d >= 0)
985 solver_disablerule(solv, r);
986 r = solv->rules + solv->featurerules + (p - solv->installed->start);
987 if (r->p && r->d >= 0)
988 solver_disablerule(solv, r);
992 reenableupdaterule(Solver *solv, Id p)
994 Pool *pool = solv->pool;
997 MAPCLR(&solv->noupdate, p - solv->installed->start);
998 r = solv->rules + solv->updaterules + (p - solv->installed->start);
1003 solver_enablerule(solv, r);
1004 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1006 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1007 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1011 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1012 if (r->p && r->d < 0)
1014 solver_enablerule(solv, r);
1015 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1017 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1018 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1024 /***********************************************************************
1026 *** Infarch rule part
1028 *** Infarch rules make sure the solver uses the best architecture of
1029 *** a package if multiple archetectures are available
1034 solver_addinfarchrules(Solver *solv, Map *addedmap)
1036 Pool *pool = solv->pool;
1038 Id p, pp, a, aa, bestarch;
1039 Solvable *s, *ps, *bests;
1040 Queue badq, allowedarchs;
1043 queue_init(&allowedarchs);
1044 solv->infarchrules = solv->nrules;
1045 for (i = 1; i < pool->nsolvables; i++)
1047 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1049 s = pool->solvables + i;
1053 queue_empty(&allowedarchs);
1054 FOR_PROVIDES(p, pp, s->name)
1056 ps = pool->solvables + p;
1057 if (ps->name != s->name || !MAPTST(addedmap, p))
1064 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1065 if (a != 1 && pool->installed && ps->repo == pool->installed)
1067 if (!solv->distupgrade)
1068 queue_pushunique(&allowedarchs, ps->arch); /* also ok to keep this architecture */
1069 continue; /* ignore installed solvables when calculating the best arch */
1071 if (a && a != 1 && (!bestarch || a < bestarch))
1079 /* speed up common case where installed package already has best arch */
1080 if (allowedarchs.count == 1 && bests && allowedarchs.elements[0] == bests->arch)
1081 allowedarchs.count--; /* installed arch is best */
1083 FOR_PROVIDES(p, pp, s->name)
1085 ps = pool->solvables + p;
1086 if (ps->name != s->name || !MAPTST(addedmap, p))
1089 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1090 if (a != 1 && bestarch && ((a ^ bestarch) & 0xffff0000) != 0)
1092 if (pool->installed && ps->repo == pool->installed)
1093 continue; /* always ok to keep an installed package */
1094 for (j = 0; j < allowedarchs.count; j++)
1096 aa = allowedarchs.elements[j];
1099 aa = (aa <= pool->lastarch) ? pool->id2arch[aa] : 0;
1100 if (aa && ((a ^ aa) & 0xffff0000) == 0)
1101 break; /* compatible */
1103 if (j == allowedarchs.count)
1104 queue_push(&badq, p);
1109 /* block all solvables in the badq! */
1110 for (j = 0; j < badq.count; j++)
1112 p = badq.elements[j];
1113 solver_addrule(solv, -p, 0);
1117 queue_free(&allowedarchs);
1118 solv->infarchrules_end = solv->nrules;
1122 disableinfarchrule(Solver *solv, Id name)
1124 Pool *pool = solv->pool;
1127 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1129 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1130 solver_disablerule(solv, r);
1135 reenableinfarchrule(Solver *solv, Id name)
1137 Pool *pool = solv->pool;
1140 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1142 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1144 solver_enablerule(solv, r);
1145 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1147 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1148 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1155 /***********************************************************************
1159 *** Dup rules make sure a package is selected from the specified dup
1160 *** repositories if an update candidate is included in one of them.
1165 solver_createdupmaps(Solver *solv)
1167 Queue *job = &solv->job;
1168 Pool *pool = solv->pool;
1170 Id how, what, p, pi, pp, obs, *obsp;
1174 map_init(&solv->dupmap, pool->nsolvables);
1175 map_init(&solv->dupinvolvedmap, pool->nsolvables);
1176 for (i = 0; i < job->count; i += 2)
1178 how = job->elements[i];
1179 what = job->elements[i + 1];
1180 switch (how & SOLVER_JOBMASK)
1182 case SOLVER_DISTUPGRADE:
1183 if ((how & SOLVER_SELECTMASK) != SOLVER_SOLVABLE_REPO)
1185 if (what <= 0 || what > pool->nrepos)
1187 repo = pool_id2repo(pool, what);
1188 FOR_REPO_SOLVABLES(repo, p, s)
1190 MAPSET(&solv->dupmap, p);
1191 FOR_PROVIDES(pi, pp, s->name)
1193 ps = pool->solvables + pi;
1194 if (ps->name != s->name)
1196 MAPSET(&solv->dupinvolvedmap, pi);
1200 /* FIXME: check obsoletes/provides combination */
1201 obsp = s->repo->idarraydata + s->obsoletes;
1202 while ((obs = *obsp++) != 0)
1204 FOR_PROVIDES(pi, pp, obs)
1206 Solvable *pis = pool->solvables + pi;
1207 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pis, obs))
1209 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, pis))
1211 MAPSET(&solv->dupinvolvedmap, pi);
1221 MAPCLR(&solv->dupinvolvedmap, SYSTEMSOLVABLE);
1225 solver_freedupmaps(Solver *solv)
1227 map_free(&solv->dupmap);
1228 map_free(&solv->dupinvolvedmap);
1232 solver_addduprules(Solver *solv, Map *addedmap)
1234 Pool *pool = solv->pool;
1239 solv->duprules = solv->nrules;
1240 for (i = 1; i < pool->nsolvables; i++)
1242 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1244 s = pool->solvables + i;
1246 FOR_PROVIDES(p, pp, s->name)
1248 ps = pool->solvables + p;
1249 if (ps->name != s->name || !MAPTST(addedmap, p))
1255 if (!MAPTST(&solv->dupinvolvedmap, p))
1257 if (solv->installed && ps->repo == solv->installed)
1259 if (!solv->updatemap.size)
1260 map_grow(&solv->updatemap, solv->installed->end - solv->installed->start);
1261 MAPSET(&solv->updatemap, p - solv->installed->start);
1262 if (!MAPTST(&solv->dupmap, p))
1265 /* is installed identical to a good one? */
1266 FOR_PROVIDES(ip, ipp, ps->name)
1268 Solvable *is = pool->solvables + ip;
1269 if (!MAPTST(&solv->dupmap, ip))
1271 if (is->evr == ps->evr && solvable_identical(ps, is))
1275 solver_addrule(solv, -p, 0); /* no match, sorry */
1278 else if (!MAPTST(&solv->dupmap, p))
1279 solver_addrule(solv, -p, 0);
1282 solv->duprules_end = solv->nrules;
1287 disableduprule(Solver *solv, Id name)
1289 Pool *pool = solv->pool;
1292 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1294 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1295 solver_disablerule(solv, r);
1300 reenableduprule(Solver *solv, Id name)
1302 Pool *pool = solv->pool;
1305 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1307 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1309 solver_enablerule(solv, r);
1310 IF_POOLDEBUG (SAT_DEBUG_SOLUTIONS)
1312 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1313 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, r);
1320 /***********************************************************************
1322 *** Policy rule disabling/reenabling
1324 *** Disable all policy rules that conflict with our jobs. If a job
1325 *** gets disabled later on, reenable the involved policy rules again.
1329 #define DISABLE_UPDATE 1
1330 #define DISABLE_INFARCH 2
1331 #define DISABLE_DUP 3
1334 jobtodisablelist(Solver *solv, Id how, Id what, Queue *q)
1336 Pool *pool = solv->pool;
1342 installed = solv->installed;
1343 select = how & SOLVER_SELECTMASK;
1344 switch (how & SOLVER_JOBMASK)
1346 case SOLVER_INSTALL:
1347 if ((select == SOLVER_SOLVABLE_NAME || select == SOLVER_SOLVABLE_PROVIDES) && solv->infarchrules != solv->infarchrules_end && ISRELDEP(what))
1349 Reldep *rd = GETRELDEP(pool, what);
1350 if (rd->flags == REL_ARCH)
1352 int qcnt = q->count;
1353 FOR_JOB_SELECT(p, pp, select, what)
1355 s = pool->solvables + p;
1357 for (i = qcnt; i < q->count; i += 2)
1358 if (q->elements[i + 1] == s->name)
1362 queue_push2(q, DISABLE_INFARCH, s->name);
1366 if (select != SOLVER_SOLVABLE)
1368 s = pool->solvables + what;
1369 if (solv->infarchrules != solv->infarchrules_end)
1370 queue_push2(q, DISABLE_INFARCH, s->name);
1371 if (solv->duprules != solv->duprules_end)
1372 queue_push2(q, DISABLE_DUP, s->name);
1375 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, what))
1377 /* XXX: remove if we always do distupgrade with DUP rules */
1378 if (solv->distupgrade && s->repo == installed)
1379 queue_push2(q, DISABLE_UPDATE, what);
1382 if (s->repo == installed)
1384 queue_push2(q, DISABLE_UPDATE, what);
1390 obsp = s->repo->idarraydata + s->obsoletes;
1391 while ((obs = *obsp++) != 0)
1392 FOR_PROVIDES(p, pp, obs)
1394 Solvable *ps = pool->solvables + p;
1395 if (ps->repo != installed)
1397 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
1399 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1401 queue_push2(q, DISABLE_UPDATE, p);
1404 FOR_PROVIDES(p, pp, s->name)
1406 Solvable *ps = pool->solvables + p;
1407 if (ps->repo != installed)
1409 if (!pool->implicitobsoleteusesprovides && ps->name != s->name)
1411 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1413 queue_push2(q, DISABLE_UPDATE, p);
1419 FOR_JOB_SELECT(p, pp, select, what)
1420 if (pool->solvables[p].repo == installed)
1421 queue_push2(q, DISABLE_UPDATE, p);
1428 /* disable all policy rules that are in conflict with our job list */
1430 solver_disablepolicyrules(Solver *solv)
1432 Queue *job = &solv->job;
1439 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
1441 for (i = solv->jobrules; i < solv->jobrules_end; i++)
1443 r = solv->rules + i;
1444 if (r->d < 0) /* disabled? */
1446 j = solv->ruletojob.elements[i - solv->jobrules];
1450 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
1452 if (solv->cleandepsmap.size)
1454 solver_createcleandepsmap(solv);
1455 for (i = solv->installed->start; i < solv->installed->end; i++)
1456 if (MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1457 queue_push2(&allq, DISABLE_UPDATE, i);
1459 MAPZERO(&solv->noupdate);
1460 for (i = 0; i < allq.count; i += 2)
1462 Id type = allq.elements[i], arg = allq.elements[i + 1];
1465 case DISABLE_UPDATE:
1466 disableupdaterule(solv, arg);
1468 case DISABLE_INFARCH:
1469 disableinfarchrule(solv, arg);
1472 disableduprule(solv, arg);
1481 /* we just disabled job #jobidx, now reenable all policy rules that were
1482 * disabled because of this job */
1484 solver_reenablepolicyrules(Solver *solv, int jobidx)
1486 Queue *job = &solv->job;
1491 Id qbuf[32], allqbuf[128];
1493 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1494 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
1495 jobtodisablelist(solv, job->elements[jobidx], job->elements[jobidx + 1], &q);
1498 for (i = solv->jobrules; i < solv->jobrules_end; i++)
1500 r = solv->rules + i;
1501 if (r->d < 0) /* disabled? */
1503 j = solv->ruletojob.elements[i - solv->jobrules];
1507 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
1509 if (solv->cleandepsmap.size)
1511 solver_createcleandepsmap(solv);
1512 for (i = solv->installed->start; i < solv->installed->end; i++)
1513 if (MAPTST(&solv->cleandepsmap, i - solv->installed->start))
1514 queue_push2(&allq, DISABLE_UPDATE, i);
1516 for (j = 0; j < q.count; j += 2)
1518 Id type = q.elements[j], arg = q.elements[j + 1];
1519 for (i = 0; i < allq.count; i += 2)
1520 if (allq.elements[i] == type && allq.elements[i + 1] == arg)
1523 continue; /* still disabled */
1526 case DISABLE_UPDATE:
1527 reenableupdaterule(solv, arg);
1529 case DISABLE_INFARCH:
1530 reenableinfarchrule(solv, arg);
1533 reenableduprule(solv, arg);
1542 /***********************************************************************
1544 *** Rule info part, tell the user what the rule is about.
1549 addrpmruleinfo(Solver *solv, Id p, Id d, int type, Id dep)
1551 Pool *pool = solv->pool;
1555 /* check if this creates the rule we're searching for */
1556 r = solv->rules + solv->ruleinfoq->elements[0];
1558 od = r->d < 0 ? -r->d - 1 : r->d;
1563 if (p < 0 && d > 0 && (!pool->whatprovidesdata[d] || !pool->whatprovidesdata[d + 1]))
1565 w2 = pool->whatprovidesdata[d];
1569 if (p > 0 && d < 0) /* this hack is used for buddy deps */
1581 Id *dp = pool->whatprovidesdata + d;
1582 Id *odp = pool->whatprovidesdata + od;
1584 if (*dp++ != *odp++)
1590 /* handle multiversion conflict rules */
1591 if (p < 0 && pool->whatprovidesdata[d] < 0)
1593 w2 = pool->whatprovidesdata[d];
1594 /* XXX: free memory */
1604 if (w2 != op || p != ow2)
1609 if (p != op || w2 != ow2)
1613 /* yep, rule matches. record info */
1614 queue_push(solv->ruleinfoq, type);
1615 if (type == SOLVER_RULE_RPM_SAME_NAME)
1617 /* we normalize same name order */
1618 queue_push(solv->ruleinfoq, op < 0 ? -op : 0);
1619 queue_push(solv->ruleinfoq, ow2 < 0 ? -ow2 : 0);
1623 queue_push(solv->ruleinfoq, p < 0 ? -p : 0);
1624 queue_push(solv->ruleinfoq, w2 < 0 ? -w2 : 0);
1626 queue_push(solv->ruleinfoq, dep);
1630 solver_allruleinfos_cmp(const void *ap, const void *bp, void *dp)
1632 const Id *a = ap, *b = bp;
1651 solver_allruleinfos(Solver *solv, Id rid, Queue *rq)
1653 Pool *pool = solv->pool;
1654 Rule *r = solv->rules + rid;
1658 if (rid <= 0 || rid >= solv->rpmrules_end)
1660 Id type, from, to, dep;
1661 type = solver_ruleinfo(solv, rid, &from, &to, &dep);
1662 queue_push(rq, type);
1663 queue_push(rq, from);
1665 queue_push(rq, dep);
1670 queue_push(rq, rid);
1671 solv->ruleinfoq = rq;
1672 solver_addrpmrulesforsolvable(solv, pool->solvables - r->p, 0);
1673 /* also try reverse direction for conflicts */
1674 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
1675 solver_addrpmrulesforsolvable(solv, pool->solvables - r->w2, 0);
1676 solv->ruleinfoq = 0;
1678 /* now sort & unify em */
1681 sat_sort(rq->elements, rq->count / 4, 4 * sizeof(Id), solver_allruleinfos_cmp, 0);
1682 /* throw out identical entries */
1683 for (i = j = 0; i < rq->count; i += 4)
1687 if (rq->elements[i] == rq->elements[j - 4] &&
1688 rq->elements[i + 1] == rq->elements[j - 3] &&
1689 rq->elements[i + 2] == rq->elements[j - 2] &&
1690 rq->elements[i + 3] == rq->elements[j - 1])
1693 rq->elements[j++] = rq->elements[i];
1694 rq->elements[j++] = rq->elements[i + 1];
1695 rq->elements[j++] = rq->elements[i + 2];
1696 rq->elements[j++] = rq->elements[i + 3];
1703 solver_ruleinfo(Solver *solv, Id rid, Id *fromp, Id *top, Id *depp)
1705 Pool *pool = solv->pool;
1706 Rule *r = solv->rules + rid;
1707 SolverRuleinfo type = SOLVER_RULE_UNKNOWN;
1715 if (rid > 0 && rid < solv->rpmrules_end)
1721 return SOLVER_RULE_RPM;
1725 queue_push(&rq, rid);
1726 solv->ruleinfoq = &rq;
1727 solver_addrpmrulesforsolvable(solv, pool->solvables - r->p, 0);
1728 /* also try reverse direction for conflicts */
1729 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
1730 solver_addrpmrulesforsolvable(solv, pool->solvables - r->w2, 0);
1731 solv->ruleinfoq = 0;
1732 type = SOLVER_RULE_RPM;
1733 for (i = 1; i < rq.count; i += 4)
1736 qt = rq.elements[i];
1737 qp = rq.elements[i + 1];
1738 qo = rq.elements[i + 2];
1739 qd = rq.elements[i + 3];
1740 if (type == SOLVER_RULE_RPM || type > qt)
1754 if (rid >= solv->jobrules && rid < solv->jobrules_end)
1756 Id jidx = solv->ruletojob.elements[rid - solv->jobrules];
1760 *top = solv->job.elements[jidx];
1762 *depp = solv->job.elements[jidx + 1];
1763 if ((r->d == 0 || r->d == -1) && r->w2 == 0 && r->p == -SYSTEMSOLVABLE && (solv->job.elements[jidx] & SOLVER_SELECTMASK) != SOLVER_SOLVABLE_ONE_OF)
1764 return SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP;
1765 return SOLVER_RULE_JOB;
1767 if (rid >= solv->updaterules && rid < solv->updaterules_end)
1770 *fromp = solv->installed->start + (rid - solv->updaterules);
1771 return SOLVER_RULE_UPDATE;
1773 if (rid >= solv->featurerules && rid < solv->featurerules_end)
1776 *fromp = solv->installed->start + (rid - solv->featurerules);
1777 return SOLVER_RULE_FEATURE;
1779 if (rid >= solv->duprules && rid < solv->duprules_end)
1784 *depp = pool->solvables[-r->p].name;
1785 return SOLVER_RULE_DISTUPGRADE;
1787 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
1792 *depp = pool->solvables[-r->p].name;
1793 return SOLVER_RULE_INFARCH;
1795 if (rid >= solv->choicerules && rid < solv->choicerules_end)
1797 return SOLVER_RULE_CHOICE;
1799 if (rid >= solv->learntrules)
1801 return SOLVER_RULE_LEARNT;
1803 return SOLVER_RULE_UNKNOWN;
1807 addchoicerules(Solver *solv)
1809 Pool *pool = solv->pool;
1813 int i, j, rid, havechoice;
1818 solv->choicerules = solv->nrules;
1819 if (!pool->installed)
1821 solv->choicerules_end = solv->nrules;
1824 solv->choicerules_ref = sat_calloc(solv->rpmrules_end, sizeof(Id));
1827 map_init(&m, pool->nsolvables);
1828 map_init(&mneg, pool->nsolvables);
1829 /* set up negative assertion map from infarch and dup rules */
1830 for (rid = solv->infarchrules, r = solv->rules + rid; rid < solv->infarchrules_end; rid++, r++)
1831 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
1832 MAPSET(&mneg, -r->p);
1833 for (rid = solv->duprules, r = solv->rules + rid; rid < solv->duprules_end; rid++, r++)
1834 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
1835 MAPSET(&mneg, -r->p);
1836 for (rid = 1; rid < solv->rpmrules_end ; rid++)
1838 r = solv->rules + rid;
1839 if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 < 0))
1840 continue; /* only look at requires rules */
1841 // solver_printrule(solv, SAT_DEBUG_RESULT, r);
1845 FOR_RULELITERALS(p, pp, r)
1849 s = pool->solvables + p;
1852 if (s->repo == pool->installed)
1857 /* check if this package is "blocked" by a installed package */
1859 FOR_PROVIDES(p2, pp2, s->name)
1861 s2 = pool->solvables + p2;
1862 if (s2->repo != pool->installed)
1864 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
1866 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
1872 /* found installed package p2 that we can update to p */
1873 if (!solv->allowarchchange && s->arch != s2->arch && policy_illegal_archchange(solv, s, s2))
1875 if (!solv->allowvendorchange && s->vendor != s2->vendor && policy_illegal_vendorchange(solv, s, s2))
1877 if (MAPTST(&mneg, p))
1879 queue_push(&qi, p2);
1885 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1887 while ((obs = *obsp++) != 0)
1889 FOR_PROVIDES(p2, pp2, obs)
1891 s2 = pool->solvables + p2;
1892 if (s2->repo != pool->installed)
1894 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
1896 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
1905 /* found installed package p2 that we can update to p */
1906 if (!solv->allowarchchange && s->arch != s2->arch && policy_illegal_archchange(solv, s, s2))
1908 if (!solv->allowvendorchange && s->vendor != s2->vendor && policy_illegal_vendorchange(solv, s, s2))
1910 if (MAPTST(&mneg, p))
1912 queue_push(&qi, p2);
1917 /* package p is independent of the installed ones */
1920 if (!havechoice || !q.count)
1921 continue; /* no choice */
1923 /* now check the update rules of the installed package.
1924 * if all packages of the update rules are contained in
1925 * the dependency rules, there's no need to set up the choice rule */
1927 FOR_RULELITERALS(p, pp, r)
1930 for (i = 0; i < qi.count; i++)
1932 if (!qi.elements[i])
1934 Rule *ur = solv->rules + solv->updaterules + (qi.elements[i] - pool->installed->start);
1936 ur = solv->rules + solv->featurerules + (qi.elements[i] - pool->installed->start);
1939 FOR_RULELITERALS(p, pp, ur)
1944 for (j = i + 1; j < qi.count; j++)
1945 if (qi.elements[i] == qi.elements[j])
1951 printf("skipping choice ");
1952 solver_printrule(solv, SAT_DEBUG_RESULT, solv->rules + rid);
1956 d = q.count ? pool_queuetowhatprovides(pool, &q) : 0;
1957 solver_addrule(solv, r->p, d);
1958 queue_push(&solv->weakruleq, solv->nrules - 1);
1959 solv->choicerules_ref[solv->nrules - 1 - solv->choicerules] = rid;
1962 solver_printrule(solv, SAT_DEBUG_RESULT, solv->rules + rid);
1963 printf("WEAK CHOICE ");
1964 solver_printrule(solv, SAT_DEBUG_RESULT, solv->rules + solv->nrules - 1);
1971 solv->choicerules_end = solv->nrules;
1974 /* called when a choice rule is disabled by analyze_unsolvable. We also
1975 * have to disable all other choice rules so that the best packages get
1978 solver_disablechoicerules(Solver *solv, Rule *r)
1981 Pool *pool = solv->pool;
1985 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
1986 map_init(&m, pool->nsolvables);
1987 FOR_RULELITERALS(p, pp, or)
1990 FOR_RULELITERALS(p, pp, r)
1993 for (rid = solv->choicerules; rid < solv->choicerules_end; rid++)
1995 r = solv->rules + rid;
1998 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
1999 FOR_RULELITERALS(p, pp, or)
2000 if (p > 0 && MAPTST(&m, p))
2003 solver_disablerule(solv, r);
2007 static void solver_createcleandepsmap(Solver *solv)
2009 Pool *pool = solv->pool;
2010 Repo *installed = solv->installed;
2011 Queue *job = &solv->job;
2016 Id rid, how, what, select;
2018 Id req, *reqp, sup, *supp;
2023 map_init(&userinstalled, installed->end - installed->start);
2024 map_init(&im, pool->nsolvables);
2025 map_init(&installedm, pool->nsolvables);
2026 map_empty(&solv->cleandepsmap);
2029 for (i = 0; i < job->count; i += 2)
2031 how = job->elements[i];
2032 if ((how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
2034 what = job->elements[i + 1];
2035 select = how & SOLVER_SELECTMASK;
2036 FOR_JOB_SELECT(p, pp, select, what)
2037 if (pool->solvables[p].repo == installed)
2038 MAPSET(&userinstalled, p - installed->start);
2041 /* add all positive elements (e.g. locks) to "userinstalled" */
2042 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2044 r = solv->rules + rid;
2047 FOR_RULELITERALS(p, jp, r)
2048 if (p > 0 && pool->solvables[p].repo == installed)
2049 MAPSET(&userinstalled, p - installed->start);
2051 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2053 r = solv->rules + rid;
2054 if (r->p >= 0 || r->d != 0)
2055 continue; /* disabled or not erase */
2057 if (pool->solvables[p].repo != installed)
2059 MAPCLR(&userinstalled, p - installed->start);
2060 i = solv->ruletojob.elements[rid - solv->jobrules];
2061 how = job->elements[i];
2062 if ((how & (SOLVER_JOBMASK|SOLVER_CLEANDEPS)) == (SOLVER_ERASE|SOLVER_CLEANDEPS))
2065 for (p = installed->start; p < installed->end; p++)
2067 if (pool->solvables[p].repo != installed)
2069 MAPSET(&installedm, p);
2075 ip = queue_shift(&iq);
2076 if (!MAPTST(&im, ip))
2078 if (!MAPTST(&installedm, ip))
2080 if (MAPTST(&userinstalled, ip))
2083 s = pool->solvables + ip;
2084 #ifdef CLEANDEPSDEBUG
2085 printf("hello %s\n", solvable2str(pool, s));
2089 reqp = s->repo->idarraydata + s->requires;
2090 while ((req = *reqp++) != 0)
2092 if (req == SOLVABLE_PREREQMARKER)
2095 /* count number of installed packages that match */
2097 FOR_PROVIDES(p, pp, req)
2098 if (MAPTST(&installedm, p))
2103 FOR_PROVIDES(p, pp, req)
2107 #ifdef CLEANDEPSDEBUG
2108 printf("%s requires %s\n", solvid2str(pool, ip), solvid2str(pool, p));
2117 reqp = s->repo->idarraydata + s->recommends;
2118 while ((req = *reqp++) != 0)
2122 FOR_PROVIDES(p, pp, req)
2123 if (MAPTST(&installedm, p))
2128 FOR_PROVIDES(p, pp, req)
2132 #ifdef CLEANDEPSDEBUG
2133 printf("%s recommends %s\n", solvid2str(pool, ip), solvid2str(pool, p));
2142 /* supplements pass */
2143 for (ip = solv->installed->start; ip < solv->installed->end; ip++)
2145 if (!MAPTST(&installedm, ip))
2147 s = pool->solvables + ip;
2148 if (!s->supplements)
2150 if (!MAPTST(&im, ip))
2152 supp = s->repo->idarraydata + s->supplements;
2153 while ((sup = *supp++) != 0)
2154 if (!dep_possible(solv, sup, &im) && dep_possible(solv, sup, &installedm))
2156 /* no longer supplemented, also erase */
2159 #ifdef CLEANDEPSDEBUG
2160 printf("%s supplemented\n", solvid2str(pool, ip));
2162 queue_push(&iq, ip);
2168 /* turn userinstalled into remove set for pruning */
2169 map_empty(&userinstalled);
2170 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2172 r = solv->rules + rid;
2173 if (r->p >= 0 || r->d != 0)
2174 continue; /* disabled or not erase */
2177 if (pool->solvables[p].repo == installed)
2178 MAPSET(&userinstalled, p - installed->start);
2180 for (p = installed->start; p < installed->end; p++)
2183 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
2185 r = solv->rules + rid;
2188 FOR_RULELITERALS(p, jp, r)
2192 /* also put directly addressed packages on the install queue
2193 * so we can mark patterns as installed */
2194 for (i = 0; i < job->count; i += 2)
2196 how = job->elements[i];
2197 if ((how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
2199 what = job->elements[i + 1];
2200 select = how & SOLVER_SELECTMASK;
2201 if (select == SOLVER_SOLVABLE && pool->solvables[what].repo != installed)
2202 queue_push(&iq, what);
2207 ip = queue_shift(&iq);
2208 s = pool->solvables + ip;
2209 #ifdef CLEANDEPSDEBUG
2210 printf("bye %s\n", solvable2str(pool, s));
2214 reqp = s->repo->idarraydata + s->requires;
2215 while ((req = *reqp++) != 0)
2217 FOR_PROVIDES(p, pp, req)
2219 if (!MAPTST(&im, p) && MAPTST(&installedm, p))
2223 #ifdef CLEANDEPSDEBUG
2224 printf("%s requires %s\n", solvid2str(pool, ip), solvid2str(pool, p));
2234 reqp = s->repo->idarraydata + s->recommends;
2235 while ((req = *reqp++) != 0)
2237 FOR_PROVIDES(p, pp, req)
2239 if (!MAPTST(&im, p) && MAPTST(&installedm, p))
2243 if (MAPTST(&userinstalled, p - installed->start))
2245 #ifdef CLEANDEPSDEBUG
2246 printf("%s recommends %s\n", solvid2str(pool, ip), solvid2str(pool, p));
2256 /* supplements pass */
2257 for (ip = installed->start; ip < installed->end; ip++)
2259 if (!MAPTST(&installedm, ip))
2261 if (MAPTST(&userinstalled, ip - installed->start))
2263 s = pool->solvables + ip;
2264 if (!s->supplements)
2266 if (MAPTST(&im, ip) || !MAPTST(&installedm, ip))
2268 supp = s->repo->idarraydata + s->supplements;
2269 while ((sup = *supp++) != 0)
2270 if (dep_possible(solv, sup, &im))
2274 #ifdef CLEANDEPSDEBUG
2275 printf("%s supplemented\n", solvid2str(pool, ip));
2278 queue_push(&iq, ip);
2285 for (p = installed->start; p < installed->end; p++)
2287 if (pool->solvables[p].repo != installed)
2289 if (!MAPTST(&im, p))
2290 MAPSET(&solv->cleandepsmap, p - installed->start);
2293 map_free(&installedm);
2294 map_free(&userinstalled);