2 * Copyright (c) 2007-2017, SUSE 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);
37 is_otherproviders_dep(Pool *pool, Id dep)
41 Reldep *rd = GETRELDEP(pool, dep);
42 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
48 /********************************************************************
52 * - unify rules, remove duplicates
55 /*-------------------------------------------------------------------
57 * compare rules for unification sort
62 unifyrules_sortcmp(const void *ap, const void *bp, void *dp)
72 return x; /* p differs */
75 if (a->d == 0 && b->d == 0) /* both assertions or binary */
78 if (a->d == 0) /* a is assertion or binary, b not */
80 x = a->w2 - pool->whatprovidesdata[b->d];
84 if (b->d == 0) /* b is assertion or binary, a not */
86 x = pool->whatprovidesdata[a->d] - b->w2;
93 /* compare whatprovidesdata */
94 ad = pool->whatprovidesdata + a->d;
95 bd = pool->whatprovidesdata + b->d;
97 if ((x = *ad++ - *bd++) != 0)
103 solver_rulecmp(Solver *solv, Rule *r1, Rule *r2)
105 return unifyrules_sortcmp(r1, r2, solv->pool);
109 /*-------------------------------------------------------------------
112 * go over all rules and remove duplicates
116 solver_unifyrules(Solver *solv)
118 Pool *pool = solv->pool;
122 if (solv->nrules <= 2) /* nothing to unify */
125 if (solv->recommendsruleq)
127 /* mis-use n2 as recommends rule marker */
128 for (i = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
130 for (i = 0; i < solv->recommendsruleq->count; i++)
131 solv->rules[solv->recommendsruleq->elements[i]].n2 = 1;
134 /* sort rules first */
135 solv_sort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp, solv->pool);
139 for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
141 if (jr && !unifyrules_sortcmp(ir, jr, pool))
143 jr->n2 &= ir->n2; /* bitwise-and recommends marker */
144 continue; /* prune! */
146 jr = solv->rules + j++; /* keep! */
151 /* reduced count from nrules to j rules */
152 POOL_DEBUG(SOLV_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
154 /* adapt rule buffer */
155 solver_shrinkrules(solv, j);
157 if (solv->recommendsruleq)
159 /* rebuild recommendsruleq */
160 queue_empty(solv->recommendsruleq);
161 for (i = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
165 queue_push(solv->recommendsruleq, i);
170 * debug: log rule statistics
172 IF_POOLDEBUG (SOLV_DEBUG_STATS)
179 for (i = 1; i < solv->nrules; i++)
186 dp = solv->pool->whatprovidesdata + r->d;
191 POOL_DEBUG(SOLV_DEBUG_STATS, " binary: %d\n", binr);
192 POOL_DEBUG(SOLV_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
203 hashrule(Solver *solv, Id p, Id d, int n)
205 unsigned int x = (unsigned int)p;
209 return (x * 37) ^ (unsigned int)d;
210 dp = solv->pool->whatprovidesdata + d;
212 x = (x * 37) ^ (unsigned int)*dp++;
218 /*-------------------------------------------------------------------
225 * A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
227 * p < 0 : pkg id of A
228 * d > 0 : Offset in whatprovidesdata (list of providers of b)
230 * A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
231 * p < 0 : pkg id of A
232 * p2 < 0 : Id of solvable (e.g. B1)
234 * d == 0, p2 == 0: unary rule, assertion => (A) or (-A)
236 * Install: p > 0, d = 0 (A) user requested install
237 * Remove: p < 0, d = 0 (-A) user requested remove (also: uninstallable)
238 * Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
239 * Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
240 * Conflicts: p < 0, p2 < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
241 * also used for obsoletes
242 * No-op ?: p = 0, d = 0 (null) (used as placeholder in update/feature rules)
246 * Direct assertion (no watch needed) --> d = 0, w1 = p, w2 = 0
247 * Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
248 * every other : w1 = p, w2 = whatprovidesdata[d];
250 * always returns a rule for non-pkg rules
254 solver_addrule(Solver *solv, Id p, Id p2, Id d)
256 Pool *pool = solv->pool;
261 assert(!p2 && d > 0);
262 if (!pool->whatprovidesdata[d])
264 else if (!pool->whatprovidesdata[d + 1])
266 p2 = pool->whatprovidesdata[d];
271 /* now we have two cases:
272 * 1 or 2 literals: d = 0, p, p2 contain the literals
273 * 3 or more literals: d > 0, p2 == 0, d is offset into whatprovidesdata
276 /* it often happenes that requires lead to adding the same pkg rule
277 * multiple times, so we prune those duplicates right away to make
278 * the work for unifyrules a bit easier */
279 if (!solv->pkgrules_end) /* we add pkg rules */
281 r = solv->rules + solv->lastpkgrule;
285 /* check if rule is identical */
291 dp2 = pool->whatprovidesdata + r->d;
292 for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
298 /* check if rule is self-fulfilling */
299 for (dp = pool->whatprovidesdata + d; *dp; dp++)
301 return 0; /* rule is self-fulfilling */
307 Id o = p; /* switch p1 and p2 */
311 if (r->p == p && !r->d && r->w2 == p2)
314 return 0; /* rule is self-fulfilling */
316 solv->lastpkgrule = solv->nrules;
319 solv->rules = solv_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
320 r = solv->rules + solv->nrules++; /* point to rule space */
324 r->w2 = d ? pool->whatprovidesdata[d] : p2;
327 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
329 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, " Add rule: ");
330 solver_printrule(solv, SOLV_DEBUG_RULE_CREATION, r);
337 solver_shrinkrules(Solver *solv, int nrules)
339 solv->nrules = nrules;
340 solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
341 solv->lastpkgrule = 0;
344 /******************************************************************************
346 *** pkg rule part: create rules representing the package dependencies
351 * special multiversion patch conflict handling:
352 * a patch conflict is also satisfied if some other
353 * version with the same name/arch that doesn't conflict
354 * gets installed. The generated rule is thus:
355 * -patch|-cpack|opack1|opack2|...
358 makemultiversionconflict(Solver *solv, Id n, Id con)
360 Pool *pool = solv->pool;
365 sn = pool->solvables + n;
366 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
368 FOR_PROVIDES(p, pp, sn->name)
370 s = pool->solvables + p;
371 if (s->name != sn->name || s->arch != sn->arch)
373 if (!MAPTST(&solv->multiversion, p))
375 if (pool_match_nevr(pool, pool->solvables + p, con))
377 /* here we have a multiversion solvable that doesn't conflict */
378 /* thus we're not in conflict if it is installed */
382 n = 0; /* no other package found, normal conflict handling */
384 n = pool_queuetowhatprovides(pool, &q);
390 addpkgrule(Solver *solv, Id p, Id p2, Id d, int type, Id dep)
392 if (!solv->ruleinfoq)
393 solver_addrule(solv, p, p2, d);
395 addpkgruleinfo(solv, p, p2, d, type, dep);
398 #ifdef ENABLE_LINKED_PKGS
401 addlinks_cmp(const void *ap, const void *bp, void *dp)
406 Solvable *sa = pool->solvables + a;
407 Solvable *sb = pool->solvables + b;
408 if (sa->name != sb->name)
409 return sa->name - sb->name;
414 addlinks(Solver *solv, Solvable *s, Id req, Queue *qr, Id prv, Queue *qp, Map *m, Queue *workq)
416 Pool *pool = solv->pool;
421 solv_sort(qp->elements, qp->count, sizeof(Id), addlinks_cmp, pool);
423 printf("ADDLINKS %s\n -> %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, req));
424 for (i = 0; i < qr->count; i++)
425 printf(" - %s\n", pool_solvid2str(pool, qr->elements[i]));
426 printf(" <- %s\n", pool_dep2str(pool, prv));
427 for (i = 0; i < qp->count; i++)
428 printf(" - %s\n", pool_solvid2str(pool, qp->elements[i]));
432 addpkgrule(solv, -(s - pool->solvables), qr->elements[0], 0, SOLVER_RULE_PKG_REQUIRES, req);
434 addpkgrule(solv, -(s - pool->solvables), 0, pool_queuetowhatprovides(pool, qr), SOLVER_RULE_PKG_REQUIRES, req);
438 for (i = j = 0; i < qp->count; i = j)
440 Id d = pool->solvables[qp->elements[i]].name;
441 for (j = i + 1; j < qp->count; j++)
442 if (d != pool->solvables[qp->elements[j]].name)
444 d = pool_ids2whatprovides(pool, qp->elements + i, j - i);
445 for (i = 0; i < qr->count; i++)
446 addpkgrule(solv, -qr->elements[i], 0, d, SOLVER_RULE_PKG_REQUIRES, prv);
451 for (i = 0; i < qr->count; i++)
452 addpkgrule(solv, -qr->elements[i], qp->elements[0], 0, SOLVER_RULE_PKG_REQUIRES, prv);
455 return; /* nothing more to do if called from getpkgruleinfos() */
456 for (i = 0; i < qr->count; i++)
457 if (!MAPTST(m, qr->elements[i]))
458 queue_push(workq, qr->elements[i]);
459 for (i = 0; i < qp->count; i++)
460 if (!MAPTST(m, qp->elements[i]))
461 queue_push(workq, qp->elements[i]);
462 if (solv->installed && s->repo == solv->installed)
464 Repo *installed = solv->installed;
465 /* record installed buddies */
466 if (!solv->instbuddy)
467 solv->instbuddy = solv_calloc(installed->end - installed->start, sizeof(Id));
469 solv->instbuddy[s - pool->solvables - installed->start] = qr->elements[0];
470 for (i = 0; i < qr->count; i++)
472 Id p = qr->elements[i];
473 if (pool->solvables[p].repo != installed)
475 if (qp->count > 1 || (solv->instbuddy[p - installed->start] != 0 && solv->instbuddy[p - installed->start] != s - pool->solvables))
476 solv->instbuddy[p - installed->start] = 1; /* 1: ambiguous buddy */
478 solv->instbuddy[p - installed->start] = s - pool->solvables;
484 add_package_link(Solver *solv, Solvable *s, Map *m, Queue *workq)
490 find_package_link(solv->pool, s, &req, &qr, &prv, &qp);
492 addlinks(solv, s, req, &qr, prv, &qp, m, workq);
499 #ifdef ENABLE_COMPLEX_DEPS
503 suse_isptf(Pool *pool, Solvable *s)
505 if (!strncmp("ptf-", pool_id2str(pool, s->name), 4))
512 add_complex_deprules(Solver *solv, Id p, Id dep, int type, int dontfix, Queue *workq, Map *m)
514 Pool *pool = solv->pool;
515 Repo *installed = solv->installed;
520 flags = dontfix ? CPLXDEPS_DONTFIX : 0;
521 /* CNF expansion for requires, DNF + INVERT expansion for conflicts */
522 if (type == SOLVER_RULE_PKG_CONFLICTS)
523 flags |= CPLXDEPS_TODNF | CPLXDEPS_EXPAND | CPLXDEPS_INVERT;
525 if (type == SOLVER_RULE_PKG_REQUIRES && suse_isptf(pool, pool->solvables + p))
526 flags |= CPLXDEPS_NAME; /* do not match provides */
529 i = pool_normalize_complex_dep(pool, dep, &bq, flags);
530 /* handle special cases */
535 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "ignoring broken dependency %s of installed package %s\n", pool_dep2str(pool, dep), pool_solvid2str(pool, p));
539 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", pool_solvid2str(pool, p), p, pool_dep2str(pool, dep));
540 addpkgrule(solv, -p, 0, 0, type == SOLVER_RULE_PKG_REQUIRES ? SOLVER_RULE_PKG_NOTHING_PROVIDES_DEP : type, dep);
551 /* go through all blocks and add a rule for each block */
552 for (i = 0; i < bq.count; i++)
556 if (bq.elements[i] == pool->nsolvables)
558 /* conventional requires (cannot be a conflicts as they have been expanded) */
559 Id *dp = pool->whatprovidesdata + bq.elements[i + 1];
563 for (j = 0; dp[j] != 0; j++)
564 if (pool->solvables[dp[j]].repo == installed)
565 break; /* provider was installed */
569 if (type == SOLVER_RULE_PKG_RECOMMENDS && !*dp)
571 /* check if the rule contains both p and -p */
572 for (j = 0; dp[j] != 0; j++)
577 addpkgrule(solv, -p, 0, dp - pool->whatprovidesdata, type, dep);
578 /* push all non-visited providers on the work queue */
582 queue_push(workq, *dp);
585 if (!bq.elements[i + 1])
587 Id p2 = bq.elements[i++];
588 /* simple rule with just two literals, we'll add a (-p, p2) rule */
591 if (p2 < 0 && pool->solvables[-p2].repo == installed)
593 if (p2 > 0 && pool->solvables[p2].repo != installed)
598 if (type == SOLVER_RULE_PKG_CONFLICTS)
600 if (pool->forbidselfconflicts && !is_otherproviders_dep(pool, dep))
601 addpkgrule(solv, -p, 0, 0, SOLVER_RULE_PKG_SELF_CONFLICT, dep);
604 addpkgrule(solv, -p, 0, 0, type, dep);
607 /* check if the rule contains both p and -p */
610 addpkgrule(solv, -p, p2, 0, type, dep);
611 if (m && p2 > 0 && !MAPTST(m, p2))
612 queue_push(workq, p2);
619 qele = bq.elements + i;
621 while (bq.elements[i])
626 for (j = 0; j < qcnt; j++)
628 if (qele[j] > 0 && pool->solvables[qele[j]].repo == installed)
630 if (qele[j] < 0 && pool->solvables[-qele[j]].repo != installed)
636 /* add -p to (ordered) rule (overwriting the trailing zero) */
639 if (j == qcnt || qele[j] > -p)
642 memmove(qele + j + 1, qele + j, (qcnt - j) * sizeof(Id));
650 /* check if the rule contains both p and -p */
651 for (j = 0; j < qcnt; j++)
656 d = pool_ids2whatprovides(pool, qele + 1, qcnt - 1);
657 if (solv->ruleinfoq && qele[0] != p)
659 int oldcount = solv->ruleinfoq->count;
660 addpkgrule(solv, qele[0], 0, d, type, dep);
661 /* fixup from element of ruleinfo */
662 if (solv->ruleinfoq->count > oldcount)
663 solv->ruleinfoq->elements[oldcount + 1] = p;
666 addpkgrule(solv, qele[0], 0, d, type, dep);
668 for (j = 0; j < qcnt; j++)
669 if (qele[j] > 0 && !MAPTST(m, qele[j]))
670 queue_push(workq, qele[j]);
680 add_conda_constrains_rule(Solver *solv, Id n, Id dep, int dontfix)
682 Pool *pool = solv->pool;
687 rd = GETRELDEP(pool, dep);
688 pdep = pool_whatprovides(pool, dep);
689 FOR_PROVIDES(p, pp, rd->name)
694 if (dontfix && pool->solvables[p].repo == solv->installed)
696 while ((p2 = pool->whatprovidesdata[pdep]) != 0 && p2 < p)
701 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_CONSTRAINS, dep);
706 /*-------------------------------------------------------------------
708 * add dependency rules for solvable
710 * s: Solvable for which to add rules
711 * m: m[s] = 1 for solvables which have rules, prevent rule duplication
713 * Algorithm: 'visit all nodes of a graph'. The graph nodes are
714 * solvables, the edges their dependencies.
715 * Starting from an installed solvable, this will create all rules
716 * representing the graph created by the solvables dependencies.
718 * for unfulfilled requirements, conflicts, obsoletes,....
719 * add a negative assertion for solvables that are not installable
721 * It will also create rules for all solvables referenced by 's'
722 * i.e. descend to all providers of requirements of 's'
727 solver_addpkgrulesforsolvable(Solver *solv, Solvable *s, Map *m)
729 Pool *pool = solv->pool;
730 Repo *installed = solv->installed;
732 Queue workq; /* list of solvables we still have to work on */
734 Queue depq; /* list of pre-req ids to ignore */
738 int dontfix; /* ignore dependency errors for installed solvables */
744 Id p, pp; /* whatprovides loops */
745 Id *dp; /* ptr to 'whatprovides' */
746 Id n; /* Id for current solvable 's' */
748 queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
749 queue_push(&workq, s - pool->solvables); /* push solvable Id to work queue */
751 queue_init_buffer(&depq, depqbuf, sizeof(depqbuf)/sizeof(*depqbuf));
753 /* loop until there's no more work left */
758 * s: Pointer to solvable
761 n = queue_shift(&workq); /* 'pop' next solvable to work on from queue */
764 if (MAPTST(m, n)) /* continue if already visited */
766 MAPSET(m, n); /* mark as visited */
769 s = pool->solvables + n;
772 if (installed /* Installed system available */
773 && s->repo == installed /* solvable is installed */
774 && !solv->fixmap_all /* NOT repair errors in dependency graph */
775 && !(solv->fixmap.size && MAPTST(&solv->fixmap, n - installed->start)))
777 dontfix = 1; /* dont care about broken deps */
782 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC
783 ? pool_disabled_solvable(pool, s)
784 : !pool_installable(pool, s))
786 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", pool_solvid2str(pool, n), n);
787 addpkgrule(solv, -n, 0, 0, SOLVER_RULE_PKG_NOT_INSTALLABLE, 0);
791 #ifdef ENABLE_LINKED_PKGS
792 /* add pseudo-package <-> real-package links */
793 if (has_package_link(pool, s))
794 add_package_link(solv, s, m, &workq);
797 /*-----------------------------------------
798 * check requires of s
804 reqp = s->repo->idarraydata + s->requires;
805 while ((req = *reqp++) != 0) /* go through all requires */
807 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
809 if (installed && s->repo == installed)
811 solvable_lookup_idarray(s, SOLVABLE_PREREQ_IGNOREINST, &depq);
812 filterpre = depq.count;
818 /* check if this id is filtered. assumes that depq.count is small */
819 for (i = 0; i < depq.count; i++)
820 if (req == depq.elements[i])
824 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s: ignoring filtered pre-req dependency %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, req));
829 #ifdef ENABLE_COMPLEX_DEPS
830 if (pool_is_complex_dep(pool, req))
832 /* we have AND/COND deps, normalize */
833 add_complex_deprules(solv, n, req, SOLVER_RULE_PKG_REQUIRES, dontfix, &workq, m);
838 /* find list of solvables providing 'req' */
839 dp = pool_whatprovides_ptr(pool, req);
841 if (*dp == SYSTEMSOLVABLE) /* always installed */
846 /* the strategy here is to not insist on dependencies
847 * that are already broken. so if we find one provider
848 * that was already installed, we know that the
849 * dependency was not broken before so we enforce it */
850 for (i = 0; (p = dp[i]) != 0; i++)
851 if (pool->solvables[p].repo == installed)
852 break; /* found installed provider */
855 /* didn't find an installed provider: previously broken dependency */
856 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", pool_dep2str(pool, req), pool_solvable2str(pool, s));
863 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", pool_solvid2str(pool, n), n, pool_dep2str(pool, req));
864 addpkgrule(solv, -n, 0, 0, SOLVER_RULE_PKG_NOTHING_PROVIDES_DEP, req);
868 for (i = 0; dp[i] != 0; i++)
872 continue; /* provided by itself, no need to add rule */
874 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
876 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION," %s requires %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, req));
877 for (i = 0; dp[i]; i++)
878 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, " provided by %s\n", pool_solvid2str(pool, dp[i]));
881 /* add 'requires' dependency */
882 /* rule: (-requestor|provider1|provider2|...|providerN) */
883 addpkgrule(solv, -n, 0, dp - pool->whatprovidesdata, SOLVER_RULE_PKG_REQUIRES, req);
885 /* push all non-visited providers on the work queue */
889 queue_push(&workq, *dp);
893 if (s->recommends && solv->strongrecommends)
895 int start = solv->nrules;
896 solv->lastpkgrule = 0;
897 reqp = s->repo->idarraydata + s->recommends;
898 while ((req = *reqp++) != 0) /* go through all recommends */
900 #ifdef ENABLE_COMPLEX_DEPS
901 if (pool_is_complex_dep(pool, req))
903 /* we have AND/COND deps, normalize */
904 add_complex_deprules(solv, n, req, SOLVER_RULE_PKG_RECOMMENDS, dontfix, &workq, m);
908 dp = pool_whatprovides_ptr(pool, req);
909 if (*dp == SYSTEMSOLVABLE || !*dp) /* always installed or not installable */
911 for (i = 0; dp[i] != 0; i++)
915 continue; /* provided by itself, no need to add rule */
916 addpkgrule(solv, -n, 0, dp - pool->whatprovidesdata, SOLVER_RULE_PKG_RECOMMENDS, req);
920 queue_push(&workq, *dp);
922 if (!solv->ruleinfoq && start < solv->nrules)
924 if (!solv->recommendsruleq)
926 solv->recommendsruleq = solv_calloc(1, sizeof(Queue));
927 queue_init(solv->recommendsruleq);
929 for (i = start; i < solv->nrules; i++)
930 queue_push(solv->recommendsruleq, i);
931 solv->lastpkgrule = 0;
936 if (pool->disttype == DISTTYPE_CONDA)
938 solvable_lookup_idarray(s, SOLVABLE_CONSTRAINS, &depq);
939 for (i = 0; i < depq.count; i++)
940 add_conda_constrains_rule(solv, n, depq.elements[i], dontfix);
944 /* that's all we check for src packages */
945 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
948 /*-----------------------------------------
949 * check conflicts of s
956 /* we treat conflicts in patches a bit differen:
958 * - multiversion handling
959 * XXX: we should really handle this different, looking
960 * at the name is a bad hack
962 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
964 conp = s->repo->idarraydata + s->conflicts;
965 /* foreach conflicts of 's' */
966 while ((con = *conp++) != 0)
968 #ifdef ENABLE_COMPLEX_DEPS
969 if (!ispatch && pool_is_complex_dep(pool, con))
971 /* we have AND/COND deps, normalize */
972 add_complex_deprules(solv, n, con, SOLVER_RULE_PKG_CONFLICTS, dontfix, &workq, m);
976 /* foreach providers of a conflict of 's' */
977 FOR_PROVIDES(p, pp, con)
979 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, con))
981 /* dontfix: dont care about conflicts with already installed packs */
982 if (dontfix && pool->solvables[p].repo == installed)
984 if (p == n) /* p == n: self conflict */
986 if (!pool->forbidselfconflicts || is_otherproviders_dep(pool, con))
988 addpkgrule(solv, -n, 0, 0, SOLVER_RULE_PKG_SELF_CONFLICT, con);
991 if (ispatch && solv->multiversion.size && MAPTST(&solv->multiversion, p) && ISRELDEP(con))
993 /* our patch conflicts with a multiversion package */
994 Id d = makemultiversionconflict(solv, p, con);
997 addpkgrule(solv, -n, 0, d, SOLVER_RULE_PKG_CONFLICTS, con);
1001 if (p == SYSTEMSOLVABLE)
1003 /* rule: -n|-p: either solvable _or_ provider of conflict */
1004 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_CONFLICTS, con);
1009 /*-----------------------------------------
1010 * check obsoletes and implicit obsoletes of a package
1011 * if ignoreinstalledsobsoletes is not set, we're also checking
1012 * obsoletes of installed packages (like newer rpm versions)
1014 if ((!installed || s->repo != installed) || !pool->noinstalledobsoletes)
1016 int multi = solv->multiversion.size && MAPTST(&solv->multiversion, n);
1017 int isinstalled = (installed && s->repo == installed);
1018 if (s->obsoletes && (!multi || solv->keepexplicitobsoletes))
1020 obsp = s->repo->idarraydata + s->obsoletes;
1021 /* foreach obsoletes */
1022 while ((obs = *obsp++) != 0)
1024 /* foreach provider of an obsoletes of 's' */
1025 FOR_PROVIDES(p, pp, obs)
1027 Solvable *ps = pool->solvables + p;
1030 if (isinstalled && dontfix && ps->repo == installed)
1031 continue; /* don't repair installed/installed problems */
1032 if (!pool->obsoleteusesprovides /* obsoletes are matched names, not provides */
1033 && !pool_match_nevr(pool, ps, obs))
1035 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1037 if (p == SYSTEMSOLVABLE)
1040 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_OBSOLETES, obs);
1042 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_INSTALLED_OBSOLETES, obs);
1046 /* check implicit obsoletes
1047 * for installed packages we only need to check installed/installed problems (and
1048 * only when dontfix is not set), as the others are picked up when looking at the
1049 * uninstalled package.
1051 if (!isinstalled || !dontfix)
1053 FOR_PROVIDES(p, pp, s->name)
1055 Solvable *ps = pool->solvables + p;
1058 if (isinstalled && ps->repo != installed)
1060 /* we still obsolete packages with same nevra, like rpm does */
1061 /* (actually, rpm mixes those packages. yuck...) */
1062 if (multi && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
1064 if (isinstalled || ps->repo != installed)
1066 /* also check the installed package for multi-ness */
1067 if (MAPTST(&solv->multiversion, p))
1070 if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
1072 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, ps))
1074 if (p == SYSTEMSOLVABLE)
1076 if (s->name == ps->name)
1078 /* optimization: do not add the same-name conflict rule if it was
1079 * already added when we looked at the other package.
1080 * (this assumes pool_colormatch is symmetric) */
1081 if (p && m && ps->repo != installed && MAPTST(m, p) &&
1082 (ps->arch != ARCH_SRC && ps->arch != ARCH_NOSRC) &&
1083 !(solv->multiversion.size && MAPTST(&solv->multiversion, p)))
1085 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_SAME_NAME, 0);
1088 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_IMPLICIT_OBSOLETES, s->name);
1093 if (m && pool->implicitobsoleteusescolors && pool_arch2score(pool, s->arch) > 1)
1095 unsigned int pa, a = pool_arch2score(pool, s->arch);
1096 /* check lock-step candidates */
1097 FOR_PROVIDES(p, pp, s->name)
1099 Solvable *ps = pool->solvables + p;
1100 if (s->name != ps->name || s->evr != ps->evr || MAPTST(m, p))
1102 pa = pool_arch2score(pool, ps->arch);
1103 if (!pa || pa == 1 || pa >= a)
1105 queue_push(&workq, p);
1109 /*-----------------------------------------
1110 * add recommends/suggests to the work queue
1112 if (s->recommends && m)
1114 recp = s->repo->idarraydata + s->recommends;
1115 while ((rec = *recp++) != 0)
1117 #ifdef ENABLE_COMPLEX_DEPS
1118 if (pool_is_complex_dep(pool, rec))
1120 pool_add_pos_literals_complex_dep(pool, rec, &workq, m, 0);
1124 FOR_PROVIDES(p, pp, rec)
1126 queue_push(&workq, p);
1129 if (s->suggests && m)
1131 sugp = s->repo->idarraydata + s->suggests;
1132 while ((sug = *sugp++) != 0)
1134 #ifdef ENABLE_COMPLEX_DEPS
1135 if (pool_is_complex_dep(pool, sug))
1137 pool_add_pos_literals_complex_dep(pool, sug, &workq, m, 0);
1141 FOR_PROVIDES(p, pp, sug)
1143 queue_push(&workq, p);
1151 #ifdef ENABLE_LINKED_PKGS
1153 solver_addpkgrulesforlinked(Solver *solv, Map *m)
1155 Pool *pool = solv->pool;
1161 for (i = 1; i < pool->nsolvables; i++)
1165 s = pool->solvables + i;
1166 if (!s->repo || s->repo == solv->installed)
1168 if (!strchr(pool_id2str(pool, s->name), ':'))
1170 if (!pool_installable(pool, s))
1172 find_package_link(pool, s, 0, &qr, 0, 0);
1175 for (j = 0; j < qr.count; j++)
1176 if (MAPTST(m, qr.elements[j]))
1178 solver_addpkgrulesforsolvable(solv, s, m);
1188 /*-------------------------------------------------------------------
1190 * Add rules for packages possibly selected in by weak dependencies
1192 * m: already added solvables
1196 solver_addpkgrulesforweak(Solver *solv, Map *m)
1198 Pool *pool = solv->pool;
1203 /* foreach solvable in pool */
1204 for (i = n = 1; n < pool->nsolvables; i++, n++)
1206 if (i == pool->nsolvables) /* wrap i */
1208 if (MAPTST(m, i)) /* already added that one */
1211 s = pool->solvables + i;
1214 if (s->repo != pool->installed && !pool_installable(pool, s))
1215 continue; /* only look at installable ones */
1220 /* find possible supplements */
1221 supp = s->repo->idarraydata + s->supplements;
1222 while ((sup = *supp++) != 0)
1223 if (solver_dep_possible(solv, sup, m))
1227 /* if nothing found, check for enhances */
1228 if (!sup && s->enhances)
1230 supp = s->repo->idarraydata + s->enhances;
1231 while ((sup = *supp++) != 0)
1232 if (solver_dep_possible(solv, sup, m))
1235 /* if nothing found, goto next solvables */
1238 solver_addpkgrulesforsolvable(solv, s, m);
1239 n = 0; /* check all solvables again because we added solvables to m */
1244 /*-------------------------------------------------------------------
1246 * add package rules for possible updates
1249 * m: map of already visited solvables
1250 * allow_all: 0 = dont allow downgrades, 1 = allow all candidates
1254 solver_addpkgrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
1256 Pool *pool = solv->pool;
1258 /* queue and buffer for it */
1262 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1263 /* find update candidates for 's' */
1264 policy_findupdatepackages(solv, s, &qs, allow_all);
1265 /* add rule for 's' if not already done */
1266 if (!MAPTST(m, s - pool->solvables))
1267 solver_addpkgrulesforsolvable(solv, s, m);
1268 /* foreach update candidate, add rule if not already done */
1269 for (i = 0; i < qs.count; i++)
1270 if (!MAPTST(m, qs.elements[i]))
1271 solver_addpkgrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1276 /***********************************************************************
1278 *** Update/Feature rule part
1280 *** Those rules make sure an installed package isn't silently deleted
1285 dup_maykeepinstalled(Solver *solv, Solvable *s)
1287 Pool *pool = solv->pool;
1290 if (solv->dupmap.size && MAPTST(&solv->dupmap, s - pool->solvables))
1292 /* is installed identical to a good one? */
1293 FOR_PROVIDES(ip, pp, s->name)
1295 Solvable *is = pool->solvables + ip;
1296 if (is->evr != s->evr)
1298 if (solv->dupmap.size)
1300 if (!MAPTST(&solv->dupmap, ip))
1303 else if (is->repo == pool->installed)
1305 if (solvable_identical(s, is))
1312 /* stash away the original updaters for multiversion packages. We do this so that
1313 * we can update the package later */
1315 set_specialupdaters(Solver *solv, Solvable *s, Id d)
1317 Repo *installed = solv->installed;
1318 if (!solv->specialupdaters)
1319 solv->specialupdaters = solv_calloc(installed->end - installed->start, sizeof(Id));
1320 solv->specialupdaters[s - solv->pool->solvables - installed->start] = d;
1323 #ifdef ENABLE_LINKED_PKGS
1324 /* Check if this is a linked pseudo package. As it is linked, we do not need an update/feature rule */
1326 is_linked_pseudo_package(Solver *solv, Solvable *s)
1328 Pool *pool = solv->pool;
1329 if (solv->instbuddy && solv->instbuddy[s - pool->solvables - solv->installed->start])
1331 const char *name = pool_id2str(pool, s->name);
1332 if (strncmp(name, "pattern:", 8) == 0 || strncmp(name, "application:", 12) == 0)
1340 solver_addfeaturerule(Solver *solv, Solvable *s)
1342 Pool *pool = solv->pool;
1348 #ifdef ENABLE_LINKED_PKGS
1349 if (is_linked_pseudo_package(solv, s))
1351 solver_addrule(solv, 0, 0, 0); /* no feature rules for those */
1355 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1356 p = s - pool->solvables;
1357 policy_findupdatepackages(solv, s, &qs, 1);
1358 if (solv->dupinvolvedmap_all || (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
1360 if (!dup_maykeepinstalled(solv, s))
1362 for (i = 0; i < qs.count; i++)
1364 Solvable *ns = pool->solvables + qs.elements[i];
1365 if (ns->repo != pool->installed || dup_maykeepinstalled(solv, ns))
1370 solver_addrule(solv, 0, 0, 0); /* this is an orphan */
1378 Id d = pool_queuetowhatprovides(pool, &qs);
1380 solver_addrule(solv, p, 0, d); /* allow update of s */
1384 Id d = qs.count ? qs.elements[0] : 0;
1386 solver_addrule(solv, p, d, 0); /* allow update of s */
1390 /* check if multiversion solvable s2 has an obsoletes for installed solvable s */
1392 is_multiversion_obsoleteed(Pool *pool, Solvable *s, Solvable *s2)
1396 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
1398 obsp = s2->repo->idarraydata + s2->obsoletes;
1399 if (!pool->obsoleteusesprovides)
1401 while ((obs = *obsp++) != 0)
1402 if (pool_match_nevr(pool, s, obs))
1407 while ((obs = *obsp++) != 0)
1408 for (wp = pool_whatprovides_ptr(pool, obs); *wp; wp++)
1409 if (pool->solvables + *wp == s)
1415 /*-------------------------------------------------------------------
1417 * add rule for update
1418 * (A|A1|A2|A3...) An = update candidates for A
1420 * s = (installed) solvable
1424 solver_addupdaterule(Solver *solv, Solvable *s)
1426 /* installed packages get a special upgrade allowed rule */
1427 Pool *pool = solv->pool;
1432 int dupinvolved = 0;
1434 p = s - pool->solvables;
1436 if (pool->considered && pool_disabled_solvable(pool, s))
1438 /* disabled installed solvables must stay installed */
1439 solver_addrule(solv, p, 0, 0);
1443 /* Orphan detection. We cheat by looking at the feature rule, which
1444 * we already calculated */
1445 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1448 #ifdef ENABLE_LINKED_PKGS
1449 if (is_linked_pseudo_package(solv, s))
1451 solver_addrule(solv, 0, 0, 0);
1456 queue_push(&solv->orphaned, s - pool->solvables); /* an orphaned package */
1457 if (solv->keep_orphans && !(solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, s - pool->solvables - solv->installed->start))))
1458 p = s - pool->solvables; /* keep this orphaned package installed */
1459 solver_addrule(solv, p, 0, 0);
1463 /* find update candidates for 's' */
1464 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1465 dupinvolved = solv->dupinvolvedmap_all || (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p));
1466 policy_findupdatepackages(solv, s, &qs, dupinvolved ? 2 : 0);
1468 if (qs.count && solv->multiversion.size)
1472 for (i = 0; i < qs.count; i++)
1473 if (MAPTST(&solv->multiversion, qs.elements[i]))
1477 /* filter out all multiversion packages as they don't update */
1478 d = pool_queuetowhatprovides(pool, &qs); /* save qs away */
1479 for (j = i; i < qs.count; i++)
1481 if (MAPTST(&solv->multiversion, qs.elements[i]))
1483 Solvable *ps = pool->solvables + qs.elements[i];
1484 /* check if there is an explicit obsoletes */
1485 if (solv->keepexplicitobsoletes && ps->obsoletes && is_multiversion_obsoleteed(pool, s, ps))
1487 qs.elements[j++] = qs.elements[i];
1490 /* it's ok if they have same nevra */
1491 if (ps->name != s->name || ps->evr != s->evr || ps->arch != s->arch)
1494 qs.elements[j++] = qs.elements[i];
1497 if (j == 0 && dupinvolved && !dup_maykeepinstalled(solv, s))
1499 /* this is a multiversion orphan */
1500 queue_push(&solv->orphaned, p);
1501 set_specialupdaters(solv, s, d);
1502 if (solv->keep_orphans && !(solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))))
1504 /* we need to keep the orphan */
1506 solver_addrule(solv, p, 0, 0);
1509 /* we can drop it as long as we update */
1513 if (j < qs.count) /* filtered at least one package? */
1515 if (d && (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, p - solv->installed->start))))
1517 /* non-orphan multiversion package, set special updaters if we want an update */
1518 set_specialupdaters(solv, s, d);
1524 /* could fallthrough, but then we would do pool_queuetowhatprovides twice */
1526 solver_addrule(solv, p, 0, d); /* allow update of s */
1533 d = pool_queuetowhatprovides(pool, &qs);
1535 solver_addrule(solv, p, 0, d); /* allow update of s */
1539 d = qs.count ? qs.elements[0] : 0;
1541 solver_addrule(solv, p, d, 0); /* allow update of s */
1546 disableupdaterule(Solver *solv, Id p)
1550 MAPSET(&solv->noupdate, p - solv->installed->start);
1551 r = solv->rules + solv->updaterules + (p - solv->installed->start);
1552 if (r->p && r->d >= 0)
1553 solver_disablerule(solv, r);
1554 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1555 if (r->p && r->d >= 0)
1556 solver_disablerule(solv, r);
1557 if (solv->bestrules_info)
1560 ni = solv->bestrules_end - solv->bestrules;
1561 for (i = solv->bestrules_up - solv->bestrules; i < ni; i++)
1562 if (solv->bestrules_info[i] == p)
1563 solver_disablerule(solv, solv->rules + solv->bestrules + i);
1568 reenableupdaterule(Solver *solv, Id p)
1570 Pool *pool = solv->pool;
1573 MAPCLR(&solv->noupdate, p - solv->installed->start);
1574 r = solv->rules + solv->updaterules + (p - solv->installed->start);
1579 solver_enablerule(solv, r);
1580 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1582 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1583 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1589 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1590 if (r->p && r->d < 0)
1592 solver_enablerule(solv, r);
1593 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1595 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1596 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1600 if (solv->bestrules_info)
1603 ni = solv->bestrules_end - solv->bestrules;
1604 for (i = solv->bestrules_up - solv->bestrules; i < ni; i++)
1605 if (solv->bestrules_info[i] == p)
1606 solver_enablerule(solv, solv->rules + solv->bestrules + i);
1611 /***********************************************************************
1613 *** Infarch rule part
1615 *** Infarch rules make sure the solver uses the best architecture of
1616 *** a package if multiple archetectures are available
1621 solver_addinfarchrules(Solver *solv, Map *addedmap)
1623 Pool *pool = solv->pool;
1624 Repo *installed = pool->installed;
1627 unsigned int a, bestscore;
1628 Solvable *s, *ps, *bests;
1629 Queue badq, allowedarchs;
1633 queue_init(&allowedarchs);
1635 solv->infarchrules = solv->nrules;
1636 for (i = 1; i < pool->nsolvables; i++)
1638 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1640 s = pool->solvables + i;
1644 queue_empty(&allowedarchs);
1645 FOR_PROVIDES(p, pp, s->name)
1647 ps = pool->solvables + p;
1648 if (ps->name != s->name || !MAPTST(addedmap, p))
1654 a = pool_arch2score(pool, ps->arch);
1655 if (a != 1 && installed && ps->repo == installed)
1657 if (solv->dupinvolvedmap_all || (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
1659 queue_pushunique(&allowedarchs, ps->arch); /* also ok to keep this architecture */
1660 continue; /* but ignore installed solvables when calculating the best arch */
1662 if (a && a != 1 && (!bestscore || a < bestscore))
1669 continue; /* not the first in the group */
1672 continue; /* did not find a score for this group */
1674 /* speed up common case where installed package already has best arch */
1675 if (allowedarchs.count == 1 && bests && allowedarchs.elements[0] == bests->arch)
1676 allowedarchs.count--; /* installed arch is best */
1678 if (allowedarchs.count && pool->implicitobsoleteusescolors && installed)
1680 /* need an extra pass for lockstep checking: we only allow to keep an inferior arch
1681 * if the corresponding installed package is not lock-stepped */
1682 queue_empty(&allowedarchs);
1683 FOR_PROVIDES(p, pp, s->name)
1686 ps = pool->solvables + p;
1687 if (ps->name != s->name || ps->repo != installed || !MAPTST(addedmap, p))
1689 if (solv->dupinvolvedmap_all || (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
1691 a = pool_arch2score(pool, ps->arch);
1694 queue_pushunique(&allowedarchs, ps->arch); /* strange arch, allow */
1697 if (a == 1 || ((a ^ bestscore) & 0xffff0000) == 0)
1699 /* have installed package with inferior arch, check if lock-stepped */
1700 FOR_PROVIDES(p2, pp2, s->name)
1702 Solvable *s2 = pool->solvables + p2;
1704 if (p2 == p || s2->name != s->name || s2->evr != pool->solvables[p].evr || s2->arch == pool->solvables[p].arch)
1706 a2 = pool_arch2score(pool, s2->arch);
1707 if (a2 && (a2 == 1 || ((a2 ^ bestscore) & 0xffff0000) == 0))
1711 queue_pushunique(&allowedarchs, ps->arch);
1715 /* find all bad packages */
1717 FOR_PROVIDES(p, pp, s->name)
1719 ps = pool->solvables + p;
1720 if (ps->name != s->name || !MAPTST(addedmap, p))
1722 a = pool_arch2score(pool, ps->arch);
1723 if (a != 1 && ((a ^ bestscore) & 0xffff0000) != 0)
1725 if (installed && ps->repo == installed)
1727 if (pool->implicitobsoleteusescolors)
1728 queue_push(&badq, p); /* special lock-step handling, see below */
1729 continue; /* always ok to keep an installed package */
1731 for (j = 0; j < allowedarchs.count; j++)
1734 aa = allowedarchs.elements[j];
1737 aas = pool_arch2score(pool, aa);
1738 if (aas && ((a ^ aas) & 0xffff0000) == 0)
1739 break; /* compatible */
1741 if (j == allowedarchs.count)
1742 queue_push(&badq, p);
1746 /* block all solvables in the badq! */
1747 for (j = 0; j < badq.count; j++)
1749 p = badq.elements[j];
1750 /* special lock-step handling */
1751 if (pool->implicitobsoleteusescolors)
1754 int haveinstalled = 0;
1756 FOR_PROVIDES(p2, pp, s->name)
1758 Solvable *s2 = pool->solvables + p2;
1759 if (p2 == p || s2->name != s->name || s2->evr != pool->solvables[p].evr || s2->arch == pool->solvables[p].arch)
1761 a = pool_arch2score(pool, s2->arch);
1762 if (a && (a == 1 || ((a ^ bestscore) & 0xffff000) == 0))
1764 queue_push(&lsq, p2);
1765 if (installed && s2->repo == installed)
1769 if (installed && pool->solvables[p].repo == installed && !haveinstalled)
1770 continue; /* installed package not in lock-step */
1772 solver_addrule(solv, -p, lsq.count ? lsq.elements[0] : 0, 0);
1774 solver_addrule(solv, -p, 0, pool_queuetowhatprovides(pool, &lsq));
1778 solver_addrule(solv, -p, 0, 0);
1784 queue_free(&allowedarchs);
1785 solv->infarchrules_end = solv->nrules;
1789 disableinfarchrule(Solver *solv, Id name)
1791 Pool *pool = solv->pool;
1794 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1796 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1797 solver_disablerule(solv, r);
1802 reenableinfarchrule(Solver *solv, Id name)
1804 Pool *pool = solv->pool;
1807 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1809 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1811 solver_enablerule(solv, r);
1812 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1814 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1815 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1822 /***********************************************************************
1826 *** Dup rules make sure a package is selected from the specified dup
1827 *** repositories if an update candidate is included in one of them.
1832 add_cleandeps_updatepkg(Solver *solv, Id p)
1834 if (!solv->cleandeps_updatepkgs)
1836 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
1837 queue_init(solv->cleandeps_updatepkgs);
1839 queue_pushunique(solv->cleandeps_updatepkgs, p);
1843 solver_addtodupmaps(Solver *solv, Id p, Id how, int targeted)
1845 Pool *pool = solv->pool;
1846 Solvable *ps, *s = pool->solvables + p;
1847 Repo *installed = solv->installed;
1848 Id pi, pip, obs, *obsp;
1850 if (!solv->dupinvolvedmap.size)
1851 map_grow(&solv->dupinvolvedmap, pool->nsolvables);
1853 MAPSET(&solv->dupinvolvedmap, p);
1855 MAPSET(&solv->dupmap, p);
1856 FOR_PROVIDES(pi, pip, s->name)
1858 ps = pool->solvables + pi;
1859 if (ps->name != s->name)
1861 MAPSET(&solv->dupinvolvedmap, pi);
1862 if (targeted && ps->repo == installed && solv->obsoletes && solv->obsoletes[pi - installed->start])
1865 for (opp = solv->obsoletes_data + solv->obsoletes[pi - installed->start]; (pi2 = *opp++) != 0;)
1866 if (pool->solvables[pi2].repo != installed)
1867 MAPSET(&solv->dupinvolvedmap, pi2);
1869 if (ps->repo == installed && (how & SOLVER_FORCEBEST) != 0 && !solv->bestupdatemap_all)
1871 if (!solv->bestupdatemap.size)
1872 map_grow(&solv->bestupdatemap, installed->end - installed->start);
1873 MAPSET(&solv->bestupdatemap, pi - installed->start);
1875 if (ps->repo == installed && (how & SOLVER_CLEANDEPS) != 0)
1876 add_cleandeps_updatepkg(solv, pi);
1877 if (!targeted && ps->repo != installed)
1878 MAPSET(&solv->dupmap, pi);
1880 if (s->repo == installed && solv->obsoletes && solv->obsoletes[p - installed->start])
1883 for (opp = solv->obsoletes_data + solv->obsoletes[p - installed->start]; (pi = *opp++) != 0;)
1885 ps = pool->solvables + pi;
1886 if (ps->repo == installed)
1888 MAPSET(&solv->dupinvolvedmap, pi);
1890 MAPSET(&solv->dupmap, pi);
1893 if (targeted && s->repo != installed && s->obsoletes)
1895 /* XXX: check obsoletes/provides combination */
1896 obsp = s->repo->idarraydata + s->obsoletes;
1897 while ((obs = *obsp++) != 0)
1899 FOR_PROVIDES(pi, pip, obs)
1901 Solvable *ps = pool->solvables + pi;
1902 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
1904 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1906 MAPSET(&solv->dupinvolvedmap, pi);
1907 if (targeted && ps->repo == installed && solv->obsoletes && solv->obsoletes[pi - installed->start])
1910 for (opp = solv->obsoletes_data + solv->obsoletes[pi - installed->start]; (pi2 = *opp++) != 0;)
1911 if (pool->solvables[pi2].repo != installed)
1912 MAPSET(&solv->dupinvolvedmap, pi2);
1914 if (ps->repo == installed && (how & SOLVER_FORCEBEST) != 0 && !solv->bestupdatemap_all)
1916 if (!solv->bestupdatemap.size)
1917 map_grow(&solv->bestupdatemap, installed->end - installed->start);
1918 MAPSET(&solv->bestupdatemap, pi - installed->start);
1920 if (ps->repo == installed && (how & SOLVER_CLEANDEPS) != 0)
1921 add_cleandeps_updatepkg(solv, pi);
1927 /* create the two dupmaps:
1928 * - dupmap: packages in that map are good to install/keep
1929 * - dupinvolvedmap: packages are subject to dup mode
1932 solver_createdupmaps(Solver *solv)
1934 Queue *job = &solv->job;
1935 Pool *pool = solv->pool;
1936 Repo *installed = solv->installed;
1937 Id select, how, what, p, pp;
1941 map_init(&solv->dupmap, pool->nsolvables);
1942 solv->dupinvolvedmap_all = 0;
1943 map_init(&solv->dupinvolvedmap, 0);
1944 for (i = 0; i < job->count; i += 2)
1946 how = job->elements[i];
1947 select = job->elements[i] & SOLVER_SELECTMASK;
1948 what = job->elements[i + 1];
1949 switch (how & SOLVER_JOBMASK)
1951 case SOLVER_DISTUPGRADE:
1952 if (select == SOLVER_SOLVABLE_REPO)
1955 if (what <= 0 || what > pool->nrepos)
1957 repo = pool_id2repo(pool, what);
1960 if (repo != installed && !(how & SOLVER_TARGETED) && solv->noautotarget)
1962 targeted = repo != installed || (how & SOLVER_TARGETED) != 0;
1963 FOR_REPO_SOLVABLES(repo, p, s)
1965 if (repo != installed && !pool_installable(pool, s))
1967 solver_addtodupmaps(solv, p, how, targeted);
1970 else if (select == SOLVER_SOLVABLE_ALL)
1972 solv->dupinvolvedmap_all = 1;
1973 FOR_POOL_SOLVABLES(p)
1975 Solvable *s = pool->solvables + p;
1976 if (!s->repo || s->repo == installed)
1978 if (!pool_installable(pool, s))
1980 MAPSET(&solv->dupmap, p);
1982 if ((how & SOLVER_FORCEBEST) != 0)
1983 solv->bestupdatemap_all = 1;
1984 if ((how & SOLVER_CLEANDEPS) != 0 && installed)
1986 FOR_REPO_SOLVABLES(installed, p, s)
1987 add_cleandeps_updatepkg(solv, p);
1992 targeted = how & SOLVER_TARGETED ? 1 : 0;
1993 if (installed && !targeted && !solv->noautotarget)
1995 FOR_JOB_SELECT(p, pp, select, what)
1996 if (pool->solvables[p].repo == installed)
2000 else if (!installed && !solv->noautotarget)
2002 FOR_JOB_SELECT(p, pp, select, what)
2004 Solvable *s = pool->solvables + p;
2007 if (s->repo != installed && !targeted)
2009 if (s->repo != installed && !pool_installable(pool, s))
2011 solver_addtodupmaps(solv, p, how, targeted);
2019 if (solv->dupinvolvedmap.size)
2020 MAPCLR(&solv->dupinvolvedmap, SYSTEMSOLVABLE);
2021 /* set update for all involved installed packages. We need to do
2022 * this before creating the update rules */
2023 if (solv->dupinvolvedmap_all)
2024 solv->updatemap_all = 1;
2025 else if (installed && !solv->updatemap_all && solv->dupinvolvedmap.size)
2027 FOR_REPO_SOLVABLES(installed, p, s)
2029 if (!MAPTST(&solv->dupinvolvedmap, p))
2031 if (!solv->updatemap.size)
2032 map_grow(&solv->updatemap, installed->end - installed->start);
2033 MAPSET(&solv->updatemap, p - installed->start);
2039 solver_freedupmaps(Solver *solv)
2041 map_free(&solv->dupmap);
2042 /* we no longer free solv->dupinvolvedmap as we need it in
2043 * policy's priority pruning code. sigh. */
2047 solver_addduprules(Solver *solv, Map *addedmap)
2049 Pool *pool = solv->pool;
2050 Repo *installed = solv->installed;
2056 solv->duprules = solv->nrules;
2057 for (i = 1; i < pool->nsolvables; i++)
2059 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
2061 s = pool->solvables + i;
2063 FOR_PROVIDES(p, pp, s->name)
2065 ps = pool->solvables + p;
2066 if (ps->name != s->name || !MAPTST(addedmap, p))
2072 if (!solv->dupinvolvedmap_all && !MAPTST(&solv->dupinvolvedmap, p))
2074 if (installed && ps->repo == installed)
2076 if (pool->considered && pool_disabled_solvable(pool, ps))
2077 continue; /* always keep disabled installed packages */
2078 if (!MAPTST(&solv->dupmap, p))
2081 /* is installed identical to a good one? */
2082 FOR_PROVIDES(ip, ipp, ps->name)
2084 Solvable *is = pool->solvables + ip;
2085 if (!MAPTST(&solv->dupmap, ip))
2087 if (is->evr == ps->evr && solvable_identical(ps, is))
2092 /* ok, identical to a good one. we may keep this package. */
2093 MAPSET(&solv->dupmap, p); /* for best rules processing */
2096 /* check if it's orphaned. If yes, we may keep it */
2097 r = solv->rules + solv->updaterules + (p - installed->start);
2099 r = solv->rules + solv->featurerules + (p - installed->start);
2102 /* no update/feature rule, this is an orphan */
2103 MAPSET(&solv->dupmap, p); /* for best rules processing */
2106 if (solv->specialupdaters && solv->specialupdaters[p - installed->start])
2108 /* this is a multiversion orphan, we're good if an update is installed */
2109 solver_addrule(solv, -p, 0, solv->specialupdaters[p - installed->start]);
2112 if (r->p == p && !r->d && !r->w2)
2114 r = solv->rules + solv->featurerules + (p - installed->start);
2115 if (!r->p || (!r->d && !r->w2))
2117 /* this is an orphan */
2118 MAPSET(&solv->dupmap, p); /* for best rules processing */
2122 solver_addrule(solv, -p, 0, 0); /* no match, sorry */
2125 else if (!MAPTST(&solv->dupmap, p))
2126 solver_addrule(solv, -p, 0, 0);
2129 solv->duprules_end = solv->nrules;
2134 disableduprule(Solver *solv, Id name)
2136 Pool *pool = solv->pool;
2139 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
2141 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
2142 solver_disablerule(solv, r);
2147 reenableduprule(Solver *solv, Id name)
2149 Pool *pool = solv->pool;
2152 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
2154 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
2156 solver_enablerule(solv, r);
2157 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
2159 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
2160 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
2166 /***********************************************************************
2172 disableblackrule(Solver *solv, Id p)
2176 for (i = solv->blackrules, r = solv->rules + i; i < solv->blackrules_end; i++, r++)
2178 solver_disablerule(solv, r);
2182 reenableblackrule(Solver *solv, Id p)
2184 Pool *pool = solv->pool;
2187 for (i = solv->blackrules, r = solv->rules + i; i < solv->blackrules_end; i++, r++)
2190 solver_enablerule(solv, r);
2191 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
2193 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
2194 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
2200 solver_addblackrules(Solver *solv)
2203 Id how, select, what, p, pp;
2204 Queue *job = &solv->job;
2205 Pool *pool = solv->pool;
2206 Repo *installed = solv->installed;
2209 map_init(&updatemap, 0);
2210 solv->blackrules = solv->nrules;
2213 for (i = 0; i < job->count; i += 2)
2215 how = job->elements[i];
2216 select = job->elements[i] & SOLVER_SELECTMASK;
2217 what = job->elements[i + 1];
2218 switch (how & SOLVER_JOBMASK)
2220 case SOLVER_BLACKLIST:
2221 FOR_JOB_SELECT(p, pp, select, what)
2223 Solvable *s = pool->solvables + p;
2224 if (s->repo != installed)
2226 if (!updatemap.size)
2227 map_grow(&updatemap, pool->ss.nstrings);
2228 if (s->name > 0 && s->name < pool->ss.nstrings)
2229 MAPSET(&updatemap, s->name);
2234 for (i = 0; i < job->count; i += 2)
2236 how = job->elements[i];
2237 select = job->elements[i] & SOLVER_SELECTMASK;
2238 what = job->elements[i + 1];
2239 switch (how & SOLVER_JOBMASK)
2241 case SOLVER_BLACKLIST:
2242 FOR_JOB_SELECT(p, pp, select, what)
2244 Solvable *s = pool->solvables + p;
2245 if (s->repo == installed)
2247 if (updatemap.size && s->name > 0 && s->name < pool->ss.nstrings && MAPTST(&updatemap, s->name))
2248 continue; /* installed package with same name is already blacklisted */
2249 solver_addrule(solv, -p, 0, 0);
2254 map_free(&updatemap);
2255 solv->blackrules_end = solv->nrules;
2258 /***********************************************************************
2260 *** Strict repo prio rule part
2263 /* add rules to exclude solvables provided by lower
2264 * precedence repositories */
2265 void solver_addstrictrepopriorules(struct s_Solver *solv, Map *addedmap)
2267 Pool *pool = solv->pool;
2273 map_init_clone(&priomap, addedmap);
2274 solv->strictrepopriorules = solv->nrules;
2276 FOR_POOL_SOLVABLES(p)
2278 if (!MAPTST(&priomap, p))
2281 s = pool->solvables + p;
2282 max_prio = s->repo->priority;
2283 FOR_PROVIDES(p2, pp2, s->name)
2285 Solvable *s2 = pool->solvables + p2;
2286 if (s->name != s2->name)
2288 if (s2->repo->priority > max_prio)
2289 max_prio = s2->repo->priority;
2292 FOR_PROVIDES(p2, pp2, s->name)
2294 Solvable *s2 = pool->solvables + p2;
2295 if (s->name != s2->name || !MAPTST(&priomap, p2))
2297 MAPCLR(&priomap, p2);
2298 if (pool->installed && s2->repo == pool->installed)
2300 if (s2->repo->priority < max_prio)
2301 solver_addrule(solv, -p2, 0, 0);
2304 solv->strictrepopriorules_end = solv->nrules;
2309 disablerepopriorule(Solver *solv, Id name)
2311 Pool *pool = solv->pool;
2314 for (i = solv->strictrepopriorules, r = solv->rules + i; i < solv->strictrepopriorules_end; i++, r++)
2316 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
2317 solver_disablerule(solv, r);
2322 reenablerepopriorule(Solver *solv, Id name)
2324 Pool *pool = solv->pool;
2327 for (i = solv->strictrepopriorules, r = solv->rules + i; i < solv->strictrepopriorules_end; i++, r++)
2329 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
2331 solver_enablerule(solv, r);
2332 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
2334 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
2335 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
2341 /***********************************************************************
2343 *** Policy rule disabling/reenabling
2345 *** Disable all policy rules that conflict with our jobs. If a job
2346 *** gets disabled later on, reenable the involved policy rules again.
2350 #define DISABLE_UPDATE 1
2351 #define DISABLE_INFARCH 2
2352 #define DISABLE_DUP 3
2353 #define DISABLE_BLACK 4
2354 #define DISABLE_REPOPRIO 5
2357 jobtodisablelist(Solver *solv, Id how, Id what, Queue *q)
2359 Pool *pool = solv->pool;
2363 int i, j, set, qstart;
2366 installed = solv->installed;
2367 select = how & SOLVER_SELECTMASK;
2368 switch (how & SOLVER_JOBMASK)
2370 case SOLVER_INSTALL:
2371 set = how & SOLVER_SETMASK;
2372 if (!(set & SOLVER_NOAUTOSET))
2374 /* automatically add set bits by analysing the job */
2375 if (select == SOLVER_SOLVABLE_NAME)
2376 set |= SOLVER_SETNAME;
2377 if (select == SOLVER_SOLVABLE)
2378 set |= SOLVER_SETNAME | SOLVER_SETARCH | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_SETEVR;
2379 else if ((select == SOLVER_SOLVABLE_NAME || select == SOLVER_SOLVABLE_PROVIDES) && ISRELDEP(what))
2381 Reldep *rd = GETRELDEP(pool, what);
2382 if (rd->flags == REL_EQ && select == SOLVER_SOLVABLE_NAME)
2384 if (pool->disttype != DISTTYPE_DEB)
2386 const char *rel = strrchr(pool_id2str(pool, rd->evr), '-');
2387 set |= rel ? SOLVER_SETEVR : SOLVER_SETEV;
2390 set |= SOLVER_SETEVR;
2392 if (rd->flags <= 7 && ISRELDEP(rd->name))
2393 rd = GETRELDEP(pool, rd->name);
2394 if (rd->flags == REL_ARCH)
2395 set |= SOLVER_SETARCH;
2399 set &= ~SOLVER_NOAUTOSET;
2402 if ((set & SOLVER_SETARCH) != 0 && solv->infarchrules != solv->infarchrules_end)
2404 if (select == SOLVER_SOLVABLE)
2406 for (i = solv->infarchrules; i < solv->infarchrules_end; i++)
2407 if (solv->rules[i].p == -what)
2409 if (i < solv->infarchrules_end)
2410 queue_push2(q, DISABLE_INFARCH, pool->solvables[what].name);
2414 int qcnt = q->count;
2415 /* does not work for SOLVER_SOLVABLE_ALL and SOLVER_SOLVABLE_REPO, but
2416 they are not useful for SOLVER_INSTALL jobs anyway */
2417 FOR_JOB_SELECT(p, pp, select, what)
2419 s = pool->solvables + p;
2421 for (i = qcnt; i < q->count; i += 2)
2422 if (q->elements[i + 1] == s->name)
2425 continue; /* already have that DISABLE_INFARCH element */
2426 for (i = solv->infarchrules; i < solv->infarchrules_end; i++)
2427 if (solv->rules[i].p == -p)
2429 if (i < solv->infarchrules_end)
2430 queue_push2(q, DISABLE_INFARCH, s->name);
2434 if ((set & SOLVER_SETREPO) != 0 && solv->duprules != solv->duprules_end)
2436 if (select == SOLVER_SOLVABLE)
2437 queue_push2(q, DISABLE_DUP, pool->solvables[what].name);
2440 int qcnt = q->count;
2441 FOR_JOB_SELECT(p, pp, select, what)
2443 s = pool->solvables + p;
2445 for (i = qcnt; i < q->count; i += 2)
2446 if (q->elements[i + 1] == s->name)
2450 queue_push2(q, DISABLE_DUP, s->name);
2454 if ((set & SOLVER_SETREPO) != 0 && solv->strictrepopriorules != solv->strictrepopriorules_end)
2456 if (select == SOLVER_SOLVABLE)
2457 queue_push2(q, DISABLE_REPOPRIO, pool->solvables[what].name);
2460 int qcnt = q->count;
2461 FOR_JOB_SELECT(p, pp, select, what)
2463 s = pool->solvables + p;
2465 for (i = qcnt; i < q->count; i += 2)
2466 if (q->elements[i + 1] == s->name)
2470 queue_push2(q, DISABLE_REPOPRIO, s->name);
2474 if ((set & SOLVER_SETEVR) != 0 && solv->blackrules != solv->blackrules_end)
2476 if (select == SOLVER_SOLVABLE)
2477 queue_push2(q, DISABLE_BLACK, what);
2480 FOR_JOB_SELECT(p, pp, select, what)
2481 queue_push2(q, DISABLE_BLACK, p);
2484 if (!installed || installed->end == installed->start)
2486 /* now the hard part: disable some update rules */
2488 /* first check if we have installed or multiversion packages in the job */
2489 FOR_JOB_SELECT(p, pp, select, what)
2491 if (pool->solvables[p].repo == installed)
2493 if (solv->multiversion.size && MAPTST(&solv->multiversion, p) && !solv->keepexplicitobsoletes)
2494 return; /* will not obsolete anything, so just return */
2498 FOR_JOB_SELECT(p, pp, select, what)
2500 solver_intersect_obsoleted(solv, p, q, qstart, &omap);
2501 if (q->count == qstart)
2507 if (qstart == q->count)
2508 return; /* nothing to prune */
2510 /* convert result to (DISABLE_UPDATE, p) pairs */
2512 for (j = qstart; j < i; j++)
2513 queue_push(q, q->elements[j]);
2514 for (j = qstart; j < q->count; j += 2)
2516 q->elements[j] = DISABLE_UPDATE;
2517 q->elements[j + 1] = q->elements[i++];
2520 /* now that we know which installed packages are obsoleted check each of them */
2521 if ((set & (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR)) == (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR))
2522 return; /* all is set, nothing to do */
2524 for (i = j = qstart; i < q->count; i += 2)
2526 Solvable *is = pool->solvables + q->elements[i + 1];
2527 FOR_JOB_SELECT(p, pp, select, what)
2530 s = pool->solvables + p;
2531 if ((set & SOLVER_SETEVR) != 0)
2532 illegal |= POLICY_ILLEGAL_DOWNGRADE; /* ignore */
2533 if ((set & SOLVER_SETNAME) != 0)
2534 illegal |= POLICY_ILLEGAL_NAMECHANGE; /* ignore */
2535 if ((set & SOLVER_SETARCH) != 0)
2536 illegal |= POLICY_ILLEGAL_ARCHCHANGE; /* ignore */
2537 if ((set & SOLVER_SETVENDOR) != 0)
2538 illegal |= POLICY_ILLEGAL_VENDORCHANGE; /* ignore */
2539 illegal = policy_is_illegal(solv, is, s, illegal);
2540 if (illegal && illegal == POLICY_ILLEGAL_DOWNGRADE && (set & SOLVER_SETEV) != 0)
2542 /* it's ok if the EV is different */
2543 if (pool_evrcmp(pool, is->evr, s->evr, EVRCMP_COMPARE_EVONLY) != 0)
2551 /* no package conflicts with the update rule */
2552 /* thus keep the DISABLE_UPDATE */
2553 q->elements[j + 1] = q->elements[i + 1];
2557 queue_truncate(q, j);
2563 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
2565 FOR_REPO_SOLVABLES(installed, p, s)
2566 queue_push2(q, DISABLE_UPDATE, p);
2568 FOR_JOB_SELECT(p, pp, select, what)
2569 if (pool->solvables[p].repo == installed)
2571 queue_push2(q, DISABLE_UPDATE, p);
2572 #ifdef ENABLE_LINKED_PKGS
2573 if (solv->instbuddy && solv->instbuddy[p - installed->start] > 1)
2574 queue_push2(q, DISABLE_UPDATE, solv->instbuddy[p - installed->start]);
2583 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
2585 FOR_REPO_SOLVABLES(installed, p, s)
2587 for (i = qstart; i < q->count; i += 2)
2588 if (q->elements[i] == DISABLE_DUP && q->elements[i + 1] == pool->solvables[p].name)
2591 queue_push2(q, DISABLE_DUP, pool->solvables[p].name);
2594 FOR_JOB_SELECT(p, pp, select, what)
2596 if (pool->solvables[p].repo != installed)
2598 for (i = qstart; i < q->count; i += 2)
2599 if (q->elements[i] == DISABLE_DUP && q->elements[i + 1] == pool->solvables[p].name)
2602 queue_push2(q, DISABLE_DUP, pool->solvables[p].name);
2611 /* disable all policy rules that are in conflict with our job list */
2613 solver_disablepolicyrules(Solver *solv)
2615 Queue *job = &solv->job;
2622 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2624 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2626 r = solv->rules + i;
2627 if (r->d < 0) /* disabled? */
2629 j = solv->ruletojob.elements[i - solv->jobrules];
2633 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2635 if (solv->cleandepsmap.size)
2637 solver_createcleandepsmap(solv, &solv->cleandepsmap, 0);
2638 for (i = solv->installed->start; i < solv->installed->end; i++)
2639 if (MAPTST(&solv->cleandepsmap, i - solv->installed->start))
2640 queue_push2(&allq, DISABLE_UPDATE, i);
2642 MAPZERO(&solv->noupdate);
2643 for (i = 0; i < allq.count; i += 2)
2645 Id type = allq.elements[i], arg = allq.elements[i + 1];
2648 case DISABLE_UPDATE:
2649 disableupdaterule(solv, arg);
2651 case DISABLE_INFARCH:
2652 disableinfarchrule(solv, arg);
2655 disableduprule(solv, arg);
2658 disableblackrule(solv, arg);
2660 case DISABLE_REPOPRIO:
2661 disablerepopriorule(solv, arg);
2670 /* we just disabled job #jobidx, now reenable all policy rules that were
2671 * disabled because of this job */
2673 solver_reenablepolicyrules(Solver *solv, int jobidx)
2675 Queue *job = &solv->job;
2680 Id qbuf[32], allqbuf[32];
2682 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
2683 jobtodisablelist(solv, job->elements[jobidx - 1], job->elements[jobidx], &q);
2689 /* now remove everything from q that is disabled by other jobs */
2691 /* first remove cleandeps packages, they count as DISABLE_UPDATE */
2692 if (solv->cleandepsmap.size)
2694 solver_createcleandepsmap(solv, &solv->cleandepsmap, 0);
2695 for (j = k = 0; j < q.count; j += 2)
2697 if (q.elements[j] == DISABLE_UPDATE)
2699 Id p = q.elements[j + 1];
2700 if (p >= solv->installed->start && p < solv->installed->end && MAPTST(&solv->cleandepsmap, p - solv->installed->start))
2701 continue; /* remove element from q */
2703 q.elements[k++] = q.elements[j];
2704 q.elements[k++] = q.elements[j + 1];
2714 /* now go through the disable list of all other jobs */
2715 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2716 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2718 r = solv->rules + i;
2719 if (r->d < 0) /* disabled? */
2721 j = solv->ruletojob.elements[i - solv->jobrules];
2725 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2728 /* remove all elements in allq from q */
2729 for (j = k = 0; j < q.count; j += 2)
2731 Id type = q.elements[j], arg = q.elements[j + 1];
2732 for (ai = 0; ai < allq.count; ai += 2)
2733 if (allq.elements[ai] == type && allq.elements[ai + 1] == arg)
2735 if (ai < allq.count)
2736 continue; /* found it in allq, remove element from q */
2737 q.elements[k++] = q.elements[j];
2738 q.elements[k++] = q.elements[j + 1];
2751 /* now re-enable anything that's left in q */
2752 for (j = 0; j < q.count; j += 2)
2754 Id type = q.elements[j], arg = q.elements[j + 1];
2757 case DISABLE_UPDATE:
2758 reenableupdaterule(solv, arg);
2760 case DISABLE_INFARCH:
2761 reenableinfarchrule(solv, arg);
2764 reenableduprule(solv, arg);
2767 reenableblackrule(solv, arg);
2769 case DISABLE_REPOPRIO:
2770 reenablerepopriorule(solv, arg);
2777 /* we just removed a package from the cleandeps map, now reenable all policy rules that were
2778 * disabled because of this */
2780 solver_reenablepolicyrules_cleandeps(Solver *solv, Id pkg)
2782 Queue *job = &solv->job;
2789 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2790 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2792 r = solv->rules + i;
2793 if (r->d < 0) /* disabled? */
2795 j = solv->ruletojob.elements[i - solv->jobrules];
2799 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2801 for (i = 0; i < allq.count; i += 2)
2802 if (allq.elements[i] == DISABLE_UPDATE && allq.elements[i + 1] == pkg)
2804 if (i == allq.count)
2805 reenableupdaterule(solv, pkg);
2810 /***********************************************************************
2812 *** Rule info part, tell the user what the rule is about.
2817 addpkgruleinfo(Solver *solv, Id p, Id p2, Id d, int type, Id dep)
2819 Pool *pool = solv->pool;
2824 assert(!p2 && d > 0);
2825 if (!pool->whatprovidesdata[d])
2827 else if (!pool->whatprovidesdata[d + 1])
2829 p2 = pool->whatprovidesdata[d];
2834 /* check if this creates the rule we're searching for */
2835 r = solv->rules + solv->ruleinfoq->elements[0];
2838 /* three or more literals */
2839 Id od = r->d < 0 ? -r->d - 1 : r->d;
2840 if (p != r->p && !od)
2844 Id *dp = pool->whatprovidesdata + d;
2845 Id *odp = pool->whatprovidesdata + od;
2847 if (*dp++ != *odp++)
2852 /* set p2 for multiversion conflicts */
2853 if (p < 0 && pool->whatprovidesdata[d] < 0 && pool->whatprovidesdata[d + 1] >= 0 && type == SOLVER_RULE_PKG_CONFLICTS)
2854 p2 = pool->whatprovidesdata[d];
2858 /* one or two literals */
2859 Id op = p, op2 = p2;
2860 if (op2 && op > op2) /* normalize */
2866 if (r->p != op || r->w2 != op2 || (r->d && r->d != -1))
2868 if (type == SOLVER_RULE_PKG_CONFLICTS && !p2)
2869 p2 = -SYSTEMSOLVABLE;
2870 if (type == SOLVER_RULE_PKG_SAME_NAME)
2872 p = op; /* we normalize same name order */
2876 /* yep, rule matches. record info */
2877 queue_push(solv->ruleinfoq, type);
2878 queue_push(solv->ruleinfoq, p < 0 ? -p : 0);
2879 queue_push(solv->ruleinfoq, p2 < 0 ? -p2 : 0);
2880 queue_push(solv->ruleinfoq, dep);
2884 solver_allruleinfos_cmp(const void *ap, const void *bp, void *dp)
2886 const Id *a = ap, *b = bp;
2905 getpkgruleinfos(Solver *solv, Rule *r, Queue *rq)
2907 Pool *pool = solv->pool;
2911 queue_push(rq, r - solv->rules); /* push the rule we're interested in */
2912 solv->ruleinfoq = rq;
2913 FOR_RULELITERALS(l, pp, r)
2917 solver_addpkgrulesforsolvable(solv, pool->solvables - l, 0);
2919 #ifdef ENABLE_LINKED_PKGS
2920 FOR_RULELITERALS(l, pp, r)
2928 if (!strchr(pool_id2str(pool, pool->solvables[l].name), ':') || !has_package_link(pool, pool->solvables + l))
2930 add_package_link(solv, pool->solvables + l, 0, 0);
2933 solv->ruleinfoq = 0;
2938 solver_allruleinfos(Solver *solv, Id rid, Queue *rq)
2940 Rule *r = solv->rules + rid;
2944 if (rid <= 0 || rid >= solv->pkgrules_end)
2946 Id type, from, to, dep;
2947 type = solver_ruleinfo(solv, rid, &from, &to, &dep);
2948 queue_push(rq, type);
2949 queue_push(rq, from);
2951 queue_push(rq, dep);
2954 getpkgruleinfos(solv, r, rq);
2955 /* now sort & unify em */
2958 solv_sort(rq->elements, rq->count / 4, 4 * sizeof(Id), solver_allruleinfos_cmp, 0);
2959 /* throw out identical entries */
2960 for (i = j = 0; i < rq->count; i += 4)
2964 if (rq->elements[i] == rq->elements[j - 4] &&
2965 rq->elements[i + 1] == rq->elements[j - 3] &&
2966 rq->elements[i + 2] == rq->elements[j - 2] &&
2967 rq->elements[i + 3] == rq->elements[j - 1])
2970 rq->elements[j++] = rq->elements[i];
2971 rq->elements[j++] = rq->elements[i + 1];
2972 rq->elements[j++] = rq->elements[i + 2];
2973 rq->elements[j++] = rq->elements[i + 3];
2980 solver_ruleinfo(Solver *solv, Id rid, Id *fromp, Id *top, Id *depp)
2982 Pool *pool = solv->pool;
2983 Rule *r = solv->rules + rid;
2984 SolverRuleinfo type = SOLVER_RULE_UNKNOWN;
2992 if (rid > 0 && rid < solv->pkgrules_end)
2998 return SOLVER_RULE_PKG;
3002 getpkgruleinfos(solv, r, &rq);
3003 type = SOLVER_RULE_PKG;
3004 for (i = 0; i < rq.count; i += 4)
3007 qt = rq.elements[i];
3008 qp = rq.elements[i + 1];
3009 qo = rq.elements[i + 2];
3010 qd = rq.elements[i + 3];
3011 if (type == SOLVER_RULE_PKG || type > qt)
3025 if (rid >= solv->jobrules && rid < solv->jobrules_end)
3027 Id jidx = solv->ruletojob.elements[rid - solv->jobrules];
3031 *top = solv->job.elements[jidx];
3033 *depp = solv->job.elements[jidx + 1];
3034 if ((r->d == 0 || r->d == -1) && r->w2 == 0 && r->p == -SYSTEMSOLVABLE)
3036 Id how = solv->job.elements[jidx];
3037 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_INSTALL|SOLVER_SOLVABLE_NAME))
3038 return SOLVER_RULE_JOB_UNKNOWN_PACKAGE;
3039 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES))
3040 return SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP;
3041 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_ERASE|SOLVER_SOLVABLE_NAME))
3042 return SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM;
3043 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_ERASE|SOLVER_SOLVABLE_PROVIDES))
3044 return SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM;
3045 return SOLVER_RULE_JOB_UNSUPPORTED;
3047 return SOLVER_RULE_JOB;
3049 if (rid >= solv->updaterules && rid < solv->updaterules_end)
3052 *fromp = solv->installed->start + (rid - solv->updaterules);
3053 return SOLVER_RULE_UPDATE;
3055 if (rid >= solv->featurerules && rid < solv->featurerules_end)
3058 *fromp = solv->installed->start + (rid - solv->featurerules);
3059 return SOLVER_RULE_FEATURE;
3061 if (rid >= solv->duprules && rid < solv->duprules_end)
3066 *depp = pool->solvables[-r->p].name;
3067 return SOLVER_RULE_DISTUPGRADE;
3069 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
3074 *depp = pool->solvables[-r->p].name;
3075 return SOLVER_RULE_INFARCH;
3077 if (rid >= solv->bestrules && rid < solv->bestrules_end)
3079 if (fromp && solv->bestrules_info[rid - solv->bestrules] > 0)
3080 *fromp = solv->bestrules_info[rid - solv->bestrules];
3081 return SOLVER_RULE_BEST;
3083 if (rid >= solv->yumobsrules && rid < solv->yumobsrules_end)
3089 /* first solvable is enough, we just need it for the name */
3090 if (!r->d || r->d == -1)
3093 *top = pool->whatprovidesdata[r->d < 0 ? -r->d : r->d];
3096 *depp = solv->yumobsrules_info[rid - solv->yumobsrules];
3097 return SOLVER_RULE_YUMOBS;
3099 if (rid >= solv->blackrules && rid < solv->blackrules_end)
3103 return SOLVER_RULE_BLACK;
3105 if (rid >= solv->strictrepopriorules && rid < solv->strictrepopriorules_end)
3109 return SOLVER_RULE_STRICT_REPO_PRIORITY;
3111 if (rid >= solv->choicerules && rid < solv->choicerules_end)
3112 return SOLVER_RULE_CHOICE;
3113 if (rid >= solv->recommendsrules && rid < solv->recommendsrules_end)
3114 return SOLVER_RULE_RECOMMENDS;
3115 if (rid >= solv->learntrules)
3116 return SOLVER_RULE_LEARNT;
3117 return SOLVER_RULE_UNKNOWN;
3121 solver_ruleclass(Solver *solv, Id rid)
3124 return SOLVER_RULE_UNKNOWN;
3125 if (rid > 0 && rid < solv->pkgrules_end)
3126 return SOLVER_RULE_PKG;
3127 if (rid >= solv->jobrules && rid < solv->jobrules_end)
3128 return SOLVER_RULE_JOB;
3129 if (rid >= solv->updaterules && rid < solv->updaterules_end)
3130 return SOLVER_RULE_UPDATE;
3131 if (rid >= solv->featurerules && rid < solv->featurerules_end)
3132 return SOLVER_RULE_FEATURE;
3133 if (rid >= solv->duprules && rid < solv->duprules_end)
3134 return SOLVER_RULE_DISTUPGRADE;
3135 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
3136 return SOLVER_RULE_INFARCH;
3137 if (rid >= solv->bestrules && rid < solv->bestrules_end)
3138 return SOLVER_RULE_BEST;
3139 if (rid >= solv->yumobsrules && rid < solv->yumobsrules_end)
3140 return SOLVER_RULE_YUMOBS;
3141 if (rid >= solv->blackrules && rid < solv->blackrules_end)
3142 return SOLVER_RULE_BLACK;
3143 if (rid >= solv->choicerules && rid < solv->choicerules_end)
3144 return SOLVER_RULE_CHOICE;
3145 if (rid >= solv->recommendsrules && rid < solv->recommendsrules_end)
3146 return SOLVER_RULE_RECOMMENDS;
3147 if (rid >= solv->strictrepopriorules && rid < solv->strictrepopriorules_end)
3148 return SOLVER_RULE_STRICT_REPO_PRIORITY;
3149 if (rid >= solv->learntrules && rid < solv->nrules)
3150 return SOLVER_RULE_LEARNT;
3151 return SOLVER_RULE_UNKNOWN;
3155 solver_ruleliterals(Solver *solv, Id rid, Queue *q)
3157 Pool *pool = solv->pool;
3162 r = solv->rules + rid;
3163 FOR_RULELITERALS(p, pp, r)
3164 if (p != -SYSTEMSOLVABLE)
3167 queue_push(q, -SYSTEMSOLVABLE); /* hmm, better to return an empty result? */
3171 solver_rule2jobidx(Solver *solv, Id rid)
3173 if (rid < solv->jobrules || rid >= solv->jobrules_end)
3175 return solv->ruletojob.elements[rid - solv->jobrules] + 1;
3178 /* job rule introspection */
3180 solver_rule2job(Solver *solv, Id rid, Id *whatp)
3183 if (rid < solv->jobrules || rid >= solv->jobrules_end)
3189 idx = solv->ruletojob.elements[rid - solv->jobrules];
3191 *whatp = solv->job.elements[idx + 1];
3192 return solv->job.elements[idx];
3195 /* update/feature rule introspection */
3197 solver_rule2solvable(Solver *solv, Id rid)
3199 if (rid >= solv->updaterules && rid < solv->updaterules_end)
3200 return rid - solv->updaterules;
3201 if (rid >= solv->featurerules && rid < solv->featurerules_end)
3202 return rid - solv->featurerules;
3207 solver_rule2pkgrule(Solver *solv, Id rid)
3209 if (rid >= solv->choicerules && rid < solv->choicerules_end)
3210 return solv->choicerules_info[rid - solv->choicerules];
3211 if (rid >= solv->recommendsrules && rid < solv->recommendsrules_end)
3212 return solv->recommendsrules_info[rid - solv->recommendsrules];
3217 solver_rule2rules_rec(Solver *solv, Id rid, Queue *q, Map *seen)
3224 for (i = solv->learnt_why.elements[rid - solv->learntrules]; (rid2 = solv->learnt_pool.elements[i]) != 0; i++)
3228 if (MAPTST(seen, rid2))
3230 if (rid2 >= solv->learntrules)
3231 solver_rule2rules_rec(solv, rid2, q, seen);
3234 queue_push(q, rid2);
3238 /* learnt rule introspection */
3240 solver_rule2rules(Solver *solv, Id rid, Queue *q, int recursive)
3243 if (rid < solv->learntrules || rid >= solv->nrules)
3248 map_init(&seen, solv->nrules);
3249 solver_rule2rules_rec(solv, rid, q, &seen);
3253 solver_rule2rules_rec(solv, rid, q, 0);
3257 /* check if the newest versions of pi still provides the dependency we're looking for */
3259 solver_choicerulecheck(Solver *solv, Id pi, Rule *r, Map *m, Queue *q)
3261 Pool *pool = solv->pool;
3266 if (!q->count || q->elements[0] != pi)
3270 ur = solv->rules + solv->updaterules + (pi - pool->installed->start);
3272 ur = solv->rules + solv->featurerules + (pi - pool->installed->start);
3275 queue_push2(q, pi, 0);
3276 FOR_RULELITERALS(p, pp, ur)
3285 return MAPTST(m, p) ? 0 : 1;
3287 if (!q->elements[1])
3289 for (i = 2; i < q->count; i++)
3290 if (!MAPTST(m, q->elements[i]))
3293 return 0; /* all provide it, no need to filter */
3294 /* some don't provide it, have to filter */
3295 queue_deleten(q, 0, 2);
3296 policy_filter_unwanted(solv, q, POLICY_MODE_CHOOSE);
3297 queue_unshift(q, 1); /* filter mark */
3298 queue_unshift(q, pi);
3300 for (i = 2; i < q->count; i++)
3301 if (MAPTST(m, q->elements[i]))
3302 return 0; /* at least one provides it */
3303 return 1; /* none of the new packages provided it */
3307 solver_choicerulecheck2(Solver *solv, Id pi, Id pt, Queue *q)
3309 Pool *pool = solv->pool;
3314 if (!q->count || q->elements[0] != pi)
3318 ur = solv->rules + solv->updaterules + (pi - pool->installed->start);
3320 ur = solv->rules + solv->featurerules + (pi - pool->installed->start);
3322 return 1; /* orphaned, thus newest */
3323 queue_push2(q, pi, 0);
3324 FOR_RULELITERALS(p, pp, ur)
3325 if (p > 0 && p != pi)
3330 return q->count == 3 && q->elements[2] == pt ? 1 : 0;
3331 if (!q->elements[1])
3333 queue_deleten(q, 0, 2);
3334 policy_filter_unwanted(solv, q, POLICY_MODE_CHOOSE);
3335 queue_unshift(q, 1); /* filter mark */
3336 queue_unshift(q, pi);
3338 for (i = 2; i < q->count; i++)
3339 if (q->elements[i] == pt)
3341 return 0; /* not newest */
3345 solver_choicerulecheck3(Solver *solv, Id pt, Queue *q)
3347 Pool *pool = solv->pool;
3351 if (!q->count || q->elements[0] != pt)
3353 Solvable *s = pool->solvables + pt;
3356 /* no installed package, so check all with same name */
3357 queue_push2(q, pt, 0);
3358 FOR_PROVIDES(p, pp, s->name)
3359 if (pool->solvables[p].name == s->name && p != pt)
3364 return q->count == 3 && q->elements[2] == pt ? 1 : 0;
3365 if (!q->elements[1])
3367 queue_deleten(q, 0, 2);
3368 policy_filter_unwanted(solv, q, POLICY_MODE_CHOOSE);
3369 queue_unshift(q, 1); /* filter mark */
3370 queue_unshift(q, pt);
3372 for (i = 2; i < q->count; i++)
3373 if (q->elements[i] == pt)
3375 return 0; /* not newest */
3379 queue_removeelement(Queue *q, Id el)
3382 for (i = 0; i < q->count; i++)
3383 if (q->elements[i] == el)
3387 for (j = i++; i < q->count; i++)
3388 if (q->elements[i] != el)
3389 q->elements[j++] = q->elements[i];
3390 queue_truncate(q, j);
3395 choicerule_find_installed(Pool *pool, Id p)
3397 Solvable *s = pool->solvables + p;
3402 if (s->repo == pool->installed)
3404 FOR_PROVIDES(p2, pp2, s->name)
3406 Solvable *s2 = pool->solvables + p2;
3407 if (s2->repo != pool->installed)
3409 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
3411 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, s2))
3417 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
3418 while ((obs = *obsp++) != 0)
3420 FOR_PROVIDES(p2, pp2, obs)
3422 Solvable *s2 = pool->solvables + p2;
3423 if (s2->repo != pool->installed)
3425 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
3427 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
3437 solver_addchoicerules(Solver *solv)
3439 Pool *pool = solv->pool;
3442 Queue q, qi, qcheck, qcheck2, infoq;
3443 int i, j, rid, havechoice, negcnt;
3446 Id lastaddedp, lastaddedd;
3451 solv->choicerules = solv->nrules;
3452 if (!pool->installed)
3454 solv->choicerules_end = solv->nrules;
3457 now = solv_timems(0);
3460 queue_init(&qcheck);
3461 queue_init(&qcheck2);
3463 map_init(&m, pool->nsolvables);
3464 map_init(&mneg, pool->nsolvables);
3465 /* set up negative assertion map from infarch and dup rules */
3466 for (rid = solv->infarchrules, r = solv->rules + rid; rid < solv->infarchrules_end; rid++, r++)
3467 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
3468 MAPSET(&mneg, -r->p);
3469 for (rid = solv->duprules, r = solv->rules + rid; rid < solv->duprules_end; rid++, r++)
3470 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
3471 MAPSET(&mneg, -r->p);
3475 for (rid = 1; rid < solv->pkgrules_end ; rid++)
3477 r = solv->rules + rid;
3478 if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 <= 0))
3479 continue; /* only look at requires rules */
3480 /* solver_printrule(solv, SOLV_DEBUG_RESULT, r); */
3484 FOR_RULELITERALS(p, pp, r)
3488 s = pool->solvables + p;
3491 if (s->repo == pool->installed)
3493 queue_push2(&qi, p, p);
3497 /* find an installed package p2 that we can update/downgrade to p */
3498 p2 = choicerule_find_installed(pool, p);
3501 if (MAPTST(&mneg, p))
3503 if (policy_is_illegal(solv, pool->solvables + p2, s, 0))
3505 queue_push2(&qi, p2, p);
3509 /* package p is independent of the installed ones */
3513 printf("havechoice: %d qcount %d qicount %d\n", havechoice, q.count, qi.count);
3515 if (!havechoice || !q.count || !qi.count)
3516 continue; /* no choice */
3518 FOR_RULELITERALS(p, pp, r)
3523 FOR_RULELITERALS(p, pp, r)
3527 p2 = choicerule_find_installed(pool, -p);
3528 if (p2 && !solver_choicerulecheck2(solv, p2, -p, &qcheck2))
3533 if (!p2 && !solver_choicerulecheck3(solv, -p, &qcheck2))
3539 /* do extra checking */
3540 for (i = j = 0; i < qi.count; i += 2)
3542 p2 = qi.elements[i];
3545 if (isnewest && solver_choicerulecheck(solv, p2, r, &m, &qcheck))
3547 /* oops, remove element p from q */
3548 queue_removeelement(&q, qi.elements[i + 1]);
3551 qi.elements[j++] = p2;
3553 queue_truncate(&qi, j);
3555 if (!q.count || !qi.count)
3557 FOR_RULELITERALS(p, pp, r)
3564 /* now check the update rules of the installed package.
3565 * if all packages of the update rules are contained in
3566 * the dependency rules, there's no need to set up the choice rule */
3567 for (i = 0; i < qi.count; i++)
3570 if (!qi.elements[i])
3572 ur = solv->rules + solv->updaterules + (qi.elements[i] - pool->installed->start);
3574 ur = solv->rules + solv->featurerules + (qi.elements[i] - pool->installed->start);
3577 FOR_RULELITERALS(p, pp, ur)
3582 for (j = i + 1; j < qi.count; j++)
3583 if (qi.elements[i] == qi.elements[j])
3586 /* empty map again */
3588 FOR_RULELITERALS(p, pp, r)
3596 printf("skipping choice ");
3597 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + rid);
3601 /* add neg elements to the front */
3605 FOR_RULELITERALS(p, pp, r)
3606 if (p < 0 && p != r->p)
3607 queue_insert(&q, i++, p);
3609 /* don't add identical rules */
3610 if (lastaddedp == r->p && lastaddedcnt == q.count)
3612 for (i = 0; i < q.count; i++)
3613 if (q.elements[i] != pool->whatprovidesdata[lastaddedd + i])
3616 continue; /* already added that one */
3618 d = q.count ? pool_queuetowhatprovides(pool, &q) : 0;
3622 lastaddedcnt = q.count;
3624 solver_addrule(solv, r->p, 0, d);
3625 queue_push(&solv->weakruleq, solv->nrules - 1);
3626 queue_push(&infoq, rid);
3629 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + rid);
3630 printf("WEAK CHOICE ");
3631 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + solv->nrules - 1);
3635 solv->choicerules_info = solv_memdup2(infoq.elements, infoq.count, sizeof(Id));
3638 queue_free(&qcheck);
3639 queue_free(&qcheck2);
3643 solv->choicerules_end = solv->nrules;
3644 POOL_DEBUG(SOLV_DEBUG_STATS, "choice rule creation took %d ms\n", solv_timems(now));
3647 /* called when a choice rule needs to be disabled by analyze_unsolvable.
3648 * We also have to disable all other choice rules so that the best packages
3651 solver_disablechoicerules(Solver *solv, Rule *r)
3654 Pool *pool = solv->pool;
3658 solver_disablerule(solv, r);
3659 or = solv->rules + solv->choicerules_info[(r - solv->rules) - solv->choicerules];
3660 map_init(&m, pool->nsolvables);
3661 FOR_RULELITERALS(p, pp, or)
3664 FOR_RULELITERALS(p, pp, r)
3667 for (rid = solv->choicerules; rid < solv->choicerules_end; rid++)
3669 r = solv->rules + rid;
3672 or = solv->rules + solv->choicerules_info[rid - solv->choicerules];
3673 FOR_RULELITERALS(p, pp, or)
3674 if (p > 0 && MAPTST(&m, p))
3677 solver_disablerule(solv, r);
3682 prune_to_update_targets(Solver *solv, Id *cp, Queue *q)
3686 for (i = j = 0; i < q->count; i++)
3689 for (cp2 = cp; *cp2; cp2++)
3692 q->elements[j++] = p;
3696 queue_truncate(q, j);
3700 prune_to_dup_packages(Solver *solv, Id p, Queue *q)
3703 for (i = j = 0; i < q->count; i++)
3705 Id p = q->elements[i];
3706 if (MAPTST(&solv->dupmap, p))
3707 q->elements[j++] = p;
3709 queue_truncate(q, j);
3713 prune_best_update(Solver *solv, Id p, Queue *q)
3715 if (solv->update_targets && solv->update_targets->elements[p - solv->installed->start])
3716 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[p - solv->installed->start], q);
3717 if (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
3718 prune_to_dup_packages(solv, p, q);
3719 /* select best packages, just look at prio and version */
3720 policy_filter_unwanted(solv, q, POLICY_MODE_RECOMMEND);
3724 prune_disabled(Pool *pool, Queue *q)
3727 for (i = j = 0; i < q->count; i++)
3729 Id p = q->elements[i];
3730 Solvable *s = pool->solvables + p;
3731 if (s->repo && s->repo != pool->installed && !MAPTST(pool->considered, p))
3733 q->elements[j++] = p;
3735 queue_truncate(q, j);
3739 solver_addbestrules(Solver *solv, int havebestinstalljobs, int haslockjob)
3741 Pool *pool = solv->pool;
3744 Repo *installed = solv->installed;
3751 solv->bestrules = solv->nrules;
3759 lockedmap = solv_calloc(1, sizeof(Map));
3760 map_init(lockedmap, pool->nsolvables);
3761 for (i = 0, r = solv->rules + solv->jobrules; i < solv->ruletojob.count; i++, r++)
3763 if (r->w2 || (solv->job.elements[solv->ruletojob.elements[i]] & SOLVER_JOBMASK) != SOLVER_LOCK)
3765 p = r->p > 0 ? r->p : -r->p;
3766 MAPSET(lockedmap, p);
3769 if (havebestinstalljobs)
3771 for (i = 0; i < solv->job.count; i += 2)
3773 Id how = solv->job.elements[i];
3774 if ((how & (SOLVER_JOBMASK | SOLVER_FORCEBEST)) == (SOLVER_INSTALL | SOLVER_FORCEBEST))
3778 for (j = 0; j < solv->ruletojob.count; j++)
3780 if (solv->ruletojob.elements[j] != i)
3782 r = solv->rules + solv->jobrules + j;
3785 FOR_RULELITERALS(p2, pp2, r)
3790 queue_push(&q2, p2);
3792 if (pool->considered && pool->whatprovideswithdisabled)
3793 prune_disabled(pool, &q);
3795 continue; /* orphaned */
3796 /* select best packages, just look at prio and version */
3798 policy_filter_unwanted(solv, &q, POLICY_MODE_RECOMMEND);
3799 if (q.count == oldcnt)
3800 continue; /* nothing filtered */
3803 queue_insertn(&q, 0, q2.count, q2.elements);
3805 FOR_RULELITERALS(p2, pp2, r)
3809 if (installed && pool->solvables[p2].repo == installed)
3811 if (MAPTST(lockedmap, p2))
3812 queue_pushunique(&q, p2); /* we always want that package */
3814 else if (MAPTST(lockedmap, p2))
3816 queue_push(&q2, p2);
3818 if (pool->considered && pool->whatprovideswithdisabled)
3819 prune_disabled(pool, &q2);
3820 policy_filter_unwanted(solv, &q2, POLICY_MODE_RECOMMEND);
3821 for (k = 0; k < q2.count; k++)
3822 queue_pushunique(&q, q2.elements[k]);
3826 queue_insertn(&q, 0, q2.count, q2.elements);
3827 p2 = queue_shift(&q);
3829 solver_addrule(solv, p2, q.count ? q.elements[0] : 0, 0);
3831 solver_addrule(solv, p2, 0, pool_queuetowhatprovides(pool, &q));
3832 if ((how & SOLVER_WEAK) != 0)
3833 queue_push(&solv->weakruleq, solv->nrules - 1);
3834 queue_push(&infoq, -(solv->jobrules + j));
3839 solv->bestrules_up = solv->nrules;
3841 if (installed && (solv->bestupdatemap_all || solv->bestupdatemap.size))
3845 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
3846 map_init(&m, pool->nsolvables);
3849 FOR_REPO_SOLVABLES(installed, p, s)
3852 if (!solv->updatemap_all && (!solv->updatemap.size || !MAPTST(&solv->updatemap, p - installed->start)))
3854 if (!solv->bestupdatemap_all && (!solv->bestupdatemap.size || !MAPTST(&solv->bestupdatemap, p - installed->start)))
3857 if (solv->bestobeypolicy)
3858 r = solv->rules + solv->updaterules + (p - installed->start);
3861 r = solv->rules + solv->featurerules + (p - installed->start);
3862 if (!r->p) /* identical to update rule? */
3863 r = solv->rules + solv->updaterules + (p - installed->start);
3865 if (solv->specialupdaters && (d = solv->specialupdaters[p - installed->start]) != 0 && r == solv->rules + solv->updaterules + (p - installed->start))
3867 /* need to check specialupdaters */
3868 if (r->p == p) /* be careful with the dup case */
3870 while ((p2 = pool->whatprovidesdata[d++]) != 0)
3875 FOR_RULELITERALS(p2, pp2, r)
3882 queue_insertn(&q2, 0, q.count, q.elements);
3884 prune_best_update(solv, p, &q);
3886 continue; /* orphaned */
3890 /* always ok to keep installed locked packages */
3891 if (MAPTST(lockedmap, p))
3892 queue_pushunique(&q2, p);
3893 for (j = 0; j < q2.count; j++)
3895 Id p2 = q2.elements[j];
3896 if (pool->solvables[p2].repo == installed && MAPTST(lockedmap, p2))
3897 queue_pushunique(&q, p2);
3899 /* filter out locked packages */
3900 for (i = j = 0; j < q2.count; j++)
3902 Id p2 = q2.elements[j];
3903 if (pool->solvables[p2].repo == installed || !MAPTST(lockedmap, p2))
3904 q2.elements[i++] = p2;
3906 queue_truncate(&q2, i);
3907 prune_best_update(solv, p, &q2);
3908 for (j = 0; j < q2.count; j++)
3909 queue_pushunique(&q, q2.elements[j]);
3911 if (solv->bestobeypolicy)
3913 /* also filter the best of the feature rule packages and add them */
3914 r = solv->rules + solv->featurerules + (p - installed->start);
3919 FOR_RULELITERALS(p2, pp2, r)
3921 queue_push(&q2, p2);
3922 prune_best_update(solv, p, &q2);
3923 for (j = 0; j < q2.count; j++)
3924 queue_pushunique(&q, q2.elements[j]);
3928 FOR_RULELITERALS(p2, pp2, r)
3930 if (pool->solvables[p2].repo == installed || !MAPTST(lockedmap, p2))
3931 queue_push(&q2, p2);
3932 prune_best_update(solv, p, &q2);
3933 for (j = 0; j < q2.count; j++)
3934 queue_pushunique(&q, q2.elements[j]);
3938 if (solv->allowuninstall || solv->allowuninstall_all || (solv->allowuninstallmap.size && MAPTST(&solv->allowuninstallmap, p - installed->start)))
3940 /* package is flagged both for allowuninstall and best, add negative rules */
3941 d = q.count == 1 ? q.elements[0] : -pool_queuetowhatprovides(pool, &q);
3942 for (i = 0; i < q.count; i++)
3943 MAPSET(&m, q.elements[i]);
3944 r = solv->rules + solv->featurerules + (p - installed->start);
3945 if (!r->p) /* identical to update rule? */
3946 r = solv->rules + solv->updaterules + (p - installed->start);
3947 FOR_RULELITERALS(p2, pp2, r)
3952 solver_addrule(solv, -p2, d, 0);
3954 solver_addrule(solv, -p2, 0, -d);
3955 queue_push(&infoq, p);
3957 for (i = 0; i < q.count; i++)
3958 MAPCLR(&m, q.elements[i]);
3961 p2 = queue_shift(&q);
3963 solver_addrule(solv, p2, q.count ? q.elements[0] : 0, 0);
3965 solver_addrule(solv, p2, 0, pool_queuetowhatprovides(pool, &q));
3966 queue_push(&infoq, p);
3971 solv->bestrules_info = solv_memdup2(infoq.elements, infoq.count, sizeof(Id));
3972 solv->bestrules_end = solv->nrules;
3978 map_free(lockedmap);
3979 solv_free(lockedmap);
3986 /* yumobs rule handling */
3987 /* note that we use pool->obsoleteusescolors || pool->implicitobsoleteusescolors
3988 * like in policy_findupdatepackages */
3991 find_obsolete_group(Solver *solv, Id obs, Queue *q)
3993 Pool *pool = solv->pool;
3995 Id p2, pp2, op, *opp, opp2;
3996 int i, j, qnc, ncnt;
3999 FOR_PROVIDES(p2, pp2, obs)
4001 Solvable *s2 = pool->solvables + p2;
4002 if (s2->repo != pool->installed)
4004 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
4006 /* we obsolete installed package s2 with obs. now find all other packages that have the same dep */
4007 for (opp = solv->obsoletes_data + solv->obsoletes[p2 - solv->installed->start]; (op = *opp++) != 0;)
4009 Solvable *os = pool->solvables + op;
4013 if ((pool->obsoleteusescolors || pool->implicitobsoleteusescolors) && !pool_colormatch(pool, s2, os))
4015 obsp2 = os->repo->idarraydata + os->obsoletes;
4016 while ((obs2 = *obsp2++) != 0)
4020 queue_pushunique(q, op);
4022 /* also search packages with the same name */
4023 FOR_PROVIDES(op, opp2, s2->name)
4025 Solvable *os = pool->solvables + op;
4027 if (os->name != s2->name)
4031 if ((pool->obsoleteusescolors || pool->implicitobsoleteusescolors) && !pool_colormatch(pool, s2, os))
4033 obsp2 = os->repo->idarraydata + os->obsoletes;
4034 while ((obs2 = *obsp2++) != 0)
4038 queue_pushunique(q, op);
4041 /* find names so that we can build groups */
4042 queue_init_clone(&qn, q);
4043 prune_to_best_version(solv->pool, &qn);
4046 for (i = 0; i < qn.count; i++)
4047 printf(" + %s\n", pool_solvid2str(pool, qn.elements[i]));
4050 /* filter into name groups */
4059 for (i = 0; i < qnc; i++)
4061 Id n = pool->solvables[qn.elements[i]].name;
4063 for (j = 0; j < q->count; j++)
4065 Id p = q->elements[j];
4066 if (pool->solvables[p].name == n)
4085 queue_insertn(q, 0, qn.count - qnc, qn.elements + qnc);
4091 solver_addyumobsrules(Solver *solv)
4093 Pool *pool = solv->pool;
4094 Repo *installed = solv->installed;
4097 Queue qo, qq, infoq;
4101 solv->yumobsrules = solv->nrules;
4102 if (!installed || !solv->obsoletes)
4104 solv->yumobsrules_end = solv->nrules;
4107 now = solv_timems(0);
4109 FOR_REPO_SOLVABLES(installed, p, s)
4111 if (!solv->obsoletes[p - installed->start])
4114 printf("checking yumobs for %s\n", pool_solvable2str(pool, s));
4116 for (opp = solv->obsoletes_data + solv->obsoletes[p - installed->start]; (op = *opp++) != 0;)
4118 Solvable *os = pool->solvables + op;
4119 Id obs, *obsp = os->repo->idarraydata + os->obsoletes;
4121 while ((obs = *obsp++) != 0)
4123 FOR_PROVIDES(p2, pp2, obs)
4125 Solvable *s2 = pool->solvables + p2;
4126 if (s2->repo != installed)
4128 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
4130 if ((pool->obsoleteusescolors || pool->implicitobsoleteusescolors) && !pool_colormatch(pool, s, s2))
4132 queue_pushunique(&qo, obs);
4145 for (i = 0; i < qo.count; i++)
4147 int group, groupk, groupstart;
4150 printf("investigating %s\n", pool_dep2str(pool, qo.elements[i]));
4152 find_obsolete_group(solv, qo.elements[i], &qq);
4154 printf("result:\n");
4155 for (j = 0; j < qq.count; j++)
4156 if (qq.elements[j] == 0)
4159 printf("%s\n", pool_solvid2str(pool, qq.elements[j]));
4164 /* at least two goups, build rules */
4166 for (j = 0; j < qq.count; j++)
4174 if (pool->solvables[p].repo == installed)
4178 for (k = 0; k < qq.count; k++)
4180 Id pk = qq.elements[k];
4183 if (group != groupk && k > groupstart)
4186 if (k - groupstart == 1)
4187 solver_addrule(solv, -p, qq.elements[groupstart], 0);
4189 solver_addrule(solv, -p, 0, pool_ids2whatprovides(pool, qq.elements + groupstart, k - groupstart));
4190 queue_push(&infoq, qo.elements[i]);
4198 solv->yumobsrules_info = solv_memdup2(infoq.elements, infoq.count, sizeof(Id));
4202 solv->yumobsrules_end = solv->nrules;
4203 POOL_DEBUG(SOLV_DEBUG_STATS, "yumobs rule creation took %d ms\n", solv_timems(now));
4206 /* recommendsrules are a copy of some recommends package rule but
4207 * with some disfavored literals removed */
4209 solver_addrecommendsrules(Solver *solv)
4211 Pool *pool = solv->pool;
4212 int i, havedis, havepos;
4216 solv->recommendsrules = solv->nrules;
4219 for (i = 0; i < solv->recommendsruleq->count; i++)
4221 int rid = solv->recommendsruleq->elements[i];
4222 Rule *r = solv->rules + rid;
4224 havedis = havepos = 0;
4225 FOR_RULELITERALS(p, pp, r)
4227 if (p > 0 && solv->favormap[p] < 0)
4238 solver_disablerule(solv, r);
4239 if (!havepos || q.count < 2)
4242 solver_addrule(solv, q.elements[0], q.elements[1], 0);
4244 solver_addrule(solv, q.elements[0], 0, pool_ids2whatprovides(pool, q.elements + 1, q.count - 1));
4245 queue_push(&infoq, rid);
4248 solv->recommendsrules_info = solv_memdup2(infoq.elements, infoq.count, sizeof(Id));
4251 solv->recommendsrules_end = solv->nrules;
4255 solver_breakorphans(Solver *solv)
4257 Pool *pool = solv->pool;
4258 Repo *installed = solv->installed;
4262 if (!installed || solv->droporphanedmap_all)
4264 solv->brokenorphanrules = solv_calloc(1, sizeof(Queue));
4265 queue_init(solv->brokenorphanrules);
4266 map_init(&m, installed->end - installed->start);
4267 for (i = 0; i < solv->orphaned.count; i++)
4269 Id p = solv->orphaned.elements[i];
4270 if (pool->solvables[p].repo != installed)
4272 if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - installed->start))
4274 MAPSET(&m, p - installed->start);
4276 for (rid = 1; rid < solv->pkgrules_end ; rid++)
4279 Rule *r = solv->rules + rid;
4280 /* ignore non-deps and simple conflicts */
4281 if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 < 0))
4284 if (p < installed->start || p >= installed->end || !MAPTST(&m, p - installed->start))
4286 /* need to check other literals */
4287 if (r->d == 0 || r->d == -1)
4289 for (dp = pool->whatprovidesdata + (r->d < 0 ? -r->d - 1 : r->d); *dp < 0; dp++)
4292 if (p >= installed->start && p < installed->end && MAPTST(&m, p - installed->start))
4298 /* ok, disable this rule */
4299 queue_push(solv->brokenorphanrules, rid);
4301 solver_disablerule(solv, r);
4304 if (!solv->brokenorphanrules->count)
4306 queue_free(solv->brokenorphanrules);
4307 solv->brokenorphanrules = solv_free(solv->brokenorphanrules);
4312 solver_check_brokenorphanrules(Solver *solv, Queue *dq)
4314 Pool *pool = solv->pool;
4319 if (!solv->brokenorphanrules)
4321 for (i = 0; i < solv->brokenorphanrules->count; i++)
4323 int rid = solv->brokenorphanrules->elements[i];
4324 Rule *r = solv->rules + rid;
4325 FOR_RULELITERALS(l, pp, r)
4329 if (solv->decisionmap[-l] <= 0)
4334 if (solv->decisionmap[l] > 0 && pool->solvables[l].repo != solv->installed)
4340 FOR_RULELITERALS(l, pp, r)
4341 if (l > 0 && solv->decisionmap[l] == 0 && pool->solvables[l].repo != solv->installed)
4342 queue_pushunique(dq, l);