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"
30 #define RULES_BLOCK 63
32 static void addrpmruleinfo(Solver *solv, Id p, Id d, int type, Id dep);
33 static void solver_createcleandepsmap(Solver *solv, Map *cleandepsmap, int unneeded);
35 /*-------------------------------------------------------------------
36 * Check if dependency is possible
38 * mirrors solver_dep_fulfilled but uses map m instead of the decisionmap.
39 * used in solver_addrpmrulesforweak and solver_createcleandepsmap.
43 dep_possible(Solver *solv, Id dep, Map *m)
45 Pool *pool = solv->pool;
50 Reldep *rd = GETRELDEP(pool, dep);
53 if (rd->flags == REL_AND)
55 if (!dep_possible(solv, rd->name, m))
57 return dep_possible(solv, rd->evr, m);
59 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
60 return solver_splitprovides(solv, rd->evr);
61 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
62 return solver_dep_installed(solv, rd->evr);
65 FOR_PROVIDES(p, pp, dep)
73 /********************************************************************
77 * - unify rules, remove duplicates
80 /*-------------------------------------------------------------------
82 * compare rules for unification sort
87 unifyrules_sortcmp(const void *ap, const void *bp, void *dp)
97 return x; /* p differs */
100 if (a->d == 0 && b->d == 0)
101 return a->w2 - b->w2; /* assertion: return w2 diff */
103 if (a->d == 0) /* a is assertion, b not */
105 x = a->w2 - pool->whatprovidesdata[b->d];
109 if (b->d == 0) /* b is assertion, a not */
111 x = pool->whatprovidesdata[a->d] - b->w2;
115 /* compare whatprovidesdata */
116 ad = pool->whatprovidesdata + a->d;
117 bd = pool->whatprovidesdata + b->d;
119 if ((x = *ad++ - *bd++) != 0)
125 solver_rulecmp(Solver *solv, Rule *r1, Rule *r2)
127 return unifyrules_sortcmp(r1, r2, solv->pool);
131 /*-------------------------------------------------------------------
134 * go over all rules and remove duplicates
138 solver_unifyrules(Solver *solv)
140 Pool *pool = solv->pool;
144 if (solv->nrules <= 2) /* nothing to unify */
147 /* sort rules first */
148 solv_sort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp, solv->pool);
155 for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
157 if (jr && !unifyrules_sortcmp(ir, jr, pool))
158 continue; /* prune! */
159 jr = solv->rules + j++; /* keep! */
164 /* reduced count from nrules to j rules */
165 POOL_DEBUG(SOLV_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
167 /* adapt rule buffer */
169 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
172 * debug: log rule statistics
174 IF_POOLDEBUG (SOLV_DEBUG_STATS)
181 for (i = 1; i < solv->nrules; i++)
188 dp = solv->pool->whatprovidesdata + r->d;
193 POOL_DEBUG(SOLV_DEBUG_STATS, " binary: %d\n", binr);
194 POOL_DEBUG(SOLV_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
205 hashrule(Solver *solv, Id p, Id d, int n)
207 unsigned int x = (unsigned int)p;
211 return (x * 37) ^ (unsigned int)d;
212 dp = solv->pool->whatprovidesdata + d;
214 x = (x * 37) ^ (unsigned int)*dp++;
220 /*-------------------------------------------------------------------
226 * p = direct literal; always < 0 for installed rpm rules
227 * d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
230 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
232 * p < 0 : pkg id of A
233 * d > 0 : Offset in whatprovidesdata (list of providers of b)
235 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
236 * p < 0 : pkg id of A
237 * d < 0 : Id of solvable (e.g. B1)
239 * d == 0: unary rule, assertion => (A) or (-A)
241 * Install: p > 0, d = 0 (A) user requested install
242 * Remove: p < 0, d = 0 (-A) user requested remove (also: uninstallable)
243 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
244 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
245 * Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
246 * also used for obsoletes
247 * ?: p > 0, d < 0 (A|-B)
248 * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
252 * Direct assertion (no watch needed) --> d = 0, w1 = p, w2 = 0
253 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
254 * every other : w1 = p, w2 = whatprovidesdata[d];
255 * Disabled rule: w1 = 0
257 * always returns a rule for non-rpm rules
261 solver_addrule(Solver *solv, Id p, Id d)
263 Pool *pool = solv->pool;
267 int n = 0; /* number of literals in rule - 1
268 0 = direct assertion (single literal)
273 /* it often happenes that requires lead to adding the same rpm rule
274 * multiple times, so we prune those duplicates right away to make
275 * the work for unifyrules a bit easier */
277 if (!solv->rpmrules_end) /* we add rpm rules */
279 r = solv->rules + solv->nrules - 1; /* get the last added rule */
280 if (r->p == p && r->d == d && (d != 0 || !r->w2))
285 * compute number of literals (n) in rule
290 /* always a binary rule */
292 return 0; /* ignore self conflict */
297 for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
299 return 0; /* rule is self-fulfilling */
301 if (n == 1) /* convert to binary rule */
305 if (n == 1 && p > d && !solv->rpmrules_end)
307 /* smallest literal first so we can find dups */
308 n = p; p = d; d = n; /* p <-> d */
309 n = 1; /* re-set n, was used as temp var */
313 * check for duplicate
316 /* check if the last added rule (r) is exactly the same as what we're looking for. */
317 if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
318 return r; /* binary rule */
320 /* have n-ary rule with same first literal, check other literals */
321 if (r && n > 1 && r->d && r->p == p)
323 /* Rule where d is an offset in whatprovidesdata */
327 dp2 = pool->whatprovidesdata + r->d;
328 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
339 /* extend rule buffer */
340 solv->rules = solv_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
341 r = solv->rules + solv->nrules++; /* point to rule space */
350 /* direct assertion, no watch needed */
366 r->w2 = pool->whatprovidesdata[d];
371 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
373 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, " Add rule: ");
374 solver_printrule(solv, SOLV_DEBUG_RULE_CREATION, r);
381 solver_shrinkrules(Solver *solv, int nrules)
383 solv->nrules = nrules;
384 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
387 /******************************************************************************
389 *** rpm rule part: create rules representing the package dependencies
394 * special multiversion patch conflict handling:
395 * a patch conflict is also satisfied if some other
396 * version with the same name/arch that doesn't conflict
397 * gets installed. The generated rule is thus:
398 * -patch|-cpack|opack1|opack2|...
401 makemultiversionconflict(Solver *solv, Id n, Id con)
403 Pool *pool = solv->pool;
408 sn = pool->solvables + n;
409 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
411 FOR_PROVIDES(p, pp, sn->name)
413 s = pool->solvables + p;
414 if (s->name != sn->name || s->arch != sn->arch)
416 if (!MAPTST(&solv->multiversion, p))
418 if (pool_match_nevr(pool, pool->solvables + p, con))
420 /* here we have a multiversion solvable that doesn't conflict */
421 /* thus we're not in conflict if it is installed */
425 return -n; /* no other package found, generate normal conflict */
426 return pool_queuetowhatprovides(pool, &q);
430 addrpmrule(Solver *solv, Id p, Id d, int type, Id dep)
432 if (!solv->ruleinfoq)
433 solver_addrule(solv, p, d);
435 addrpmruleinfo(solv, p, d, type, dep);
439 addlinks(Solver *solv, Solvable *s, Id req, Queue *qr, Id prv, Queue *qp, Map *m, Queue *workq)
441 Pool *pool = solv->pool;
446 if (m && !MAPTST(m, s - pool->solvables))
448 /* called from solver_addrpmrulesforlinked */
449 for (i = 0; i < qr->count; i++)
450 if (MAPTST(m, qr->elements[i]))
454 queue_push(workq, s - pool->solvables);
458 printf("ADDLINKS %s\n -> %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, req));
459 for (i = 0; i < qr->count; i++)
460 printf(" - %s\n", pool_solvid2str(pool, qr->elements[i]));
461 printf(" <- %s\n", pool_dep2str(pool, prv));
462 for (i = 0; i < qp->count; i++)
463 printf(" - %s\n", pool_solvid2str(pool, qp->elements[i]));
467 addrpmrule(solv, qr->elements[0], -(s - pool->solvables), SOLVER_RULE_RPM_PACKAGE_REQUIRES, req);
469 addrpmrule(solv, -(s - pool->solvables), pool_queuetowhatprovides(pool, qr), SOLVER_RULE_RPM_PACKAGE_REQUIRES, req);
472 Id d = pool_queuetowhatprovides(pool, qp);
473 for (i = 0; i < qr->count; i++)
474 addrpmrule(solv, -qr->elements[i], d, SOLVER_RULE_RPM_PACKAGE_REQUIRES, prv);
478 for (i = 0; i < qr->count; i++)
479 addrpmrule(solv, qp->elements[0], -qr->elements[i], SOLVER_RULE_RPM_PACKAGE_REQUIRES, prv);
483 for (i = 0; i < qr->count; i++)
484 if (m && !MAPTST(m, qr->elements[i]))
485 queue_push(workq, qr->elements[i]);
486 for (i = 0; i < qp->count; i++)
487 if (m && !MAPTST(m, qp->elements[i]))
488 queue_push(workq, qp->elements[i]);
489 if (solv->installed && s->repo == solv->installed)
491 Repo *installed = solv->installed;
492 /* record installed buddies */
493 if (!solv->instbuddy)
494 solv->instbuddy = solv_calloc(installed->end - installed->start, sizeof(Id));
496 solv->instbuddy[s - pool->solvables - installed->start] = qr->elements[0];
497 for (i = 0; i < qp->count; i++)
499 Id p = qp->elements[i];
500 if (pool->solvables[p].repo != installed)
502 if (qp->count > 1 || (solv->instbuddy[p - installed->start] != 0 && solv->instbuddy[p - installed->start] != s - pool->solvables))
503 solv->instbuddy[p - installed->start] = 1; /* 1: ambiguous buddy */
505 solv->instbuddy[p - installed->start] = s - pool->solvables;
511 add_application_link(Solver *solv, Solvable *s, Map *m, Queue *workq)
513 Pool *pool = solv->pool;
519 /* find appdata requires */
522 Id *reqp = s->repo->idarraydata + s->requires;
523 while ((req = *reqp++) != 0) /* go through all requires */
527 if (!strncmp("appdata(", pool_id2str(pool, req), 8))
533 /* find application-appdata provides */
536 Id *prvp = s->repo->idarraydata + s->provides;
537 while ((prv = *prvp++) != 0) /* go through all provides */
541 if (strncmp("application-appdata(", pool_id2str(pool, prv), 20))
543 if (!strcmp(pool_id2str(pool, prv) + 12, pool_id2str(pool, req)))
552 FOR_PROVIDES(p, pp, req)
553 if (pool->solvables[p].repo == s->repo)
555 FOR_PROVIDES(p, pp, prv)
556 if (pool->solvables[p].repo == s->repo)
558 addlinks(solv, s, req, &qr, prv, &qp, m, workq);
564 add_product_link(Solver *solv, Solvable *s, Map *m, Queue *workq)
566 Pool *pool = solv->pool;
567 Id n = s - pool->solvables;
572 if (pool->nscallback)
574 Id buddy = pool->nscallback(pool, pool->nscallbackdata, NAMESPACE_PRODUCTBUDDY, n);
575 if (buddy > 0 && buddy != SYSTEMSOLVABLE && buddy != n && buddy < pool->nsolvables)
579 queue_push(&qr, buddy);
581 addlinks(solv, s, solvable_selfprovidedep(pool->solvables + buddy), &qr, solvable_selfprovidedep(s), &qp, m, workq);
584 if (m && !MAPTST(m, buddy))
585 queue_push(workq, buddy);
589 /* search for project requires */
593 Id req, *reqp = s->repo->idarraydata + s->requires;
594 const char *nn = pool_id2str(pool, s->name);
595 int nnl = strlen(nn);
596 while ((req = *reqp++) != 0) /* go through all requires */
600 Reldep *rd = GETRELDEP(pool, req);
601 if (rd->flags != REL_EQ || rd->evr != s->evr)
603 rn = pool_id2str(pool, rd->name);
604 if (!strncmp(rn, "product(", 8) && !strncmp(rn + 8, nn + 8, nnl - 8) && !strcmp( rn + nnl, ")"))
613 /* too bad. construct from scratch */
614 str = pool_tmpjoin(pool, pool_id2str(pool, s->name), ")", 0);
616 namerelid = pool_rel2id(pool, pool_str2id(pool, str, 1), s->evr, REL_EQ, 1);
620 FOR_PROVIDES(p, pp, namerelid)
622 Solvable *ps = pool->solvables + p;
623 if (ps->repo != s->repo || ps->arch != s->arch)
627 if (!qr.count && s->repo == solv->installed)
629 /* oh no! Look up reference file */
631 const char *refbasename = solvable_lookup_str(s, PRODUCT_REFERENCEFILE);
632 dataiterator_init(&di, pool, s->repo, 0, SOLVABLE_FILELIST, refbasename, SEARCH_STRING);
633 while (dataiterator_step(&di))
634 queue_push(&qr, di.solvid);
635 dataiterator_free(&di);
636 dataiterator_init(&di, pool, s->repo, 0, PRODUCT_REFERENCEFILE, refbasename, SEARCH_STRING);
637 while (dataiterator_step(&di))
638 queue_push(&qp, di.solvid);
639 dataiterator_free(&di);
644 FOR_PROVIDES(p, pp, s->name)
646 Solvable *ps = pool->solvables + p;
647 if (s->name != ps->name || ps->repo != s->repo || ps->arch != s->arch || s->evr != ps->evr)
652 addlinks(solv, s, namerelid, &qr, solvable_selfprovidedep(s), &qp, m, workq);
658 add_autopattern_link(Solver *solv, Solvable *s, Map *m, Queue *workq)
660 Pool *pool = solv->pool;
661 Id p, pp, *pr, apevr = 0, aprel = 0;
664 /* check if autopattern */
667 for (pr = s->repo->idarraydata + s->provides; (p = *pr++) != 0; )
670 Reldep *rd = GETRELDEP(pool, p);
671 if (rd->flags == REL_EQ && !strcmp(pool_id2str(pool, rd->name), "autopattern()"))
682 FOR_PROVIDES(p, pp, apevr)
684 Solvable *s2 = pool->solvables + p;
685 if (s2->repo == s->repo && s2->name == apevr && s2->evr == s->evr && s2->vendor == s->vendor)
688 FOR_PROVIDES(p, pp, aprel)
690 Solvable *s2 = pool->solvables + p;
691 if (s2->repo == s->repo && s2->evr == s->evr && s2->vendor == s->vendor)
694 addlinks(solv, s, apevr, &qr, aprel, &qp, m, workq);
700 add_package_link(Solver *solv, Solvable *s, Map *m, Queue *workq)
702 const char *name = pool_id2str(solv->pool, s->name);
703 if (name[0] == 'a' && !strncmp("application:", name, 12))
704 add_application_link(solv, s, m, workq);
705 if (name[0] == 'p' && !strncmp("pattern:", name, 7))
706 add_autopattern_link(solv, s, m, workq);
707 if (name[0] == 'p' && !strncmp("product:", name, 8))
708 add_product_link(solv, s, m, workq);
711 /*-------------------------------------------------------------------
713 * add (install) rules for solvable
715 * s: Solvable for which to add rules
716 * m: m[s] = 1 for solvables which have rules, prevent rule duplication
718 * Algorithm: 'visit all nodes of a graph'. The graph nodes are
719 * solvables, the edges their dependencies.
720 * Starting from an installed solvable, this will create all rules
721 * representing the graph created by the solvables dependencies.
723 * for unfulfilled requirements, conflicts, obsoletes,....
724 * add a negative assertion for solvables that are not installable
726 * It will also create rules for all solvables referenced by 's'
727 * i.e. descend to all providers of requirements of 's'
732 solver_addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
734 Pool *pool = solv->pool;
735 Repo *installed = solv->installed;
737 /* 'work' queue. keeps Ids of solvables we still have to work on.
738 And buffer for it. */
743 /* if to add rules for broken deps ('rpm -V' functionality)
747 /* Id var and pointer for each dependency
748 * (not used in parallel)
755 Id p, pp; /* whatprovides loops */
756 Id *dp; /* ptr to 'whatprovides' */
757 Id n; /* Id for current solvable 's' */
759 queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
760 queue_push(&workq, s - pool->solvables); /* push solvable Id to work queue */
762 /* loop until there's no more work left */
767 * s: Pointer to solvable
770 n = queue_shift(&workq); /* 'pop' next solvable to work on from queue */
773 if (MAPTST(m, n)) /* continue if already visited */
775 MAPSET(m, n); /* mark as visited */
778 s = pool->solvables + n; /* s = Solvable in question */
781 if (installed /* Installed system available */
782 && s->repo == installed /* solvable is installed */
783 && !solv->fixmap_all /* NOT repair errors in rpm dependency graph */
784 && !(solv->fixmap.size && MAPTST(&solv->fixmap, n - installed->start)))
786 dontfix = 1; /* dont care about broken rpm deps */
791 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC
792 ? pool_disabled_solvable(pool, s)
793 : !pool_installable(pool, s))
795 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", pool_solvable2str(pool, s), (Id)(s - pool->solvables));
796 addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOT_INSTALLABLE, 0);
800 /* add pseudo-package <-> real-package links */
801 add_package_link(solv, s, m, &workq);
803 /*-----------------------------------------
804 * check requires of s
809 reqp = s->repo->idarraydata + s->requires;
810 while ((req = *reqp++) != 0) /* go through all requires */
812 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
815 /* find list of solvables providing 'req' */
816 dp = pool_whatprovides_ptr(pool, req);
818 if (*dp == SYSTEMSOLVABLE) /* always installed */
823 /* the strategy here is to not insist on dependencies
824 * that are already broken. so if we find one provider
825 * that was already installed, we know that the
826 * dependency was not broken before so we enforce it */
828 /* check if any of the providers for 'req' is installed */
829 for (i = 0; (p = dp[i]) != 0; i++)
831 if (pool->solvables[p].repo == installed)
832 break; /* provider was installed */
834 /* didn't find an installed provider: previously broken dependency */
837 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", pool_dep2str(pool, req), pool_solvable2str(pool, s));
844 /* nothing provides req! */
845 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", pool_solvable2str(pool, s), (Id)(s - pool->solvables), pool_dep2str(pool, req));
846 addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP, req);
850 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
852 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION," %s requires %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, req));
853 for (i = 0; dp[i]; i++)
854 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, " provided by %s\n", pool_solvid2str(pool, dp[i]));
857 /* add 'requires' dependency */
858 /* rule: (-requestor|provider1|provider2|...|providerN) */
859 addrpmrule(solv, -n, dp - pool->whatprovidesdata, SOLVER_RULE_RPM_PACKAGE_REQUIRES, req);
861 /* descend the dependency tree
862 push all non-visited providers on the work queue */
868 queue_push(&workq, *dp);
872 } /* while, requirements of n */
874 } /* if, requirements */
876 /* that's all we check for src packages */
877 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
880 /*-----------------------------------------
881 * check conflicts of s
888 /* we treat conflicts in patches a bit differen:
890 * - multiversion handling
891 * XXX: we should really handle this different, looking
892 * at the name is a bad hack
894 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
896 conp = s->repo->idarraydata + s->conflicts;
897 /* foreach conflicts of 's' */
898 while ((con = *conp++) != 0)
900 /* foreach providers of a conflict of 's' */
901 FOR_PROVIDES(p, pp, con)
903 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, con))
905 /* dontfix: dont care about conflicts with already installed packs */
906 if (dontfix && pool->solvables[p].repo == installed)
908 /* p == n: self conflict */
909 if (p == n && pool->forbidselfconflicts)
913 Reldep *rd = GETRELDEP(pool, con);
914 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
917 p = 0; /* make it a negative assertion, aka 'uninstallable' */
919 if (p && ispatch && solv->multiversion.size && MAPTST(&solv->multiversion, p) && ISRELDEP(con))
921 /* our patch conflicts with a multiversion package */
922 p = -makemultiversionconflict(solv, p, con);
924 /* rule: -n|-p: either solvable _or_ provider of conflict */
925 addrpmrule(solv, -n, -p, p ? SOLVER_RULE_RPM_PACKAGE_CONFLICT : SOLVER_RULE_RPM_SELF_CONFLICT, con);
930 /*-----------------------------------------
931 * check obsoletes and implicit obsoletes of a package
932 * if ignoreinstalledsobsoletes is not set, we're also checking
933 * obsoletes of installed packages (like newer rpm versions)
935 if ((!installed || s->repo != installed) || !pool->noinstalledobsoletes)
937 int multi = solv->multiversion.size && MAPTST(&solv->multiversion, n);
938 int isinstalled = (installed && s->repo == installed);
939 if (s->obsoletes && (!multi || solv->keepexplicitobsoletes))
941 obsp = s->repo->idarraydata + s->obsoletes;
942 /* foreach obsoletes */
943 while ((obs = *obsp++) != 0)
945 /* foreach provider of an obsoletes of 's' */
946 FOR_PROVIDES(p, pp, obs)
948 Solvable *ps = pool->solvables + p;
951 if (isinstalled && dontfix && ps->repo == installed)
952 continue; /* don't repair installed/installed problems */
953 if (!pool->obsoleteusesprovides /* obsoletes are matched names, not provides */
954 && !pool_match_nevr(pool, ps, obs))
956 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
959 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_PACKAGE_OBSOLETES, obs);
961 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES, obs);
965 /* check implicit obsoletes
966 * for installed packages we only need to check installed/installed problems (and
967 * only when dontfix is not set), as the others are picked up when looking at the
968 * uninstalled package.
970 if (!isinstalled || !dontfix)
972 FOR_PROVIDES(p, pp, s->name)
974 Solvable *ps = pool->solvables + p;
977 if (isinstalled && ps->repo != installed)
979 /* we still obsolete packages with same nevra, like rpm does */
980 /* (actually, rpm mixes those packages. yuck...) */
981 if (multi && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
983 if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
985 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, ps))
987 if (s->name == ps->name)
988 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_SAME_NAME, 0);
990 addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_IMPLICIT_OBSOLETES, s->name);
995 /*-----------------------------------------
996 * add recommends to the work queue
998 if (s->recommends && m)
1000 recp = s->repo->idarraydata + s->recommends;
1001 while ((rec = *recp++) != 0)
1003 FOR_PROVIDES(p, pp, rec)
1005 queue_push(&workq, p);
1008 if (s->suggests && m)
1010 sugp = s->repo->idarraydata + s->suggests;
1011 while ((sug = *sugp++) != 0)
1013 FOR_PROVIDES(p, pp, sug)
1015 queue_push(&workq, p);
1023 solver_addrpmrulesforlinked(Solver *solv, Map *m)
1025 Pool *pool = solv->pool;
1032 for (i = 1; i < pool->nsolvables; i++)
1036 s = pool->solvables + i;
1037 if (!s->repo || s->repo == solv->installed)
1039 name = pool_id2str(pool, s->name);
1040 if (!strchr(name, ':'))
1042 if (!pool_installable(pool, s))
1044 add_package_link(solv, s, m, &workq);
1048 for (j = 0; j < workq.count; j++)
1049 solver_addrpmrulesforsolvable(solv, pool->solvables + workq.elements[j], m);
1050 queue_empty(&workq);
1056 /*-------------------------------------------------------------------
1058 * Add rules for packages possibly selected in by weak dependencies
1060 * m: already added solvables
1064 solver_addrpmrulesforweak(Solver *solv, Map *m)
1066 Pool *pool = solv->pool;
1071 /* foreach solvable in pool */
1072 for (i = n = 1; n < pool->nsolvables; i++, n++)
1074 if (i == pool->nsolvables) /* wrap i */
1076 if (MAPTST(m, i)) /* already added that one */
1079 s = pool->solvables + i;
1082 if (s->repo != pool->installed && !pool_installable(pool, s))
1083 continue; /* only look at installable ones */
1088 /* find possible supplements */
1089 supp = s->repo->idarraydata + s->supplements;
1090 while ((sup = *supp++) != 0)
1091 if (dep_possible(solv, sup, m))
1095 /* if nothing found, check for enhances */
1096 if (!sup && s->enhances)
1098 supp = s->repo->idarraydata + s->enhances;
1099 while ((sup = *supp++) != 0)
1100 if (dep_possible(solv, sup, m))
1103 /* if nothing found, goto next solvables */
1106 solver_addrpmrulesforsolvable(solv, s, m);
1107 n = 0; /* check all solvables again because we added solvables to m */
1112 /*-------------------------------------------------------------------
1114 * add package rules for possible updates
1117 * m: map of already visited solvables
1118 * allow_all: 0 = dont allow downgrades, 1 = allow all candidates
1122 solver_addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
1124 Pool *pool = solv->pool;
1126 /* queue and buffer for it */
1130 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1131 /* find update candidates for 's' */
1132 policy_findupdatepackages(solv, s, &qs, allow_all);
1133 /* add rule for 's' if not already done */
1134 if (!MAPTST(m, s - pool->solvables))
1135 solver_addrpmrulesforsolvable(solv, s, m);
1136 /* foreach update candidate, add rule if not already done */
1137 for (i = 0; i < qs.count; i++)
1138 if (!MAPTST(m, qs.elements[i]))
1139 solver_addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1144 /***********************************************************************
1146 *** Update/Feature rule part
1148 *** Those rules make sure an installed package isn't silently deleted
1153 finddistupgradepackages(Solver *solv, Solvable *s, Queue *qs, int allow_all)
1155 Pool *pool = solv->pool;
1158 policy_findupdatepackages(solv, s, qs, allow_all ? allow_all : 2);
1162 return 0; /* orphaned, don't create feature rule */
1163 /* check if this is an orphaned package */
1164 policy_findupdatepackages(solv, s, qs, 1);
1166 return 0; /* orphaned, don't create update rule */
1168 return -SYSTEMSOLVABLE; /* supported but not installable */
1171 return s - pool->solvables;
1172 /* check if it is ok to keep the installed package */
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;
1183 /* add packages from the dup repositories to the update candidates
1184 * this isn't needed for the global dup mode as all packages are
1185 * from dup repos in that case */
1187 addduppackages(Solver *solv, Solvable *s, Queue *qs)
1192 int oldnoupdateprovide = solv->noupdateprovide;
1194 queue_init_buffer(&dupqs, dupqsbuf, sizeof(dupqsbuf)/sizeof(*dupqsbuf));
1195 solv->noupdateprovide = 1;
1196 policy_findupdatepackages(solv, s, &dupqs, 2);
1197 solv->noupdateprovide = oldnoupdateprovide;
1198 for (i = 0; i < dupqs.count; i++)
1200 p = dupqs.elements[i];
1201 if (MAPTST(&solv->dupmap, p))
1202 queue_pushunique(qs, p);
1207 /*-------------------------------------------------------------------
1209 * add rule for update
1210 * (A|A1|A2|A3...) An = update candidates for A
1212 * s = (installed) solvable
1216 solver_addupdaterule(Solver *solv, Solvable *s, int allow_all)
1218 /* installed packages get a special upgrade allowed rule */
1219 Pool *pool = solv->pool;
1224 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1225 p = s - pool->solvables;
1226 /* find update candidates for 's' */
1227 if (solv->dupmap_all)
1228 p = finddistupgradepackages(solv, s, &qs, allow_all);
1230 policy_findupdatepackages(solv, s, &qs, allow_all);
1231 if (!allow_all && !solv->dupmap_all && solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
1232 addduppackages(solv, s, &qs);
1234 if (!allow_all && qs.count && solv->multiversion.size)
1238 d = pool_queuetowhatprovides(pool, &qs);
1239 /* filter out all multiversion packages as they don't update */
1240 for (i = j = 0; i < qs.count; i++)
1242 if (MAPTST(&solv->multiversion, qs.elements[i]))
1244 Solvable *ps = pool->solvables + qs.elements[i];
1245 /* if keepexplicitobsoletes is set and the name is different,
1246 * we assume that there is an obsoletes. XXX: not 100% correct */
1247 if (solv->keepexplicitobsoletes && ps->name != s->name)
1249 qs.elements[j++] = qs.elements[i];
1252 /* it's ok if they have same nevra */
1253 if (ps->name != s->name || ps->evr != s->evr || ps->arch != s->arch)
1256 qs.elements[j++] = qs.elements[i];
1260 if (d && solv->installed && s->repo == solv->installed &&
1261 (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, s - pool->solvables - solv->installed->start))))
1263 if (!solv->multiversionupdaters)
1264 solv->multiversionupdaters = solv_calloc(solv->installed->end - solv->installed->start, sizeof(Id));
1265 solv->multiversionupdaters[s - pool->solvables - solv->installed->start] = d;
1267 if (j == 0 && p == -SYSTEMSOLVABLE && solv->dupmap_all)
1269 queue_push(&solv->orphaned, s - pool->solvables); /* treat as orphaned */
1274 else if (p != -SYSTEMSOLVABLE)
1276 /* could fallthrough, but then we would do pool_queuetowhatprovides twice */
1278 solver_addrule(solv, p, d); /* allow update of s */
1282 if (qs.count && p == -SYSTEMSOLVABLE)
1283 p = queue_shift(&qs);
1284 d = qs.count ? pool_queuetowhatprovides(pool, &qs) : 0;
1286 solver_addrule(solv, p, d); /* allow update of s */
1290 disableupdaterule(Solver *solv, Id p)
1294 MAPSET(&solv->noupdate, p - solv->installed->start);
1295 r = solv->rules + solv->updaterules + (p - solv->installed->start);
1296 if (r->p && r->d >= 0)
1297 solver_disablerule(solv, r);
1298 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1299 if (r->p && r->d >= 0)
1300 solver_disablerule(solv, r);
1301 if (solv->bestrules_pkg)
1304 ni = solv->bestrules_end - solv->bestrules;
1305 for (i = 0; i < ni; i++)
1306 if (solv->bestrules_pkg[i] == p)
1307 solver_disablerule(solv, solv->rules + solv->bestrules + i);
1312 reenableupdaterule(Solver *solv, Id p)
1314 Pool *pool = solv->pool;
1317 MAPCLR(&solv->noupdate, p - solv->installed->start);
1318 r = solv->rules + solv->updaterules + (p - solv->installed->start);
1323 solver_enablerule(solv, r);
1324 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1326 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1327 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1333 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1334 if (r->p && r->d < 0)
1336 solver_enablerule(solv, r);
1337 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1339 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1340 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1344 if (solv->bestrules_pkg)
1347 ni = solv->bestrules_end - solv->bestrules;
1348 for (i = 0; i < ni; i++)
1349 if (solv->bestrules_pkg[i] == p)
1350 solver_enablerule(solv, solv->rules + solv->bestrules + i);
1355 /***********************************************************************
1357 *** Infarch rule part
1359 *** Infarch rules make sure the solver uses the best architecture of
1360 *** a package if multiple archetectures are available
1365 solver_addinfarchrules(Solver *solv, Map *addedmap)
1367 Pool *pool = solv->pool;
1369 Id p, pp, a, aa, bestarch;
1370 Solvable *s, *ps, *bests;
1371 Queue badq, allowedarchs;
1374 queue_init(&allowedarchs);
1375 solv->infarchrules = solv->nrules;
1376 for (i = 1; i < pool->nsolvables; i++)
1378 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1380 s = pool->solvables + i;
1384 queue_empty(&allowedarchs);
1385 FOR_PROVIDES(p, pp, s->name)
1387 ps = pool->solvables + p;
1388 if (ps->name != s->name || !MAPTST(addedmap, p))
1395 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1396 if (a != 1 && pool->installed && ps->repo == pool->installed)
1398 if (!solv->dupmap_all && !(solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
1399 queue_pushunique(&allowedarchs, ps->arch); /* also ok to keep this architecture */
1400 continue; /* ignore installed solvables when calculating the best arch */
1402 if (a && a != 1 && (!bestarch || a < bestarch))
1410 /* speed up common case where installed package already has best arch */
1411 if (allowedarchs.count == 1 && bests && allowedarchs.elements[0] == bests->arch)
1412 allowedarchs.count--; /* installed arch is best */
1414 FOR_PROVIDES(p, pp, s->name)
1416 ps = pool->solvables + p;
1417 if (ps->name != s->name || !MAPTST(addedmap, p))
1420 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1421 if (a != 1 && bestarch && ((a ^ bestarch) & 0xffff0000) != 0)
1423 if (pool->installed && ps->repo == pool->installed)
1424 continue; /* always ok to keep an installed package */
1425 for (j = 0; j < allowedarchs.count; j++)
1427 aa = allowedarchs.elements[j];
1430 aa = (aa <= pool->lastarch) ? pool->id2arch[aa] : 0;
1431 if (aa && ((a ^ aa) & 0xffff0000) == 0)
1432 break; /* compatible */
1434 if (j == allowedarchs.count)
1435 queue_push(&badq, p);
1440 /* block all solvables in the badq! */
1441 for (j = 0; j < badq.count; j++)
1443 p = badq.elements[j];
1444 solver_addrule(solv, -p, 0);
1448 queue_free(&allowedarchs);
1449 solv->infarchrules_end = solv->nrules;
1453 disableinfarchrule(Solver *solv, Id name)
1455 Pool *pool = solv->pool;
1458 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1460 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1461 solver_disablerule(solv, r);
1466 reenableinfarchrule(Solver *solv, Id name)
1468 Pool *pool = solv->pool;
1471 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1473 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1475 solver_enablerule(solv, r);
1476 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1478 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1479 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1486 /***********************************************************************
1490 *** Dup rules make sure a package is selected from the specified dup
1491 *** repositories if an update candidate is included in one of them.
1496 add_cleandeps_package(Solver *solv, Id p)
1498 if (!solv->cleandeps_updatepkgs)
1500 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
1501 queue_init(solv->cleandeps_updatepkgs);
1503 queue_pushunique(solv->cleandeps_updatepkgs, p);
1507 solver_addtodupmaps(Solver *solv, Id p, Id how, int targeted)
1509 Pool *pool = solv->pool;
1510 Solvable *ps, *s = pool->solvables + p;
1511 Repo *installed = solv->installed;
1512 Id pi, pip, obs, *obsp;
1514 MAPSET(&solv->dupinvolvedmap, p);
1516 MAPSET(&solv->dupmap, p);
1517 FOR_PROVIDES(pi, pip, s->name)
1519 ps = pool->solvables + pi;
1520 if (ps->name != s->name)
1522 MAPSET(&solv->dupinvolvedmap, pi);
1523 if (targeted && ps->repo == installed && solv->obsoletes && solv->obsoletes[pi - installed->start])
1526 for (opp = solv->obsoletes_data + solv->obsoletes[pi - installed->start]; (pi2 = *opp++) != 0;)
1527 if (pool->solvables[pi2].repo != installed)
1528 MAPSET(&solv->dupinvolvedmap, pi2);
1530 if (ps->repo == installed && (how & SOLVER_FORCEBEST) != 0)
1532 if (!solv->bestupdatemap.size)
1533 map_grow(&solv->bestupdatemap, installed->end - installed->start);
1534 MAPSET(&solv->bestupdatemap, pi - installed->start);
1536 if (ps->repo == installed && (how & SOLVER_CLEANDEPS) != 0)
1537 add_cleandeps_package(solv, pi);
1538 if (!targeted && ps->repo != installed)
1539 MAPSET(&solv->dupmap, pi);
1541 if (s->repo == installed && solv->obsoletes && solv->obsoletes[p - installed->start])
1544 for (opp = solv->obsoletes_data + solv->obsoletes[p - installed->start]; (pi = *opp++) != 0;)
1546 ps = pool->solvables + pi;
1547 if (ps->repo == installed)
1549 MAPSET(&solv->dupinvolvedmap, pi);
1551 MAPSET(&solv->dupmap, pi);
1554 if (targeted && s->repo != installed && s->obsoletes)
1556 /* XXX: check obsoletes/provides combination */
1557 obsp = s->repo->idarraydata + s->obsoletes;
1558 while ((obs = *obsp++) != 0)
1560 FOR_PROVIDES(pi, pip, obs)
1562 Solvable *ps = pool->solvables + pi;
1563 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
1565 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1567 MAPSET(&solv->dupinvolvedmap, pi);
1568 if (targeted && ps->repo == installed && solv->obsoletes && solv->obsoletes[pi - installed->start])
1571 for (opp = solv->obsoletes_data + solv->obsoletes[pi - installed->start]; (pi2 = *opp++) != 0;)
1572 if (pool->solvables[pi2].repo != installed)
1573 MAPSET(&solv->dupinvolvedmap, pi2);
1575 if (ps->repo == installed && (how & SOLVER_FORCEBEST) != 0)
1577 if (!solv->bestupdatemap.size)
1578 map_grow(&solv->bestupdatemap, installed->end - installed->start);
1579 MAPSET(&solv->bestupdatemap, pi - installed->start);
1581 if (ps->repo == installed && (how & SOLVER_CLEANDEPS) != 0)
1582 add_cleandeps_package(solv, pi);
1589 solver_createdupmaps(Solver *solv)
1591 Queue *job = &solv->job;
1592 Pool *pool = solv->pool;
1593 Repo *installed = solv->installed;
1594 Id select, how, what, p, pp;
1598 map_init(&solv->dupmap, pool->nsolvables);
1599 map_init(&solv->dupinvolvedmap, pool->nsolvables);
1600 for (i = 0; i < job->count; i += 2)
1602 how = job->elements[i];
1603 select = job->elements[i] & SOLVER_SELECTMASK;
1604 what = job->elements[i + 1];
1605 switch (how & SOLVER_JOBMASK)
1607 case SOLVER_DISTUPGRADE:
1608 if (select == SOLVER_SOLVABLE_REPO)
1611 if (what <= 0 || what > pool->nrepos)
1613 repo = pool_id2repo(pool, what);
1616 if (repo != installed && !(how & SOLVER_TARGETED) && solv->noautotarget)
1618 targeted = repo != installed || (how & SOLVER_TARGETED) != 0;
1619 FOR_REPO_SOLVABLES(repo, p, s)
1621 if (repo != installed && !pool_installable(pool, s))
1623 solver_addtodupmaps(solv, p, how, targeted);
1628 targeted = how & SOLVER_TARGETED ? 1 : 0;
1629 if (installed && !targeted && !solv->noautotarget)
1631 FOR_JOB_SELECT(p, pp, select, what)
1632 if (pool->solvables[p].repo == installed)
1636 else if (!installed && !solv->noautotarget)
1638 FOR_JOB_SELECT(p, pp, select, what)
1640 Solvable *s = pool->solvables + p;
1643 if (s->repo != installed && !targeted)
1645 if (s->repo != installed && !pool_installable(pool, s))
1647 solver_addtodupmaps(solv, p, how, targeted);
1655 MAPCLR(&solv->dupinvolvedmap, SYSTEMSOLVABLE);
1659 solver_freedupmaps(Solver *solv)
1661 map_free(&solv->dupmap);
1662 /* we no longer free solv->dupinvolvedmap as we need it in
1663 * policy's priority pruning code. sigh. */
1667 solver_addduprules(Solver *solv, Map *addedmap)
1669 Pool *pool = solv->pool;
1674 solv->duprules = solv->nrules;
1675 for (i = 1; i < pool->nsolvables; i++)
1677 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1679 s = pool->solvables + i;
1681 FOR_PROVIDES(p, pp, s->name)
1683 ps = pool->solvables + p;
1684 if (ps->name != s->name || !MAPTST(addedmap, p))
1690 if (!MAPTST(&solv->dupinvolvedmap, p))
1692 if (solv->installed && ps->repo == solv->installed)
1694 if (!solv->updatemap.size)
1695 map_grow(&solv->updatemap, solv->installed->end - solv->installed->start);
1696 MAPSET(&solv->updatemap, p - solv->installed->start);
1697 if (!MAPTST(&solv->dupmap, p))
1700 /* is installed identical to a good one? */
1701 FOR_PROVIDES(ip, ipp, ps->name)
1703 Solvable *is = pool->solvables + ip;
1704 if (!MAPTST(&solv->dupmap, ip))
1706 if (is->evr == ps->evr && solvable_identical(ps, is))
1710 solver_addrule(solv, -p, 0); /* no match, sorry */
1712 MAPSET(&solv->dupmap, p); /* for best rules processing */
1715 else if (!MAPTST(&solv->dupmap, p))
1716 solver_addrule(solv, -p, 0);
1719 solv->duprules_end = solv->nrules;
1724 disableduprule(Solver *solv, Id name)
1726 Pool *pool = solv->pool;
1729 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1731 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1732 solver_disablerule(solv, r);
1737 reenableduprule(Solver *solv, Id name)
1739 Pool *pool = solv->pool;
1742 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
1744 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1746 solver_enablerule(solv, r);
1747 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1749 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1750 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1757 /***********************************************************************
1759 *** Policy rule disabling/reenabling
1761 *** Disable all policy rules that conflict with our jobs. If a job
1762 *** gets disabled later on, reenable the involved policy rules again.
1766 #define DISABLE_UPDATE 1
1767 #define DISABLE_INFARCH 2
1768 #define DISABLE_DUP 3
1771 * add all installed packages that package p obsoletes to Queue q.
1772 * Package p is not installed. Also, we know that if
1773 * solv->keepexplicitobsoletes is not set, p is not in the multiversion map.
1774 * Entries may get added multiple times.
1777 add_obsoletes(Solver *solv, Id p, Queue *q)
1779 Pool *pool = solv->pool;
1780 Repo *installed = solv->installed;
1782 Solvable *s = pool->solvables + p;
1786 if (!solv->keepexplicitobsoletes || !(solv->multiversion.size && MAPTST(&solv->multiversion, p)))
1788 FOR_PROVIDES(p2, pp2, s->name)
1790 Solvable *ps = pool->solvables + p2;
1791 if (ps->repo != installed)
1793 if (!pool->implicitobsoleteusesprovides && ps->name != s->name)
1795 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, ps))
1803 obsp = s->repo->idarraydata + s->obsoletes;
1804 while ((obs = *obsp++) != 0)
1805 FOR_PROVIDES(p2, pp2, obs)
1807 Solvable *ps = pool->solvables + p2;
1808 if (ps->repo != installed)
1810 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
1812 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1822 * Call add_obsoletes and intersect the result with the
1823 * elements in Queue q starting at qstart.
1824 * Assumes that it's the first call if qstart == q->count.
1825 * May use auxillary map m for the intersection process, all
1826 * elements of q starting at qstart must have their bit cleared.
1827 * (This is also true after the function returns.)
1830 intersect_obsoletes(Solver *solv, Id p, Queue *q, int qstart, Map *m)
1833 int qcount = q->count;
1835 add_obsoletes(solv, p, q);
1836 if (qcount == qstart)
1837 return; /* first call */
1838 if (qcount == q->count)
1840 else if (qcount == qstart + 1)
1842 /* easy if there's just one element */
1844 for (i = qcount; i < q->count; i++)
1845 if (q->elements[i] == q->elements[qstart])
1847 j++; /* keep the element */
1851 else if (!m->size && q->count - qstart <= 8)
1853 /* faster than a map most of the time */
1855 for (i = j = qstart; i < qcount; i++)
1857 Id ip = q->elements[i];
1858 for (k = qcount; k < q->count; k++)
1859 if (q->elements[k] == ip)
1861 q->elements[j++] = ip;
1868 /* for the really pathologic cases we use the map */
1869 Repo *installed = solv->installed;
1871 map_init(m, installed->end - installed->start);
1872 for (i = qcount; i < q->count; i++)
1873 MAPSET(m, q->elements[i] - installed->start);
1874 for (i = j = qstart; i < qcount; i++)
1875 if (MAPTST(m, q->elements[i] - installed->start))
1877 MAPCLR(m, q->elements[i] - installed->start);
1878 q->elements[j++] = q->elements[i];
1881 queue_truncate(q, j);
1885 jobtodisablelist(Solver *solv, Id how, Id what, Queue *q)
1887 Pool *pool = solv->pool;
1891 int i, j, set, qstart;
1894 installed = solv->installed;
1895 select = how & SOLVER_SELECTMASK;
1896 switch (how & SOLVER_JOBMASK)
1898 case SOLVER_INSTALL:
1899 set = how & SOLVER_SETMASK;
1900 if (!(set & SOLVER_NOAUTOSET))
1902 /* automatically add set bits by analysing the job */
1903 if (select == SOLVER_SOLVABLE_NAME)
1904 set |= SOLVER_SETNAME;
1905 if (select == SOLVER_SOLVABLE)
1906 set |= SOLVER_SETNAME | SOLVER_SETARCH | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_SETEVR;
1907 else if ((select == SOLVER_SOLVABLE_NAME || select == SOLVER_SOLVABLE_PROVIDES) && ISRELDEP(what))
1909 Reldep *rd = GETRELDEP(pool, what);
1910 if (rd->flags == REL_EQ && select == SOLVER_SOLVABLE_NAME)
1912 if (pool->disttype != DISTTYPE_DEB)
1914 const char *rel = strrchr(pool_id2str(pool, rd->evr), '-');
1915 set |= rel ? SOLVER_SETEVR : SOLVER_SETEV;
1918 set |= SOLVER_SETEVR;
1920 if (rd->flags <= 7 && ISRELDEP(rd->name))
1921 rd = GETRELDEP(pool, rd->name);
1922 if (rd->flags == REL_ARCH)
1923 set |= SOLVER_SETARCH;
1927 set &= ~SOLVER_NOAUTOSET;
1930 if ((set & SOLVER_SETARCH) != 0 && solv->infarchrules != solv->infarchrules_end)
1932 if (select == SOLVER_SOLVABLE)
1933 queue_push2(q, DISABLE_INFARCH, pool->solvables[what].name);
1936 int qcnt = q->count;
1937 /* does not work for SOLVER_SOLVABLE_ALL and SOLVER_SOLVABLE_REPO, but
1938 they are not useful for SOLVER_INSTALL jobs anyway */
1939 FOR_JOB_SELECT(p, pp, select, what)
1941 s = pool->solvables + p;
1943 for (i = qcnt; i < q->count; i += 2)
1944 if (q->elements[i + 1] == s->name)
1948 queue_push2(q, DISABLE_INFARCH, s->name);
1952 if ((set & SOLVER_SETREPO) != 0 && solv->duprules != solv->duprules_end)
1954 if (select == SOLVER_SOLVABLE)
1955 queue_push2(q, DISABLE_DUP, pool->solvables[what].name);
1958 int qcnt = q->count;
1959 FOR_JOB_SELECT(p, pp, select, what)
1961 s = pool->solvables + p;
1963 for (i = qcnt; i < q->count; i += 2)
1964 if (q->elements[i + 1] == s->name)
1968 queue_push2(q, DISABLE_DUP, s->name);
1972 if (!installed || installed->end == installed->start)
1974 /* now the hard part: disable some update rules */
1976 /* first check if we have multiversion or installed packages in the job */
1978 FOR_JOB_SELECT(p, pp, select, what)
1980 if (pool->solvables[p].repo == installed)
1982 else if (solv->multiversion.size && MAPTST(&solv->multiversion, p) && !solv->keepexplicitobsoletes)
1986 if (j) /* have installed packages */
1988 /* this is for dupmap_all jobs, it can go away if we create
1989 * duprules for them */
1990 if (i == 1 && (set & SOLVER_SETREPO) != 0)
1991 queue_push2(q, DISABLE_UPDATE, j);
1997 FOR_JOB_SELECT(p, pp, select, what)
1999 intersect_obsoletes(solv, p, q, qstart, &omap);
2000 if (q->count == qstart)
2006 if (qstart == q->count)
2007 return; /* nothing to prune */
2009 /* convert result to (DISABLE_UPDATE, p) pairs */
2011 for (j = qstart; j < i; j++)
2012 queue_push(q, q->elements[j]);
2013 for (j = qstart; j < q->count; j += 2)
2015 q->elements[j] = DISABLE_UPDATE;
2016 q->elements[j + 1] = q->elements[i++];
2019 /* now that we know which installed packages are obsoleted check each of them */
2020 if ((set & (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR)) == (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR))
2021 return; /* all is set, nothing to do */
2023 for (i = j = qstart; i < q->count; i += 2)
2025 Solvable *is = pool->solvables + q->elements[i + 1];
2026 FOR_JOB_SELECT(p, pp, select, what)
2029 s = pool->solvables + p;
2030 if ((set & SOLVER_SETEVR) != 0)
2031 illegal |= POLICY_ILLEGAL_DOWNGRADE; /* ignore */
2032 if ((set & SOLVER_SETNAME) != 0)
2033 illegal |= POLICY_ILLEGAL_NAMECHANGE; /* ignore */
2034 if ((set & SOLVER_SETARCH) != 0)
2035 illegal |= POLICY_ILLEGAL_ARCHCHANGE; /* ignore */
2036 if ((set & SOLVER_SETVENDOR) != 0)
2037 illegal |= POLICY_ILLEGAL_VENDORCHANGE; /* ignore */
2038 illegal = policy_is_illegal(solv, is, s, illegal);
2039 if (illegal && illegal == POLICY_ILLEGAL_DOWNGRADE && (set & SOLVER_SETEV) != 0)
2041 /* it's ok if the EV is different */
2042 if (pool_evrcmp(pool, is->evr, s->evr, EVRCMP_COMPARE_EVONLY) != 0)
2050 /* no package conflicts with the update rule */
2051 /* thus keep the DISABLE_UPDATE */
2052 q->elements[j + 1] = q->elements[i + 1];
2056 queue_truncate(q, j);
2062 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
2063 FOR_REPO_SOLVABLES(installed, p, s)
2064 queue_push2(q, DISABLE_UPDATE, p);
2065 FOR_JOB_SELECT(p, pp, select, what)
2066 if (pool->solvables[p].repo == installed)
2068 queue_push2(q, DISABLE_UPDATE, p);
2069 if (solv->instbuddy && solv->instbuddy[p - installed->start] > 1)
2070 queue_push2(q, DISABLE_UPDATE, solv->instbuddy[p - installed->start]);
2078 /* disable all policy rules that are in conflict with our job list */
2080 solver_disablepolicyrules(Solver *solv)
2082 Queue *job = &solv->job;
2089 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2091 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2093 r = solv->rules + i;
2094 if (r->d < 0) /* disabled? */
2096 j = solv->ruletojob.elements[i - solv->jobrules];
2100 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2102 if (solv->cleandepsmap.size)
2104 solver_createcleandepsmap(solv, &solv->cleandepsmap, 0);
2105 for (i = solv->installed->start; i < solv->installed->end; i++)
2106 if (MAPTST(&solv->cleandepsmap, i - solv->installed->start))
2107 queue_push2(&allq, DISABLE_UPDATE, i);
2109 MAPZERO(&solv->noupdate);
2110 for (i = 0; i < allq.count; i += 2)
2112 Id type = allq.elements[i], arg = allq.elements[i + 1];
2115 case DISABLE_UPDATE:
2116 disableupdaterule(solv, arg);
2118 case DISABLE_INFARCH:
2119 disableinfarchrule(solv, arg);
2122 disableduprule(solv, arg);
2131 /* we just disabled job #jobidx, now reenable all policy rules that were
2132 * disabled because of this job */
2134 solver_reenablepolicyrules(Solver *solv, int jobidx)
2136 Queue *job = &solv->job;
2141 Id qbuf[32], allqbuf[32];
2143 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
2144 jobtodisablelist(solv, job->elements[jobidx - 1], job->elements[jobidx], &q);
2150 /* now remove everything from q that is disabled by other jobs */
2152 /* first remove cleandeps packages, they count as DISABLE_UPDATE */
2153 if (solv->cleandepsmap.size)
2155 solver_createcleandepsmap(solv, &solv->cleandepsmap, 0);
2156 for (j = k = 0; j < q.count; j += 2)
2158 if (q.elements[j] == DISABLE_UPDATE)
2160 Id p = q.elements[j + 1];
2161 if (p >= solv->installed->start && p < solv->installed->end && MAPTST(&solv->cleandepsmap, p - solv->installed->start))
2162 continue; /* remove element from q */
2164 q.elements[k++] = q.elements[j];
2165 q.elements[k++] = q.elements[j + 1];
2175 /* now go through the disable list of all other jobs */
2176 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2177 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2179 r = solv->rules + i;
2180 if (r->d < 0) /* disabled? */
2182 j = solv->ruletojob.elements[i - solv->jobrules];
2186 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2189 /* remove all elements in allq from q */
2190 for (j = k = 0; j < q.count; j += 2)
2192 Id type = q.elements[j], arg = q.elements[j + 1];
2193 for (ai = 0; ai < allq.count; ai += 2)
2194 if (allq.elements[ai] == type && allq.elements[ai + 1] == arg)
2196 if (ai < allq.count)
2197 continue; /* found it in allq, remove element from q */
2198 q.elements[k++] = q.elements[j];
2199 q.elements[k++] = q.elements[j + 1];
2212 /* now re-enable anything that's left in q */
2213 for (j = 0; j < q.count; j += 2)
2215 Id type = q.elements[j], arg = q.elements[j + 1];
2218 case DISABLE_UPDATE:
2219 reenableupdaterule(solv, arg);
2221 case DISABLE_INFARCH:
2222 reenableinfarchrule(solv, arg);
2225 reenableduprule(solv, arg);
2232 /* we just removed a package from the cleandeps map, now reenable all policy rules that were
2233 * disabled because of this */
2235 solver_reenablepolicyrules_cleandeps(Solver *solv, Id pkg)
2237 Queue *job = &solv->job;
2244 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2245 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2247 r = solv->rules + i;
2248 if (r->d < 0) /* disabled? */
2250 j = solv->ruletojob.elements[i - solv->jobrules];
2254 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2256 for (i = 0; i < allq.count; i += 2)
2257 if (allq.elements[i] == DISABLE_UPDATE && allq.elements[i + 1] == pkg)
2259 if (i == allq.count)
2260 reenableupdaterule(solv, pkg);
2265 /***********************************************************************
2267 *** Rule info part, tell the user what the rule is about.
2272 addrpmruleinfo(Solver *solv, Id p, Id d, int type, Id dep)
2274 Pool *pool = solv->pool;
2278 /* check if this creates the rule we're searching for */
2279 r = solv->rules + solv->ruleinfoq->elements[0];
2281 od = r->d < 0 ? -r->d - 1 : r->d;
2286 if (p < 0 && d > 0 && (!pool->whatprovidesdata[d] || !pool->whatprovidesdata[d + 1]))
2288 w2 = pool->whatprovidesdata[d];
2291 if (p > 0 && d < 0) /* this hack is used for buddy deps */
2303 Id *dp = pool->whatprovidesdata + d;
2304 Id *odp = pool->whatprovidesdata + od;
2306 if (*dp++ != *odp++)
2312 /* handle multiversion conflict rules */
2313 if (p < 0 && pool->whatprovidesdata[d] < 0)
2315 w2 = pool->whatprovidesdata[d];
2316 /* XXX: free memory */
2326 if (w2 != op || p != ow2)
2331 if (p != op || w2 != ow2)
2335 /* yep, rule matches. record info */
2336 queue_push(solv->ruleinfoq, type);
2337 if (type == SOLVER_RULE_RPM_SAME_NAME)
2339 /* we normalize same name order */
2340 queue_push(solv->ruleinfoq, op < 0 ? -op : 0);
2341 queue_push(solv->ruleinfoq, ow2 < 0 ? -ow2 : 0);
2345 queue_push(solv->ruleinfoq, p < 0 ? -p : 0);
2346 queue_push(solv->ruleinfoq, w2 < 0 ? -w2 : 0);
2348 queue_push(solv->ruleinfoq, dep);
2352 solver_allruleinfos_cmp(const void *ap, const void *bp, void *dp)
2354 const Id *a = ap, *b = bp;
2373 getrpmruleinfos(Solver *solv, Rule *r, Queue *rq)
2375 Pool *pool = solv->pool;
2379 queue_push(rq, r - solv->rules); /* push the rule we're interested in */
2380 solv->ruleinfoq = rq;
2381 solver_addrpmrulesforsolvable(solv, pool->solvables - r->p, 0);
2382 /* also try reverse direction for conflicts */
2383 if ((r->d == 0 || r->d == -1) && r->w2 < 0)
2384 solver_addrpmrulesforsolvable(solv, pool->solvables - r->w2, 0);
2385 /* check linked packages */
2387 if ((r->d == 0 || r->d == -1))
2391 d = r->d < 0 ? -r->d - 1 : r->d;
2392 l = pool->whatprovidesdata[d++];
2394 for (; l; l = (d ? pool->whatprovidesdata[d++] : 0))
2396 if (l <= 0 || !strchr(pool_id2str(pool, pool->solvables[l].name), ':'))
2398 add_package_link(solv, pool->solvables + l, 0, 0);
2400 solv->ruleinfoq = 0;
2405 solver_allruleinfos(Solver *solv, Id rid, Queue *rq)
2407 Rule *r = solv->rules + rid;
2411 if (rid <= 0 || rid >= solv->rpmrules_end)
2413 Id type, from, to, dep;
2414 type = solver_ruleinfo(solv, rid, &from, &to, &dep);
2415 queue_push(rq, type);
2416 queue_push(rq, from);
2418 queue_push(rq, dep);
2421 getrpmruleinfos(solv, r, rq);
2422 /* now sort & unify em */
2425 solv_sort(rq->elements, rq->count / 4, 4 * sizeof(Id), solver_allruleinfos_cmp, 0);
2426 /* throw out identical entries */
2427 for (i = j = 0; i < rq->count; i += 4)
2431 if (rq->elements[i] == rq->elements[j - 4] &&
2432 rq->elements[i + 1] == rq->elements[j - 3] &&
2433 rq->elements[i + 2] == rq->elements[j - 2] &&
2434 rq->elements[i + 3] == rq->elements[j - 1])
2437 rq->elements[j++] = rq->elements[i];
2438 rq->elements[j++] = rq->elements[i + 1];
2439 rq->elements[j++] = rq->elements[i + 2];
2440 rq->elements[j++] = rq->elements[i + 3];
2447 solver_ruleinfo(Solver *solv, Id rid, Id *fromp, Id *top, Id *depp)
2449 Pool *pool = solv->pool;
2450 Rule *r = solv->rules + rid;
2451 SolverRuleinfo type = SOLVER_RULE_UNKNOWN;
2459 if (rid > 0 && rid < solv->rpmrules_end)
2465 return SOLVER_RULE_RPM;
2469 getrpmruleinfos(solv, r, &rq);
2470 type = SOLVER_RULE_RPM;
2471 for (i = 0; i < rq.count; i += 4)
2474 qt = rq.elements[i];
2475 qp = rq.elements[i + 1];
2476 qo = rq.elements[i + 2];
2477 qd = rq.elements[i + 3];
2478 if (type == SOLVER_RULE_RPM || type > qt)
2492 if (rid >= solv->jobrules && rid < solv->jobrules_end)
2494 Id jidx = solv->ruletojob.elements[rid - solv->jobrules];
2498 *top = solv->job.elements[jidx];
2500 *depp = solv->job.elements[jidx + 1];
2501 if ((r->d == 0 || r->d == -1) && r->w2 == 0 && r->p == -SYSTEMSOLVABLE)
2503 Id how = solv->job.elements[jidx];
2504 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_INSTALL|SOLVER_SOLVABLE_NAME))
2505 return SOLVER_RULE_JOB_UNKNOWN_PACKAGE;
2506 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES))
2507 return SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP;
2508 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_ERASE|SOLVER_SOLVABLE_NAME))
2509 return SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM;
2510 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_ERASE|SOLVER_SOLVABLE_PROVIDES))
2511 return SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM;
2512 return SOLVER_RULE_JOB_UNSUPPORTED;
2514 return SOLVER_RULE_JOB;
2516 if (rid >= solv->updaterules && rid < solv->updaterules_end)
2519 *fromp = solv->installed->start + (rid - solv->updaterules);
2520 return SOLVER_RULE_UPDATE;
2522 if (rid >= solv->featurerules && rid < solv->featurerules_end)
2525 *fromp = solv->installed->start + (rid - solv->featurerules);
2526 return SOLVER_RULE_FEATURE;
2528 if (rid >= solv->duprules && rid < solv->duprules_end)
2533 *depp = pool->solvables[-r->p].name;
2534 return SOLVER_RULE_DISTUPGRADE;
2536 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
2541 *depp = pool->solvables[-r->p].name;
2542 return SOLVER_RULE_INFARCH;
2544 if (rid >= solv->bestrules && rid < solv->bestrules_end)
2546 return SOLVER_RULE_BEST;
2548 if (rid >= solv->choicerules && rid < solv->choicerules_end)
2550 return SOLVER_RULE_CHOICE;
2552 if (rid >= solv->learntrules)
2554 return SOLVER_RULE_LEARNT;
2556 return SOLVER_RULE_UNKNOWN;
2560 solver_ruleclass(Solver *solv, Id rid)
2563 return SOLVER_RULE_UNKNOWN;
2564 if (rid > 0 && rid < solv->rpmrules_end)
2565 return SOLVER_RULE_RPM;
2566 if (rid >= solv->jobrules && rid < solv->jobrules_end)
2567 return SOLVER_RULE_JOB;
2568 if (rid >= solv->updaterules && rid < solv->updaterules_end)
2569 return SOLVER_RULE_UPDATE;
2570 if (rid >= solv->featurerules && rid < solv->featurerules_end)
2571 return SOLVER_RULE_FEATURE;
2572 if (rid >= solv->duprules && rid < solv->duprules_end)
2573 return SOLVER_RULE_DISTUPGRADE;
2574 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
2575 return SOLVER_RULE_INFARCH;
2576 if (rid >= solv->bestrules && rid < solv->bestrules_end)
2577 return SOLVER_RULE_BEST;
2578 if (rid >= solv->choicerules && rid < solv->choicerules_end)
2579 return SOLVER_RULE_CHOICE;
2580 if (rid >= solv->learntrules)
2581 return SOLVER_RULE_LEARNT;
2582 return SOLVER_RULE_UNKNOWN;
2586 solver_ruleliterals(Solver *solv, Id rid, Queue *q)
2588 Pool *pool = solv->pool;
2593 r = solv->rules + rid;
2594 FOR_RULELITERALS(p, pp, r)
2595 if (p != -SYSTEMSOLVABLE)
2598 queue_push(q, -SYSTEMSOLVABLE); /* hmm, better to return an empty result? */
2602 solver_rule2jobidx(Solver *solv, Id rid)
2604 if (rid < solv->jobrules || rid >= solv->jobrules_end)
2606 return solv->ruletojob.elements[rid - solv->jobrules] + 1;
2609 /* job rule introspection */
2611 solver_rule2job(Solver *solv, Id rid, Id *whatp)
2614 if (rid < solv->jobrules || rid >= solv->jobrules_end)
2620 idx = solv->ruletojob.elements[rid - solv->jobrules];
2622 *whatp = solv->job.elements[idx + 1];
2623 return solv->job.elements[idx];
2626 /* update/feature rule introspection */
2628 solver_rule2solvable(Solver *solv, Id rid)
2630 if (rid >= solv->updaterules && rid < solv->updaterules_end)
2631 return rid - solv->updaterules;
2632 if (rid >= solv->featurerules && rid < solv->featurerules_end)
2633 return rid - solv->featurerules;
2638 solver_rule2rules_rec(Solver *solv, Id rid, Queue *q, Map *seen)
2645 for (i = solv->learnt_why.elements[rid - solv->learntrules]; (rid2 = solv->learnt_pool.elements[i]) != 0; i++)
2649 if (MAPTST(seen, rid2))
2651 if (rid2 >= solv->learntrules)
2652 solver_rule2rules_rec(solv, rid2, q, seen);
2655 queue_push(q, rid2);
2659 /* learnt rule introspection */
2661 solver_rule2rules(Solver *solv, Id rid, Queue *q, int recursive)
2664 if (rid < solv->learntrules || rid >= solv->nrules)
2669 map_init(&seen, solv->nrules);
2670 solver_rule2rules_rec(solv, rid, q, &seen);
2674 solver_rule2rules_rec(solv, rid, q, 0);
2678 /* check if the newest versions of pi still provides the dependency we're looking for */
2680 solver_choicerulecheck(Solver *solv, Id pi, Rule *r, Map *m)
2682 Pool *pool = solv->pool;
2688 ur = solv->rules + solv->updaterules + (pi - pool->installed->start);
2690 ur = solv->rules + solv->featurerules + (pi - pool->installed->start);
2693 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
2694 FOR_RULELITERALS(p, pp, ur)
2698 policy_filter_unwanted(solv, &q, POLICY_MODE_CHOOSE);
2699 for (i = 0; i < q.count; i++)
2700 if (MAPTST(m, q.elements[i]))
2702 /* 1: none of the newest versions provide it */
2703 i = i == q.count ? 1 : 0;
2709 queue_removeelement(Queue *q, Id el)
2712 for (i = 0; i < q->count; i++)
2713 if (q->elements[i] == el)
2717 for (j = i++; i < q->count; i++)
2718 if (q->elements[i] != el)
2719 q->elements[j++] = q->elements[i];
2720 queue_truncate(q, j);
2725 solver_addchoicerules(Solver *solv)
2727 Pool *pool = solv->pool;
2731 int i, j, rid, havechoice;
2735 Id lastaddedp, lastaddedd;
2739 solv->choicerules = solv->nrules;
2740 if (!pool->installed)
2742 solv->choicerules_end = solv->nrules;
2745 now = solv_timems(0);
2746 solv->choicerules_ref = solv_calloc(solv->rpmrules_end, sizeof(Id));
2749 map_init(&m, pool->nsolvables);
2750 map_init(&mneg, pool->nsolvables);
2751 /* set up negative assertion map from infarch and dup rules */
2752 for (rid = solv->infarchrules, r = solv->rules + rid; rid < solv->infarchrules_end; rid++, r++)
2753 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
2754 MAPSET(&mneg, -r->p);
2755 for (rid = solv->duprules, r = solv->rules + rid; rid < solv->duprules_end; rid++, r++)
2756 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
2757 MAPSET(&mneg, -r->p);
2761 for (rid = 1; rid < solv->rpmrules_end ; rid++)
2763 r = solv->rules + rid;
2764 if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 < 0))
2765 continue; /* only look at requires rules */
2766 /* solver_printrule(solv, SOLV_DEBUG_RESULT, r); */
2770 FOR_RULELITERALS(p, pp, r)
2774 s = pool->solvables + p;
2777 if (s->repo == pool->installed)
2782 /* check if this package is "blocked" by a installed package */
2784 FOR_PROVIDES(p2, pp2, s->name)
2786 s2 = pool->solvables + p2;
2787 if (s2->repo != pool->installed)
2789 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
2791 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, s2))
2797 /* found installed package p2 that we can update to p */
2798 if (MAPTST(&mneg, p))
2800 if (policy_is_illegal(solv, s2, s, 0))
2803 if (solver_choicerulecheck(solv, p2, r, &m))
2805 queue_push(&qi, p2);
2807 queue_push2(&qi, p2, p);
2814 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
2816 while ((obs = *obsp++) != 0)
2818 FOR_PROVIDES(p2, pp2, obs)
2820 s2 = pool->solvables + p2;
2821 if (s2->repo != pool->installed)
2823 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
2825 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
2834 /* found installed package p2 that we can update to p */
2835 if (MAPTST(&mneg, p))
2837 if (policy_is_illegal(solv, s2, s, 0))
2840 if (solver_choicerulecheck(solv, p2, r, &m))
2842 queue_push(&qi, p2);
2844 queue_push2(&qi, p2, p);
2850 /* package p is independent of the installed ones */
2853 if (!havechoice || !q.count || !qi.count)
2854 continue; /* no choice */
2856 FOR_RULELITERALS(p, pp, r)
2860 /* do extra checking */
2861 for (i = j = 0; i < qi.count; i += 2)
2863 p2 = qi.elements[i];
2866 if (solver_choicerulecheck(solv, p2, r, &m))
2868 /* oops, remove element p from q */
2869 queue_removeelement(&q, qi.elements[i + 1]);
2872 qi.elements[j++] = p2;
2874 queue_truncate(&qi, j);
2875 if (!q.count || !qi.count)
2877 FOR_RULELITERALS(p, pp, r)
2884 /* now check the update rules of the installed package.
2885 * if all packages of the update rules are contained in
2886 * the dependency rules, there's no need to set up the choice rule */
2887 for (i = 0; i < qi.count; i++)
2890 if (!qi.elements[i])
2892 ur = solv->rules + solv->updaterules + (qi.elements[i] - pool->installed->start);
2894 ur = solv->rules + solv->featurerules + (qi.elements[i] - pool->installed->start);
2897 FOR_RULELITERALS(p, pp, ur)
2902 for (j = i + 1; j < qi.count; j++)
2903 if (qi.elements[i] == qi.elements[j])
2906 /* empty map again */
2907 FOR_RULELITERALS(p, pp, r)
2913 printf("skipping choice ");
2914 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + rid);
2919 /* don't add identical rules */
2920 if (lastaddedp == r->p && lastaddedcnt == q.count)
2922 for (i = 0; i < q.count; i++)
2923 if (q.elements[i] != pool->whatprovidesdata[lastaddedd + i])
2926 continue; /* already added that one */
2928 d = q.count ? pool_queuetowhatprovides(pool, &q) : 0;
2932 lastaddedcnt = q.count;
2934 solver_addrule(solv, r->p, d);
2935 queue_push(&solv->weakruleq, solv->nrules - 1);
2936 solv->choicerules_ref[solv->nrules - 1 - solv->choicerules] = rid;
2939 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + rid);
2940 printf("WEAK CHOICE ");
2941 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + solv->nrules - 1);
2948 solv->choicerules_end = solv->nrules;
2949 /* shrink choicerules_ref */
2950 solv->choicerules_ref = solv_realloc2(solv->choicerules_ref, solv->choicerules_end - solv->choicerules, sizeof(Id));
2951 POOL_DEBUG(SOLV_DEBUG_STATS, "choice rule creation took %d ms\n", solv_timems(now));
2954 /* called when a choice rule is disabled by analyze_unsolvable. We also
2955 * have to disable all other choice rules so that the best packages get
2958 solver_disablechoicerules(Solver *solv, Rule *r)
2961 Pool *pool = solv->pool;
2965 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
2966 map_init(&m, pool->nsolvables);
2967 FOR_RULELITERALS(p, pp, or)
2970 FOR_RULELITERALS(p, pp, r)
2973 for (rid = solv->choicerules; rid < solv->choicerules_end; rid++)
2975 r = solv->rules + rid;
2978 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
2979 FOR_RULELITERALS(p, pp, or)
2980 if (p > 0 && MAPTST(&m, p))
2983 solver_disablerule(solv, r);
2988 prune_to_update_targets(Solver *solv, Id *cp, Queue *q)
2992 for (i = j = 0; i < q->count; i++)
2995 for (cp2 = cp; *cp2; cp2++)
2998 q->elements[j++] = p;
3002 queue_truncate(q, j);
3006 prune_to_dup_packages(Solver *solv, Id p, Queue *q)
3009 for (i = j = 0; i < q->count; i++)
3011 Id p = q->elements[i];
3012 if (MAPTST(&solv->dupmap, p))
3013 q->elements[j++] = p;
3015 queue_truncate(q, j);
3019 solver_addbestrules(Solver *solv, int havebestinstalljobs)
3021 Pool *pool = solv->pool;
3024 Repo *installed = solv->installed;
3030 solv->bestrules = solv->nrules;
3033 solv->bestrules_end = solv->nrules;
3040 if (havebestinstalljobs)
3042 for (i = 0; i < solv->job.count; i += 2)
3044 if ((solv->job.elements[i] & (SOLVER_JOBMASK | SOLVER_FORCEBEST)) == (SOLVER_INSTALL | SOLVER_FORCEBEST))
3048 for (j = 0; j < solv->ruletojob.count; j++)
3049 if (solv->ruletojob.elements[j] == i)
3051 if (j == solv->ruletojob.count)
3053 r = solv->rules + solv->jobrules + j;
3055 FOR_RULELITERALS(p2, pp2, r)
3059 continue; /* orphaned */
3060 /* select best packages, just look at prio and version */
3062 policy_filter_unwanted(solv, &q, POLICY_MODE_RECOMMEND);
3063 if (q.count == oldcnt)
3064 continue; /* nothing filtered */
3065 p2 = queue_shift(&q);
3066 solver_addrule(solv, p2, q.count ? pool_queuetowhatprovides(pool, &q) : 0);
3067 queue_push(&r2pkg, -(solv->jobrules + j));
3072 if (solv->bestupdatemap_all || solv->bestupdatemap.size)
3074 FOR_REPO_SOLVABLES(installed, p, s)
3077 if (!solv->updatemap_all && (!solv->updatemap.size || !MAPTST(&solv->updatemap, p - installed->start)))
3079 if (!solv->bestupdatemap_all && (!solv->bestupdatemap.size || !MAPTST(&solv->bestupdatemap, p - installed->start)))
3082 if (solv->bestobeypolicy)
3083 r = solv->rules + solv->updaterules + (p - installed->start);
3086 r = solv->rules + solv->featurerules + (p - installed->start);
3087 if (!r->p) /* identical to update rule? */
3088 r = solv->rules + solv->updaterules + (p - installed->start);
3090 if (solv->multiversionupdaters && (d = solv->multiversionupdaters[p - installed->start]) != 0 && r == solv->rules + solv->updaterules + (p - installed->start))
3092 /* need to check multiversionupdaters */
3093 if (r->p == p) /* be careful with the dup case */
3095 while ((p2 = pool->whatprovidesdata[d++]) != 0)
3100 FOR_RULELITERALS(p2, pp2, r)
3104 if (solv->update_targets && solv->update_targets->elements[p - installed->start])
3105 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[p - installed->start], &q);
3106 if (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
3107 prune_to_dup_packages(solv, p, &q);
3108 /* select best packages, just look at prio and version */
3109 policy_filter_unwanted(solv, &q, POLICY_MODE_RECOMMEND);
3111 continue; /* orphaned */
3112 if (solv->bestobeypolicy)
3114 /* also filter the best of the feature rule packages and add them */
3115 r = solv->rules + solv->featurerules + (p - installed->start);
3120 FOR_RULELITERALS(p2, pp2, r)
3122 queue_push(&q2, p2);
3123 if (solv->update_targets && solv->update_targets->elements[p - installed->start])
3124 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[p - installed->start], &q2);
3125 if (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
3126 prune_to_dup_packages(solv, p, &q);
3127 policy_filter_unwanted(solv, &q2, POLICY_MODE_RECOMMEND);
3128 for (j = 0; j < q2.count; j++)
3129 queue_pushunique(&q, q2.elements[j]);
3132 p2 = queue_shift(&q);
3133 solver_addrule(solv, p2, q.count ? pool_queuetowhatprovides(pool, &q) : 0);
3134 queue_push(&r2pkg, p);
3138 solv->bestrules_pkg = solv_memdup2(r2pkg.elements, r2pkg.count, sizeof(Id));
3139 solv->bestrules_end = solv->nrules;
3145 #undef CLEANDEPSDEBUG
3148 * This functions collects all packages that are looked at
3149 * when a dependency is checked. We need it to "pin" installed
3150 * packages when removing a supplemented package in createcleandepsmap.
3151 * Here's an not uncommon example:
3152 * A contains "Supplements: packageand(B, C)"
3153 * B contains "Requires: A"
3154 * Now if we remove C, the supplements is no longer true,
3155 * thus we also remove A. Without the dep_pkgcheck function, we
3156 * would now also remove B, but this is wrong, as adding back
3157 * C doesn't make the supplements true again. Thus we "pin" B
3159 * There's probably a better way to do this, but I haven't come
3163 dep_pkgcheck(Solver *solv, Id dep, Map *m, Queue *q)
3165 Pool *pool = solv->pool;
3170 Reldep *rd = GETRELDEP(pool, dep);
3173 if (rd->flags == REL_AND)
3175 dep_pkgcheck(solv, rd->name, m, q);
3176 dep_pkgcheck(solv, rd->evr, m, q);
3179 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
3181 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
3185 FOR_PROVIDES(p, pp, dep)
3186 if (!m || MAPTST(m, p))
3191 check_xsupp(Solver *solv, Queue *depq, Id dep)
3193 Pool *pool = solv->pool;
3198 Reldep *rd = GETRELDEP(pool, dep);
3201 if (rd->flags == REL_AND)
3203 if (!check_xsupp(solv, depq, rd->name))
3205 return check_xsupp(solv, depq, rd->evr);
3207 if (rd->flags == REL_OR)
3209 if (check_xsupp(solv, depq, rd->name))
3211 return check_xsupp(solv, depq, rd->evr);
3213 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
3214 return solver_splitprovides(solv, rd->evr);
3215 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
3216 return solver_dep_installed(solv, rd->evr);
3218 if (depq && rd->flags == REL_NAMESPACE)
3221 for (i = 0; i < depq->count; i++)
3222 if (depq->elements[i] == dep || depq->elements[i] == rd->name)
3226 FOR_PROVIDES(p, pp, dep)
3227 if (p == SYSTEMSOLVABLE || pool->solvables[p].repo == solv->installed)
3233 queue_contains(Queue *q, Id id)
3236 for (i = 0; i < q->count; i++)
3237 if (q->elements[i] == id)
3244 * Find all installed packages that are no longer
3245 * needed regarding the current solver job.
3248 * - remove pass: remove all packages that could have
3249 * been dragged in by the obsoleted packages.
3250 * i.e. if package A is obsolete and contains "Requires: B",
3251 * also remove B, as installing A will have pulled in B.
3252 * after this pass, we have a set of still installed packages
3253 * with broken dependencies.
3255 * now add back all packages that the still installed packages
3258 * The cleandeps packages are the packages removed in the first
3259 * pass and not added back in the second pass.
3261 * If we search for unneeded packages (unneeded is true), we
3262 * simply remove all packages except the userinstalled ones in
3266 solver_createcleandepsmap(Solver *solv, Map *cleandepsmap, int unneeded)
3268 Pool *pool = solv->pool;
3269 Repo *installed = solv->installed;
3270 Queue *job = &solv->job;
3275 Id rid, how, what, select;
3277 Id req, *reqp, sup, *supp;
3279 Queue iq, iqcopy, xsuppq;
3282 map_empty(cleandepsmap);
3283 if (!installed || installed->end == installed->start)
3285 map_init(&userinstalled, installed->end - installed->start);
3286 map_init(&im, pool->nsolvables);
3287 map_init(&installedm, pool->nsolvables);
3289 queue_init(&xsuppq);
3291 for (i = 0; i < job->count; i += 2)
3293 how = job->elements[i];
3294 if ((how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
3296 what = job->elements[i + 1];
3297 select = how & SOLVER_SELECTMASK;
3298 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
3299 FOR_REPO_SOLVABLES(installed, p, s)
3300 MAPSET(&userinstalled, p - installed->start);
3301 FOR_JOB_SELECT(p, pp, select, what)
3302 if (pool->solvables[p].repo == installed)
3303 MAPSET(&userinstalled, p - installed->start);
3305 if ((how & (SOLVER_JOBMASK | SOLVER_SELECTMASK)) == (SOLVER_ERASE | SOLVER_SOLVABLE_PROVIDES))
3307 what = job->elements[i + 1];
3310 Reldep *rd = GETRELDEP(pool, what);
3311 if (rd->flags != REL_NAMESPACE)
3315 queue_pushunique(&iq, rd->name);
3318 FOR_PROVIDES(p, pp, what)
3323 queue_pushunique(&iq, what);
3328 /* have special namespace cleandeps erases */
3331 for (ip = solv->installed->start; ip < solv->installed->end; ip++)
3333 s = pool->solvables + ip;
3334 if (s->repo != installed)
3336 if (!s->supplements)
3338 supp = s->repo->idarraydata + s->supplements;
3339 while ((sup = *supp++) != 0)
3340 if (check_xsupp(solv, &iq, sup) && !check_xsupp(solv, 0, sup))
3342 #ifdef CLEANDEPSDEBUG
3343 printf("xsupp %s from %s\n", pool_dep2str(pool, sup), pool_solvid2str(pool, ip));
3345 queue_pushunique(&xsuppq, sup);
3351 /* also add visible patterns to userinstalled for openSUSE */
3355 dataiterator_init(&di, pool, 0, 0, SOLVABLE_ISVISIBLE, 0, 0);
3356 while (dataiterator_step(&di))
3361 s = pool->solvables + di.solvid;
3362 if (!s->repo || !s->requires)
3364 if (s->repo != installed && !pool_installable(pool, s))
3366 if (strncmp(pool_id2str(pool, s->name), "pattern:", 8) != 0)
3368 dp = s->repo->idarraydata + s->requires;
3369 for (dp = s->repo->idarraydata + s->requires; *dp; dp++)
3370 FOR_PROVIDES(p, pp, *dp)
3371 if (pool->solvables[p].repo == installed)
3373 if (strncmp(pool_id2str(pool, pool->solvables[p].name), "pattern", 7) != 0)
3375 MAPSET(&userinstalled, p - installed->start);
3378 dataiterator_free(&di);
3382 /* all products and their buddies are userinstalled */
3383 for (p = installed->start; p < installed->end; p++)
3385 Solvable *s = pool->solvables + p;
3386 if (s->repo != installed)
3388 if (!strncmp("product:", pool_id2str(pool, s->name), 8))
3390 MAPSET(&userinstalled, p - installed->start);
3391 if (pool->nscallback)
3393 Id buddy = pool->nscallback(pool, pool->nscallbackdata, NAMESPACE_PRODUCTBUDDY, p);
3394 if (buddy >= installed->start && buddy < installed->end && pool->solvables[buddy].repo == installed)
3395 MAPSET(&userinstalled, buddy - installed->start);
3401 /* add all positive elements (e.g. locks) to "userinstalled" */
3402 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
3404 r = solv->rules + rid;
3407 i = solv->ruletojob.elements[rid - solv->jobrules];
3408 if ((job->elements[i] & SOLVER_CLEANDEPS) == SOLVER_CLEANDEPS)
3410 FOR_RULELITERALS(p, jp, r)
3411 if (p > 0 && pool->solvables[p].repo == installed)
3412 MAPSET(&userinstalled, p - installed->start);
3415 /* add all cleandeps candidates to iq */
3416 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
3418 r = solv->rules + rid;
3419 if (r->d < 0) /* disabled? */
3421 if (r->d == 0 && r->p < 0 && r->w2 == 0) /* negative assertion (erase job)? */
3424 if (pool->solvables[p].repo != installed)
3426 MAPCLR(&userinstalled, p - installed->start);
3429 i = solv->ruletojob.elements[rid - solv->jobrules];
3430 how = job->elements[i];
3431 if ((how & (SOLVER_JOBMASK|SOLVER_CLEANDEPS)) == (SOLVER_ERASE|SOLVER_CLEANDEPS))
3434 else if (r->p > 0) /* install job */
3438 i = solv->ruletojob.elements[rid - solv->jobrules];
3439 if ((job->elements[i] & SOLVER_CLEANDEPS) == SOLVER_CLEANDEPS)
3441 /* check if the literals all obsolete some installed package */
3445 /* just one installed literal */
3446 if (r->d == 0 && r->w2 == 0 && pool->solvables[r->p].repo == installed)
3448 /* multiversion is bad */
3449 if (solv->multiversion.size && !solv->keepexplicitobsoletes)
3451 FOR_RULELITERALS(p, jp, r)
3452 if (MAPTST(&solv->multiversion, p))
3460 FOR_RULELITERALS(p, jp, r)
3464 queue_truncate(&iq, iqstart); /* abort */
3467 if (pool->solvables[p].repo == installed)
3469 if (iq.count == iqstart)
3473 for (i = iqstart; i < iq.count; i++)
3474 if (iq.elements[i] == p)
3476 queue_truncate(&iq, iqstart);
3482 intersect_obsoletes(solv, p, &iq, iqstart, &om);
3483 if (iq.count == iqstart)
3491 queue_init_clone(&iqcopy, &iq);
3495 if (solv->cleandeps_updatepkgs)
3496 for (i = 0; i < solv->cleandeps_updatepkgs->count; i++)
3497 queue_push(&iq, solv->cleandeps_updatepkgs->elements[i]);
3501 queue_empty(&iq); /* just in case... */
3503 /* clear userinstalled bit for the packages we really want to delete/update */
3504 for (i = 0; i < iq.count; i++)
3507 if (pool->solvables[p].repo != installed)
3509 MAPCLR(&userinstalled, p - installed->start);
3512 for (p = installed->start; p < installed->end; p++)
3514 if (pool->solvables[p].repo != installed)
3516 MAPSET(&installedm, p);
3517 if (unneeded && !MAPTST(&userinstalled, p - installed->start))
3521 MAPSET(&installedm, SYSTEMSOLVABLE);
3522 MAPSET(&im, SYSTEMSOLVABLE);
3524 #ifdef CLEANDEPSDEBUG
3525 printf("REMOVE PASS\n");
3534 /* supplements pass */
3535 for (ip = installed->start; ip < installed->end; ip++)
3537 if (!MAPTST(&installedm, ip))
3539 s = pool->solvables + ip;
3540 if (!s->supplements)
3542 if (!MAPTST(&im, ip))
3544 if (MAPTST(&userinstalled, ip - installed->start))
3546 supp = s->repo->idarraydata + s->supplements;
3547 while ((sup = *supp++) != 0)
3548 if (dep_possible(solv, sup, &im))
3552 supp = s->repo->idarraydata + s->supplements;
3553 while ((sup = *supp++) != 0)
3554 if (dep_possible(solv, sup, &installedm) || (xsuppq.count && queue_contains(&xsuppq, sup)))
3556 /* no longer supplemented, also erase */
3557 int iqcount = iq.count;
3558 /* pin packages, see comment above dep_pkgcheck */
3559 dep_pkgcheck(solv, sup, &im, &iq);
3560 for (i = iqcount; i < iq.count; i++)
3562 Id pqp = iq.elements[i];
3563 if (pool->solvables[pqp].repo == installed)
3564 MAPSET(&userinstalled, pqp - installed->start);
3566 queue_truncate(&iq, iqcount);
3567 #ifdef CLEANDEPSDEBUG
3568 printf("%s supplemented [%s]\n", pool_solvid2str(pool, ip), pool_dep2str(pool, sup));
3570 queue_push(&iq, ip);
3575 break; /* no supplementing package found, we're done */
3577 ip = queue_shift(&iq);
3578 s = pool->solvables + ip;
3579 if (!MAPTST(&im, ip))
3581 if (!MAPTST(&installedm, ip))
3583 if (s->repo == installed && MAPTST(&userinstalled, ip - installed->start))
3586 #ifdef CLEANDEPSDEBUG
3587 printf("removing %s\n", pool_solvable2str(pool, s));
3591 reqp = s->repo->idarraydata + s->requires;
3592 while ((req = *reqp++) != 0)
3594 if (req == SOLVABLE_PREREQMARKER)
3597 /* count number of installed packages that match */
3599 FOR_PROVIDES(p, pp, req)
3600 if (MAPTST(&installedm, p))
3605 FOR_PROVIDES(p, pp, req)
3607 if (p != SYSTEMSOLVABLE && MAPTST(&im, p))
3609 #ifdef CLEANDEPSDEBUG
3610 printf("%s requires %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
3619 reqp = s->repo->idarraydata + s->recommends;
3620 while ((req = *reqp++) != 0)
3624 FOR_PROVIDES(p, pp, req)
3625 if (MAPTST(&installedm, p))
3630 FOR_PROVIDES(p, pp, req)
3632 if (p != SYSTEMSOLVABLE && MAPTST(&im, p))
3634 #ifdef CLEANDEPSDEBUG
3635 printf("%s recommends %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
3644 /* turn userinstalled into remove set for pruning */
3645 map_empty(&userinstalled);
3646 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
3648 r = solv->rules + rid;
3649 if (r->p >= 0 || r->d != 0 || r->w2 != 0)
3650 continue; /* disabled or not erase */
3653 if (pool->solvables[p].repo == installed)
3654 MAPSET(&userinstalled, p - installed->start);
3656 if (!unneeded && solv->cleandeps_updatepkgs)
3658 for (i = 0; i < solv->cleandeps_updatepkgs->count; i++)
3660 p = solv->cleandeps_updatepkgs->elements[i];
3661 if (pool->solvables[p].repo == installed)
3662 MAPSET(&userinstalled, p - installed->start);
3665 MAPSET(&im, SYSTEMSOLVABLE); /* in case we cleared it above */
3666 for (p = installed->start; p < installed->end; p++)
3669 for (rid = solv->jobrules; rid < solv->jobrules_end; rid++)
3671 r = solv->rules + rid;
3674 FOR_RULELITERALS(p, jp, r)
3678 /* also put directly addressed packages on the install queue
3679 * so we can mark patterns as installed */
3680 for (i = 0; i < job->count; i += 2)
3682 how = job->elements[i];
3683 if ((how & SOLVER_JOBMASK) == SOLVER_USERINSTALLED)
3685 what = job->elements[i + 1];
3686 select = how & SOLVER_SELECTMASK;
3687 if (select == SOLVER_SOLVABLE && pool->solvables[what].repo != installed)
3688 queue_push(&iq, what);
3692 #ifdef CLEANDEPSDEBUG
3693 printf("ADDBACK PASS\n");
3699 /* supplements pass */
3700 for (ip = installed->start; ip < installed->end; ip++)
3702 if (!MAPTST(&installedm, ip))
3704 if (MAPTST(&userinstalled, ip - installed->start))
3706 s = pool->solvables + ip;
3707 if (!s->supplements)
3709 if (MAPTST(&im, ip))
3711 supp = s->repo->idarraydata + s->supplements;
3712 while ((sup = *supp++) != 0)
3713 if (dep_possible(solv, sup, &im))
3717 #ifdef CLEANDEPSDEBUG
3718 printf("%s supplemented\n", pool_solvid2str(pool, ip));
3721 queue_push(&iq, ip);
3727 ip = queue_shift(&iq);
3728 s = pool->solvables + ip;
3729 #ifdef CLEANDEPSDEBUG
3730 printf("adding back %s\n", pool_solvable2str(pool, s));
3734 reqp = s->repo->idarraydata + s->requires;
3735 while ((req = *reqp++) != 0)
3737 FOR_PROVIDES(p, pp, req)
3742 FOR_PROVIDES(p, pp, req)
3744 if (!MAPTST(&im, p) && MAPTST(&installedm, p))
3748 if (MAPTST(&userinstalled, p - installed->start))
3750 #ifdef CLEANDEPSDEBUG
3751 printf("%s requires %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
3761 reqp = s->repo->idarraydata + s->recommends;
3762 while ((req = *reqp++) != 0)
3764 FOR_PROVIDES(p, pp, req)
3769 FOR_PROVIDES(p, pp, req)
3771 if (!MAPTST(&im, p) && MAPTST(&installedm, p))
3775 if (MAPTST(&userinstalled, p - installed->start))
3777 #ifdef CLEANDEPSDEBUG
3778 printf("%s recommends %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
3789 /* make sure the updatepkgs and mistakes are not in the cleandeps map */
3790 if (solv->cleandeps_updatepkgs)
3791 for (i = 0; i < solv->cleandeps_updatepkgs->count; i++)
3792 MAPSET(&im, solv->cleandeps_updatepkgs->elements[i]);
3793 if (solv->cleandeps_mistakes)
3794 for (i = 0; i < solv->cleandeps_mistakes->count; i++)
3795 MAPSET(&im, solv->cleandeps_mistakes->elements[i]);
3796 /* also remove original iq packages */
3797 for (i = 0; i < iqcopy.count; i++)
3798 MAPSET(&im, iqcopy.elements[i]);
3799 queue_free(&iqcopy);
3800 for (p = installed->start; p < installed->end; p++)
3802 if (pool->solvables[p].repo != installed)
3804 if (!MAPTST(&im, p))
3805 MAPSET(cleandepsmap, p - installed->start);
3808 map_free(&installedm);
3809 map_free(&userinstalled);
3810 queue_free(&xsuppq);
3811 #ifdef CLEANDEPSDEBUG
3812 printf("=== final cleandeps map:\n");
3813 for (p = installed->start; p < installed->end; p++)
3814 if (MAPTST(cleandepsmap, p - installed->start))
3815 printf(" - %s\n", pool_solvid2str(pool, p));
3828 /* Tarjan's SCC algorithm, slightly modifed */
3830 trj_visit(struct trj_data *trj, Id node)
3833 Queue *edges = trj->edges;
3834 Id nnode, myidx, stackstart;
3837 low[node] = myidx = trj->idx++;
3838 low[(stackstart = trj->nstack++)] = node;
3839 for (i = edges->elements[node]; (nnode = edges->elements[i]) != 0; i++)
3844 if (!edges->elements[edges->elements[nnode]])
3850 trj_visit(trj, nnode);
3855 if (l < trj->firstidx)
3858 for (k = l; low[low[k]] == l; k++)
3861 else if (l < low[node])
3864 if (low[node] == myidx)
3866 if (myidx != trj->firstidx)
3868 for (i = stackstart; i < trj->nstack; i++)
3869 low[low[i]] = myidx;
3870 trj->nstack = stackstart;
3876 solver_get_unneeded(Solver *solv, Queue *unneededq, int filtered)
3878 Repo *installed = solv->installed;
3882 queue_empty(unneededq);
3883 if (!installed || installed->end == installed->start)
3886 map_init(&cleandepsmap, installed->end - installed->start);
3887 solver_createcleandepsmap(solv, &cleandepsmap, 1);
3888 for (i = installed->start; i < installed->end; i++)
3889 if (MAPTST(&cleandepsmap, i - installed->start))
3890 queue_push(unneededq, i);
3892 if (filtered && unneededq->count > 1)
3894 Pool *pool = solv->pool;
3898 int j, pass, count = unneededq->count;
3901 map_init(&installedm, pool->nsolvables);
3902 for (i = installed->start; i < installed->end; i++)
3903 if (pool->solvables[i].repo == installed)
3904 MAPSET(&installedm, i);
3906 nrequires = solv_calloc(count, sizeof(Id));
3908 queue_prealloc(&edges, count * 4 + 10); /* pre-size */
3911 * Go through the solvables in the nodes queue and create edges for
3912 * all requires/recommends/supplements between the nodes.
3913 * The edges are stored in the edges queue, we add 1 to the node
3914 * index so that nodes in the edges queue are != 0 and we can
3915 * terminate the edge list with 0.
3916 * Thus for node element 5, the edges are stored starting at
3917 * edges.elements[6] and are 0-terminated.
3919 /* leave first element zero to make things easier */
3920 /* also add trailing zero */
3921 queue_insertn(&edges, 0, 1 + count + 1, 0);
3923 /* first requires and recommends */
3924 for (i = 0; i < count; i++)
3926 Solvable *s = pool->solvables + unneededq->elements[i];
3927 edges.elements[i + 1] = edges.count;
3928 for (pass = 0; pass < 2; pass++)
3931 unsigned int off = pass == 0 ? s->requires : s->recommends;
3934 for (dp = s->repo->idarraydata + off; *dp; dp++)
3935 FOR_PROVIDES(p, pp, *dp)
3937 Solvable *sp = pool->solvables + p;
3938 if (s == sp || sp->repo != installed || !MAPTST(&cleandepsmap, p - installed->start))
3940 for (j = 0; j < count; j++)
3941 if (p == unneededq->elements[j])
3945 if (num && edges.elements[edges.count - 1] == j + 1)
3947 queue_push(&edges, j + 1);
3953 queue_push(&edges, 0);
3956 printf("requires + recommends\n");
3957 for (i = 0; i < count; i++)
3960 printf(" %s (%d requires):\n", pool_solvid2str(pool, unneededq->elements[i]), nrequires[i]);
3961 for (j = edges.elements[i + 1]; edges.elements[j]; j++)
3962 printf(" - %s\n", pool_solvid2str(pool, unneededq->elements[edges.elements[j] - 1]));
3966 /* then add supplements */
3967 for (i = 0; i < count; i++)
3969 Solvable *s = pool->solvables + unneededq->elements[i];
3974 for (dp = s->repo->idarraydata + s->supplements; *dp; dp++)
3975 if (dep_possible(solv, *dp, &installedm))
3979 queue_init_buffer(&iq, iqbuf, sizeof(iqbuf)/sizeof(*iqbuf));
3980 dep_pkgcheck(solv, *dp, 0, &iq);
3981 for (k = 0; k < iq.count; k++)
3983 Id p = iq.elements[k];
3984 Solvable *sp = pool->solvables + p;
3985 if (p == unneededq->elements[i] || sp->repo != installed || !MAPTST(&cleandepsmap, p - installed->start))
3987 for (j = 0; j < count; j++)
3988 if (p == unneededq->elements[j])
3990 /* now add edge from j + 1 to i + 1 */
3991 queue_insert(&edges, edges.elements[j + 1] + nrequires[j], i + 1);
3992 /* addapt following edge pointers */
3993 for (k = j + 2; k < count + 2; k++)
3994 edges.elements[k]++;
4002 printf("+ supplements\n");
4003 for (i = 0; i < count; i++)
4006 printf(" %s (%d requires):\n", pool_solvid2str(pool, unneededq->elements[i]), nrequires[i]);
4007 for (j = edges.elements[i + 1]; edges.elements[j]; j++)
4008 printf(" - %s\n", pool_solvid2str(pool, unneededq->elements[edges.elements[j] - 1]));
4011 map_free(&installedm);
4013 /* now run SCC algo two times, first with requires+recommends+supplements,
4014 * then again without the requires. We run it the second time to get rid
4015 * of packages that got dragged in via recommends/supplements */
4017 * low will contain the result of the SCC search.
4018 * it must be of at least size 2 * (count + 1) and
4019 * must be zero initialized.
4021 * 0 low low ... low stack stack ...stack 0
4024 low = solv_calloc(count + 1, 2 * sizeof(Id));
4025 for (pass = 0; pass < 2; pass++)
4027 struct trj_data trj;
4030 memset(low, 0, (count + 1) * (2 * sizeof(Id)));
4031 for (i = 0; i < count; i++)
4033 edges.elements[i + 1] += nrequires[i];
4034 if (!unneededq->elements[i])
4035 low[i + 1] = -1; /* ignore this node */
4040 trj.idx = count + 1; /* stack starts here */
4041 for (i = 1; i <= count; i++)
4045 if (edges.elements[edges.elements[i]])
4047 trj.firstidx = trj.nstack = trj.idx;
4052 Id myidx = trj.idx++;
4057 /* prune packages */
4058 for (i = 0; i < count; i++)
4059 if (low[i + 1] <= 0)
4060 unneededq->elements[i] = 0;
4063 solv_free(nrequires);
4066 /* finally remove all pruned entries from unneededq */
4067 for (i = j = 0; i < count; i++)
4068 if (unneededq->elements[i])
4069 unneededq->elements[j++] = unneededq->elements[i];
4070 queue_truncate(unneededq, j);
4072 map_free(&cleandepsmap);