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 *** Policy rule disabling/reenabling
2262 *** Disable all policy rules that conflict with our jobs. If a job
2263 *** gets disabled later on, reenable the involved policy rules again.
2267 #define DISABLE_UPDATE 1
2268 #define DISABLE_INFARCH 2
2269 #define DISABLE_DUP 3
2270 #define DISABLE_BLACK 4
2273 jobtodisablelist(Solver *solv, Id how, Id what, Queue *q)
2275 Pool *pool = solv->pool;
2279 int i, j, set, qstart;
2282 installed = solv->installed;
2283 select = how & SOLVER_SELECTMASK;
2284 switch (how & SOLVER_JOBMASK)
2286 case SOLVER_INSTALL:
2287 set = how & SOLVER_SETMASK;
2288 if (!(set & SOLVER_NOAUTOSET))
2290 /* automatically add set bits by analysing the job */
2291 if (select == SOLVER_SOLVABLE_NAME)
2292 set |= SOLVER_SETNAME;
2293 if (select == SOLVER_SOLVABLE)
2294 set |= SOLVER_SETNAME | SOLVER_SETARCH | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_SETEVR;
2295 else if ((select == SOLVER_SOLVABLE_NAME || select == SOLVER_SOLVABLE_PROVIDES) && ISRELDEP(what))
2297 Reldep *rd = GETRELDEP(pool, what);
2298 if (rd->flags == REL_EQ && select == SOLVER_SOLVABLE_NAME)
2300 if (pool->disttype != DISTTYPE_DEB)
2302 const char *rel = strrchr(pool_id2str(pool, rd->evr), '-');
2303 set |= rel ? SOLVER_SETEVR : SOLVER_SETEV;
2306 set |= SOLVER_SETEVR;
2308 if (rd->flags <= 7 && ISRELDEP(rd->name))
2309 rd = GETRELDEP(pool, rd->name);
2310 if (rd->flags == REL_ARCH)
2311 set |= SOLVER_SETARCH;
2315 set &= ~SOLVER_NOAUTOSET;
2318 if ((set & SOLVER_SETARCH) != 0 && solv->infarchrules != solv->infarchrules_end)
2320 if (select == SOLVER_SOLVABLE)
2322 for (i = solv->infarchrules; i < solv->infarchrules_end; i++)
2323 if (solv->rules[i].p == -what)
2325 if (i < solv->infarchrules_end)
2326 queue_push2(q, DISABLE_INFARCH, pool->solvables[what].name);
2330 int qcnt = q->count;
2331 /* does not work for SOLVER_SOLVABLE_ALL and SOLVER_SOLVABLE_REPO, but
2332 they are not useful for SOLVER_INSTALL jobs anyway */
2333 FOR_JOB_SELECT(p, pp, select, what)
2335 s = pool->solvables + p;
2337 for (i = qcnt; i < q->count; i += 2)
2338 if (q->elements[i + 1] == s->name)
2341 continue; /* already have that DISABLE_INFARCH element */
2342 for (i = solv->infarchrules; i < solv->infarchrules_end; i++)
2343 if (solv->rules[i].p == -p)
2345 if (i < solv->infarchrules_end)
2346 queue_push2(q, DISABLE_INFARCH, s->name);
2350 if ((set & SOLVER_SETREPO) != 0 && solv->duprules != solv->duprules_end)
2352 if (select == SOLVER_SOLVABLE)
2353 queue_push2(q, DISABLE_DUP, pool->solvables[what].name);
2356 int qcnt = q->count;
2357 FOR_JOB_SELECT(p, pp, select, what)
2359 s = pool->solvables + p;
2361 for (i = qcnt; i < q->count; i += 2)
2362 if (q->elements[i + 1] == s->name)
2366 queue_push2(q, DISABLE_DUP, s->name);
2370 if ((set & SOLVER_SETEVR) != 0 && solv->blackrules != solv->blackrules_end)
2372 if (select == SOLVER_SOLVABLE)
2373 queue_push2(q, DISABLE_BLACK, what);
2376 FOR_JOB_SELECT(p, pp, select, what)
2377 queue_push2(q, DISABLE_BLACK, p);
2380 if (!installed || installed->end == installed->start)
2382 /* now the hard part: disable some update rules */
2384 /* first check if we have installed or multiversion packages in the job */
2385 FOR_JOB_SELECT(p, pp, select, what)
2387 if (pool->solvables[p].repo == installed)
2389 if (solv->multiversion.size && MAPTST(&solv->multiversion, p) && !solv->keepexplicitobsoletes)
2390 return; /* will not obsolete anything, so just return */
2394 FOR_JOB_SELECT(p, pp, select, what)
2396 solver_intersect_obsoleted(solv, p, q, qstart, &omap);
2397 if (q->count == qstart)
2403 if (qstart == q->count)
2404 return; /* nothing to prune */
2406 /* convert result to (DISABLE_UPDATE, p) pairs */
2408 for (j = qstart; j < i; j++)
2409 queue_push(q, q->elements[j]);
2410 for (j = qstart; j < q->count; j += 2)
2412 q->elements[j] = DISABLE_UPDATE;
2413 q->elements[j + 1] = q->elements[i++];
2416 /* now that we know which installed packages are obsoleted check each of them */
2417 if ((set & (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR)) == (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR))
2418 return; /* all is set, nothing to do */
2420 for (i = j = qstart; i < q->count; i += 2)
2422 Solvable *is = pool->solvables + q->elements[i + 1];
2423 FOR_JOB_SELECT(p, pp, select, what)
2426 s = pool->solvables + p;
2427 if ((set & SOLVER_SETEVR) != 0)
2428 illegal |= POLICY_ILLEGAL_DOWNGRADE; /* ignore */
2429 if ((set & SOLVER_SETNAME) != 0)
2430 illegal |= POLICY_ILLEGAL_NAMECHANGE; /* ignore */
2431 if ((set & SOLVER_SETARCH) != 0)
2432 illegal |= POLICY_ILLEGAL_ARCHCHANGE; /* ignore */
2433 if ((set & SOLVER_SETVENDOR) != 0)
2434 illegal |= POLICY_ILLEGAL_VENDORCHANGE; /* ignore */
2435 illegal = policy_is_illegal(solv, is, s, illegal);
2436 if (illegal && illegal == POLICY_ILLEGAL_DOWNGRADE && (set & SOLVER_SETEV) != 0)
2438 /* it's ok if the EV is different */
2439 if (pool_evrcmp(pool, is->evr, s->evr, EVRCMP_COMPARE_EVONLY) != 0)
2447 /* no package conflicts with the update rule */
2448 /* thus keep the DISABLE_UPDATE */
2449 q->elements[j + 1] = q->elements[i + 1];
2453 queue_truncate(q, j);
2459 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
2461 FOR_REPO_SOLVABLES(installed, p, s)
2462 queue_push2(q, DISABLE_UPDATE, p);
2464 FOR_JOB_SELECT(p, pp, select, what)
2465 if (pool->solvables[p].repo == installed)
2467 queue_push2(q, DISABLE_UPDATE, p);
2468 #ifdef ENABLE_LINKED_PKGS
2469 if (solv->instbuddy && solv->instbuddy[p - installed->start] > 1)
2470 queue_push2(q, DISABLE_UPDATE, solv->instbuddy[p - installed->start]);
2479 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
2481 FOR_REPO_SOLVABLES(installed, p, s)
2483 for (i = qstart; i < q->count; i += 2)
2484 if (q->elements[i] == DISABLE_DUP && q->elements[i + 1] == pool->solvables[p].name)
2487 queue_push2(q, DISABLE_DUP, pool->solvables[p].name);
2490 FOR_JOB_SELECT(p, pp, select, what)
2492 if (pool->solvables[p].repo != installed)
2494 for (i = qstart; i < q->count; i += 2)
2495 if (q->elements[i] == DISABLE_DUP && q->elements[i + 1] == pool->solvables[p].name)
2498 queue_push2(q, DISABLE_DUP, pool->solvables[p].name);
2507 /* disable all policy rules that are in conflict with our job list */
2509 solver_disablepolicyrules(Solver *solv)
2511 Queue *job = &solv->job;
2518 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2520 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2522 r = solv->rules + i;
2523 if (r->d < 0) /* disabled? */
2525 j = solv->ruletojob.elements[i - solv->jobrules];
2529 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2531 if (solv->cleandepsmap.size)
2533 solver_createcleandepsmap(solv, &solv->cleandepsmap, 0);
2534 for (i = solv->installed->start; i < solv->installed->end; i++)
2535 if (MAPTST(&solv->cleandepsmap, i - solv->installed->start))
2536 queue_push2(&allq, DISABLE_UPDATE, i);
2538 MAPZERO(&solv->noupdate);
2539 for (i = 0; i < allq.count; i += 2)
2541 Id type = allq.elements[i], arg = allq.elements[i + 1];
2544 case DISABLE_UPDATE:
2545 disableupdaterule(solv, arg);
2547 case DISABLE_INFARCH:
2548 disableinfarchrule(solv, arg);
2551 disableduprule(solv, arg);
2554 disableblackrule(solv, arg);
2563 /* we just disabled job #jobidx, now reenable all policy rules that were
2564 * disabled because of this job */
2566 solver_reenablepolicyrules(Solver *solv, int jobidx)
2568 Queue *job = &solv->job;
2573 Id qbuf[32], allqbuf[32];
2575 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
2576 jobtodisablelist(solv, job->elements[jobidx - 1], job->elements[jobidx], &q);
2582 /* now remove everything from q that is disabled by other jobs */
2584 /* first remove cleandeps packages, they count as DISABLE_UPDATE */
2585 if (solv->cleandepsmap.size)
2587 solver_createcleandepsmap(solv, &solv->cleandepsmap, 0);
2588 for (j = k = 0; j < q.count; j += 2)
2590 if (q.elements[j] == DISABLE_UPDATE)
2592 Id p = q.elements[j + 1];
2593 if (p >= solv->installed->start && p < solv->installed->end && MAPTST(&solv->cleandepsmap, p - solv->installed->start))
2594 continue; /* remove element from q */
2596 q.elements[k++] = q.elements[j];
2597 q.elements[k++] = q.elements[j + 1];
2607 /* now go through the disable list of all other jobs */
2608 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2609 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2611 r = solv->rules + i;
2612 if (r->d < 0) /* disabled? */
2614 j = solv->ruletojob.elements[i - solv->jobrules];
2618 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2621 /* remove all elements in allq from q */
2622 for (j = k = 0; j < q.count; j += 2)
2624 Id type = q.elements[j], arg = q.elements[j + 1];
2625 for (ai = 0; ai < allq.count; ai += 2)
2626 if (allq.elements[ai] == type && allq.elements[ai + 1] == arg)
2628 if (ai < allq.count)
2629 continue; /* found it in allq, remove element from q */
2630 q.elements[k++] = q.elements[j];
2631 q.elements[k++] = q.elements[j + 1];
2644 /* now re-enable anything that's left in q */
2645 for (j = 0; j < q.count; j += 2)
2647 Id type = q.elements[j], arg = q.elements[j + 1];
2650 case DISABLE_UPDATE:
2651 reenableupdaterule(solv, arg);
2653 case DISABLE_INFARCH:
2654 reenableinfarchrule(solv, arg);
2657 reenableduprule(solv, arg);
2660 reenableblackrule(solv, arg);
2667 /* we just removed a package from the cleandeps map, now reenable all policy rules that were
2668 * disabled because of this */
2670 solver_reenablepolicyrules_cleandeps(Solver *solv, Id pkg)
2672 Queue *job = &solv->job;
2679 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2680 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2682 r = solv->rules + i;
2683 if (r->d < 0) /* disabled? */
2685 j = solv->ruletojob.elements[i - solv->jobrules];
2689 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2691 for (i = 0; i < allq.count; i += 2)
2692 if (allq.elements[i] == DISABLE_UPDATE && allq.elements[i + 1] == pkg)
2694 if (i == allq.count)
2695 reenableupdaterule(solv, pkg);
2700 /***********************************************************************
2702 *** Rule info part, tell the user what the rule is about.
2707 addpkgruleinfo(Solver *solv, Id p, Id p2, Id d, int type, Id dep)
2709 Pool *pool = solv->pool;
2714 assert(!p2 && d > 0);
2715 if (!pool->whatprovidesdata[d])
2717 else if (!pool->whatprovidesdata[d + 1])
2719 p2 = pool->whatprovidesdata[d];
2724 /* check if this creates the rule we're searching for */
2725 r = solv->rules + solv->ruleinfoq->elements[0];
2728 /* three or more literals */
2729 Id od = r->d < 0 ? -r->d - 1 : r->d;
2730 if (p != r->p && !od)
2734 Id *dp = pool->whatprovidesdata + d;
2735 Id *odp = pool->whatprovidesdata + od;
2737 if (*dp++ != *odp++)
2742 /* set p2 for multiversion conflicts */
2743 if (p < 0 && pool->whatprovidesdata[d] < 0 && pool->whatprovidesdata[d + 1] >= 0 && type == SOLVER_RULE_PKG_CONFLICTS)
2744 p2 = pool->whatprovidesdata[d];
2748 /* one or two literals */
2749 Id op = p, op2 = p2;
2750 if (op2 && op > op2) /* normalize */
2756 if (r->p != op || r->w2 != op2 || (r->d && r->d != -1))
2758 if (type == SOLVER_RULE_PKG_CONFLICTS && !p2)
2759 p2 = -SYSTEMSOLVABLE;
2760 if (type == SOLVER_RULE_PKG_SAME_NAME)
2762 p = op; /* we normalize same name order */
2766 /* yep, rule matches. record info */
2767 queue_push(solv->ruleinfoq, type);
2768 queue_push(solv->ruleinfoq, p < 0 ? -p : 0);
2769 queue_push(solv->ruleinfoq, p2 < 0 ? -p2 : 0);
2770 queue_push(solv->ruleinfoq, dep);
2774 solver_allruleinfos_cmp(const void *ap, const void *bp, void *dp)
2776 const Id *a = ap, *b = bp;
2795 getpkgruleinfos(Solver *solv, Rule *r, Queue *rq)
2797 Pool *pool = solv->pool;
2801 queue_push(rq, r - solv->rules); /* push the rule we're interested in */
2802 solv->ruleinfoq = rq;
2803 FOR_RULELITERALS(l, pp, r)
2807 solver_addpkgrulesforsolvable(solv, pool->solvables - l, 0);
2809 #ifdef ENABLE_LINKED_PKGS
2810 FOR_RULELITERALS(l, pp, r)
2818 if (!strchr(pool_id2str(pool, pool->solvables[l].name), ':') || !has_package_link(pool, pool->solvables + l))
2820 add_package_link(solv, pool->solvables + l, 0, 0);
2823 solv->ruleinfoq = 0;
2828 solver_allruleinfos(Solver *solv, Id rid, Queue *rq)
2830 Rule *r = solv->rules + rid;
2834 if (rid <= 0 || rid >= solv->pkgrules_end)
2836 Id type, from, to, dep;
2837 type = solver_ruleinfo(solv, rid, &from, &to, &dep);
2838 queue_push(rq, type);
2839 queue_push(rq, from);
2841 queue_push(rq, dep);
2844 getpkgruleinfos(solv, r, rq);
2845 /* now sort & unify em */
2848 solv_sort(rq->elements, rq->count / 4, 4 * sizeof(Id), solver_allruleinfos_cmp, 0);
2849 /* throw out identical entries */
2850 for (i = j = 0; i < rq->count; i += 4)
2854 if (rq->elements[i] == rq->elements[j - 4] &&
2855 rq->elements[i + 1] == rq->elements[j - 3] &&
2856 rq->elements[i + 2] == rq->elements[j - 2] &&
2857 rq->elements[i + 3] == rq->elements[j - 1])
2860 rq->elements[j++] = rq->elements[i];
2861 rq->elements[j++] = rq->elements[i + 1];
2862 rq->elements[j++] = rq->elements[i + 2];
2863 rq->elements[j++] = rq->elements[i + 3];
2870 solver_ruleinfo(Solver *solv, Id rid, Id *fromp, Id *top, Id *depp)
2872 Pool *pool = solv->pool;
2873 Rule *r = solv->rules + rid;
2874 SolverRuleinfo type = SOLVER_RULE_UNKNOWN;
2882 if (rid > 0 && rid < solv->pkgrules_end)
2888 return SOLVER_RULE_PKG;
2892 getpkgruleinfos(solv, r, &rq);
2893 type = SOLVER_RULE_PKG;
2894 for (i = 0; i < rq.count; i += 4)
2897 qt = rq.elements[i];
2898 qp = rq.elements[i + 1];
2899 qo = rq.elements[i + 2];
2900 qd = rq.elements[i + 3];
2901 if (type == SOLVER_RULE_PKG || type > qt)
2915 if (rid >= solv->jobrules && rid < solv->jobrules_end)
2917 Id jidx = solv->ruletojob.elements[rid - solv->jobrules];
2921 *top = solv->job.elements[jidx];
2923 *depp = solv->job.elements[jidx + 1];
2924 if ((r->d == 0 || r->d == -1) && r->w2 == 0 && r->p == -SYSTEMSOLVABLE)
2926 Id how = solv->job.elements[jidx];
2927 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_INSTALL|SOLVER_SOLVABLE_NAME))
2928 return SOLVER_RULE_JOB_UNKNOWN_PACKAGE;
2929 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES))
2930 return SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP;
2931 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_ERASE|SOLVER_SOLVABLE_NAME))
2932 return SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM;
2933 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_ERASE|SOLVER_SOLVABLE_PROVIDES))
2934 return SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM;
2935 return SOLVER_RULE_JOB_UNSUPPORTED;
2937 return SOLVER_RULE_JOB;
2939 if (rid >= solv->updaterules && rid < solv->updaterules_end)
2942 *fromp = solv->installed->start + (rid - solv->updaterules);
2943 return SOLVER_RULE_UPDATE;
2945 if (rid >= solv->featurerules && rid < solv->featurerules_end)
2948 *fromp = solv->installed->start + (rid - solv->featurerules);
2949 return SOLVER_RULE_FEATURE;
2951 if (rid >= solv->duprules && rid < solv->duprules_end)
2956 *depp = pool->solvables[-r->p].name;
2957 return SOLVER_RULE_DISTUPGRADE;
2959 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
2964 *depp = pool->solvables[-r->p].name;
2965 return SOLVER_RULE_INFARCH;
2967 if (rid >= solv->bestrules && rid < solv->bestrules_end)
2969 if (fromp && solv->bestrules_info[rid - solv->bestrules] > 0)
2970 *fromp = solv->bestrules_info[rid - solv->bestrules];
2971 return SOLVER_RULE_BEST;
2973 if (rid >= solv->yumobsrules && rid < solv->yumobsrules_end)
2979 /* first solvable is enough, we just need it for the name */
2980 if (!r->d || r->d == -1)
2983 *top = pool->whatprovidesdata[r->d < 0 ? -r->d : r->d];
2986 *depp = solv->yumobsrules_info[rid - solv->yumobsrules];
2987 return SOLVER_RULE_YUMOBS;
2989 if (rid >= solv->blackrules && rid < solv->blackrules_end)
2993 return SOLVER_RULE_BLACK;
2995 if (rid >= solv->choicerules && rid < solv->choicerules_end)
2996 return SOLVER_RULE_CHOICE;
2997 if (rid >= solv->recommendsrules && rid < solv->recommendsrules_end)
2998 return SOLVER_RULE_RECOMMENDS;
2999 if (rid >= solv->learntrules)
3000 return SOLVER_RULE_LEARNT;
3001 return SOLVER_RULE_UNKNOWN;
3005 solver_ruleclass(Solver *solv, Id rid)
3008 return SOLVER_RULE_UNKNOWN;
3009 if (rid > 0 && rid < solv->pkgrules_end)
3010 return SOLVER_RULE_PKG;
3011 if (rid >= solv->jobrules && rid < solv->jobrules_end)
3012 return SOLVER_RULE_JOB;
3013 if (rid >= solv->updaterules && rid < solv->updaterules_end)
3014 return SOLVER_RULE_UPDATE;
3015 if (rid >= solv->featurerules && rid < solv->featurerules_end)
3016 return SOLVER_RULE_FEATURE;
3017 if (rid >= solv->duprules && rid < solv->duprules_end)
3018 return SOLVER_RULE_DISTUPGRADE;
3019 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
3020 return SOLVER_RULE_INFARCH;
3021 if (rid >= solv->bestrules && rid < solv->bestrules_end)
3022 return SOLVER_RULE_BEST;
3023 if (rid >= solv->yumobsrules && rid < solv->yumobsrules_end)
3024 return SOLVER_RULE_YUMOBS;
3025 if (rid >= solv->blackrules && rid < solv->blackrules_end)
3026 return SOLVER_RULE_BLACK;
3027 if (rid >= solv->choicerules && rid < solv->choicerules_end)
3028 return SOLVER_RULE_CHOICE;
3029 if (rid >= solv->recommendsrules && rid < solv->recommendsrules_end)
3030 return SOLVER_RULE_RECOMMENDS;
3031 if (rid >= solv->blackrules && rid < solv->blackrules_end)
3032 return SOLVER_RULE_BLACK;
3033 if (rid >= solv->learntrules && rid < solv->nrules)
3034 return SOLVER_RULE_LEARNT;
3035 return SOLVER_RULE_UNKNOWN;
3039 solver_ruleliterals(Solver *solv, Id rid, Queue *q)
3041 Pool *pool = solv->pool;
3046 r = solv->rules + rid;
3047 FOR_RULELITERALS(p, pp, r)
3048 if (p != -SYSTEMSOLVABLE)
3051 queue_push(q, -SYSTEMSOLVABLE); /* hmm, better to return an empty result? */
3055 solver_rule2jobidx(Solver *solv, Id rid)
3057 if (rid < solv->jobrules || rid >= solv->jobrules_end)
3059 return solv->ruletojob.elements[rid - solv->jobrules] + 1;
3062 /* job rule introspection */
3064 solver_rule2job(Solver *solv, Id rid, Id *whatp)
3067 if (rid < solv->jobrules || rid >= solv->jobrules_end)
3073 idx = solv->ruletojob.elements[rid - solv->jobrules];
3075 *whatp = solv->job.elements[idx + 1];
3076 return solv->job.elements[idx];
3079 /* update/feature rule introspection */
3081 solver_rule2solvable(Solver *solv, Id rid)
3083 if (rid >= solv->updaterules && rid < solv->updaterules_end)
3084 return rid - solv->updaterules;
3085 if (rid >= solv->featurerules && rid < solv->featurerules_end)
3086 return rid - solv->featurerules;
3091 solver_rule2pkgrule(Solver *solv, Id rid)
3093 if (rid >= solv->choicerules && rid < solv->choicerules_end)
3094 return solv->choicerules_info[rid - solv->choicerules];
3095 if (rid >= solv->recommendsrules && rid < solv->recommendsrules_end)
3096 return solv->recommendsrules_info[rid - solv->recommendsrules];
3101 solver_rule2rules_rec(Solver *solv, Id rid, Queue *q, Map *seen)
3108 for (i = solv->learnt_why.elements[rid - solv->learntrules]; (rid2 = solv->learnt_pool.elements[i]) != 0; i++)
3112 if (MAPTST(seen, rid2))
3114 if (rid2 >= solv->learntrules)
3115 solver_rule2rules_rec(solv, rid2, q, seen);
3118 queue_push(q, rid2);
3122 /* learnt rule introspection */
3124 solver_rule2rules(Solver *solv, Id rid, Queue *q, int recursive)
3127 if (rid < solv->learntrules || rid >= solv->nrules)
3132 map_init(&seen, solv->nrules);
3133 solver_rule2rules_rec(solv, rid, q, &seen);
3137 solver_rule2rules_rec(solv, rid, q, 0);
3141 /* check if the newest versions of pi still provides the dependency we're looking for */
3143 solver_choicerulecheck(Solver *solv, Id pi, Rule *r, Map *m, Queue *q)
3145 Pool *pool = solv->pool;
3150 if (!q->count || q->elements[0] != pi)
3154 ur = solv->rules + solv->updaterules + (pi - pool->installed->start);
3156 ur = solv->rules + solv->featurerules + (pi - pool->installed->start);
3159 queue_push2(q, pi, 0);
3160 FOR_RULELITERALS(p, pp, ur)
3169 return MAPTST(m, p) ? 0 : 1;
3171 if (!q->elements[1])
3173 for (i = 2; i < q->count; i++)
3174 if (!MAPTST(m, q->elements[i]))
3177 return 0; /* all provide it, no need to filter */
3178 /* some don't provide it, have to filter */
3179 queue_deleten(q, 0, 2);
3180 policy_filter_unwanted(solv, q, POLICY_MODE_CHOOSE);
3181 queue_unshift(q, 1); /* filter mark */
3182 queue_unshift(q, pi);
3184 for (i = 2; i < q->count; i++)
3185 if (MAPTST(m, q->elements[i]))
3186 return 0; /* at least one provides it */
3187 return 1; /* none of the new packages provided it */
3191 solver_choicerulecheck2(Solver *solv, Id pi, Id pt, Queue *q)
3193 Pool *pool = solv->pool;
3198 if (!q->count || q->elements[0] != pi)
3202 ur = solv->rules + solv->updaterules + (pi - pool->installed->start);
3204 ur = solv->rules + solv->featurerules + (pi - pool->installed->start);
3207 queue_push2(q, pi, 0);
3208 FOR_RULELITERALS(p, pp, ur)
3209 if (p > 0 && p != pi)
3214 return q->count == 3 && q->elements[2] == pt ? 1 : 0;
3215 if (!q->elements[1])
3217 queue_deleten(q, 0, 2);
3218 policy_filter_unwanted(solv, q, POLICY_MODE_CHOOSE);
3219 queue_unshift(q, 1); /* filter mark */
3220 queue_unshift(q, pi);
3222 for (i = 2; i < q->count; i++)
3223 if (q->elements[i] == pt)
3225 return 0; /* not newest */
3229 solver_choicerulecheck3(Solver *solv, Id pt, Queue *q)
3231 Pool *pool = solv->pool;
3235 if (!q->count || q->elements[0] != pt)
3237 Solvable *s = pool->solvables + pt;
3240 /* no installed package, so check all with same name */
3241 queue_push2(q, pt, 0);
3242 FOR_PROVIDES(p, pp, s->name)
3243 if (pool->solvables[p].name == s->name && p != pt)
3248 return q->count == 3 && q->elements[2] == pt ? 1 : 0;
3249 if (!q->elements[1])
3251 queue_deleten(q, 0, 2);
3252 policy_filter_unwanted(solv, q, POLICY_MODE_CHOOSE);
3253 queue_unshift(q, 1); /* filter mark */
3254 queue_unshift(q, pt);
3256 for (i = 2; i < q->count; i++)
3257 if (q->elements[i] == pt)
3259 return 0; /* not newest */
3263 queue_removeelement(Queue *q, Id el)
3266 for (i = 0; i < q->count; i++)
3267 if (q->elements[i] == el)
3271 for (j = i++; i < q->count; i++)
3272 if (q->elements[i] != el)
3273 q->elements[j++] = q->elements[i];
3274 queue_truncate(q, j);
3279 choicerule_find_installed(Pool *pool, Id p)
3281 Solvable *s = pool->solvables + p;
3286 if (s->repo == pool->installed)
3288 FOR_PROVIDES(p2, pp2, s->name)
3290 Solvable *s2 = pool->solvables + p2;
3291 if (s2->repo != pool->installed)
3293 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
3295 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, s2))
3301 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
3302 while ((obs = *obsp++) != 0)
3304 FOR_PROVIDES(p2, pp2, obs)
3306 Solvable *s2 = pool->solvables + p2;
3307 if (s2->repo != pool->installed)
3309 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
3311 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
3321 solver_addchoicerules(Solver *solv)
3323 Pool *pool = solv->pool;
3326 Queue q, qi, qcheck, qcheck2, infoq;
3327 int i, j, rid, havechoice, negcnt;
3330 Id lastaddedp, lastaddedd;
3335 solv->choicerules = solv->nrules;
3336 if (!pool->installed)
3338 solv->choicerules_end = solv->nrules;
3341 now = solv_timems(0);
3344 queue_init(&qcheck);
3345 queue_init(&qcheck2);
3347 map_init(&m, pool->nsolvables);
3348 map_init(&mneg, pool->nsolvables);
3349 /* set up negative assertion map from infarch and dup rules */
3350 for (rid = solv->infarchrules, r = solv->rules + rid; rid < solv->infarchrules_end; rid++, r++)
3351 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
3352 MAPSET(&mneg, -r->p);
3353 for (rid = solv->duprules, r = solv->rules + rid; rid < solv->duprules_end; rid++, r++)
3354 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
3355 MAPSET(&mneg, -r->p);
3359 for (rid = 1; rid < solv->pkgrules_end ; rid++)
3361 r = solv->rules + rid;
3362 if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 <= 0))
3363 continue; /* only look at requires rules */
3364 /* solver_printrule(solv, SOLV_DEBUG_RESULT, r); */
3368 FOR_RULELITERALS(p, pp, r)
3372 s = pool->solvables + p;
3375 if (s->repo == pool->installed)
3377 queue_push2(&qi, p, p);
3381 /* find an installed package p2 that we can update/downgrade to p */
3382 p2 = choicerule_find_installed(pool, p);
3385 if (MAPTST(&mneg, p))
3387 if (policy_is_illegal(solv, pool->solvables + p2, s, 0))
3389 queue_push2(&qi, p2, p);
3393 /* package p is independent of the installed ones */
3397 printf("havechoice: %d qcount %d qicount %d\n", havechoice, q.count, qi.count);
3399 if (!havechoice || !q.count || !qi.count)
3400 continue; /* no choice */
3402 FOR_RULELITERALS(p, pp, r)
3407 FOR_RULELITERALS(p, pp, r)
3411 p2 = choicerule_find_installed(pool, -p);
3412 if (p2 && !solver_choicerulecheck2(solv, p2, -p, &qcheck2))
3417 if (!p2 && !solver_choicerulecheck3(solv, -p, &qcheck2))
3423 /* do extra checking */
3424 for (i = j = 0; i < qi.count; i += 2)
3426 p2 = qi.elements[i];
3429 if (isnewest && solver_choicerulecheck(solv, p2, r, &m, &qcheck))
3431 /* oops, remove element p from q */
3432 queue_removeelement(&q, qi.elements[i + 1]);
3435 qi.elements[j++] = p2;
3437 queue_truncate(&qi, j);
3439 if (!q.count || !qi.count)
3441 FOR_RULELITERALS(p, pp, r)
3448 /* now check the update rules of the installed package.
3449 * if all packages of the update rules are contained in
3450 * the dependency rules, there's no need to set up the choice rule */
3451 for (i = 0; i < qi.count; i++)
3454 if (!qi.elements[i])
3456 ur = solv->rules + solv->updaterules + (qi.elements[i] - pool->installed->start);
3458 ur = solv->rules + solv->featurerules + (qi.elements[i] - pool->installed->start);
3461 FOR_RULELITERALS(p, pp, ur)
3466 for (j = i + 1; j < qi.count; j++)
3467 if (qi.elements[i] == qi.elements[j])
3470 /* empty map again */
3472 FOR_RULELITERALS(p, pp, r)
3480 printf("skipping choice ");
3481 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + rid);
3485 /* add neg elements to the front */
3489 FOR_RULELITERALS(p, pp, r)
3490 if (p < 0 && p != r->p)
3491 queue_insert(&q, i++, p);
3493 /* don't add identical rules */
3494 if (lastaddedp == r->p && lastaddedcnt == q.count)
3496 for (i = 0; i < q.count; i++)
3497 if (q.elements[i] != pool->whatprovidesdata[lastaddedd + i])
3500 continue; /* already added that one */
3502 d = q.count ? pool_queuetowhatprovides(pool, &q) : 0;
3506 lastaddedcnt = q.count;
3508 solver_addrule(solv, r->p, 0, d);
3509 queue_push(&solv->weakruleq, solv->nrules - 1);
3510 queue_push(&infoq, rid);
3513 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + rid);
3514 printf("WEAK CHOICE ");
3515 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + solv->nrules - 1);
3519 solv->choicerules_info = solv_memdup2(infoq.elements, infoq.count, sizeof(Id));
3522 queue_free(&qcheck);
3523 queue_free(&qcheck2);
3527 solv->choicerules_end = solv->nrules;
3528 POOL_DEBUG(SOLV_DEBUG_STATS, "choice rule creation took %d ms\n", solv_timems(now));
3531 /* called when a choice rule needs to be disabled by analyze_unsolvable.
3532 * We also have to disable all other choice rules so that the best packages
3535 solver_disablechoicerules(Solver *solv, Rule *r)
3538 Pool *pool = solv->pool;
3542 solver_disablerule(solv, r);
3543 or = solv->rules + solv->choicerules_info[(r - solv->rules) - solv->choicerules];
3544 map_init(&m, pool->nsolvables);
3545 FOR_RULELITERALS(p, pp, or)
3548 FOR_RULELITERALS(p, pp, r)
3551 for (rid = solv->choicerules; rid < solv->choicerules_end; rid++)
3553 r = solv->rules + rid;
3556 or = solv->rules + solv->choicerules_info[rid - solv->choicerules];
3557 FOR_RULELITERALS(p, pp, or)
3558 if (p > 0 && MAPTST(&m, p))
3561 solver_disablerule(solv, r);
3566 prune_to_update_targets(Solver *solv, Id *cp, Queue *q)
3570 for (i = j = 0; i < q->count; i++)
3573 for (cp2 = cp; *cp2; cp2++)
3576 q->elements[j++] = p;
3580 queue_truncate(q, j);
3584 prune_to_dup_packages(Solver *solv, Id p, Queue *q)
3587 for (i = j = 0; i < q->count; i++)
3589 Id p = q->elements[i];
3590 if (MAPTST(&solv->dupmap, p))
3591 q->elements[j++] = p;
3593 queue_truncate(q, j);
3597 prune_best_update(Solver *solv, Id p, Queue *q)
3599 if (solv->update_targets && solv->update_targets->elements[p - solv->installed->start])
3600 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[p - solv->installed->start], q);
3601 if (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
3602 prune_to_dup_packages(solv, p, q);
3603 /* select best packages, just look at prio and version */
3604 policy_filter_unwanted(solv, q, POLICY_MODE_RECOMMEND);
3608 prune_disabled(Pool *pool, Queue *q)
3611 for (i = j = 0; i < q->count; i++)
3613 Id p = q->elements[i];
3614 Solvable *s = pool->solvables + p;
3615 if (s->repo && s->repo != pool->installed && !MAPTST(pool->considered, p))
3617 q->elements[j++] = p;
3619 queue_truncate(q, j);
3623 solver_addbestrules(Solver *solv, int havebestinstalljobs, int haslockjob)
3625 Pool *pool = solv->pool;
3628 Repo *installed = solv->installed;
3635 solv->bestrules = solv->nrules;
3643 lockedmap = solv_calloc(1, sizeof(Map));
3644 map_init(lockedmap, pool->nsolvables);
3645 for (i = 0, r = solv->rules + solv->jobrules; i < solv->ruletojob.count; i++, r++)
3647 if (r->w2 || (solv->job.elements[solv->ruletojob.elements[i]] & SOLVER_JOBMASK) != SOLVER_LOCK)
3649 p = r->p > 0 ? r->p : -r->p;
3650 MAPSET(lockedmap, p);
3653 if (havebestinstalljobs)
3655 for (i = 0; i < solv->job.count; i += 2)
3657 Id how = solv->job.elements[i];
3658 if ((how & (SOLVER_JOBMASK | SOLVER_FORCEBEST)) == (SOLVER_INSTALL | SOLVER_FORCEBEST))
3662 for (j = 0; j < solv->ruletojob.count; j++)
3664 if (solv->ruletojob.elements[j] != i)
3666 r = solv->rules + solv->jobrules + j;
3669 FOR_RULELITERALS(p2, pp2, r)
3674 queue_push(&q2, p2);
3676 if (pool->considered && pool->whatprovideswithdisabled)
3677 prune_disabled(pool, &q);
3679 continue; /* orphaned */
3680 /* select best packages, just look at prio and version */
3682 policy_filter_unwanted(solv, &q, POLICY_MODE_RECOMMEND);
3683 if (q.count == oldcnt)
3684 continue; /* nothing filtered */
3687 queue_insertn(&q, 0, q2.count, q2.elements);
3689 FOR_RULELITERALS(p2, pp2, r)
3693 if (installed && pool->solvables[p2].repo == installed)
3695 if (MAPTST(lockedmap, p2))
3696 queue_pushunique(&q, p2); /* we always want that package */
3698 else if (MAPTST(lockedmap, p2))
3700 queue_push(&q2, p2);
3702 if (pool->considered && pool->whatprovideswithdisabled)
3703 prune_disabled(pool, &q2);
3704 policy_filter_unwanted(solv, &q2, POLICY_MODE_RECOMMEND);
3705 for (k = 0; k < q2.count; k++)
3706 queue_pushunique(&q, q2.elements[k]);
3710 queue_insertn(&q, 0, q2.count, q2.elements);
3711 p2 = queue_shift(&q);
3713 solver_addrule(solv, p2, q.count ? q.elements[0] : 0, 0);
3715 solver_addrule(solv, p2, 0, pool_queuetowhatprovides(pool, &q));
3716 if ((how & SOLVER_WEAK) != 0)
3717 queue_push(&solv->weakruleq, solv->nrules - 1);
3718 queue_push(&infoq, -(solv->jobrules + j));
3723 solv->bestrules_up = solv->nrules;
3725 if (installed && (solv->bestupdatemap_all || solv->bestupdatemap.size))
3729 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
3730 map_init(&m, pool->nsolvables);
3733 FOR_REPO_SOLVABLES(installed, p, s)
3736 if (!solv->updatemap_all && (!solv->updatemap.size || !MAPTST(&solv->updatemap, p - installed->start)))
3738 if (!solv->bestupdatemap_all && (!solv->bestupdatemap.size || !MAPTST(&solv->bestupdatemap, p - installed->start)))
3741 if (solv->bestobeypolicy)
3742 r = solv->rules + solv->updaterules + (p - installed->start);
3745 r = solv->rules + solv->featurerules + (p - installed->start);
3746 if (!r->p) /* identical to update rule? */
3747 r = solv->rules + solv->updaterules + (p - installed->start);
3749 if (solv->specialupdaters && (d = solv->specialupdaters[p - installed->start]) != 0 && r == solv->rules + solv->updaterules + (p - installed->start))
3751 /* need to check specialupdaters */
3752 if (r->p == p) /* be careful with the dup case */
3754 while ((p2 = pool->whatprovidesdata[d++]) != 0)
3759 FOR_RULELITERALS(p2, pp2, r)
3766 queue_insertn(&q2, 0, q.count, q.elements);
3768 prune_best_update(solv, p, &q);
3770 continue; /* orphaned */
3774 /* always ok to keep installed locked packages */
3775 if (MAPTST(lockedmap, p))
3776 queue_pushunique(&q2, p);
3777 for (j = 0; j < q2.count; j++)
3779 Id p2 = q2.elements[j];
3780 if (pool->solvables[p2].repo == installed && MAPTST(lockedmap, p2))
3781 queue_pushunique(&q, p2);
3783 /* filter out locked packages */
3784 for (i = j = 0; j < q2.count; j++)
3786 Id p2 = q2.elements[j];
3787 if (pool->solvables[p2].repo == installed || !MAPTST(lockedmap, p2))
3788 q2.elements[i++] = p2;
3790 queue_truncate(&q2, i);
3791 prune_best_update(solv, p, &q2);
3792 for (j = 0; j < q2.count; j++)
3793 queue_pushunique(&q, q2.elements[j]);
3795 if (solv->bestobeypolicy)
3797 /* also filter the best of the feature rule packages and add them */
3798 r = solv->rules + solv->featurerules + (p - installed->start);
3803 FOR_RULELITERALS(p2, pp2, r)
3805 queue_push(&q2, p2);
3806 prune_best_update(solv, p, &q2);
3807 for (j = 0; j < q2.count; j++)
3808 queue_pushunique(&q, q2.elements[j]);
3812 FOR_RULELITERALS(p2, pp2, r)
3814 if (pool->solvables[p2].repo == installed || !MAPTST(lockedmap, p2))
3815 queue_push(&q2, p2);
3816 prune_best_update(solv, p, &q2);
3817 for (j = 0; j < q2.count; j++)
3818 queue_pushunique(&q, q2.elements[j]);
3822 if (solv->allowuninstall || solv->allowuninstall_all || (solv->allowuninstallmap.size && MAPTST(&solv->allowuninstallmap, p - installed->start)))
3824 /* package is flagged both for allowuninstall and best, add negative rules */
3825 d = q.count == 1 ? q.elements[0] : -pool_queuetowhatprovides(pool, &q);
3826 for (i = 0; i < q.count; i++)
3827 MAPSET(&m, q.elements[i]);
3828 r = solv->rules + solv->featurerules + (p - installed->start);
3829 if (!r->p) /* identical to update rule? */
3830 r = solv->rules + solv->updaterules + (p - installed->start);
3831 FOR_RULELITERALS(p2, pp2, r)
3836 solver_addrule(solv, -p2, d, 0);
3838 solver_addrule(solv, -p2, 0, -d);
3839 queue_push(&infoq, p);
3841 for (i = 0; i < q.count; i++)
3842 MAPCLR(&m, q.elements[i]);
3845 p2 = queue_shift(&q);
3847 solver_addrule(solv, p2, q.count ? q.elements[0] : 0, 0);
3849 solver_addrule(solv, p2, 0, pool_queuetowhatprovides(pool, &q));
3850 queue_push(&infoq, p);
3855 solv->bestrules_info = solv_memdup2(infoq.elements, infoq.count, sizeof(Id));
3856 solv->bestrules_end = solv->nrules;
3862 map_free(lockedmap);
3863 solv_free(lockedmap);
3870 /* yumobs rule handling */
3871 /* note that we use pool->obsoleteusescolors || pool->implicitobsoleteusescolors
3872 * like in policy_findupdatepackages */
3875 find_obsolete_group(Solver *solv, Id obs, Queue *q)
3877 Pool *pool = solv->pool;
3879 Id p2, pp2, op, *opp, opp2;
3880 int i, j, qnc, ncnt;
3883 FOR_PROVIDES(p2, pp2, obs)
3885 Solvable *s2 = pool->solvables + p2;
3886 if (s2->repo != pool->installed)
3888 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
3890 /* we obsolete installed package s2 with obs. now find all other packages that have the same dep */
3891 for (opp = solv->obsoletes_data + solv->obsoletes[p2 - solv->installed->start]; (op = *opp++) != 0;)
3893 Solvable *os = pool->solvables + op;
3897 if ((pool->obsoleteusescolors || pool->implicitobsoleteusescolors) && !pool_colormatch(pool, s2, os))
3899 obsp2 = os->repo->idarraydata + os->obsoletes;
3900 while ((obs2 = *obsp2++) != 0)
3904 queue_pushunique(q, op);
3906 /* also search packages with the same name */
3907 FOR_PROVIDES(op, opp2, s2->name)
3909 Solvable *os = pool->solvables + op;
3911 if (os->name != s2->name)
3915 if ((pool->obsoleteusescolors || pool->implicitobsoleteusescolors) && !pool_colormatch(pool, s2, os))
3917 obsp2 = os->repo->idarraydata + os->obsoletes;
3918 while ((obs2 = *obsp2++) != 0)
3922 queue_pushunique(q, op);
3925 /* find names so that we can build groups */
3926 queue_init_clone(&qn, q);
3927 prune_to_best_version(solv->pool, &qn);
3930 for (i = 0; i < qn.count; i++)
3931 printf(" + %s\n", pool_solvid2str(pool, qn.elements[i]));
3934 /* filter into name groups */
3943 for (i = 0; i < qnc; i++)
3945 Id n = pool->solvables[qn.elements[i]].name;
3947 for (j = 0; j < q->count; j++)
3949 Id p = q->elements[j];
3950 if (pool->solvables[p].name == n)
3969 queue_insertn(q, 0, qn.count - qnc, qn.elements + qnc);
3975 solver_addyumobsrules(Solver *solv)
3977 Pool *pool = solv->pool;
3978 Repo *installed = solv->installed;
3981 Queue qo, qq, infoq;
3985 solv->yumobsrules = solv->nrules;
3986 if (!installed || !solv->obsoletes)
3988 solv->yumobsrules_end = solv->nrules;
3991 now = solv_timems(0);
3993 FOR_REPO_SOLVABLES(installed, p, s)
3995 if (!solv->obsoletes[p - installed->start])
3998 printf("checking yumobs for %s\n", pool_solvable2str(pool, s));
4000 for (opp = solv->obsoletes_data + solv->obsoletes[p - installed->start]; (op = *opp++) != 0;)
4002 Solvable *os = pool->solvables + op;
4003 Id obs, *obsp = os->repo->idarraydata + os->obsoletes;
4005 while ((obs = *obsp++) != 0)
4007 FOR_PROVIDES(p2, pp2, obs)
4009 Solvable *s2 = pool->solvables + p2;
4010 if (s2->repo != installed)
4012 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
4014 if ((pool->obsoleteusescolors || pool->implicitobsoleteusescolors) && !pool_colormatch(pool, s, s2))
4016 queue_pushunique(&qo, obs);
4029 for (i = 0; i < qo.count; i++)
4031 int group, groupk, groupstart;
4034 printf("investigating %s\n", pool_dep2str(pool, qo.elements[i]));
4036 find_obsolete_group(solv, qo.elements[i], &qq);
4038 printf("result:\n");
4039 for (j = 0; j < qq.count; j++)
4040 if (qq.elements[j] == 0)
4043 printf("%s\n", pool_solvid2str(pool, qq.elements[j]));
4048 /* at least two goups, build rules */
4050 for (j = 0; j < qq.count; j++)
4058 if (pool->solvables[p].repo == installed)
4062 for (k = 0; k < qq.count; k++)
4064 Id pk = qq.elements[k];
4067 if (group != groupk && k > groupstart)
4070 if (k - groupstart == 1)
4071 solver_addrule(solv, -p, qq.elements[groupstart], 0);
4073 solver_addrule(solv, -p, 0, pool_ids2whatprovides(pool, qq.elements + groupstart, k - groupstart));
4074 queue_push(&infoq, qo.elements[i]);
4082 solv->yumobsrules_info = solv_memdup2(infoq.elements, infoq.count, sizeof(Id));
4086 solv->yumobsrules_end = solv->nrules;
4087 POOL_DEBUG(SOLV_DEBUG_STATS, "yumobs rule creation took %d ms\n", solv_timems(now));
4090 /* recommendsrules are a copy of some recommends package rule but
4091 * with some disfavored literals removed */
4093 solver_addrecommendsrules(Solver *solv)
4095 Pool *pool = solv->pool;
4096 int i, havedis, havepos;
4100 solv->recommendsrules = solv->nrules;
4103 for (i = 0; i < solv->recommendsruleq->count; i++)
4105 int rid = solv->recommendsruleq->elements[i];
4106 Rule *r = solv->rules + rid;
4108 havedis = havepos = 0;
4109 FOR_RULELITERALS(p, pp, r)
4111 if (p > 0 && solv->favormap[p] < 0)
4122 solver_disablerule(solv, r);
4123 if (!havepos || q.count < 2)
4126 solver_addrule(solv, q.elements[0], q.elements[1], 0);
4128 solver_addrule(solv, q.elements[0], 0, pool_ids2whatprovides(pool, q.elements + 1, q.count - 1));
4129 queue_push(&infoq, rid);
4132 solv->recommendsrules_info = solv_memdup2(infoq.elements, infoq.count, sizeof(Id));
4135 solv->recommendsrules_end = solv->nrules;
4139 solver_breakorphans(Solver *solv)
4141 Pool *pool = solv->pool;
4142 Repo *installed = solv->installed;
4146 if (!installed || solv->droporphanedmap_all)
4148 solv->brokenorphanrules = solv_calloc(1, sizeof(Queue));
4149 queue_init(solv->brokenorphanrules);
4150 map_init(&m, installed->end - installed->start);
4151 for (i = 0; i < solv->orphaned.count; i++)
4153 Id p = solv->orphaned.elements[i];
4154 if (pool->solvables[p].repo != installed)
4156 if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - installed->start))
4158 MAPSET(&m, p - installed->start);
4160 for (rid = 1; rid < solv->pkgrules_end ; rid++)
4163 Rule *r = solv->rules + rid;
4164 /* ignore non-deps and simple conflicts */
4165 if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 < 0))
4168 if (p < installed->start || p >= installed->end || !MAPTST(&m, p - installed->start))
4170 /* need to check other literals */
4171 if (r->d == 0 || r->d == -1)
4173 for (dp = pool->whatprovidesdata + (r->d < 0 ? -r->d - 1 : r->d); *dp < 0; dp++)
4176 if (p >= installed->start && p < installed->end && MAPTST(&m, p - installed->start))
4182 /* ok, disable this rule */
4183 queue_push(solv->brokenorphanrules, rid);
4185 solver_disablerule(solv, r);
4188 if (!solv->brokenorphanrules->count)
4190 queue_free(solv->brokenorphanrules);
4191 solv->brokenorphanrules = solv_free(solv->brokenorphanrules);
4196 solver_check_brokenorphanrules(Solver *solv, Queue *dq)
4198 Pool *pool = solv->pool;
4203 if (!solv->brokenorphanrules)
4205 for (i = 0; i < solv->brokenorphanrules->count; i++)
4207 int rid = solv->brokenorphanrules->elements[i];
4208 Rule *r = solv->rules + rid;
4209 FOR_RULELITERALS(l, pp, r)
4213 if (solv->decisionmap[-l] <= 0)
4218 if (solv->decisionmap[l] > 0 && pool->solvables[l].repo != solv->installed)
4224 FOR_RULELITERALS(l, pp, r)
4225 if (l > 0 && solv->decisionmap[l] == 0 && pool->solvables[l].repo != solv->installed)
4226 queue_pushunique(dq, l);