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
21 #include "solver_private.h"
28 #include "solverdebug.h"
29 #include "linkedpkg.h"
32 #define RULES_BLOCK 63
34 static void addpkgruleinfo(Solver *solv, Id p, Id p2, Id d, int type, Id dep);
35 static void solver_createcleandepsmap(Solver *solv, Map *cleandepsmap, int unneeded);
37 /*-------------------------------------------------------------------
38 * Check if dependency is possible
40 * mirrors solver_dep_fulfilled but uses map m instead of the decisionmap.
41 * used in solver_addpkgrulesforweak and solver_createcleandepsmap.
45 dep_possible(Solver *solv, Id dep, Map *m)
47 Pool *pool = solv->pool;
52 Reldep *rd = GETRELDEP(pool, dep);
55 if (rd->flags == REL_COND)
57 if (rd->flags == REL_AND)
59 if (!dep_possible(solv, rd->name, m))
61 return dep_possible(solv, rd->evr, m);
63 if (rd->flags == REL_OR)
65 if (dep_possible(solv, rd->name, m))
67 return dep_possible(solv, rd->evr, m);
69 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
70 return solver_splitprovides(solv, rd->evr, m);
73 FOR_PROVIDES(p, pp, dep)
82 is_otherproviders_dep(Pool *pool, Id dep)
86 Reldep *rd = GETRELDEP(pool, dep);
87 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
93 /********************************************************************
97 * - unify rules, remove duplicates
100 /*-------------------------------------------------------------------
102 * compare rules for unification sort
107 unifyrules_sortcmp(const void *ap, const void *bp, void *dp)
110 Rule *a = (Rule *)ap;
111 Rule *b = (Rule *)bp;
117 return x; /* p differs */
120 if (a->d == 0 && b->d == 0)
121 return a->w2 - b->w2; /* assertion: return w2 diff */
123 if (a->d == 0) /* a is assertion, b not */
125 x = a->w2 - pool->whatprovidesdata[b->d];
129 if (b->d == 0) /* b is assertion, a not */
131 x = pool->whatprovidesdata[a->d] - b->w2;
135 /* compare whatprovidesdata */
136 ad = pool->whatprovidesdata + a->d;
137 bd = pool->whatprovidesdata + b->d;
139 if ((x = *ad++ - *bd++) != 0)
145 solver_rulecmp(Solver *solv, Rule *r1, Rule *r2)
147 return unifyrules_sortcmp(r1, r2, solv->pool);
151 /*-------------------------------------------------------------------
154 * go over all rules and remove duplicates
158 solver_unifyrules(Solver *solv)
160 Pool *pool = solv->pool;
164 if (solv->nrules <= 2) /* nothing to unify */
167 /* sort rules first */
168 solv_sort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp, solv->pool);
175 for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
177 if (jr && !unifyrules_sortcmp(ir, jr, pool))
178 continue; /* prune! */
179 jr = solv->rules + j++; /* keep! */
184 /* reduced count from nrules to j rules */
185 POOL_DEBUG(SOLV_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
187 /* adapt rule buffer */
189 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
192 * debug: log rule statistics
194 IF_POOLDEBUG (SOLV_DEBUG_STATS)
201 for (i = 1; i < solv->nrules; i++)
208 dp = solv->pool->whatprovidesdata + r->d;
213 POOL_DEBUG(SOLV_DEBUG_STATS, " binary: %d\n", binr);
214 POOL_DEBUG(SOLV_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
225 hashrule(Solver *solv, Id p, Id d, int n)
227 unsigned int x = (unsigned int)p;
231 return (x * 37) ^ (unsigned int)d;
232 dp = solv->pool->whatprovidesdata + d;
234 x = (x * 37) ^ (unsigned int)*dp++;
240 /*-------------------------------------------------------------------
247 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
249 * p < 0 : pkg id of A
250 * d > 0 : Offset in whatprovidesdata (list of providers of b)
252 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
253 * p < 0 : pkg id of A
254 * p2 < 0 : Id of solvable (e.g. B1)
256 * d == 0, p2 == 0: unary rule, assertion => (A) or (-A)
258 * Install: p > 0, d = 0 (A) user requested install
259 * Remove: p < 0, d = 0 (-A) user requested remove (also: uninstallable)
260 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
261 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
262 * Conflicts: p < 0, p2 < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
263 * also used for obsoletes
264 * No-op ?: p = 0, d = 0 (null) (used as placeholder in update/feature rules)
268 * Direct assertion (no watch needed) --> d = 0, w1 = p, w2 = 0
269 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
270 * every other : w1 = p, w2 = whatprovidesdata[d];
272 * always returns a rule for non-pkg rules
276 solver_addrule(Solver *solv, Id p, Id p2, Id d)
278 Pool *pool = solv->pool;
283 assert(!p2 && d > 0);
284 if (!pool->whatprovidesdata[d])
286 else if (!pool->whatprovidesdata[d + 1])
288 p2 = pool->whatprovidesdata[d];
293 /* now we have two cases:
294 * 1 or 2 literals: d = 0, p, p2 contain the literals
295 * 3 or more literals: d > 0, p2 == 0, d is offset into whatprovidesdata
298 /* it often happenes that requires lead to adding the same pkg rule
299 * multiple times, so we prune those duplicates right away to make
300 * the work for unifyrules a bit easier */
301 if (!solv->pkgrules_end) /* we add pkg rules */
303 r = solv->rules + solv->nrules - 1;
307 /* check if rule is identical */
313 dp2 = pool->whatprovidesdata + r->d;
314 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
320 /* check if rule is self-fulfilling */
321 for (dp = pool->whatprovidesdata + d; *dp; dp++)
323 return 0; /* rule is self-fulfilling */
329 Id o = p; /* switch p1 and p2 */
333 if (r->p == p && !r->d && r->w2 == p2)
336 return 0; /* rule is self-fulfilling */
340 solv->rules = solv_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
341 r = solv->rules + solv->nrules++; /* point to rule space */
345 r->w2 = d ? pool->whatprovidesdata[d] : p2;
348 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
350 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, " Add rule: ");
351 solver_printrule(solv, SOLV_DEBUG_RULE_CREATION, r);
358 solver_shrinkrules(Solver *solv, int nrules)
360 solv->nrules = nrules;
361 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
364 /******************************************************************************
366 *** pkg rule part: create rules representing the package dependencies
371 * special multiversion patch conflict handling:
372 * a patch conflict is also satisfied if some other
373 * version with the same name/arch that doesn't conflict
374 * gets installed. The generated rule is thus:
375 * -patch|-cpack|opack1|opack2|...
378 makemultiversionconflict(Solver *solv, Id n, Id con)
380 Pool *pool = solv->pool;
385 sn = pool->solvables + n;
386 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
388 FOR_PROVIDES(p, pp, sn->name)
390 s = pool->solvables + p;
391 if (s->name != sn->name || s->arch != sn->arch)
393 if (!MAPTST(&solv->multiversion, p))
395 if (pool_match_nevr(pool, pool->solvables + p, con))
397 /* here we have a multiversion solvable that doesn't conflict */
398 /* thus we're not in conflict if it is installed */
402 n = 0; /* no other package found, normal conflict handling */
404 n = pool_queuetowhatprovides(pool, &q);
410 addpkgrule(Solver *solv, Id p, Id p2, Id d, int type, Id dep)
412 if (!solv->ruleinfoq)
413 solver_addrule(solv, p, p2, d);
415 addpkgruleinfo(solv, p, p2, d, type, dep);
418 #ifdef ENABLE_LINKED_PKGS
421 addlinks(Solver *solv, Solvable *s, Id req, Queue *qr, Id prv, Queue *qp, Map *m, Queue *workq)
423 Pool *pool = solv->pool;
428 printf("ADDLINKS %s\n -> %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, req));
429 for (i = 0; i < qr->count; i++)
430 printf(" - %s\n", pool_solvid2str(pool, qr->elements[i]));
431 printf(" <- %s\n", pool_dep2str(pool, prv));
432 for (i = 0; i < qp->count; i++)
433 printf(" - %s\n", pool_solvid2str(pool, qp->elements[i]));
437 addpkgrule(solv, -(s - pool->solvables), qr->elements[0], 0, SOLVER_RULE_PKG_REQUIRES, req);
439 addpkgrule(solv, -(s - pool->solvables), 0, pool_queuetowhatprovides(pool, qr), SOLVER_RULE_PKG_REQUIRES, req);
442 Id d = pool_queuetowhatprovides(pool, qp);
443 for (i = 0; i < qr->count; i++)
444 addpkgrule(solv, -qr->elements[i], 0, d, SOLVER_RULE_PKG_REQUIRES, prv);
448 for (i = 0; i < qr->count; i++)
449 addpkgrule(solv, -qr->elements[i], qp->elements[0], 0, SOLVER_RULE_PKG_REQUIRES, prv);
452 return; /* nothing more to do if called from getpkgruleinfos() */
453 for (i = 0; i < qr->count; i++)
454 if (!MAPTST(m, qr->elements[i]))
455 queue_push(workq, qr->elements[i]);
456 for (i = 0; i < qp->count; i++)
457 if (!MAPTST(m, qp->elements[i]))
458 queue_push(workq, qp->elements[i]);
459 if (solv->installed && s->repo == solv->installed)
461 Repo *installed = solv->installed;
462 /* record installed buddies */
463 if (!solv->instbuddy)
464 solv->instbuddy = solv_calloc(installed->end - installed->start, sizeof(Id));
466 solv->instbuddy[s - pool->solvables - installed->start] = qr->elements[0];
467 for (i = 0; i < qr->count; i++)
469 Id p = qr->elements[i];
470 if (pool->solvables[p].repo != installed)
472 if (qp->count > 1 || (solv->instbuddy[p - installed->start] != 0 && solv->instbuddy[p - installed->start] != s - pool->solvables))
473 solv->instbuddy[p - installed->start] = 1; /* 1: ambiguous buddy */
475 solv->instbuddy[p - installed->start] = s - pool->solvables;
481 add_package_link(Solver *solv, Solvable *s, Map *m, Queue *workq)
487 find_package_link(solv->pool, s, &req, &qr, &prv, &qp);
489 addlinks(solv, s, req, &qr, prv, &qp, m, workq);
496 #ifdef ENABLE_COMPLEX_DEPS
499 add_complex_deprules(Solver *solv, Id p, Id dep, int type, int dontfix, Queue *workq, Map *m)
501 Pool *pool = solv->pool;
502 Repo *installed = solv->installed;
507 flags = dontfix ? CPLXDEPS_DONTFIX : 0;
508 /* CNF expansion for requires, DNF + INVERT expansion for conflicts */
509 if (type == SOLVER_RULE_PKG_CONFLICTS)
510 flags |= CPLXDEPS_TODNF | CPLXDEPS_EXPAND | CPLXDEPS_INVERT;
512 i = pool_normalize_complex_dep(pool, dep, &bq, flags);
513 /* handle special cases */
518 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "ignoring broken dependency %s of installed package %s\n", pool_dep2str(pool, dep), pool_solvid2str(pool, p));
522 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", pool_solvid2str(pool, p), p, pool_dep2str(pool, dep));
523 addpkgrule(solv, -p, 0, 0, type == SOLVER_RULE_PKG_REQUIRES ? SOLVER_RULE_PKG_NOTHING_PROVIDES_DEP : type, dep);
534 /* go through all blocks and add a rule for each block */
535 for (i = 0; i < bq.count; i++)
539 if (bq.elements[i] == pool->nsolvables)
541 /* conventional requires (cannot be a conflicts as they have been expanded) */
542 Id *dp = pool->whatprovidesdata + bq.elements[i + 1];
546 for (j = 0; dp[j] != 0; j++)
547 if (pool->solvables[dp[j]].repo == installed)
548 break; /* provider was installed */
552 /* check if the rule contains both p and -p */
553 for (j = 0; dp[j] != 0; j++)
558 addpkgrule(solv, -p, 0, dp - pool->whatprovidesdata, SOLVER_RULE_PKG_REQUIRES, dep);
559 /* push all non-visited providers on the work queue */
563 queue_push(workq, *dp);
566 if (!bq.elements[i + 1])
568 Id p2 = bq.elements[i++];
569 /* simple rule with just two literals, we'll add a (-p, p2) rule */
572 if (p2 < 0 && pool->solvables[-p2].repo == installed)
574 if (p2 > 0 && pool->solvables[p2].repo != installed)
579 if (type == SOLVER_RULE_PKG_CONFLICTS)
581 if (pool->forbidselfconflicts && !is_otherproviders_dep(pool, dep))
582 addpkgrule(solv, -p, 0, 0, SOLVER_RULE_PKG_SELF_CONFLICT, dep);
585 addpkgrule(solv, -p, 0, 0, type, dep);
588 /* check if the rule contains both p and -p */
591 addpkgrule(solv, -p, p2, 0, type, dep);
592 if (m && p2 > 0 && !MAPTST(m, p2))
593 queue_push(workq, p2);
600 qele = bq.elements + i;
602 while (bq.elements[i])
607 for (j = 0; j < qcnt; j++)
609 if (qele[j] > 0 && pool->solvables[qele[j]].repo == installed)
611 if (qele[j] < 0 && pool->solvables[-qele[j]].repo != installed)
617 /* add -p to (ordered) rule (overwriting the trailing zero) */
620 if (j == qcnt || qele[j] > -p)
623 memmove(qele + j + 1, qele + j, (qcnt - j) * sizeof(Id));
631 /* check if the rule contains both p and -p */
632 for (j = 0; j < qcnt; j++)
637 addpkgrule(solv, qele[0], 0, pool_ids2whatprovides(pool, qele + 1, qcnt - 1), type, dep);
639 for (j = 0; j < qcnt; j++)
640 if (qele[j] > 0 && !MAPTST(m, qele[j]))
641 queue_push(workq, qele[j]);
649 /*-------------------------------------------------------------------
651 * add (install) rules for solvable
653 * s: Solvable for which to add rules
654 * m: m[s] = 1 for solvables which have rules, prevent rule duplication
656 * Algorithm: 'visit all nodes of a graph'. The graph nodes are
657 * solvables, the edges their dependencies.
658 * Starting from an installed solvable, this will create all rules
659 * representing the graph created by the solvables dependencies.
661 * for unfulfilled requirements, conflicts, obsoletes,....
662 * add a negative assertion for solvables that are not installable
664 * It will also create rules for all solvables referenced by 's'
665 * i.e. descend to all providers of requirements of 's'
670 solver_addpkgrulesforsolvable(Solver *solv, Solvable *s, Map *m)
672 Pool *pool = solv->pool;
673 Repo *installed = solv->installed;
675 Queue workq; /* list of solvables we still have to work on */
679 int dontfix; /* ignore dependency errors for installed solvables */
685 Id p, pp; /* whatprovides loops */
686 Id *dp; /* ptr to 'whatprovides' */
687 Id n; /* Id for current solvable 's' */
689 queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
690 queue_push(&workq, s - pool->solvables); /* push solvable Id to work queue */
692 /* loop until there's no more work left */
697 * s: Pointer to solvable
700 n = queue_shift(&workq); /* 'pop' next solvable to work on from queue */
703 if (MAPTST(m, n)) /* continue if already visited */
705 MAPSET(m, n); /* mark as visited */
708 s = pool->solvables + n;
711 if (installed /* Installed system available */
712 && s->repo == installed /* solvable is installed */
713 && !solv->fixmap_all /* NOT repair errors in dependency graph */
714 && !(solv->fixmap.size && MAPTST(&solv->fixmap, n - installed->start)))
716 dontfix = 1; /* dont care about broken deps */
721 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC
722 ? pool_disabled_solvable(pool, s)
723 : !pool_installable(pool, s))
725 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", pool_solvid2str(pool, n), n);
726 addpkgrule(solv, -n, 0, 0, SOLVER_RULE_PKG_NOT_INSTALLABLE, 0);
730 #ifdef ENABLE_LINKED_PKGS
731 /* add pseudo-package <-> real-package links */
732 if (has_package_link(pool, s))
733 add_package_link(solv, s, m, &workq);
736 /*-----------------------------------------
737 * check requires of s
742 reqp = s->repo->idarraydata + s->requires;
743 while ((req = *reqp++) != 0) /* go through all requires */
745 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
748 #ifdef ENABLE_COMPLEX_DEPS
749 if (pool_is_complex_dep(pool, req))
751 /* we have AND/COND deps, normalize */
752 add_complex_deprules(solv, n, req, SOLVER_RULE_PKG_REQUIRES, dontfix, &workq, m);
757 /* find list of solvables providing 'req' */
758 dp = pool_whatprovides_ptr(pool, req);
760 if (*dp == SYSTEMSOLVABLE) /* always installed */
765 /* the strategy here is to not insist on dependencies
766 * that are already broken. so if we find one provider
767 * that was already installed, we know that the
768 * dependency was not broken before so we enforce it */
769 for (i = 0; (p = dp[i]) != 0; i++)
770 if (pool->solvables[p].repo == installed)
771 break; /* found installed provider */
774 /* didn't find an installed provider: previously broken dependency */
775 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", pool_dep2str(pool, req), pool_solvable2str(pool, s));
782 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", pool_solvid2str(pool, n), n, pool_dep2str(pool, req));
783 addpkgrule(solv, -n, 0, 0, SOLVER_RULE_PKG_NOTHING_PROVIDES_DEP, req);
787 for (i = 0; dp[i] != 0; i++)
791 continue; /* provided by itself, no need to add rule */
793 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
795 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION," %s requires %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, req));
796 for (i = 0; dp[i]; i++)
797 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, " provided by %s\n", pool_solvid2str(pool, dp[i]));
800 /* add 'requires' dependency */
801 /* rule: (-requestor|provider1|provider2|...|providerN) */
802 addpkgrule(solv, -n, 0, dp - pool->whatprovidesdata, SOLVER_RULE_PKG_REQUIRES, req);
804 /* push all non-visited providers on the work queue */
808 queue_push(&workq, *dp);
812 /* that's all we check for src packages */
813 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
816 /*-----------------------------------------
817 * check conflicts of s
824 /* we treat conflicts in patches a bit differen:
826 * - multiversion handling
827 * XXX: we should really handle this different, looking
828 * at the name is a bad hack
830 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
832 conp = s->repo->idarraydata + s->conflicts;
833 /* foreach conflicts of 's' */
834 while ((con = *conp++) != 0)
836 #ifdef ENABLE_COMPLEX_DEPS
837 if (!ispatch && pool_is_complex_dep(pool, con))
839 /* we have AND/COND deps, normalize */
840 add_complex_deprules(solv, n, con, SOLVER_RULE_PKG_CONFLICTS, dontfix, &workq, m);
844 /* foreach providers of a conflict of 's' */
845 FOR_PROVIDES(p, pp, con)
847 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, con))
849 /* dontfix: dont care about conflicts with already installed packs */
850 if (dontfix && pool->solvables[p].repo == installed)
852 if (p == n) /* p == n: self conflict */
854 if (!pool->forbidselfconflicts || is_otherproviders_dep(pool, con))
856 addpkgrule(solv, -n, 0, 0, SOLVER_RULE_PKG_SELF_CONFLICT, con);
859 if (ispatch && solv->multiversion.size && MAPTST(&solv->multiversion, p) && ISRELDEP(con))
861 /* our patch conflicts with a multiversion package */
862 Id d = makemultiversionconflict(solv, p, con);
865 addpkgrule(solv, -n, 0, d, SOLVER_RULE_PKG_CONFLICTS, con);
869 if (p == SYSTEMSOLVABLE)
871 /* rule: -n|-p: either solvable _or_ provider of conflict */
872 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_CONFLICTS, con);
877 /*-----------------------------------------
878 * check obsoletes and implicit obsoletes of a package
879 * if ignoreinstalledsobsoletes is not set, we're also checking
880 * obsoletes of installed packages (like newer rpm versions)
882 if ((!installed || s->repo != installed) || !pool->noinstalledobsoletes)
884 int multi = solv->multiversion.size && MAPTST(&solv->multiversion, n);
885 int isinstalled = (installed && s->repo == installed);
886 if (s->obsoletes && (!multi || solv->keepexplicitobsoletes))
888 obsp = s->repo->idarraydata + s->obsoletes;
889 /* foreach obsoletes */
890 while ((obs = *obsp++) != 0)
892 /* foreach provider of an obsoletes of 's' */
893 FOR_PROVIDES(p, pp, obs)
895 Solvable *ps = pool->solvables + p;
898 if (isinstalled && dontfix && ps->repo == installed)
899 continue; /* don't repair installed/installed problems */
900 if (!pool->obsoleteusesprovides /* obsoletes are matched names, not provides */
901 && !pool_match_nevr(pool, ps, obs))
903 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
905 if (p == SYSTEMSOLVABLE)
908 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_OBSOLETES, obs);
910 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_INSTALLED_OBSOLETES, obs);
914 /* check implicit obsoletes
915 * for installed packages we only need to check installed/installed problems (and
916 * only when dontfix is not set), as the others are picked up when looking at the
917 * uninstalled package.
919 if (!isinstalled || !dontfix)
921 FOR_PROVIDES(p, pp, s->name)
923 Solvable *ps = pool->solvables + p;
926 if (isinstalled && ps->repo != installed)
928 /* we still obsolete packages with same nevra, like rpm does */
929 /* (actually, rpm mixes those packages. yuck...) */
930 if (multi && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
932 if (isinstalled || ps->repo != installed)
934 /* also check the installed package for multi-ness */
935 if (MAPTST(&solv->multiversion, p))
938 if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
940 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, ps))
942 if (p == SYSTEMSOLVABLE)
944 if (s->name == ps->name)
946 /* optimization: do not add the same-name conflict rule if it was
947 * already added when we looked at the other package.
948 * (this assumes pool_colormatch is symmetric) */
949 if (p && m && ps->repo != installed && MAPTST(m, p) &&
950 (ps->arch != ARCH_SRC && ps->arch != ARCH_NOSRC) &&
951 !(solv->multiversion.size && MAPTST(&solv->multiversion, p)))
953 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_SAME_NAME, 0);
956 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_IMPLICIT_OBSOLETES, s->name);
961 if (m && pool->implicitobsoleteusescolors && (s->arch > pool->lastarch || pool->id2arch[s->arch] != 1))
963 int a = pool->id2arch[s->arch];
964 /* check lock-step candidates */
965 FOR_PROVIDES(p, pp, s->name)
967 Solvable *ps = pool->solvables + p;
968 if (s->name != ps->name || s->evr != ps->evr || MAPTST(m, p))
970 if (ps->arch > pool->lastarch || pool->id2arch[ps->arch] == 1 || pool->id2arch[ps->arch] >= a)
972 queue_push(&workq, p);
976 /*-----------------------------------------
977 * add recommends/suggests to the work queue
979 if (s->recommends && m)
981 recp = s->repo->idarraydata + s->recommends;
982 while ((rec = *recp++) != 0)
984 #ifdef ENABLE_COMPLEX_DEPS
985 if (pool_is_complex_dep(pool, rec))
987 pool_add_pos_literals_complex_dep(pool, rec, &workq, m, 0);
991 FOR_PROVIDES(p, pp, rec)
993 queue_push(&workq, p);
996 if (s->suggests && m)
998 sugp = s->repo->idarraydata + s->suggests;
999 while ((sug = *sugp++) != 0)
1001 #ifdef ENABLE_COMPLEX_DEPS
1002 if (pool_is_complex_dep(pool, sug))
1004 pool_add_pos_literals_complex_dep(pool, sug, &workq, m, 0);
1008 FOR_PROVIDES(p, pp, sug)
1010 queue_push(&workq, p);
1017 #ifdef ENABLE_LINKED_PKGS
1019 solver_addpkgrulesforlinked(Solver *solv, Map *m)
1021 Pool *pool = solv->pool;
1027 for (i = 1; i < pool->nsolvables; i++)
1031 s = pool->solvables + i;
1032 if (!s->repo || s->repo == solv->installed)
1034 if (!strchr(pool_id2str(pool, s->name), ':'))
1036 if (!pool_installable(pool, s))
1038 find_package_link(pool, s, 0, &qr, 0, 0);
1041 for (j = 0; j < qr.count; j++)
1042 if (MAPTST(m, qr.elements[j]))
1044 solver_addpkgrulesforsolvable(solv, s, m);
1054 /*-------------------------------------------------------------------
1056 * Add rules for packages possibly selected in by weak dependencies
1058 * m: already added solvables
1062 solver_addpkgrulesforweak(Solver *solv, Map *m)
1064 Pool *pool = solv->pool;
1069 /* foreach solvable in pool */
1070 for (i = n = 1; n < pool->nsolvables; i++, n++)
1072 if (i == pool->nsolvables) /* wrap i */
1074 if (MAPTST(m, i)) /* already added that one */
1077 s = pool->solvables + i;
1080 if (s->repo != pool->installed && !pool_installable(pool, s))
1081 continue; /* only look at installable ones */
1086 /* find possible supplements */
1087 supp = s->repo->idarraydata + s->supplements;
1088 while ((sup = *supp++) != 0)
1089 if (dep_possible(solv, sup, m))
1093 /* if nothing found, check for enhances */
1094 if (!sup && s->enhances)
1096 supp = s->repo->idarraydata + s->enhances;
1097 while ((sup = *supp++) != 0)
1098 if (dep_possible(solv, sup, m))
1101 /* if nothing found, goto next solvables */
1104 solver_addpkgrulesforsolvable(solv, s, m);
1105 n = 0; /* check all solvables again because we added solvables to m */
1110 /*-------------------------------------------------------------------
1112 * add package rules for possible updates
1115 * m: map of already visited solvables
1116 * allow_all: 0 = dont allow downgrades, 1 = allow all candidates
1120 solver_addpkgrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
1122 Pool *pool = solv->pool;
1124 /* queue and buffer for it */
1128 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1129 /* find update candidates for 's' */
1130 policy_findupdatepackages(solv, s, &qs, allow_all);
1131 /* add rule for 's' if not already done */
1132 if (!MAPTST(m, s - pool->solvables))
1133 solver_addpkgrulesforsolvable(solv, s, m);
1134 /* foreach update candidate, add rule if not already done */
1135 for (i = 0; i < qs.count; i++)
1136 if (!MAPTST(m, qs.elements[i]))
1137 solver_addpkgrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1142 /***********************************************************************
1144 *** Update/Feature rule part
1146 *** Those rules make sure an installed package isn't silently deleted
1151 finddistupgradepackages(Solver *solv, Solvable *s, Queue *qs, int allow_all)
1153 Pool *pool = solv->pool;
1156 policy_findupdatepackages(solv, s, qs, allow_all ? allow_all : 2);
1160 return 0; /* orphaned, don't create feature rule */
1161 /* check if this is an orphaned package */
1162 policy_findupdatepackages(solv, s, qs, 1);
1164 return 0; /* orphaned, don't create update rule */
1166 return -SYSTEMSOLVABLE; /* supported but not installable */
1169 return s - pool->solvables;
1170 /* check if it is ok to keep the installed package */
1171 if (solv->dupmap.size && MAPTST(&solv->dupmap, s - pool->solvables))
1172 return s - pool->solvables;
1173 for (i = 0; i < qs->count; i++)
1175 Solvable *ns = pool->solvables + qs->elements[i];
1176 if (s->evr == ns->evr && solvable_identical(s, ns))
1177 return s - pool->solvables;
1179 /* nope, it must be some other package */
1180 return -SYSTEMSOLVABLE;
1184 /* add packages from the dup repositories to the update candidates
1185 * this isn't needed for the global dup mode as all packages are
1186 * from dup repos in that case */
1188 addduppackages(Solver *solv, Solvable *s, Queue *qs)
1193 int oldnoupdateprovide = solv->noupdateprovide;
1195 queue_init_buffer(&dupqs, dupqsbuf, sizeof(dupqsbuf)/sizeof(*dupqsbuf));
1196 solv->noupdateprovide = 1;
1197 policy_findupdatepackages(solv, s, &dupqs, 2);
1198 solv->noupdateprovide = oldnoupdateprovide;
1199 for (i = 0; i < dupqs.count; i++)
1201 p = dupqs.elements[i];
1202 if (MAPTST(&solv->dupmap, p))
1203 queue_pushunique(qs, p);
1209 /* stash away the original updaters for multiversion packages. We do this so that
1210 * we can update the package later */
1212 set_specialupdaters(Solver *solv, Solvable *s, Id d)
1214 Repo *installed = solv->installed;
1215 if (!solv->specialupdaters)
1216 solv->specialupdaters = solv_calloc(installed->end - installed->start, sizeof(Id));
1217 solv->specialupdaters[s - solv->pool->solvables - installed->start] = d;
1220 /*-------------------------------------------------------------------
1222 * add rule for update
1223 * (A|A1|A2|A3...) An = update candidates for A
1225 * s = (installed) solvable
1229 solver_addupdaterule(Solver *solv, Solvable *s, int allow_all)
1231 /* installed packages get a special upgrade allowed rule */
1232 Pool *pool = solv->pool;
1238 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1239 p = s - pool->solvables;
1240 /* find update candidates for 's' */
1241 if (solv->dupmap_all || (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
1242 p = finddistupgradepackages(solv, s, &qs, allow_all);
1244 policy_findupdatepackages(solv, s, &qs, allow_all);
1246 #ifdef ENABLE_LINKED_PKGS
1247 if (solv->instbuddy && solv->instbuddy[s - pool->solvables - solv->installed->start])
1249 const char *name = pool_id2str(pool, s->name);
1250 if (strncmp(name, "pattern:", 8) == 0 || strncmp(name, "application:", 12) == 0)
1252 /* a linked pseudo package. As it is linked, we do not need an update/feature rule */
1253 /* nevertheless we set specialupdaters so we can update */
1254 solver_addrule(solv, 0, 0, 0);
1255 if (!allow_all && qs.count)
1257 if (p != -SYSTEMSOLVABLE)
1258 queue_unshift(&qs, p);
1260 set_specialupdaters(solv, s, pool_queuetowhatprovides(pool, &qs));
1268 if (!allow_all && !p) /* !p implies qs.count == 0 */
1270 queue_push(&solv->orphaned, s - pool->solvables); /* an orphaned package */
1271 if (solv->keep_orphans && !(solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, s - pool->solvables - solv->installed->start))))
1272 p = s - pool->solvables; /* keep this orphaned package installed */
1274 solver_addrule(solv, p, 0, 0);
1278 if (!allow_all && qs.count && solv->multiversion.size)
1282 for (i = 0; i < qs.count; i++)
1283 if (MAPTST(&solv->multiversion, qs.elements[i]))
1287 /* filter out all multiversion packages as they don't update */
1288 d = pool_queuetowhatprovides(pool, &qs); /* save qs away */
1289 for (j = i; i < qs.count; i++)
1291 if (MAPTST(&solv->multiversion, qs.elements[i]))
1293 Solvable *ps = pool->solvables + qs.elements[i];
1294 /* if keepexplicitobsoletes is set and the name is different,
1295 * we assume that there is an obsoletes. XXX: not 100% correct */
1296 if (solv->keepexplicitobsoletes && ps->name != s->name)
1298 qs.elements[j++] = qs.elements[i];
1301 /* it's ok if they have same nevra */
1302 if (ps->name != s->name || ps->evr != s->evr || ps->arch != s->arch)
1305 qs.elements[j++] = qs.elements[i];
1307 if (j < qs.count) /* filtered at least one package? */
1309 if (j == 0 && p == -SYSTEMSOLVABLE)
1311 /* this is a multiversion orphan */
1312 queue_push(&solv->orphaned, s - pool->solvables);
1313 set_specialupdaters(solv, s, d);
1314 if (solv->keep_orphans && !(solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, s - pool->solvables - solv->installed->start))))
1316 /* we need to keep the orphan */
1318 solver_addrule(solv, s - pool->solvables, 0, 0);
1321 /* we can drop it as long as we update */
1323 j = qs.count; /* force the update */
1325 else if (d && (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, s - pool->solvables - solv->installed->start))))
1327 /* non-orphan multiversion package, set special updaters if we want an update */
1328 set_specialupdaters(solv, s, d);
1332 else if (p != -SYSTEMSOLVABLE)
1334 /* could fallthrough, but then we would do pool_queuetowhatprovides twice */
1336 solver_addrule(solv, s - pool->solvables, 0, d); /* allow update of s */
1341 if (!isorphaned && p == -SYSTEMSOLVABLE && qs.count && solv->dupmap.size)
1342 p = s - pool->solvables; /* let the dup rules sort it out */
1343 if (qs.count && p == -SYSTEMSOLVABLE)
1344 p = queue_shift(&qs);
1347 d = pool_queuetowhatprovides(pool, &qs);
1349 solver_addrule(solv, p, 0, d); /* allow update of s */
1353 d = qs.count ? qs.elements[0] : 0;
1355 solver_addrule(solv, p, d, 0); /* allow update of s */
1360 disableupdaterule(Solver *solv, Id p)
1364 MAPSET(&solv->noupdate, p - solv->installed->start);
1365 r = solv->rules + solv->updaterules + (p - solv->installed->start);
1366 if (r->p && r->d >= 0)
1367 solver_disablerule(solv, r);
1368 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1369 if (r->p && r->d >= 0)
1370 solver_disablerule(solv, r);
1371 if (solv->bestrules_pkg)
1374 ni = solv->bestrules_end - solv->bestrules;
1375 for (i = 0; i < ni; i++)
1376 if (solv->bestrules_pkg[i] == p)
1377 solver_disablerule(solv, solv->rules + solv->bestrules + i);
1382 reenableupdaterule(Solver *solv, Id p)
1384 Pool *pool = solv->pool;
1387 MAPCLR(&solv->noupdate, p - solv->installed->start);
1388 r = solv->rules + solv->updaterules + (p - solv->installed->start);
1393 solver_enablerule(solv, r);
1394 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1396 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1397 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1403 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1404 if (r->p && r->d < 0)
1406 solver_enablerule(solv, r);
1407 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1409 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1410 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1414 if (solv->bestrules_pkg)
1417 ni = solv->bestrules_end - solv->bestrules;
1418 for (i = 0; i < ni; i++)
1419 if (solv->bestrules_pkg[i] == p)
1420 solver_enablerule(solv, solv->rules + solv->bestrules + i);
1425 /***********************************************************************
1427 *** Infarch rule part
1429 *** Infarch rules make sure the solver uses the best architecture of
1430 *** a package if multiple archetectures are available
1435 solver_addinfarchrules(Solver *solv, Map *addedmap)
1437 Pool *pool = solv->pool;
1438 Repo *installed = pool->installed;
1440 Id p, pp, a, aa, bestarch;
1441 Solvable *s, *ps, *bests;
1442 Queue badq, allowedarchs;
1446 queue_init(&allowedarchs);
1448 solv->infarchrules = solv->nrules;
1449 for (i = 1; i < pool->nsolvables; i++)
1451 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1453 s = pool->solvables + i;
1457 queue_empty(&allowedarchs);
1458 FOR_PROVIDES(p, pp, s->name)
1460 ps = pool->solvables + p;
1461 if (ps->name != s->name || !MAPTST(addedmap, p))
1468 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1469 if (a != 1 && installed && ps->repo == installed)
1471 if (!solv->dupmap_all && !(solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
1472 queue_pushunique(&allowedarchs, ps->arch); /* also ok to keep this architecture */
1473 continue; /* ignore installed solvables when calculating the best arch */
1475 if (a && a != 1 && (!bestarch || a < bestarch))
1484 /* speed up common case where installed package already has best arch */
1485 if (allowedarchs.count == 1 && bests && allowedarchs.elements[0] == bests->arch)
1486 allowedarchs.count--; /* installed arch is best */
1488 if (allowedarchs.count && pool->implicitobsoleteusescolors && installed && bestarch)
1490 /* need an extra pass for lockstep checking: we only allow to keep an inferior arch
1491 * if the corresponding installed package is not lock-stepped */
1492 queue_empty(&allowedarchs);
1493 FOR_PROVIDES(p, pp, s->name)
1496 ps = pool->solvables + p;
1497 if (ps->name != s->name || ps->repo != installed || !MAPTST(addedmap, p))
1499 if (solv->dupmap_all || (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
1502 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1505 queue_pushunique(&allowedarchs, ps->arch); /* strange arch, allow */
1508 if (a == 1 || ((a ^ bestarch) & 0xffff0000) == 0)
1510 /* have installed package with inferior arch, check if lock-stepped */
1511 FOR_PROVIDES(p2, pp2, s->name)
1513 Solvable *s2 = pool->solvables + p2;
1515 if (p2 == p || s2->name != s->name || s2->evr != pool->solvables[p].evr || s2->arch == pool->solvables[p].arch)
1518 a2 = (a2 <= pool->lastarch) ? pool->id2arch[a2] : 0;
1519 if (a2 && (a2 == 1 || ((a2 ^ bestarch) & 0xffff0000) == 0))
1523 queue_pushunique(&allowedarchs, ps->arch);
1527 /* find all bad packages */
1529 FOR_PROVIDES(p, pp, s->name)
1531 ps = pool->solvables + p;
1532 if (ps->name != s->name || !MAPTST(addedmap, p))
1535 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1536 if (a != 1 && bestarch && ((a ^ bestarch) & 0xffff0000) != 0)
1538 if (installed && ps->repo == installed)
1540 if (pool->implicitobsoleteusescolors)
1541 queue_push(&badq, p); /* special lock-step handling, see below */
1542 continue; /* always ok to keep an installed package */
1544 for (j = 0; j < allowedarchs.count; j++)
1546 aa = allowedarchs.elements[j];
1549 aa = (aa <= pool->lastarch) ? pool->id2arch[aa] : 0;
1550 if (aa && ((a ^ aa) & 0xffff0000) == 0)
1551 break; /* compatible */
1553 if (j == allowedarchs.count)
1554 queue_push(&badq, p);
1558 /* block all solvables in the badq! */
1559 for (j = 0; j < badq.count; j++)
1561 p = badq.elements[j];
1563 if (pool->implicitobsoleteusescolors)
1566 int haveinstalled = 0;
1568 FOR_PROVIDES(p2, pp, s->name)
1570 Solvable *s2 = pool->solvables + p2;
1571 if (p2 == p || s2->name != s->name || s2->evr != pool->solvables[p].evr || s2->arch == pool->solvables[p].arch)
1574 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1575 if (a && (a == 1 || ((a ^ bestarch) & 0xffff000) == 0))
1577 queue_push(&lsq, p2);
1578 if (installed && s2->repo == installed)
1582 if (installed && pool->solvables[p].repo == installed && !haveinstalled)
1583 continue; /* installed package not in lock-step */
1586 solver_addrule(solv, -p, lsq.count ? lsq.elements[0] : 0, 0);
1588 solver_addrule(solv, -p, 0, pool_queuetowhatprovides(pool, &lsq));
1593 queue_free(&allowedarchs);
1594 solv->infarchrules_end = solv->nrules;
1598 disableinfarchrule(Solver *solv, Id name)
1600 Pool *pool = solv->pool;
1603 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1605 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1606 solver_disablerule(solv, r);
1611 reenableinfarchrule(Solver *solv, Id name)
1613 Pool *pool = solv->pool;
1616 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1618 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1620 solver_enablerule(solv, r);
1621 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1623 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1624 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1631 /***********************************************************************
1635 *** Dup rules make sure a package is selected from the specified dup
1636 *** repositories if an update candidate is included in one of them.
1641 add_cleandeps_package(Solver *solv, Id p)
1643 if (!solv->cleandeps_updatepkgs)
1645 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
1646 queue_init(solv->cleandeps_updatepkgs);
1648 queue_pushunique(solv->cleandeps_updatepkgs, p);
1652 solver_addtodupmaps(Solver *solv, Id p, Id how, int targeted)
1654 Pool *pool = solv->pool;
1655 Solvable *ps, *s = pool->solvables + p;
1656 Repo *installed = solv->installed;
1657 Id pi, pip, obs, *obsp;
1659 MAPSET(&solv->dupinvolvedmap, p);
1661 MAPSET(&solv->dupmap, p);
1662 FOR_PROVIDES(pi, pip, s->name)
1664 ps = pool->solvables + pi;
1665 if (ps->name != s->name)
1667 MAPSET(&solv->dupinvolvedmap, pi);
1668 if (targeted && ps->repo == installed && solv->obsoletes && solv->obsoletes[pi - installed->start])
1671 for (opp = solv->obsoletes_data + solv->obsoletes[pi - installed->start]; (pi2 = *opp++) != 0;)
1672 if (pool->solvables[pi2].repo != installed)
1673 MAPSET(&solv->dupinvolvedmap, pi2);
1675 if (ps->repo == installed && (how & SOLVER_FORCEBEST) != 0)
1677 if (!solv->bestupdatemap.size)
1678 map_grow(&solv->bestupdatemap, installed->end - installed->start);
1679 MAPSET(&solv->bestupdatemap, pi - installed->start);
1681 if (ps->repo == installed && (how & SOLVER_CLEANDEPS) != 0)
1682 add_cleandeps_package(solv, pi);
1683 if (!targeted && ps->repo != installed)
1684 MAPSET(&solv->dupmap, pi);
1686 if (s->repo == installed && solv->obsoletes && solv->obsoletes[p - installed->start])
1689 for (opp = solv->obsoletes_data + solv->obsoletes[p - installed->start]; (pi = *opp++) != 0;)
1691 ps = pool->solvables + pi;
1692 if (ps->repo == installed)
1694 MAPSET(&solv->dupinvolvedmap, pi);
1696 MAPSET(&solv->dupmap, pi);
1699 if (targeted && s->repo != installed && s->obsoletes)
1701 /* XXX: check obsoletes/provides combination */
1702 obsp = s->repo->idarraydata + s->obsoletes;
1703 while ((obs = *obsp++) != 0)
1705 FOR_PROVIDES(pi, pip, obs)
1707 Solvable *ps = pool->solvables + pi;
1708 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
1710 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1712 MAPSET(&solv->dupinvolvedmap, pi);
1713 if (targeted && ps->repo == installed && solv->obsoletes && solv->obsoletes[pi - installed->start])
1716 for (opp = solv->obsoletes_data + solv->obsoletes[pi - installed->start]; (pi2 = *opp++) != 0;)
1717 if (pool->solvables[pi2].repo != installed)
1718 MAPSET(&solv->dupinvolvedmap, pi2);
1720 if (ps->repo == installed && (how & SOLVER_FORCEBEST) != 0)
1722 if (!solv->bestupdatemap.size)
1723 map_grow(&solv->bestupdatemap, installed->end - installed->start);
1724 MAPSET(&solv->bestupdatemap, pi - installed->start);
1726 if (ps->repo == installed && (how & SOLVER_CLEANDEPS) != 0)
1727 add_cleandeps_package(solv, pi);
1734 solver_createdupmaps(Solver *solv)
1736 Queue *job = &solv->job;
1737 Pool *pool = solv->pool;
1738 Repo *installed = solv->installed;
1739 Id select, how, what, p, pp;
1743 map_init(&solv->dupmap, pool->nsolvables);
1744 map_init(&solv->dupinvolvedmap, pool->nsolvables);
1745 for (i = 0; i < job->count; i += 2)
1747 how = job->elements[i];
1748 select = job->elements[i] & SOLVER_SELECTMASK;
1749 what = job->elements[i + 1];
1750 switch (how & SOLVER_JOBMASK)
1752 case SOLVER_DISTUPGRADE:
1753 if (select == SOLVER_SOLVABLE_REPO)
1756 if (what <= 0 || what > pool->nrepos)
1758 repo = pool_id2repo(pool, what);
1761 if (repo != installed && !(how & SOLVER_TARGETED) && solv->noautotarget)
1763 targeted = repo != installed || (how & SOLVER_TARGETED) != 0;
1764 FOR_REPO_SOLVABLES(repo, p, s)
1766 if (repo != installed && !pool_installable(pool, s))
1768 solver_addtodupmaps(solv, p, how, targeted);
1771 else if (select == SOLVER_SOLVABLE_ALL)
1773 FOR_POOL_SOLVABLES(p)
1775 MAPSET(&solv->dupinvolvedmap, p);
1776 if (installed && pool->solvables[p].repo != installed)
1777 MAPSET(&solv->dupmap, p);
1782 targeted = how & SOLVER_TARGETED ? 1 : 0;
1783 if (installed && !targeted && !solv->noautotarget)
1785 FOR_JOB_SELECT(p, pp, select, what)
1786 if (pool->solvables[p].repo == installed)
1790 else if (!installed && !solv->noautotarget)
1792 FOR_JOB_SELECT(p, pp, select, what)
1794 Solvable *s = pool->solvables + p;
1797 if (s->repo != installed && !targeted)
1799 if (s->repo != installed && !pool_installable(pool, s))
1801 solver_addtodupmaps(solv, p, how, targeted);
1809 MAPCLR(&solv->dupinvolvedmap, SYSTEMSOLVABLE);
1813 solver_freedupmaps(Solver *solv)
1815 map_free(&solv->dupmap);
1816 /* we no longer free solv->dupinvolvedmap as we need it in
1817 * policy's priority pruning code. sigh. */
1821 solver_addduprules(Solver *solv, Map *addedmap)
1823 Pool *pool = solv->pool;
1824 Repo *installed = solv->installed;
1830 solv->duprules = solv->nrules;
1831 for (i = 1; i < pool->nsolvables; i++)
1833 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1835 s = pool->solvables + i;
1837 FOR_PROVIDES(p, pp, s->name)
1839 ps = pool->solvables + p;
1840 if (ps->name != s->name || !MAPTST(addedmap, p))
1846 if (!MAPTST(&solv->dupinvolvedmap, p))
1848 if (installed && ps->repo == installed)
1850 if (!solv->updatemap.size)
1851 map_grow(&solv->updatemap, installed->end - installed->start);
1852 MAPSET(&solv->updatemap, p - installed->start);
1853 if (!MAPTST(&solv->dupmap, p))
1856 /* is installed identical to a good one? */
1857 FOR_PROVIDES(ip, ipp, ps->name)
1859 Solvable *is = pool->solvables + ip;
1860 if (!MAPTST(&solv->dupmap, ip))
1862 if (is->evr == ps->evr && solvable_identical(ps, is))
1867 /* ok, found a good one. we may keep this package. */
1868 MAPSET(&solv->dupmap, p); /* for best rules processing */
1871 r = solv->rules + solv->updaterules + (p - installed->start);
1873 r = solv->rules + solv->featurerules + (p - installed->start);
1874 if (r->p && solv->specialupdaters && solv->specialupdaters[p - installed->start])
1876 /* this is a multiversion orphan, we're good if an update is installed */
1877 solver_addrule(solv, -p, 0, solv->specialupdaters[p - installed->start]);
1880 if (!r->p || (r->p == p && !r->d && !r->w2))
1882 /* this is an orphan */
1883 MAPSET(&solv->dupmap, p); /* for best rules processing */
1886 solver_addrule(solv, -p, 0, 0); /* no match, sorry */
1889 else if (!MAPTST(&solv->dupmap, p))
1890 solver_addrule(solv, -p, 0, 0);
1893 solv->duprules_end = solv->nrules;
1898 disableduprule(Solver *solv, Id name)
1900 Pool *pool = solv->pool;
1903 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1905 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1906 solver_disablerule(solv, r);
1911 reenableduprule(Solver *solv, Id name)
1913 Pool *pool = solv->pool;
1916 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1918 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1920 solver_enablerule(solv, r);
1921 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1923 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1924 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1931 /***********************************************************************
1933 *** Policy rule disabling/reenabling
1935 *** Disable all policy rules that conflict with our jobs. If a job
1936 *** gets disabled later on, reenable the involved policy rules again.
1940 #define DISABLE_UPDATE 1
1941 #define DISABLE_INFARCH 2
1942 #define DISABLE_DUP 3
1945 * add all installed packages that package p obsoletes to Queue q.
1946 * Package p is not installed. Also, we know that if
1947 * solv->keepexplicitobsoletes is not set, p is not in the multiversion map.
1948 * Entries may get added multiple times.
1951 add_obsoletes(Solver *solv, Id p, Queue *q)
1953 Pool *pool = solv->pool;
1954 Repo *installed = solv->installed;
1956 Solvable *s = pool->solvables + p;
1960 if (!solv->keepexplicitobsoletes || !(solv->multiversion.size && MAPTST(&solv->multiversion, p)))
1962 FOR_PROVIDES(p2, pp2, s->name)
1964 Solvable *ps = pool->solvables + p2;
1965 if (ps->repo != installed)
1967 if (!pool->implicitobsoleteusesprovides && ps->name != s->name)
1969 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, ps))
1977 obsp = s->repo->idarraydata + s->obsoletes;
1978 while ((obs = *obsp++) != 0)
1979 FOR_PROVIDES(p2, pp2, obs)
1981 Solvable *ps = pool->solvables + p2;
1982 if (ps->repo != installed)
1984 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
1986 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1996 * Call add_obsoletes and intersect the result with the
1997 * elements in Queue q starting at qstart.
1998 * Assumes that it's the first call if qstart == q->count.
1999 * May use auxillary map m for the intersection process, all
2000 * elements of q starting at qstart must have their bit cleared.
2001 * (This is also true after the function returns.)
2004 intersect_obsoletes(Solver *solv, Id p, Queue *q, int qstart, Map *m)
2007 int qcount = q->count;
2009 add_obsoletes(solv, p, q);
2010 if (qcount == qstart)
2011 return; /* first call */
2012 if (qcount == q->count)
2014 else if (qcount == qstart + 1)
2016 /* easy if there's just one element */
2018 for (i = qcount; i < q->count; i++)
2019 if (q->elements[i] == q->elements[qstart])
2021 j++; /* keep the element */
2025 else if (!m->size && q->count - qstart <= 8)
2027 /* faster than a map most of the time */
2029 for (i = j = qstart; i < qcount; i++)
2031 Id ip = q->elements[i];
2032 for (k = qcount; k < q->count; k++)
2033 if (q->elements[k] == ip)
2035 q->elements[j++] = ip;
2042 /* for the really pathologic cases we use the map */
2043 Repo *installed = solv->installed;
2045 map_init(m, installed->end - installed->start);
2046 for (i = qcount; i < q->count; i++)
2047 MAPSET(m, q->elements[i] - installed->start);
2048 for (i = j = qstart; i < qcount; i++)
2049 if (MAPTST(m, q->elements[i] - installed->start))
2051 MAPCLR(m, q->elements[i] - installed->start);
2052 q->elements[j++] = q->elements[i];
2055 queue_truncate(q, j);
2059 jobtodisablelist(Solver *solv, Id how, Id what, Queue *q)
2061 Pool *pool = solv->pool;
2065 int i, j, set, qstart;
2068 installed = solv->installed;
2069 select = how & SOLVER_SELECTMASK;
2070 switch (how & SOLVER_JOBMASK)
2072 case SOLVER_INSTALL:
2073 set = how & SOLVER_SETMASK;
2074 if (!(set & SOLVER_NOAUTOSET))
2076 /* automatically add set bits by analysing the job */
2077 if (select == SOLVER_SOLVABLE_NAME)
2078 set |= SOLVER_SETNAME;
2079 if (select == SOLVER_SOLVABLE)
2080 set |= SOLVER_SETNAME | SOLVER_SETARCH | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_SETEVR;
2081 else if ((select == SOLVER_SOLVABLE_NAME || select == SOLVER_SOLVABLE_PROVIDES) && ISRELDEP(what))
2083 Reldep *rd = GETRELDEP(pool, what);
2084 if (rd->flags == REL_EQ && select == SOLVER_SOLVABLE_NAME)
2086 if (pool->disttype != DISTTYPE_DEB)
2088 const char *rel = strrchr(pool_id2str(pool, rd->evr), '-');
2089 set |= rel ? SOLVER_SETEVR : SOLVER_SETEV;
2092 set |= SOLVER_SETEVR;
2094 if (rd->flags <= 7 && ISRELDEP(rd->name))
2095 rd = GETRELDEP(pool, rd->name);
2096 if (rd->flags == REL_ARCH)
2097 set |= SOLVER_SETARCH;
2101 set &= ~SOLVER_NOAUTOSET;
2104 if ((set & SOLVER_SETARCH) != 0 && solv->infarchrules != solv->infarchrules_end)
2106 if (select == SOLVER_SOLVABLE)
2107 queue_push2(q, DISABLE_INFARCH, pool->solvables[what].name);
2110 int qcnt = q->count;
2111 /* does not work for SOLVER_SOLVABLE_ALL and SOLVER_SOLVABLE_REPO, but
2112 they are not useful for SOLVER_INSTALL jobs anyway */
2113 FOR_JOB_SELECT(p, pp, select, what)
2115 s = pool->solvables + p;
2117 for (i = qcnt; i < q->count; i += 2)
2118 if (q->elements[i + 1] == s->name)
2122 queue_push2(q, DISABLE_INFARCH, s->name);
2126 if ((set & SOLVER_SETREPO) != 0 && solv->duprules != solv->duprules_end)
2128 if (select == SOLVER_SOLVABLE)
2129 queue_push2(q, DISABLE_DUP, pool->solvables[what].name);
2132 int qcnt = q->count;
2133 FOR_JOB_SELECT(p, pp, select, what)
2135 s = pool->solvables + p;
2137 for (i = qcnt; i < q->count; i += 2)
2138 if (q->elements[i + 1] == s->name)
2142 queue_push2(q, DISABLE_DUP, s->name);
2146 if (!installed || installed->end == installed->start)
2148 /* now the hard part: disable some update rules */
2150 /* first check if we have multiversion or installed packages in the job */
2152 FOR_JOB_SELECT(p, pp, select, what)
2154 if (pool->solvables[p].repo == installed)
2156 else if (solv->multiversion.size && MAPTST(&solv->multiversion, p) && !solv->keepexplicitobsoletes)
2160 if (j) /* have installed packages */
2162 /* this is for dupmap_all jobs, it can go away if we create
2163 * duprules for them */
2164 if (i == 1 && (set & SOLVER_SETREPO) != 0)
2165 queue_push2(q, DISABLE_UPDATE, j);
2171 FOR_JOB_SELECT(p, pp, select, what)
2173 intersect_obsoletes(solv, p, q, qstart, &omap);
2174 if (q->count == qstart)
2180 if (qstart == q->count)
2181 return; /* nothing to prune */
2183 /* convert result to (DISABLE_UPDATE, p) pairs */
2185 for (j = qstart; j < i; j++)
2186 queue_push(q, q->elements[j]);
2187 for (j = qstart; j < q->count; j += 2)
2189 q->elements[j] = DISABLE_UPDATE;
2190 q->elements[j + 1] = q->elements[i++];
2193 /* now that we know which installed packages are obsoleted check each of them */
2194 if ((set & (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR)) == (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR))
2195 return; /* all is set, nothing to do */
2197 for (i = j = qstart; i < q->count; i += 2)
2199 Solvable *is = pool->solvables + q->elements[i + 1];
2200 FOR_JOB_SELECT(p, pp, select, what)
2203 s = pool->solvables + p;
2204 if ((set & SOLVER_SETEVR) != 0)
2205 illegal |= POLICY_ILLEGAL_DOWNGRADE; /* ignore */
2206 if ((set & SOLVER_SETNAME) != 0)
2207 illegal |= POLICY_ILLEGAL_NAMECHANGE; /* ignore */
2208 if ((set & SOLVER_SETARCH) != 0)
2209 illegal |= POLICY_ILLEGAL_ARCHCHANGE; /* ignore */
2210 if ((set & SOLVER_SETVENDOR) != 0)
2211 illegal |= POLICY_ILLEGAL_VENDORCHANGE; /* ignore */
2212 illegal = policy_is_illegal(solv, is, s, illegal);
2213 if (illegal && illegal == POLICY_ILLEGAL_DOWNGRADE && (set & SOLVER_SETEV) != 0)
2215 /* it's ok if the EV is different */
2216 if (pool_evrcmp(pool, is->evr, s->evr, EVRCMP_COMPARE_EVONLY) != 0)
2224 /* no package conflicts with the update rule */
2225 /* thus keep the DISABLE_UPDATE */
2226 q->elements[j + 1] = q->elements[i + 1];
2230 queue_truncate(q, j);
2236 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
2237 FOR_REPO_SOLVABLES(installed, p, s)
2238 queue_push2(q, DISABLE_UPDATE, p);
2239 FOR_JOB_SELECT(p, pp, select, what)
2240 if (pool->solvables[p].repo == installed)
2242 queue_push2(q, DISABLE_UPDATE, p);
2243 #ifdef ENABLE_LINKED_PKGS
2244 if (solv->instbuddy && solv->instbuddy[p - installed->start] > 1)
2245 queue_push2(q, DISABLE_UPDATE, solv->instbuddy[p - installed->start]);
2254 /* disable all policy rules that are in conflict with our job list */
2256 solver_disablepolicyrules(Solver *solv)
2258 Queue *job = &solv->job;
2265 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2267 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2269 r = solv->rules + i;
2270 if (r->d < 0) /* disabled? */
2272 j = solv->ruletojob.elements[i - solv->jobrules];
2276 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2278 if (solv->cleandepsmap.size)
2280 solver_createcleandepsmap(solv, &solv->cleandepsmap, 0);
2281 for (i = solv->installed->start; i < solv->installed->end; i++)
2282 if (MAPTST(&solv->cleandepsmap, i - solv->installed->start))
2283 queue_push2(&allq, DISABLE_UPDATE, i);
2285 MAPZERO(&solv->noupdate);
2286 for (i = 0; i < allq.count; i += 2)
2288 Id type = allq.elements[i], arg = allq.elements[i + 1];
2291 case DISABLE_UPDATE:
2292 disableupdaterule(solv, arg);
2294 case DISABLE_INFARCH:
2295 disableinfarchrule(solv, arg);
2298 disableduprule(solv, arg);
2307 /* we just disabled job #jobidx, now reenable all policy rules that were
2308 * disabled because of this job */
2310 solver_reenablepolicyrules(Solver *solv, int jobidx)
2312 Queue *job = &solv->job;
2317 Id qbuf[32], allqbuf[32];
2319 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
2320 jobtodisablelist(solv, job->elements[jobidx - 1], job->elements[jobidx], &q);
2326 /* now remove everything from q that is disabled by other jobs */
2328 /* first remove cleandeps packages, they count as DISABLE_UPDATE */
2329 if (solv->cleandepsmap.size)
2331 solver_createcleandepsmap(solv, &solv->cleandepsmap, 0);
2332 for (j = k = 0; j < q.count; j += 2)
2334 if (q.elements[j] == DISABLE_UPDATE)
2336 Id p = q.elements[j + 1];
2337 if (p >= solv->installed->start && p < solv->installed->end && MAPTST(&solv->cleandepsmap, p - solv->installed->start))
2338 continue; /* remove element from q */
2340 q.elements[k++] = q.elements[j];
2341 q.elements[k++] = q.elements[j + 1];
2351 /* now go through the disable list of all other jobs */
2352 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2353 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2355 r = solv->rules + i;
2356 if (r->d < 0) /* disabled? */
2358 j = solv->ruletojob.elements[i - solv->jobrules];
2362 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2365 /* remove all elements in allq from q */
2366 for (j = k = 0; j < q.count; j += 2)
2368 Id type = q.elements[j], arg = q.elements[j + 1];
2369 for (ai = 0; ai < allq.count; ai += 2)
2370 if (allq.elements[ai] == type && allq.elements[ai + 1] == arg)
2372 if (ai < allq.count)
2373 continue; /* found it in allq, remove element from q */
2374 q.elements[k++] = q.elements[j];
2375 q.elements[k++] = q.elements[j + 1];
2388 /* now re-enable anything that's left in q */
2389 for (j = 0; j < q.count; j += 2)
2391 Id type = q.elements[j], arg = q.elements[j + 1];
2394 case DISABLE_UPDATE:
2395 reenableupdaterule(solv, arg);
2397 case DISABLE_INFARCH:
2398 reenableinfarchrule(solv, arg);
2401 reenableduprule(solv, arg);
2408 /* we just removed a package from the cleandeps map, now reenable all policy rules that were
2409 * disabled because of this */
2411 solver_reenablepolicyrules_cleandeps(Solver *solv, Id pkg)
2413 Queue *job = &solv->job;
2420 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2421 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2423 r = solv->rules + i;
2424 if (r->d < 0) /* disabled? */
2426 j = solv->ruletojob.elements[i - solv->jobrules];
2430 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2432 for (i = 0; i < allq.count; i += 2)
2433 if (allq.elements[i] == DISABLE_UPDATE && allq.elements[i + 1] == pkg)
2435 if (i == allq.count)
2436 reenableupdaterule(solv, pkg);
2441 /***********************************************************************
2443 *** Rule info part, tell the user what the rule is about.
2448 addpkgruleinfo(Solver *solv, Id p, Id p2, Id d, int type, Id dep)
2450 Pool *pool = solv->pool;
2455 assert(!p2 && d > 0);
2456 if (!pool->whatprovidesdata[d])
2458 else if (!pool->whatprovidesdata[d + 1])
2460 p2 = pool->whatprovidesdata[d];
2465 /* check if this creates the rule we're searching for */
2466 r = solv->rules + solv->ruleinfoq->elements[0];
2469 /* three or more literals */
2470 Id od = r->d < 0 ? -r->d - 1 : r->d;
2471 if (p != r->p && !od)
2475 Id *dp = pool->whatprovidesdata + d;
2476 Id *odp = pool->whatprovidesdata + od;
2478 if (*dp++ != *odp++)
2483 if (p < 0 && pool->whatprovidesdata[d] < 0 && type == SOLVER_RULE_PKG_CONFLICTS)
2484 p2 = pool->whatprovidesdata[d];
2488 /* one or two literals */
2489 Id op = p, op2 = p2;
2490 if (op2 && op > op2) /* normalize */
2496 if (r->p != op || r->w2 != op2 || (r->d && r->d != -1))
2498 if (type == SOLVER_RULE_PKG_CONFLICTS && !p2)
2499 p2 = -SYSTEMSOLVABLE;
2500 if (type == SOLVER_RULE_PKG_SAME_NAME)
2502 p = op; /* we normalize same name order */
2506 /* yep, rule matches. record info */
2507 queue_push(solv->ruleinfoq, type);
2508 queue_push(solv->ruleinfoq, p < 0 ? -p : 0);
2509 queue_push(solv->ruleinfoq, p2 < 0 ? -p2 : 0);
2510 queue_push(solv->ruleinfoq, dep);
2514 solver_allruleinfos_cmp(const void *ap, const void *bp, void *dp)
2516 const Id *a = ap, *b = bp;
2535 getpkgruleinfos(Solver *solv, Rule *r, Queue *rq)
2537 Pool *pool = solv->pool;
2541 queue_push(rq, r - solv->rules); /* push the rule we're interested in */
2542 solv->ruleinfoq = rq;
2543 FOR_RULELITERALS(l, pp, r)
2547 solver_addpkgrulesforsolvable(solv, pool->solvables - l, 0);
2549 #ifdef ENABLE_LINKED_PKGS
2550 FOR_RULELITERALS(l, pp, r)
2558 if (!strchr(pool_id2str(pool, pool->solvables[l].name), ':') || !has_package_link(pool, pool->solvables + l))
2560 add_package_link(solv, pool->solvables + l, 0, 0);
2563 solv->ruleinfoq = 0;
2568 solver_allruleinfos(Solver *solv, Id rid, Queue *rq)
2570 Rule *r = solv->rules + rid;
2574 if (rid <= 0 || rid >= solv->pkgrules_end)
2576 Id type, from, to, dep;
2577 type = solver_ruleinfo(solv, rid, &from, &to, &dep);
2578 queue_push(rq, type);
2579 queue_push(rq, from);
2581 queue_push(rq, dep);
2584 getpkgruleinfos(solv, r, rq);
2585 /* now sort & unify em */
2588 solv_sort(rq->elements, rq->count / 4, 4 * sizeof(Id), solver_allruleinfos_cmp, 0);
2589 /* throw out identical entries */
2590 for (i = j = 0; i < rq->count; i += 4)
2594 if (rq->elements[i] == rq->elements[j - 4] &&
2595 rq->elements[i + 1] == rq->elements[j - 3] &&
2596 rq->elements[i + 2] == rq->elements[j - 2] &&
2597 rq->elements[i + 3] == rq->elements[j - 1])
2600 rq->elements[j++] = rq->elements[i];
2601 rq->elements[j++] = rq->elements[i + 1];
2602 rq->elements[j++] = rq->elements[i + 2];
2603 rq->elements[j++] = rq->elements[i + 3];
2610 solver_ruleinfo(Solver *solv, Id rid, Id *fromp, Id *top, Id *depp)
2612 Pool *pool = solv->pool;
2613 Rule *r = solv->rules + rid;
2614 SolverRuleinfo type = SOLVER_RULE_UNKNOWN;
2622 if (rid > 0 && rid < solv->pkgrules_end)
2628 return SOLVER_RULE_PKG;
2632 getpkgruleinfos(solv, r, &rq);
2633 type = SOLVER_RULE_PKG;
2634 for (i = 0; i < rq.count; i += 4)
2637 qt = rq.elements[i];
2638 qp = rq.elements[i + 1];
2639 qo = rq.elements[i + 2];
2640 qd = rq.elements[i + 3];
2641 if (type == SOLVER_RULE_PKG || type > qt)
2655 if (rid >= solv->jobrules && rid < solv->jobrules_end)
2657 Id jidx = solv->ruletojob.elements[rid - solv->jobrules];
2661 *top = solv->job.elements[jidx];
2663 *depp = solv->job.elements[jidx + 1];
2664 if ((r->d == 0 || r->d == -1) && r->w2 == 0 && r->p == -SYSTEMSOLVABLE)
2666 Id how = solv->job.elements[jidx];
2667 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_INSTALL|SOLVER_SOLVABLE_NAME))
2668 return SOLVER_RULE_JOB_UNKNOWN_PACKAGE;
2669 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES))
2670 return SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP;
2671 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_ERASE|SOLVER_SOLVABLE_NAME))
2672 return SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM;
2673 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_ERASE|SOLVER_SOLVABLE_PROVIDES))
2674 return SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM;
2675 return SOLVER_RULE_JOB_UNSUPPORTED;
2677 return SOLVER_RULE_JOB;
2679 if (rid >= solv->updaterules && rid < solv->updaterules_end)
2682 *fromp = solv->installed->start + (rid - solv->updaterules);
2683 return SOLVER_RULE_UPDATE;
2685 if (rid >= solv->featurerules && rid < solv->featurerules_end)
2688 *fromp = solv->installed->start + (rid - solv->featurerules);
2689 return SOLVER_RULE_FEATURE;
2691 if (rid >= solv->duprules && rid < solv->duprules_end)
2696 *depp = pool->solvables[-r->p].name;
2697 return SOLVER_RULE_DISTUPGRADE;
2699 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
2704 *depp = pool->solvables[-r->p].name;
2705 return SOLVER_RULE_INFARCH;
2707 if (rid >= solv->bestrules && rid < solv->bestrules_end)
2709 if (fromp && solv->bestrules_pkg[rid - solv->bestrules] > 0)
2710 *fromp = solv->bestrules_pkg[rid - solv->bestrules];
2711 return SOLVER_RULE_BEST;
2713 if (rid >= solv->yumobsrules && rid < solv->yumobsrules_end)
2719 /* first solvable is enough, we just need it for the name */
2720 if (!r->d || r->d == -1)
2723 *top = pool->whatprovidesdata[r->d < 0 ? -r->d : r->d];
2726 *depp = solv->yumobsrules_info[rid - solv->yumobsrules];
2727 return SOLVER_RULE_YUMOBS;
2729 if (rid >= solv->choicerules && rid < solv->choicerules_end)
2731 return SOLVER_RULE_CHOICE;
2733 if (rid >= solv->learntrules)
2735 return SOLVER_RULE_LEARNT;
2737 return SOLVER_RULE_UNKNOWN;
2741 solver_ruleclass(Solver *solv, Id rid)
2744 return SOLVER_RULE_UNKNOWN;
2745 if (rid > 0 && rid < solv->pkgrules_end)
2746 return SOLVER_RULE_PKG;
2747 if (rid >= solv->jobrules && rid < solv->jobrules_end)
2748 return SOLVER_RULE_JOB;
2749 if (rid >= solv->updaterules && rid < solv->updaterules_end)
2750 return SOLVER_RULE_UPDATE;
2751 if (rid >= solv->featurerules && rid < solv->featurerules_end)
2752 return SOLVER_RULE_FEATURE;
2753 if (rid >= solv->duprules && rid < solv->duprules_end)
2754 return SOLVER_RULE_DISTUPGRADE;
2755 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
2756 return SOLVER_RULE_INFARCH;
2757 if (rid >= solv->bestrules && rid < solv->bestrules_end)
2758 return SOLVER_RULE_BEST;
2759 if (rid >= solv->yumobsrules && rid < solv->yumobsrules_end)
2760 return SOLVER_RULE_YUMOBS;
2761 if (rid >= solv->choicerules && rid < solv->choicerules_end)
2762 return SOLVER_RULE_CHOICE;
2763 if (rid >= solv->learntrules && rid < solv->nrules)
2764 return SOLVER_RULE_LEARNT;
2765 return SOLVER_RULE_UNKNOWN;
2769 solver_ruleliterals(Solver *solv, Id rid, Queue *q)
2771 Pool *pool = solv->pool;
2776 r = solv->rules + rid;
2777 FOR_RULELITERALS(p, pp, r)
2778 if (p != -SYSTEMSOLVABLE)
2781 queue_push(q, -SYSTEMSOLVABLE); /* hmm, better to return an empty result? */
2785 solver_rule2jobidx(Solver *solv, Id rid)
2787 if (rid < solv->jobrules || rid >= solv->jobrules_end)
2789 return solv->ruletojob.elements[rid - solv->jobrules] + 1;
2792 /* job rule introspection */
2794 solver_rule2job(Solver *solv, Id rid, Id *whatp)
2797 if (rid < solv->jobrules || rid >= solv->jobrules_end)
2803 idx = solv->ruletojob.elements[rid - solv->jobrules];
2805 *whatp = solv->job.elements[idx + 1];
2806 return solv->job.elements[idx];
2809 /* update/feature rule introspection */
2811 solver_rule2solvable(Solver *solv, Id rid)
2813 if (rid >= solv->updaterules && rid < solv->updaterules_end)
2814 return rid - solv->updaterules;
2815 if (rid >= solv->featurerules && rid < solv->featurerules_end)
2816 return rid - solv->featurerules;
2821 solver_rule2pkgrule(Solver *solv, Id rid)
2823 if (rid >= solv->choicerules && rid < solv->choicerules_end)
2824 return solv->choicerules_ref[rid - solv->choicerules];
2829 solver_rule2rules_rec(Solver *solv, Id rid, Queue *q, Map *seen)
2836 for (i = solv->learnt_why.elements[rid - solv->learntrules]; (rid2 = solv->learnt_pool.elements[i]) != 0; i++)
2840 if (MAPTST(seen, rid2))
2842 if (rid2 >= solv->learntrules)
2843 solver_rule2rules_rec(solv, rid2, q, seen);
2846 queue_push(q, rid2);
2850 /* learnt rule introspection */
2852 solver_rule2rules(Solver *solv, Id rid, Queue *q, int recursive)
2855 if (rid < solv->learntrules || rid >= solv->nrules)
2860 map_init(&seen, solv->nrules);
2861 solver_rule2rules_rec(solv, rid, q, &seen);
2865 solver_rule2rules_rec(solv, rid, q, 0);
2869 /* check if the newest versions of pi still provides the dependency we're looking for */
2871 solver_choicerulecheck(Solver *solv, Id pi, Rule *r, Map *m, Queue *q)
2873 Pool *pool = solv->pool;
2878 if (!q->count || q->elements[0] != pi)
2882 ur = solv->rules + solv->updaterules + (pi - pool->installed->start);
2884 ur = solv->rules + solv->featurerules + (pi - pool->installed->start);
2887 queue_push2(q, pi, 0);
2888 FOR_RULELITERALS(p, pp, ur)
2897 return MAPTST(m, p) ? 0 : 1;
2899 if (!q->elements[1])
2901 for (i = 2; i < q->count; i++)
2902 if (!MAPTST(m, q->elements[i]))
2905 return 0; /* all provide it, no need to filter */
2906 /* some don't provide it, have to filter */
2907 queue_deleten(q, 0, 2);
2908 policy_filter_unwanted(solv, q, POLICY_MODE_CHOOSE);
2909 queue_unshift(q, 1); /* filter mark */
2910 queue_unshift(q, pi);
2912 for (i = 2; i < q->count; i++)
2913 if (MAPTST(m, q->elements[i]))
2914 return 0; /* at least one provides it */
2915 return 1; /* none of the new packages provided it */
2919 queue_removeelement(Queue *q, Id el)
2922 for (i = 0; i < q->count; i++)
2923 if (q->elements[i] == el)
2927 for (j = i++; i < q->count; i++)
2928 if (q->elements[i] != el)
2929 q->elements[j++] = q->elements[i];
2930 queue_truncate(q, j);
2935 solver_addchoicerules(Solver *solv)
2937 Pool *pool = solv->pool;
2940 Queue q, qi, qcheck;
2941 int i, j, rid, havechoice;
2945 Id lastaddedp, lastaddedd;
2949 solv->choicerules = solv->nrules;
2950 if (!pool->installed)
2952 solv->choicerules_end = solv->nrules;
2955 now = solv_timems(0);
2956 solv->choicerules_ref = solv_calloc(solv->pkgrules_end, sizeof(Id));
2959 queue_init(&qcheck);
2960 map_init(&m, pool->nsolvables);
2961 map_init(&mneg, pool->nsolvables);
2962 /* set up negative assertion map from infarch and dup rules */
2963 for (rid = solv->infarchrules, r = solv->rules + rid; rid < solv->infarchrules_end; rid++, r++)
2964 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
2965 MAPSET(&mneg, -r->p);
2966 for (rid = solv->duprules, r = solv->rules + rid; rid < solv->duprules_end; rid++, r++)
2967 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
2968 MAPSET(&mneg, -r->p);
2972 for (rid = 1; rid < solv->pkgrules_end ; rid++)
2974 r = solv->rules + rid;
2975 if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 <= 0))
2976 continue; /* only look at requires rules */
2977 /* solver_printrule(solv, SOLV_DEBUG_RESULT, r); */
2981 FOR_RULELITERALS(p, pp, r)
2985 s = pool->solvables + p;
2988 if (s->repo == pool->installed)
2993 /* check if this package is "blocked" by a installed package */
2995 FOR_PROVIDES(p2, pp2, s->name)
2997 s2 = pool->solvables + p2;
2998 if (s2->repo != pool->installed)
3000 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
3002 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, s2))
3008 /* found installed package p2 that we can update to p */
3009 if (MAPTST(&mneg, p))
3011 if (policy_is_illegal(solv, s2, s, 0))
3014 if (solver_choicerulecheck(solv, p2, r, &m))
3016 queue_push(&qi, p2);
3018 queue_push2(&qi, p2, p);
3025 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
3027 while ((obs = *obsp++) != 0)
3029 FOR_PROVIDES(p2, pp2, obs)
3031 s2 = pool->solvables + p2;
3032 if (s2->repo != pool->installed)
3034 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
3036 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
3045 /* found installed package p2 that we can update to p */
3046 if (MAPTST(&mneg, p))
3048 if (policy_is_illegal(solv, s2, s, 0))
3051 if (solver_choicerulecheck(solv, p2, r, &m))
3053 queue_push(&qi, p2);
3055 queue_push2(&qi, p2, p);
3061 /* package p is independent of the installed ones */
3064 if (!havechoice || !q.count || !qi.count)
3065 continue; /* no choice */
3067 FOR_RULELITERALS(p, pp, r)
3071 /* do extra checking */
3072 for (i = j = 0; i < qi.count; i += 2)
3074 p2 = qi.elements[i];
3077 if (solver_choicerulecheck(solv, p2, r, &m, &qcheck))
3079 /* oops, remove element p from q */
3080 queue_removeelement(&q, qi.elements[i + 1]);
3083 qi.elements[j++] = p2;
3085 queue_truncate(&qi, j);
3087 if (!q.count || !qi.count)
3089 FOR_RULELITERALS(p, pp, r)
3096 /* now check the update rules of the installed package.
3097 * if all packages of the update rules are contained in
3098 * the dependency rules, there's no need to set up the choice rule */
3099 for (i = 0; i < qi.count; i++)
3102 if (!qi.elements[i])
3104 ur = solv->rules + solv->updaterules + (qi.elements[i] - pool->installed->start);
3106 ur = solv->rules + solv->featurerules + (qi.elements[i] - pool->installed->start);
3109 FOR_RULELITERALS(p, pp, ur)
3114 for (j = i + 1; j < qi.count; j++)
3115 if (qi.elements[i] == qi.elements[j])
3118 /* empty map again */
3119 FOR_RULELITERALS(p, pp, r)
3125 printf("skipping choice ");
3126 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + rid);
3131 /* don't add identical rules */
3132 if (lastaddedp == r->p && lastaddedcnt == q.count)
3134 for (i = 0; i < q.count; i++)
3135 if (q.elements[i] != pool->whatprovidesdata[lastaddedd + i])
3138 continue; /* already added that one */
3140 d = q.count ? pool_queuetowhatprovides(pool, &q) : 0;
3144 lastaddedcnt = q.count;
3146 solver_addrule(solv, r->p, 0, d);
3147 queue_push(&solv->weakruleq, solv->nrules - 1);
3148 solv->choicerules_ref[solv->nrules - 1 - solv->choicerules] = rid;
3151 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + rid);
3152 printf("WEAK CHOICE ");
3153 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + solv->nrules - 1);
3158 queue_free(&qcheck);
3161 solv->choicerules_end = solv->nrules;
3162 /* shrink choicerules_ref */
3163 solv->choicerules_ref = solv_realloc2(solv->choicerules_ref, solv->choicerules_end - solv->choicerules, sizeof(Id));
3164 POOL_DEBUG(SOLV_DEBUG_STATS, "choice rule creation took %d ms\n", solv_timems(now));
3167 /* called when a choice rule is disabled by analyze_unsolvable. We also
3168 * have to disable all other choice rules so that the best packages get
3171 solver_disablechoicerules(Solver *solv, Rule *r)
3174 Pool *pool = solv->pool;
3178 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
3179 map_init(&m, pool->nsolvables);
3180 FOR_RULELITERALS(p, pp, or)
3183 FOR_RULELITERALS(p, pp, r)
3186 for (rid = solv->choicerules; rid < solv->choicerules_end; rid++)
3188 r = solv->rules + rid;
3191 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
3192 FOR_RULELITERALS(p, pp, or)
3193 if (p > 0 && MAPTST(&m, p))
3196 solver_disablerule(solv, r);
3201 prune_to_update_targets(Solver *solv, Id *cp, Queue *q)
3205 for (i = j = 0; i < q->count; i++)
3208 for (cp2 = cp; *cp2; cp2++)
3211 q->elements[j++] = p;
3215 queue_truncate(q, j);
3219 prune_to_dup_packages(Solver *solv, Id p, Queue *q)
3222 for (i = j = 0; i < q->count; i++)
3224 Id p = q->elements[i];
3225 if (MAPTST(&solv->dupmap, p))
3226 q->elements[j++] = p;
3228 queue_truncate(q, j);
3232 solver_addbestrules(Solver *solv, int havebestinstalljobs)
3234 Pool *pool = solv->pool;
3237 Repo *installed = solv->installed;
3243 solv->bestrules = solv->nrules;
3246 solv->bestrules_end = solv->nrules;
3253 if (havebestinstalljobs)
3255 for (i = 0; i < solv->job.count; i += 2)
3257 if ((solv->job.elements[i] & (SOLVER_JOBMASK | SOLVER_FORCEBEST)) == (SOLVER_INSTALL | SOLVER_FORCEBEST))
3261 for (j = 0; j < solv->ruletojob.count; j++)
3262 if (solv->ruletojob.elements[j] == i)
3264 if (j == solv->ruletojob.count)
3266 r = solv->rules + solv->jobrules + j;
3268 FOR_RULELITERALS(p2, pp2, r)
3272 continue; /* orphaned */
3273 /* select best packages, just look at prio and version */
3275 policy_filter_unwanted(solv, &q, POLICY_MODE_RECOMMEND);
3276 if (q.count == oldcnt)
3277 continue; /* nothing filtered */
3278 p2 = queue_shift(&q);
3280 solver_addrule(solv, p2, q.count ? q.elements[0] : 0, 0);
3282 solver_addrule(solv, p2, 0, pool_queuetowhatprovides(pool, &q));
3283 queue_push(&r2pkg, -(solv->jobrules + j));
3288 if (solv->bestupdatemap_all || solv->bestupdatemap.size)
3290 FOR_REPO_SOLVABLES(installed, p, s)
3293 if (!solv->updatemap_all && (!solv->updatemap.size || !MAPTST(&solv->updatemap, p - installed->start)))
3295 if (!solv->bestupdatemap_all && (!solv->bestupdatemap.size || !MAPTST(&solv->bestupdatemap, p - installed->start)))
3298 if (solv->bestobeypolicy)
3299 r = solv->rules + solv->updaterules + (p - installed->start);
3302 r = solv->rules + solv->featurerules + (p - installed->start);
3303 if (!r->p) /* identical to update rule? */
3304 r = solv->rules + solv->updaterules + (p - installed->start);
3306 if (solv->specialupdaters && (d = solv->specialupdaters[p - installed->start]) != 0 && r == solv->rules + solv->updaterules + (p - installed->start))
3308 /* need to check specialupdaters */
3309 if (r->p == p) /* be careful with the dup case */
3311 while ((p2 = pool->whatprovidesdata[d++]) != 0)
3316 FOR_RULELITERALS(p2, pp2, r)
3320 if (solv->update_targets && solv->update_targets->elements[p - installed->start])
3321 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[p - installed->start], &q);
3322 if (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
3323 prune_to_dup_packages(solv, p, &q);
3324 /* select best packages, just look at prio and version */
3325 policy_filter_unwanted(solv, &q, POLICY_MODE_RECOMMEND);
3327 continue; /* orphaned */
3328 if (solv->bestobeypolicy)
3330 /* also filter the best of the feature rule packages and add them */
3331 r = solv->rules + solv->featurerules + (p - installed->start);
3336 FOR_RULELITERALS(p2, pp2, r)
3338 queue_push(&q2, p2);
3339 if (solv->update_targets && solv->update_targets->elements[p - installed->start])
3340 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[p - installed->start], &q2);
3341 if (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
3342 prune_to_dup_packages(solv, p, &q2);
3343 policy_filter_unwanted(solv, &q2, POLICY_MODE_RECOMMEND);
3344 for (j = 0; j < q2.count; j++)
3345 queue_pushunique(&q, q2.elements[j]);
3348 p2 = queue_shift(&q);
3350 solver_addrule(solv, p2, q.count ? q.elements[0] : 0, 0);
3352 solver_addrule(solv, p2, 0, pool_queuetowhatprovides(pool, &q));
3353 queue_push(&r2pkg, p);
3357 solv->bestrules_pkg = solv_memdup2(r2pkg.elements, r2pkg.count, sizeof(Id));
3358 solv->bestrules_end = solv->nrules;
3367 /* yumobs rule handling */
3370 find_obsolete_group(Solver *solv, Id obs, Queue *q)
3372 Pool *pool = solv->pool;
3374 Id p2, pp2, op, *opp, opp2;
3375 int i, j, qnc, ncnt;
3378 FOR_PROVIDES(p2, pp2, obs)
3380 Solvable *s2 = pool->solvables + p2;
3381 if (s2->repo != pool->installed)
3383 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
3385 /* we obsolete installed package s2 with obs. now find all other packages that have the same dep */
3386 for (opp = solv->obsoletes_data + solv->obsoletes[p2 - solv->installed->start]; (op = *opp++) != 0;)
3388 Solvable *os = pool->solvables + op;
3392 if (pool->obsoleteusescolors && !pool_colormatch(pool, s2, os))
3394 obsp2 = os->repo->idarraydata + os->obsoletes;
3395 while ((obs2 = *obsp2++) != 0)
3399 queue_pushunique(q, op);
3401 /* also search packages with the same name */
3402 FOR_PROVIDES(op, opp2, s2->name)
3404 Solvable *os = pool->solvables + op;
3406 if (os->name != s2->name)
3410 if (pool->obsoleteusescolors && !pool_colormatch(pool, s2, os))
3412 obsp2 = os->repo->idarraydata + os->obsoletes;
3413 while ((obs2 = *obsp2++) != 0)
3417 queue_pushunique(q, op);
3420 /* find names so that we can build groups */
3421 queue_init_clone(&qn, q);
3422 prune_to_best_version(solv->pool, &qn);
3425 for (i = 0; i < qn.count; i++)
3426 printf(" + %s\n", pool_solvid2str(pool, qn.elements[i]));
3429 /* filter into name groups */
3438 for (i = 0; i < qnc; i++)
3440 Id n = pool->solvables[qn.elements[i]].name;
3442 for (j = 0; j < q->count; j++)
3444 Id p = q->elements[j];
3445 if (pool->solvables[p].name == n)
3464 queue_insertn(q, 0, qn.count - qnc, qn.elements + qnc);
3470 solver_addyumobsrules(Solver *solv)
3472 Pool *pool = solv->pool;
3473 Repo *installed = solv->installed;
3476 Queue qo, qq, yumobsinfoq;
3480 solv->yumobsrules = solv->nrules;
3481 if (!installed || !solv->obsoletes)
3483 solv->yumobsrules_end = solv->nrules;
3486 now = solv_timems(0);
3488 FOR_REPO_SOLVABLES(installed, p, s)
3490 if (!solv->obsoletes[p - installed->start])
3493 printf("checking yumobs for %s\n", pool_solvable2str(pool, s));
3496 for (opp = solv->obsoletes_data + solv->obsoletes[p - installed->start]; (op = *opp++) != 0;)
3498 Solvable *os = pool->solvables + op;
3499 Id obs, *obsp = os->repo->idarraydata + os->obsoletes;
3501 while ((obs = *obsp++) != 0)
3503 FOR_PROVIDES(p2, pp2, obs)
3505 Solvable *s2 = pool->solvables + p2;
3506 if (s2->repo != installed)
3508 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
3510 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
3512 queue_pushunique(&qo, obs);
3523 queue_init(&yumobsinfoq);
3525 for (i = 0; i < qo.count; i++)
3527 int group, groupk, groupstart;
3530 printf("investigating %s\n", pool_dep2str(pool, qo.elements[i]));
3532 find_obsolete_group(solv, qo.elements[i], &qq);
3534 printf("result:\n");
3535 for (j = 0; j < qq.count; j++)
3536 if (qq.elements[j] == 0)
3539 printf("%s\n", pool_solvid2str(pool, qq.elements[j]));
3544 /* at least two goups, build rules */
3546 for (j = 0; j < qq.count; j++)
3554 if (pool->solvables[p].repo == installed)
3558 for (k = 0; k < qq.count; k++)
3560 Id pk = qq.elements[k];
3563 if (group != groupk && k > groupstart)
3566 if (k - groupstart == 1)
3567 solver_addrule(solv, -p, qq.elements[groupstart], 0);
3569 solver_addrule(solv, -p, 0, pool_ids2whatprovides(pool, qq.elements + groupstart, k - groupstart));
3570 queue_push(&yumobsinfoq, qo.elements[i]);
3577 if (yumobsinfoq.count)
3578 solv->yumobsrules_info = solv_memdup2(yumobsinfoq.elements, yumobsinfoq.count, sizeof(Id));
3579 queue_free(&yumobsinfoq);
3582 solv->yumobsrules_end = solv->nrules;
3583 POOL_DEBUG(SOLV_DEBUG_STATS, "yumobs rule creation took %d ms\n", solv_timems(now));
3586 #undef CLEANDEPSDEBUG
3589 * This functions collects all packages that are looked at
3590 * when a dependency is checked. We need it to "pin" installed
3591 * packages when removing a supplemented package in createcleandepsmap.
3592 * Here's an not uncommon example:
3593 * A contains "Supplements: packageand(B, C)"
3594 * B contains "Requires: A"
3595 * Now if we remove C, the supplements is no longer true,
3596 * thus we also remove A. Without the dep_pkgcheck function, we
3597 * would now also remove B, but this is wrong, as adding back
3598 * C doesn't make the supplements true again. Thus we "pin" B
3600 * There's probably a better way to do this, but I haven't come
3604 dep_pkgcheck(Solver *solv, Id dep, Map *m, Queue *q)
3606 Pool *pool = solv->pool;
3611 Reldep *rd = GETRELDEP(pool, dep);
3614 if (rd->flags == REL_AND)
3616 dep_pkgcheck(solv, rd->name, m, q);
3617 dep_pkgcheck(solv, rd->evr, m, q);
3620 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
3624 FOR_PROVIDES(p, pp, dep)
3625 if (!m || MAPTST(m, p))
3630 check_xsupp(Solver *solv, Queue *depq, Id dep)
3632 Pool *pool = solv->pool;
3637 Reldep *rd = GETRELDEP(pool, dep);
3640 if (rd->flags == REL_AND)
3642 if (!check_xsupp(solv, depq, rd->name))
3644 return check_xsupp(solv, depq, rd->evr);
3646 if (rd->flags == REL_OR)
3648 if (check_xsupp(solv, depq, rd->name))
3650 return check_xsupp(solv, depq, rd->evr);
3652 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
3654 return solver_splitprovides(solv, rd->evr);
3659 if (depq && rd->flags == REL_NAMESPACE)
3662 for (i = 0; i < depq->count; i++)
3663 if (depq->elements[i] == dep || depq->elements[i] == rd->name)
3667 FOR_PROVIDES(p, pp, dep)
3668 if (p == SYSTEMSOLVABLE || pool->solvables[p].repo == solv->installed)
3674 queue_contains(Queue *q, Id id)
3677 for (i = 0; i < q->count; i++)
3678 if (q->elements[i] == id)
3683 #ifdef ENABLE_COMPLEX_DEPS
3685 complex_cleandeps_remove(Pool *pool, Id ip, Id req, Map *im, Map *installedm, Queue *iq)
3692 i = pool_normalize_complex_dep(pool, req, &dq, CPLXDEPS_EXPAND);
3693 if (i == 0 || i == 1)
3698 for (i = 0; i < dq.count; i++)
3700 for (; (p = dq.elements[i]) != 0; i++)
3704 if (!MAPTST(installedm, -p))
3708 if (p != SYSTEMSOLVABLE && MAPTST(im, p))
3710 #ifdef CLEANDEPSDEBUG
3711 printf("%s requires/recommends %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
3716 while (dq.elements[i])
3723 complex_cleandeps_addback(Pool *pool, Id ip, Id req, Map *im, Map *installedm, Queue *iq, Map *userinstalled)
3730 i = pool_normalize_complex_dep(pool, req, &dq, CPLXDEPS_EXPAND);
3731 if (i == 0 || i == 1)
3736 for (i = 0; i < dq.count; i++)
3739 for (; (p = dq.elements[i]) != 0; i++)
3743 if (!MAPTST(installedm, -p))
3752 for (i = blk; (p = dq.elements[i]) != 0; i++)
3756 if (!MAPTST(installedm, p))
3758 if (p == ip || MAPTST(userinstalled, p - pool->installed->start))
3760 #ifdef CLEANDEPSDEBUG
3761 printf("%s requires/recommends %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
3767 while (dq.elements[i])
3776 * Find all installed packages that are no longer
3777 * needed regarding the current solver job.
3780 * - remove pass: remove all packages that could have
3781 * been dragged in by the obsoleted packages.
3782 * i.e. if package A is obsolete and contains "Requires: B",
3783 * also remove B, as installing A will have pulled in B.
3784 * after this pass, we have a set of still installed packages
3785 * with broken dependencies.
3787 * now add back all packages that the still installed packages
3790 * The cleandeps packages are the packages removed in the first
3791 * pass and not added back in the second pass.
3793 * If we search for unneeded packages (unneeded is true), we
3794 * simply remove all packages except the userinstalled ones in
3798 solver_createcleandepsmap(Solver *solv, Map *cleandepsmap, int unneeded)
3800 Pool *pool = solv->pool;
3801 Repo *installed = solv->installed;
3802 Queue *job = &solv->job;
3807 Id rid, how, what, select;
3809 Id req, *reqp, sup, *supp;
3811 Queue iq, iqcopy, xsuppq;
3814 map_empty(cleandepsmap);
3815 if (!installed || installed->end == installed->start)
3817 map_init(&userinstalled, installed->end - installed->start);
3818 map_init(&im, pool->nsolvables);
3819 map_init(&installedm, pool->nsolvables);
3821 queue_init(&xsuppq);
3823 for (i = 0; i < job->count; i += 2)
3825 how = job->elements[i];
3826 if ((how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
3828 what = job->elements[i + 1];
3829 select = how & SOLVER_SELECTMASK;
3830 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
3831 FOR_REPO_SOLVABLES(installed, p, s)
3832 MAPSET(&userinstalled, p - installed->start);
3833 FOR_JOB_SELECT(p, pp, select, what)
3834 if (pool->solvables[p].repo == installed)
3835 MAPSET(&userinstalled, p - installed->start);
3837 if ((how & (SOLVER_JOBMASK | SOLVER_SELECTMASK)) == (SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES))
3839 what = job->elements[i + 1];
3842 Reldep *rd = GETRELDEP(pool, what);
3843 if (rd->flags != REL_NAMESPACE)
3847 queue_pushunique(&iq, rd->name);
3850 FOR_PROVIDES(p, pp, what)
3855 queue_pushunique(&iq, what);
3860 /* have special namespace cleandeps erases */
3863 for (ip = installed->start; ip < installed->end; ip++)
3865 s = pool->solvables + ip;
3866 if (s->repo != installed)
3868 if (!s->supplements)
3870 supp = s->repo->idarraydata + s->supplements;
3871 while ((sup = *supp++) != 0)
3872 if (ISRELDEP(sup) && check_xsupp(solv, &iq, sup) && !check_xsupp(solv, 0, sup))
3874 #ifdef CLEANDEPSDEBUG
3875 printf("xsupp %s from %s\n", pool_dep2str(pool, sup), pool_solvid2str(pool, ip));
3877 queue_pushunique(&xsuppq, sup);
3883 /* also add visible patterns to userinstalled for openSUSE */
3887 dataiterator_init(&di, pool, 0, 0, SOLVABLE_ISVISIBLE, 0, 0);
3888 while (dataiterator_step(&di))
3893 s = pool->solvables + di.solvid;
3894 if (!s->repo || !s->requires)
3896 if (s->repo != installed && !pool_installable(pool, s))
3898 if (strncmp(pool_id2str(pool, s->name), "pattern:", 8) != 0)
3900 dp = s->repo->idarraydata + s->requires;
3901 for (dp = s->repo->idarraydata + s->requires; *dp; dp++)
3902 FOR_PROVIDES(p, pp, *dp)
3903 if (pool->solvables[p].repo == installed)
3905 if (strncmp(pool_id2str(pool, pool->solvables[p].name), "pattern", 7) != 0)
3907 MAPSET(&userinstalled, p - installed->start);
3910 dataiterator_free(&di);
3914 /* all products and their buddies are userinstalled */
3915 for (p = installed->start; p < installed->end; p++)
3917 Solvable *s = pool->solvables + p;
3918 if (s->repo != installed)
3920 if (!strncmp("product:", pool_id2str(pool, s->name), 8))
3922 MAPSET(&userinstalled, p - installed->start);
3923 #ifdef ENABLE_LINKED_PKGS
3924 if (solv->instbuddy && solv->instbuddy[p - installed->start] > 1)
3926 Id buddy = solv->instbuddy[p - installed->start];
3927 if (buddy >= installed->start && buddy < installed->end)
3928 MAPSET(&userinstalled, buddy - installed->start);
3935 /* add all positive elements (e.g. locks) to "userinstalled" */
3936 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
3938 r = solv->rules + rid;
3941 i = solv->ruletojob.elements[rid - solv->jobrules];
3942 if ((job->elements[i] & SOLVER_CLEANDEPS) == SOLVER_CLEANDEPS)
3944 FOR_RULELITERALS(p, jp, r)
3945 if (p > 0 && pool->solvables[p].repo == installed)
3946 MAPSET(&userinstalled, p - installed->start);
3949 /* add all cleandeps candidates to iq */
3950 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
3952 r = solv->rules + rid;
3953 if (r->d < 0) /* disabled? */
3955 if (r->d == 0 && r->p < 0 && r->w2 == 0) /* negative assertion (erase job)? */
3958 if (pool->solvables[p].repo != installed)
3960 MAPCLR(&userinstalled, p - installed->start);
3963 i = solv->ruletojob.elements[rid - solv->jobrules];
3964 how = job->elements[i];
3965 if ((how & (SOLVER_JOBMASK|SOLVER_CLEANDEPS)) == (SOLVER_ERASE|SOLVER_CLEANDEPS))
3968 else if (r->p > 0) /* install job */
3972 i = solv->ruletojob.elements[rid - solv->jobrules];
3973 if ((job->elements[i] & SOLVER_CLEANDEPS) == SOLVER_CLEANDEPS)
3975 /* check if the literals all obsolete some installed package */
3979 /* just one installed literal */
3980 if (r->d == 0 && r->w2 == 0 && pool->solvables[r->p].repo == installed)
3982 /* multiversion is bad */
3983 if (solv->multiversion.size && !solv->keepexplicitobsoletes)
3985 FOR_RULELITERALS(p, jp, r)
3986 if (MAPTST(&solv->multiversion, p))
3994 FOR_RULELITERALS(p, jp, r)
3998 queue_truncate(&iq, iqstart); /* abort */
4001 if (pool->solvables[p].repo == installed)
4003 if (iq.count == iqstart)
4007 for (i = iqstart; i < iq.count; i++)
4008 if (iq.elements[i] == p)
4010 queue_truncate(&iq, iqstart);
4016 intersect_obsoletes(solv, p, &iq, iqstart, &om);
4017 if (iq.count == iqstart)
4025 queue_init_clone(&iqcopy, &iq);
4029 if (solv->cleandeps_updatepkgs)
4030 for (i = 0; i < solv->cleandeps_updatepkgs->count; i++)
4031 queue_push(&iq, solv->cleandeps_updatepkgs->elements[i]);
4035 queue_empty(&iq); /* just in case... */
4037 /* clear userinstalled bit for the packages we really want to delete/update */
4038 for (i = 0; i < iq.count; i++)
4041 if (pool->solvables[p].repo != installed)
4043 MAPCLR(&userinstalled, p - installed->start);
4046 for (p = installed->start; p < installed->end; p++)
4048 if (pool->solvables[p].repo != installed)
4050 MAPSET(&installedm, p);
4051 if (unneeded && !MAPTST(&userinstalled, p - installed->start))
4055 MAPSET(&installedm, SYSTEMSOLVABLE);
4056 MAPSET(&im, SYSTEMSOLVABLE);
4058 #ifdef CLEANDEPSDEBUG
4059 printf("REMOVE PASS\n");
4068 /* supplements pass */
4069 for (ip = installed->start; ip < installed->end; ip++)
4071 if (!MAPTST(&installedm, ip))
4073 s = pool->solvables + ip;
4074 if (!s->supplements)
4076 if (!MAPTST(&im, ip))
4078 if (MAPTST(&userinstalled, ip - installed->start))
4080 supp = s->repo->idarraydata + s->supplements;
4081 while ((sup = *supp++) != 0)
4082 if (dep_possible(solv, sup, &im))
4086 supp = s->repo->idarraydata + s->supplements;
4087 while ((sup = *supp++) != 0)
4088 if (dep_possible(solv, sup, &installedm) || (xsuppq.count && queue_contains(&xsuppq, sup)))
4090 /* no longer supplemented, also erase */
4091 int iqcount = iq.count;
4092 /* pin packages, see comment above dep_pkgcheck */
4093 dep_pkgcheck(solv, sup, &im, &iq);
4094 for (i = iqcount; i < iq.count; i++)
4096 Id pqp = iq.elements[i];
4097 if (pool->solvables[pqp].repo == installed)
4098 MAPSET(&userinstalled, pqp - installed->start);
4100 queue_truncate(&iq, iqcount);
4101 #ifdef CLEANDEPSDEBUG
4102 printf("%s supplemented [%s]\n", pool_solvid2str(pool, ip), pool_dep2str(pool, sup));
4104 queue_push(&iq, ip);
4109 break; /* no supplementing package found, we're done */
4111 ip = queue_shift(&iq);
4112 s = pool->solvables + ip;
4113 if (!MAPTST(&im, ip))
4115 if (!MAPTST(&installedm, ip))
4117 if (s->repo == installed && MAPTST(&userinstalled, ip - installed->start))
4120 #ifdef CLEANDEPSDEBUG
4121 printf("removing %s\n", pool_solvable2str(pool, s));
4125 reqp = s->repo->idarraydata + s->requires;
4126 while ((req = *reqp++) != 0)
4128 if (req == SOLVABLE_PREREQMARKER)
4130 #ifdef ENABLE_COMPLEX_DEPS
4131 if (pool_is_complex_dep(pool, req))
4133 complex_cleandeps_remove(pool, ip, req, &im, &installedm, &iq);
4137 FOR_PROVIDES(p, pp, req)
4139 if (p != SYSTEMSOLVABLE && MAPTST(&im, p))
4141 #ifdef CLEANDEPSDEBUG
4142 printf("%s requires %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
4151 reqp = s->repo->idarraydata + s->recommends;
4152 while ((req = *reqp++) != 0)
4154 #ifdef ENABLE_COMPLEX_DEPS
4155 if (pool_is_complex_dep(pool, req))
4157 complex_cleandeps_remove(pool, ip, req, &im, &installedm, &iq);
4161 FOR_PROVIDES(p, pp, req)
4163 if (p != SYSTEMSOLVABLE && MAPTST(&im, p))
4165 #ifdef CLEANDEPSDEBUG
4166 printf("%s recommends %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
4175 /* turn userinstalled into remove set for pruning */
4176 map_empty(&userinstalled);
4177 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
4179 r = solv->rules + rid;
4180 if (r->p >= 0 || r->d != 0 || r->w2 != 0)
4181 continue; /* disabled or not erase */
4184 if (pool->solvables[p].repo == installed)
4185 MAPSET(&userinstalled, p - installed->start);
4187 if (!unneeded && solv->cleandeps_updatepkgs)
4189 for (i = 0; i < solv->cleandeps_updatepkgs->count; i++)
4191 p = solv->cleandeps_updatepkgs->elements[i];
4192 if (pool->solvables[p].repo == installed)
4193 MAPSET(&userinstalled, p - installed->start);
4196 MAPSET(&im, SYSTEMSOLVABLE); /* in case we cleared it above */
4197 for (p = installed->start; p < installed->end; p++)
4200 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
4202 r = solv->rules + rid;
4205 FOR_RULELITERALS(p, jp, r)
4209 /* also put directly addressed packages on the install queue
4210 * so we can mark patterns as installed */
4211 for (i = 0; i < job->count; i += 2)
4213 how = job->elements[i];
4214 if ((how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
4216 what = job->elements[i + 1];
4217 select = how & SOLVER_SELECTMASK;
4218 if (select == SOLVER_SOLVABLE && pool->solvables[what].repo != installed)
4219 queue_push(&iq, what);
4223 #ifdef CLEANDEPSDEBUG
4224 printf("ADDBACK PASS\n");
4230 /* supplements pass */
4231 for (ip = installed->start; ip < installed->end; ip++)
4233 if (!MAPTST(&installedm, ip))
4235 if (MAPTST(&userinstalled, ip - installed->start))
4237 s = pool->solvables + ip;
4238 if (!s->supplements)
4240 if (MAPTST(&im, ip))
4242 supp = s->repo->idarraydata + s->supplements;
4243 while ((sup = *supp++) != 0)
4244 if (dep_possible(solv, sup, &im))
4248 #ifdef CLEANDEPSDEBUG
4249 printf("%s supplemented\n", pool_solvid2str(pool, ip));
4252 queue_push(&iq, ip);
4258 ip = queue_shift(&iq);
4259 s = pool->solvables + ip;
4260 #ifdef CLEANDEPSDEBUG
4261 printf("adding back %s\n", pool_solvable2str(pool, s));
4265 reqp = s->repo->idarraydata + s->requires;
4266 while ((req = *reqp++) != 0)
4268 #ifdef ENABLE_COMPLEX_DEPS
4269 if (pool_is_complex_dep(pool, req))
4271 complex_cleandeps_addback(pool, ip, req, &im, &installedm, &iq, &userinstalled);
4275 FOR_PROVIDES(p, pp, req)
4280 FOR_PROVIDES(p, pp, req)
4282 if (MAPTST(&installedm, p))
4286 if (MAPTST(&userinstalled, p - installed->start))
4288 #ifdef CLEANDEPSDEBUG
4289 printf("%s requires %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
4299 reqp = s->repo->idarraydata + s->recommends;
4300 while ((req = *reqp++) != 0)
4302 #ifdef ENABLE_COMPLEX_DEPS
4303 if (pool_is_complex_dep(pool, req))
4305 complex_cleandeps_addback(pool, ip, req, &im, &installedm, &iq, &userinstalled);
4309 FOR_PROVIDES(p, pp, req)
4314 FOR_PROVIDES(p, pp, req)
4316 if (MAPTST(&installedm, p))
4320 if (MAPTST(&userinstalled, p - installed->start))
4322 #ifdef CLEANDEPSDEBUG
4323 printf("%s recommends %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
4334 /* make sure the updatepkgs and mistakes are not in the cleandeps map */
4335 if (solv->cleandeps_updatepkgs)
4336 for (i = 0; i < solv->cleandeps_updatepkgs->count; i++)
4337 MAPSET(&im, solv->cleandeps_updatepkgs->elements[i]);
4338 if (solv->cleandeps_mistakes)
4339 for (i = 0; i < solv->cleandeps_mistakes->count; i++)
4340 MAPSET(&im, solv->cleandeps_mistakes->elements[i]);
4341 /* also remove original iq packages */
4342 for (i = 0; i < iqcopy.count; i++)
4343 MAPSET(&im, iqcopy.elements[i]);
4344 queue_free(&iqcopy);
4345 for (p = installed->start; p < installed->end; p++)
4347 if (pool->solvables[p].repo != installed)
4349 if (!MAPTST(&im, p))
4350 MAPSET(cleandepsmap, p - installed->start);
4353 map_free(&installedm);
4354 map_free(&userinstalled);
4355 queue_free(&xsuppq);
4356 #ifdef CLEANDEPSDEBUG
4357 printf("=== final cleandeps map:\n");
4358 for (p = installed->start; p < installed->end; p++)
4359 if (MAPTST(cleandepsmap, p - installed->start))
4360 printf(" - %s\n", pool_solvid2str(pool, p));
4373 /* Tarjan's SCC algorithm, slightly modifed */
4375 trj_visit(struct trj_data *trj, Id node)
4378 Queue *edges = trj->edges;
4379 Id nnode, myidx, stackstart;
4382 low[node] = myidx = trj->idx++;
4383 low[(stackstart = trj->nstack++)] = node;
4384 for (i = edges->elements[node]; (nnode = edges->elements[i]) != 0; i++)
4389 if (!edges->elements[edges->elements[nnode]])
4395 trj_visit(trj, nnode);
4400 if (l < trj->firstidx)
4403 for (k = l; low[low[k]] == l; k++)
4406 else if (l < low[node])
4409 if (low[node] == myidx)
4411 if (myidx != trj->firstidx)
4413 for (i = stackstart; i < trj->nstack; i++)
4414 low[low[i]] = myidx;
4415 trj->nstack = stackstart;
4419 #ifdef ENABLE_COMPLEX_DEPS
4421 complex_unneeded(Pool *pool, Id ip, Id req, Queue *edges, Map *cleandepsmap, Queue *unneededq)
4428 i = pool_normalize_complex_dep(pool, req, &dq, CPLXDEPS_EXPAND);
4429 if (i == 0 || i == 1)
4434 for (i = 0; i < dq.count; i++)
4436 for (; (p = dq.elements[i]) != 0; i++)
4440 if (pool->solvables[-p].repo != pool->installed)
4444 if (p == ip || pool->solvables[p].repo != pool->installed || !MAPTST(cleandepsmap, p - pool->installed->start))
4446 for (j = 0; j < unneededq->count; j++)
4447 if (p == unneededq->elements[j])
4449 if (edges->elements[edges->count - 1] != j + 1)
4450 queue_push(edges, j + 1);
4454 while (dq.elements[i])
4462 solver_get_unneeded(Solver *solv, Queue *unneededq, int filtered)
4464 Repo *installed = solv->installed;
4468 queue_empty(unneededq);
4469 if (!installed || installed->end == installed->start)
4472 map_init(&cleandepsmap, installed->end - installed->start);
4473 solver_createcleandepsmap(solv, &cleandepsmap, 1);
4474 for (i = installed->start; i < installed->end; i++)
4475 if (MAPTST(&cleandepsmap, i - installed->start))
4476 queue_push(unneededq, i);
4478 if (filtered && unneededq->count > 1)
4480 Pool *pool = solv->pool;
4484 int j, pass, count = unneededq->count;
4487 map_init(&installedm, pool->nsolvables);
4488 for (i = installed->start; i < installed->end; i++)
4489 if (pool->solvables[i].repo == installed)
4490 MAPSET(&installedm, i);
4492 nrequires = solv_calloc(count, sizeof(Id));
4494 queue_prealloc(&edges, count * 4 + 10); /* pre-size */
4497 * Go through the solvables in the nodes queue and create edges for
4498 * all requires/recommends/supplements between the nodes.
4499 * The edges are stored in the edges queue, we add 1 to the node
4500 * index so that nodes in the edges queue are != 0 and we can
4501 * terminate the edge list with 0.
4502 * Thus for node element 5, the edges are stored starting at
4503 * edges.elements[6] and are 0-terminated.
4505 /* leave first element zero to make things easier */
4506 /* also add trailing zero */
4507 queue_insertn(&edges, 0, 1 + count + 1, 0);
4509 /* first requires and recommends */
4510 for (i = 0; i < count; i++)
4512 Solvable *s = pool->solvables + unneededq->elements[i];
4513 int oldcount = edges.count;
4514 edges.elements[i + 1] = oldcount;
4515 for (pass = 0; pass < 2; pass++)
4517 unsigned int off = pass == 0 ? s->requires : s->recommends;
4520 for (dp = s->repo->idarraydata + off; (dep = *dp) != 0; dp++)
4522 #ifdef ENABLE_COMPLEX_DEPS
4523 if (pool_is_complex_dep(pool, dep))
4525 complex_unneeded(pool, s - pool->solvables, dep, &edges, &cleandepsmap, unneededq);
4529 FOR_PROVIDES(p, pp, dep)
4531 Solvable *sp = pool->solvables + p;
4532 if (s == sp || sp->repo != installed || !MAPTST(&cleandepsmap, p - installed->start))
4534 for (j = 0; j < count; j++)
4535 if (p == unneededq->elements[j])
4537 if (edges.elements[edges.count - 1] != j + 1)
4538 queue_push(&edges, j + 1);
4543 nrequires[i] = edges.count - oldcount;
4545 queue_push(&edges, 0);
4548 printf("requires + recommends\n");
4549 for (i = 0; i < count; i++)
4552 printf(" %s (%d requires):\n", pool_solvid2str(pool, unneededq->elements[i]), nrequires[i]);
4553 for (j = edges.elements[i + 1]; edges.elements[j]; j++)
4554 printf(" - %s\n", pool_solvid2str(pool, unneededq->elements[edges.elements[j] - 1]));
4558 /* then add supplements */
4559 for (i = 0; i < count; i++)
4561 Solvable *s = pool->solvables + unneededq->elements[i];
4566 for (dp = s->repo->idarraydata + s->supplements; *dp; dp++)
4567 if (dep_possible(solv, *dp, &installedm))
4571 queue_init_buffer(&iq, iqbuf, sizeof(iqbuf)/sizeof(*iqbuf));
4572 dep_pkgcheck(solv, *dp, 0, &iq);
4573 for (k = 0; k < iq.count; k++)
4575 Id p = iq.elements[k];
4576 Solvable *sp = pool->solvables + p;
4577 if (p == unneededq->elements[i] || sp->repo != installed || !MAPTST(&cleandepsmap, p - installed->start))
4579 for (j = 0; j < count; j++)
4580 if (p == unneededq->elements[j])
4582 /* now add edge from j + 1 to i + 1 */
4583 queue_insert(&edges, edges.elements[j + 1] + nrequires[j], i + 1);
4584 /* addapt following edge pointers */
4585 for (j = j + 2; j < count + 1; j++)
4586 edges.elements[j]++;
4594 printf("+ supplements\n");
4595 for (i = 0; i < count; i++)
4598 printf(" %s (%d requires):\n", pool_solvid2str(pool, unneededq->elements[i]), nrequires[i]);
4599 for (j = edges.elements[i + 1]; edges.elements[j]; j++)
4600 printf(" - %s\n", pool_solvid2str(pool, unneededq->elements[edges.elements[j] - 1]));
4603 map_free(&installedm);
4605 /* now run SCC algo two times, first with requires+recommends+supplements,
4606 * then again without the requires. We run it the second time to get rid
4607 * of packages that got dragged in via recommends/supplements */
4609 * low will contain the result of the SCC search.
4610 * it must be of at least size 2 * (count + 1) and
4611 * must be zero initialized.
4613 * 0 low low ... low stack stack ...stack 0
4616 low = solv_calloc(count + 1, 2 * sizeof(Id));
4617 for (pass = 0; pass < 2; pass++)
4619 struct trj_data trj;
4622 memset(low, 0, (count + 1) * (2 * sizeof(Id)));
4623 for (i = 0; i < count; i++)
4625 edges.elements[i + 1] += nrequires[i];
4626 if (!unneededq->elements[i])
4627 low[i + 1] = -1; /* ignore this node */
4632 trj.idx = count + 1; /* stack starts here */
4633 for (i = 1; i <= count; i++)
4637 if (edges.elements[edges.elements[i]])
4639 trj.firstidx = trj.nstack = trj.idx;
4644 Id myidx = trj.idx++;
4649 /* prune packages */
4650 for (i = 0; i < count; i++)
4651 if (low[i + 1] <= 0)
4652 unneededq->elements[i] = 0;
4655 solv_free(nrequires);
4658 /* finally remove all pruned entries from unneededq */
4659 for (i = j = 0; i < count; i++)
4660 if (unneededq->elements[i])
4661 unneededq->elements[j++] = unneededq->elements[i];
4662 queue_truncate(unneededq, j);
4664 map_free(&cleandepsmap);
4669 solver_breakorphans(Solver *solv)
4671 Pool *pool = solv->pool;
4672 Repo *installed = solv->installed;
4676 if (!installed || solv->droporphanedmap_all)
4678 solv->brokenorphanrules = solv_calloc(1, sizeof(Queue));
4679 queue_init(solv->brokenorphanrules);
4680 map_init(&m, installed->end - installed->start);
4681 for (i = 0; i < solv->orphaned.count; i++)
4683 Id p = solv->orphaned.elements[i];
4684 if (pool->solvables[p].repo != installed)
4686 if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - installed->start))
4688 MAPSET(&m, p - installed->start);
4690 for (rid = 1; rid < solv->pkgrules_end ; rid++)
4693 Rule *r = solv->rules + rid;
4694 /* ignore non-deps and simple conflicts */
4695 if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 < 0))
4698 if (p < installed->start || p >= installed->end || !MAPTST(&m, p - installed->start))
4700 /* need to check other literals */
4701 if (r->d == 0 || r->d == -1)
4703 for (dp = pool->whatprovidesdata + (r->d < 0 ? -r->d - 1 : r->d); *dp < 0; dp++)
4706 if (p >= installed->start && p < installed->end && MAPTST(&m, p - installed->start))
4712 /* ok, disable this rule */
4713 queue_push(solv->brokenorphanrules, rid);
4715 solver_disablerule(solv, r);
4718 if (!solv->brokenorphanrules->count)
4720 queue_free(solv->brokenorphanrules);
4721 solv->brokenorphanrules = solv_free(solv->brokenorphanrules);
4726 solver_check_brokenorphanrules(Solver *solv, Queue *dq)
4728 Pool *pool = solv->pool;
4733 if (!solv->brokenorphanrules)
4735 for (i = 0; i < solv->brokenorphanrules->count; i++)
4737 int rid = solv->brokenorphanrules->elements[i];
4738 Rule *r = solv->rules + rid;
4739 FOR_RULELITERALS(l, pp, r)
4743 if (solv->decisionmap[-l] <= 0)
4748 if (solv->decisionmap[l] > 0 && pool->solvables[l].repo != solv->installed)
4754 FOR_RULELITERALS(l, pp, r)
4755 if (l > 0 && solv->decisionmap[l] == 0 && pool->solvables[l].repo != solv->installed)
4756 queue_pushunique(dq, l);