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
502 add_complex_deprules(Solver *solv, Id p, Id dep, int type, int dontfix, Queue *workq, Map *m)
504 Pool *pool = solv->pool;
505 Repo *installed = solv->installed;
510 flags = dontfix ? CPLXDEPS_DONTFIX : 0;
511 /* CNF expansion for requires, DNF + INVERT expansion for conflicts */
512 if (type == SOLVER_RULE_PKG_CONFLICTS)
513 flags |= CPLXDEPS_TODNF | CPLXDEPS_EXPAND | CPLXDEPS_INVERT;
515 i = pool_normalize_complex_dep(pool, dep, &bq, flags);
516 /* handle special cases */
521 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "ignoring broken dependency %s of installed package %s\n", pool_dep2str(pool, dep), pool_solvid2str(pool, p));
525 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", pool_solvid2str(pool, p), p, pool_dep2str(pool, dep));
526 addpkgrule(solv, -p, 0, 0, type == SOLVER_RULE_PKG_REQUIRES ? SOLVER_RULE_PKG_NOTHING_PROVIDES_DEP : type, dep);
537 /* go through all blocks and add a rule for each block */
538 for (i = 0; i < bq.count; i++)
542 if (bq.elements[i] == pool->nsolvables)
544 /* conventional requires (cannot be a conflicts as they have been expanded) */
545 Id *dp = pool->whatprovidesdata + bq.elements[i + 1];
549 for (j = 0; dp[j] != 0; j++)
550 if (pool->solvables[dp[j]].repo == installed)
551 break; /* provider was installed */
555 if (type == SOLVER_RULE_PKG_RECOMMENDS && !*dp)
557 /* check if the rule contains both p and -p */
558 for (j = 0; dp[j] != 0; j++)
563 addpkgrule(solv, -p, 0, dp - pool->whatprovidesdata, type, dep);
564 /* push all non-visited providers on the work queue */
568 queue_push(workq, *dp);
571 if (!bq.elements[i + 1])
573 Id p2 = bq.elements[i++];
574 /* simple rule with just two literals, we'll add a (-p, p2) rule */
577 if (p2 < 0 && pool->solvables[-p2].repo == installed)
579 if (p2 > 0 && pool->solvables[p2].repo != installed)
584 if (type == SOLVER_RULE_PKG_CONFLICTS)
586 if (pool->forbidselfconflicts && !is_otherproviders_dep(pool, dep))
587 addpkgrule(solv, -p, 0, 0, SOLVER_RULE_PKG_SELF_CONFLICT, dep);
590 addpkgrule(solv, -p, 0, 0, type, dep);
593 /* check if the rule contains both p and -p */
596 addpkgrule(solv, -p, p2, 0, type, dep);
597 if (m && p2 > 0 && !MAPTST(m, p2))
598 queue_push(workq, p2);
605 qele = bq.elements + i;
607 while (bq.elements[i])
612 for (j = 0; j < qcnt; j++)
614 if (qele[j] > 0 && pool->solvables[qele[j]].repo == installed)
616 if (qele[j] < 0 && pool->solvables[-qele[j]].repo != installed)
622 /* add -p to (ordered) rule (overwriting the trailing zero) */
625 if (j == qcnt || qele[j] > -p)
628 memmove(qele + j + 1, qele + j, (qcnt - j) * sizeof(Id));
636 /* check if the rule contains both p and -p */
637 for (j = 0; j < qcnt; j++)
642 addpkgrule(solv, qele[0], 0, pool_ids2whatprovides(pool, qele + 1, qcnt - 1), type, dep);
644 for (j = 0; j < qcnt; j++)
645 if (qele[j] > 0 && !MAPTST(m, qele[j]))
646 queue_push(workq, qele[j]);
654 /*-------------------------------------------------------------------
656 * add dependency rules for solvable
658 * s: Solvable for which to add rules
659 * m: m[s] = 1 for solvables which have rules, prevent rule duplication
661 * Algorithm: 'visit all nodes of a graph'. The graph nodes are
662 * solvables, the edges their dependencies.
663 * Starting from an installed solvable, this will create all rules
664 * representing the graph created by the solvables dependencies.
666 * for unfulfilled requirements, conflicts, obsoletes,....
667 * add a negative assertion for solvables that are not installable
669 * It will also create rules for all solvables referenced by 's'
670 * i.e. descend to all providers of requirements of 's'
675 solver_addpkgrulesforsolvable(Solver *solv, Solvable *s, Map *m)
677 Pool *pool = solv->pool;
678 Repo *installed = solv->installed;
680 Queue workq; /* list of solvables we still have to work on */
682 Queue prereqq; /* list of pre-req ids to ignore */
686 int dontfix; /* ignore dependency errors for installed solvables */
692 Id p, pp; /* whatprovides loops */
693 Id *dp; /* ptr to 'whatprovides' */
694 Id n; /* Id for current solvable 's' */
696 queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
697 queue_push(&workq, s - pool->solvables); /* push solvable Id to work queue */
699 queue_init_buffer(&prereqq, prereqbuf, sizeof(prereqbuf)/sizeof(*prereqbuf));
701 /* loop until there's no more work left */
706 * s: Pointer to solvable
709 n = queue_shift(&workq); /* 'pop' next solvable to work on from queue */
712 if (MAPTST(m, n)) /* continue if already visited */
714 MAPSET(m, n); /* mark as visited */
717 s = pool->solvables + n;
720 if (installed /* Installed system available */
721 && s->repo == installed /* solvable is installed */
722 && !solv->fixmap_all /* NOT repair errors in dependency graph */
723 && !(solv->fixmap.size && MAPTST(&solv->fixmap, n - installed->start)))
725 dontfix = 1; /* dont care about broken deps */
730 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC
731 ? pool_disabled_solvable(pool, s)
732 : !pool_installable(pool, s))
734 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", pool_solvid2str(pool, n), n);
735 addpkgrule(solv, -n, 0, 0, SOLVER_RULE_PKG_NOT_INSTALLABLE, 0);
739 #ifdef ENABLE_LINKED_PKGS
740 /* add pseudo-package <-> real-package links */
741 if (has_package_link(pool, s))
742 add_package_link(solv, s, m, &workq);
745 /*-----------------------------------------
746 * check requires of s
752 reqp = s->repo->idarraydata + s->requires;
753 while ((req = *reqp++) != 0) /* go through all requires */
755 if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
757 if (installed && s->repo == installed)
760 queue_empty(&prereqq);
761 solvable_lookup_idarray(s, SOLVABLE_PREREQ_IGNOREINST, &prereqq);
762 filterpre = prereqq.count;
768 /* check if this id is filtered. assumes that prereqq.count is small */
769 for (i = 0; i < prereqq.count; i++)
770 if (req == prereqq.elements[i])
772 if (i < prereqq.count)
774 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s: ignoring filtered pre-req dependency %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, req));
779 #ifdef ENABLE_COMPLEX_DEPS
780 if (pool_is_complex_dep(pool, req))
782 /* we have AND/COND deps, normalize */
783 add_complex_deprules(solv, n, req, SOLVER_RULE_PKG_REQUIRES, dontfix, &workq, m);
788 /* find list of solvables providing 'req' */
789 dp = pool_whatprovides_ptr(pool, req);
791 if (*dp == SYSTEMSOLVABLE) /* always installed */
796 /* the strategy here is to not insist on dependencies
797 * that are already broken. so if we find one provider
798 * that was already installed, we know that the
799 * dependency was not broken before so we enforce it */
800 for (i = 0; (p = dp[i]) != 0; i++)
801 if (pool->solvables[p].repo == installed)
802 break; /* found installed provider */
805 /* didn't find an installed provider: previously broken dependency */
806 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", pool_dep2str(pool, req), pool_solvable2str(pool, s));
813 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", pool_solvid2str(pool, n), n, pool_dep2str(pool, req));
814 addpkgrule(solv, -n, 0, 0, SOLVER_RULE_PKG_NOTHING_PROVIDES_DEP, req);
818 for (i = 0; dp[i] != 0; i++)
822 continue; /* provided by itself, no need to add rule */
824 IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
826 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION," %s requires %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, req));
827 for (i = 0; dp[i]; i++)
828 POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, " provided by %s\n", pool_solvid2str(pool, dp[i]));
831 /* add 'requires' dependency */
832 /* rule: (-requestor|provider1|provider2|...|providerN) */
833 addpkgrule(solv, -n, 0, dp - pool->whatprovidesdata, SOLVER_RULE_PKG_REQUIRES, req);
835 /* push all non-visited providers on the work queue */
839 queue_push(&workq, *dp);
843 if (s->recommends && solv->strongrecommends)
845 int start = solv->nrules;
846 solv->lastpkgrule = 0;
847 reqp = s->repo->idarraydata + s->recommends;
848 while ((req = *reqp++) != 0) /* go through all recommends */
850 #ifdef ENABLE_COMPLEX_DEPS
851 if (pool_is_complex_dep(pool, req))
853 /* we have AND/COND deps, normalize */
854 add_complex_deprules(solv, n, req, SOLVER_RULE_PKG_RECOMMENDS, dontfix, &workq, m);
858 dp = pool_whatprovides_ptr(pool, req);
859 if (*dp == SYSTEMSOLVABLE || !*dp) /* always installed or not installable */
861 for (i = 0; dp[i] != 0; i++)
865 continue; /* provided by itself, no need to add rule */
866 addpkgrule(solv, -n, 0, dp - pool->whatprovidesdata, SOLVER_RULE_PKG_RECOMMENDS, req);
870 queue_push(&workq, *dp);
872 if (!solv->ruleinfoq && start < solv->nrules)
874 if (!solv->recommendsruleq)
876 solv->recommendsruleq = solv_calloc(1, sizeof(Queue));
877 queue_init(solv->recommendsruleq);
879 for (i = start; i < solv->nrules; i++)
880 queue_push(solv->recommendsruleq, i);
881 solv->lastpkgrule = 0;
885 /* that's all we check for src packages */
886 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
889 /*-----------------------------------------
890 * check conflicts of s
897 /* we treat conflicts in patches a bit differen:
899 * - multiversion handling
900 * XXX: we should really handle this different, looking
901 * at the name is a bad hack
903 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
905 conp = s->repo->idarraydata + s->conflicts;
906 /* foreach conflicts of 's' */
907 while ((con = *conp++) != 0)
909 #ifdef ENABLE_COMPLEX_DEPS
910 if (!ispatch && pool_is_complex_dep(pool, con))
912 /* we have AND/COND deps, normalize */
913 add_complex_deprules(solv, n, con, SOLVER_RULE_PKG_CONFLICTS, dontfix, &workq, m);
917 /* foreach providers of a conflict of 's' */
918 FOR_PROVIDES(p, pp, con)
920 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, con))
922 /* dontfix: dont care about conflicts with already installed packs */
923 if (dontfix && pool->solvables[p].repo == installed)
925 if (p == n) /* p == n: self conflict */
927 if (!pool->forbidselfconflicts || is_otherproviders_dep(pool, con))
929 addpkgrule(solv, -n, 0, 0, SOLVER_RULE_PKG_SELF_CONFLICT, con);
932 if (ispatch && solv->multiversion.size && MAPTST(&solv->multiversion, p) && ISRELDEP(con))
934 /* our patch conflicts with a multiversion package */
935 Id d = makemultiversionconflict(solv, p, con);
938 addpkgrule(solv, -n, 0, d, SOLVER_RULE_PKG_CONFLICTS, con);
942 if (p == SYSTEMSOLVABLE)
944 /* rule: -n|-p: either solvable _or_ provider of conflict */
945 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_CONFLICTS, con);
950 /*-----------------------------------------
951 * check obsoletes and implicit obsoletes of a package
952 * if ignoreinstalledsobsoletes is not set, we're also checking
953 * obsoletes of installed packages (like newer rpm versions)
955 if ((!installed || s->repo != installed) || !pool->noinstalledobsoletes)
957 int multi = solv->multiversion.size && MAPTST(&solv->multiversion, n);
958 int isinstalled = (installed && s->repo == installed);
959 if (s->obsoletes && (!multi || solv->keepexplicitobsoletes))
961 obsp = s->repo->idarraydata + s->obsoletes;
962 /* foreach obsoletes */
963 while ((obs = *obsp++) != 0)
965 /* foreach provider of an obsoletes of 's' */
966 FOR_PROVIDES(p, pp, obs)
968 Solvable *ps = pool->solvables + p;
971 if (isinstalled && dontfix && ps->repo == installed)
972 continue; /* don't repair installed/installed problems */
973 if (!pool->obsoleteusesprovides /* obsoletes are matched names, not provides */
974 && !pool_match_nevr(pool, ps, obs))
976 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
978 if (p == SYSTEMSOLVABLE)
981 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_OBSOLETES, obs);
983 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_INSTALLED_OBSOLETES, obs);
987 /* check implicit obsoletes
988 * for installed packages we only need to check installed/installed problems (and
989 * only when dontfix is not set), as the others are picked up when looking at the
990 * uninstalled package.
992 if (!isinstalled || !dontfix)
994 FOR_PROVIDES(p, pp, s->name)
996 Solvable *ps = pool->solvables + p;
999 if (isinstalled && ps->repo != installed)
1001 /* we still obsolete packages with same nevra, like rpm does */
1002 /* (actually, rpm mixes those packages. yuck...) */
1003 if (multi && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
1005 if (isinstalled || ps->repo != installed)
1007 /* also check the installed package for multi-ness */
1008 if (MAPTST(&solv->multiversion, p))
1011 if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
1013 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, ps))
1015 if (p == SYSTEMSOLVABLE)
1017 if (s->name == ps->name)
1019 /* optimization: do not add the same-name conflict rule if it was
1020 * already added when we looked at the other package.
1021 * (this assumes pool_colormatch is symmetric) */
1022 if (p && m && ps->repo != installed && MAPTST(m, p) &&
1023 (ps->arch != ARCH_SRC && ps->arch != ARCH_NOSRC) &&
1024 !(solv->multiversion.size && MAPTST(&solv->multiversion, p)))
1026 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_SAME_NAME, 0);
1029 addpkgrule(solv, -n, -p, 0, SOLVER_RULE_PKG_IMPLICIT_OBSOLETES, s->name);
1034 if (m && pool->implicitobsoleteusescolors && (s->arch > pool->lastarch || pool->id2arch[s->arch] != 1))
1036 int a = pool->id2arch[s->arch];
1037 /* check lock-step candidates */
1038 FOR_PROVIDES(p, pp, s->name)
1040 Solvable *ps = pool->solvables + p;
1041 if (s->name != ps->name || s->evr != ps->evr || MAPTST(m, p))
1043 if (ps->arch > pool->lastarch || pool->id2arch[ps->arch] == 1 || pool->id2arch[ps->arch] >= a)
1045 queue_push(&workq, p);
1049 /*-----------------------------------------
1050 * add recommends/suggests to the work queue
1052 if (s->recommends && m)
1054 recp = s->repo->idarraydata + s->recommends;
1055 while ((rec = *recp++) != 0)
1057 #ifdef ENABLE_COMPLEX_DEPS
1058 if (pool_is_complex_dep(pool, rec))
1060 pool_add_pos_literals_complex_dep(pool, rec, &workq, m, 0);
1064 FOR_PROVIDES(p, pp, rec)
1066 queue_push(&workq, p);
1069 if (s->suggests && m)
1071 sugp = s->repo->idarraydata + s->suggests;
1072 while ((sug = *sugp++) != 0)
1074 #ifdef ENABLE_COMPLEX_DEPS
1075 if (pool_is_complex_dep(pool, sug))
1077 pool_add_pos_literals_complex_dep(pool, sug, &workq, m, 0);
1081 FOR_PROVIDES(p, pp, sug)
1083 queue_push(&workq, p);
1087 queue_free(&prereqq);
1091 #ifdef ENABLE_LINKED_PKGS
1093 solver_addpkgrulesforlinked(Solver *solv, Map *m)
1095 Pool *pool = solv->pool;
1101 for (i = 1; i < pool->nsolvables; i++)
1105 s = pool->solvables + i;
1106 if (!s->repo || s->repo == solv->installed)
1108 if (!strchr(pool_id2str(pool, s->name), ':'))
1110 if (!pool_installable(pool, s))
1112 find_package_link(pool, s, 0, &qr, 0, 0);
1115 for (j = 0; j < qr.count; j++)
1116 if (MAPTST(m, qr.elements[j]))
1118 solver_addpkgrulesforsolvable(solv, s, m);
1128 /*-------------------------------------------------------------------
1130 * Add rules for packages possibly selected in by weak dependencies
1132 * m: already added solvables
1136 solver_addpkgrulesforweak(Solver *solv, Map *m)
1138 Pool *pool = solv->pool;
1143 /* foreach solvable in pool */
1144 for (i = n = 1; n < pool->nsolvables; i++, n++)
1146 if (i == pool->nsolvables) /* wrap i */
1148 if (MAPTST(m, i)) /* already added that one */
1151 s = pool->solvables + i;
1154 if (s->repo != pool->installed && !pool_installable(pool, s))
1155 continue; /* only look at installable ones */
1160 /* find possible supplements */
1161 supp = s->repo->idarraydata + s->supplements;
1162 while ((sup = *supp++) != 0)
1163 if (solver_dep_possible(solv, sup, m))
1167 /* if nothing found, check for enhances */
1168 if (!sup && s->enhances)
1170 supp = s->repo->idarraydata + s->enhances;
1171 while ((sup = *supp++) != 0)
1172 if (solver_dep_possible(solv, sup, m))
1175 /* if nothing found, goto next solvables */
1178 solver_addpkgrulesforsolvable(solv, s, m);
1179 n = 0; /* check all solvables again because we added solvables to m */
1184 /*-------------------------------------------------------------------
1186 * add package rules for possible updates
1189 * m: map of already visited solvables
1190 * allow_all: 0 = dont allow downgrades, 1 = allow all candidates
1194 solver_addpkgrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
1196 Pool *pool = solv->pool;
1198 /* queue and buffer for it */
1202 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1203 /* find update candidates for 's' */
1204 policy_findupdatepackages(solv, s, &qs, allow_all);
1205 /* add rule for 's' if not already done */
1206 if (!MAPTST(m, s - pool->solvables))
1207 solver_addpkgrulesforsolvable(solv, s, m);
1208 /* foreach update candidate, add rule if not already done */
1209 for (i = 0; i < qs.count; i++)
1210 if (!MAPTST(m, qs.elements[i]))
1211 solver_addpkgrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
1216 /***********************************************************************
1218 *** Update/Feature rule part
1220 *** Those rules make sure an installed package isn't silently deleted
1225 dup_maykeepinstalled(Solver *solv, Solvable *s)
1227 Pool *pool = solv->pool;
1230 if (solv->dupmap.size && MAPTST(&solv->dupmap, s - pool->solvables))
1232 /* is installed identical to a good one? */
1233 FOR_PROVIDES(ip, pp, s->name)
1235 Solvable *is = pool->solvables + ip;
1236 if (is->evr != s->evr)
1238 if (solv->dupmap.size)
1240 if (!MAPTST(&solv->dupmap, ip))
1243 else if (is->repo == pool->installed)
1245 if (solvable_identical(s, is))
1252 /* stash away the original updaters for multiversion packages. We do this so that
1253 * we can update the package later */
1255 set_specialupdaters(Solver *solv, Solvable *s, Id d)
1257 Repo *installed = solv->installed;
1258 if (!solv->specialupdaters)
1259 solv->specialupdaters = solv_calloc(installed->end - installed->start, sizeof(Id));
1260 solv->specialupdaters[s - solv->pool->solvables - installed->start] = d;
1263 #ifdef ENABLE_LINKED_PKGS
1264 /* Check if this is a linked pseudo package. As it is linked, we do not need an update/feature rule */
1266 is_linked_pseudo_package(Solver *solv, Solvable *s)
1268 Pool *pool = solv->pool;
1269 if (solv->instbuddy && solv->instbuddy[s - pool->solvables - solv->installed->start])
1271 const char *name = pool_id2str(pool, s->name);
1272 if (strncmp(name, "pattern:", 8) == 0 || strncmp(name, "application:", 12) == 0)
1280 solver_addfeaturerule(Solver *solv, Solvable *s)
1282 Pool *pool = solv->pool;
1288 #ifdef ENABLE_LINKED_PKGS
1289 if (is_linked_pseudo_package(solv, s))
1291 solver_addrule(solv, 0, 0, 0); /* no feature rules for those */
1295 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1296 p = s - pool->solvables;
1297 policy_findupdatepackages(solv, s, &qs, 1);
1298 if (solv->dupinvolvedmap_all || (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
1300 if (!dup_maykeepinstalled(solv, s))
1302 for (i = 0; i < qs.count; i++)
1304 Solvable *ns = pool->solvables + qs.elements[i];
1305 if (ns->repo != pool->installed || dup_maykeepinstalled(solv, ns))
1310 solver_addrule(solv, 0, 0, 0); /* this is an orphan */
1318 Id d = pool_queuetowhatprovides(pool, &qs);
1320 solver_addrule(solv, p, 0, d); /* allow update of s */
1324 Id d = qs.count ? qs.elements[0] : 0;
1326 solver_addrule(solv, p, d, 0); /* allow update of s */
1330 /*-------------------------------------------------------------------
1332 * add rule for update
1333 * (A|A1|A2|A3...) An = update candidates for A
1335 * s = (installed) solvable
1339 solver_addupdaterule(Solver *solv, Solvable *s)
1341 /* installed packages get a special upgrade allowed rule */
1342 Pool *pool = solv->pool;
1347 int dupinvolved = 0;
1349 p = s - pool->solvables;
1350 /* Orphan detection. We cheat by looking at the feature rule, which
1351 * we already calculated */
1352 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1355 #ifdef ENABLE_LINKED_PKGS
1356 if (is_linked_pseudo_package(solv, s))
1358 solver_addrule(solv, 0, 0, 0);
1363 queue_push(&solv->orphaned, s - pool->solvables); /* an orphaned package */
1364 if (solv->keep_orphans && !(solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, s - pool->solvables - solv->installed->start))))
1365 p = s - pool->solvables; /* keep this orphaned package installed */
1366 solver_addrule(solv, p, 0, 0);
1370 /* find update candidates for 's' */
1371 queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
1372 dupinvolved = solv->dupinvolvedmap_all || (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p));
1373 policy_findupdatepackages(solv, s, &qs, dupinvolved ? 2 : 0);
1375 if (qs.count && solv->multiversion.size)
1379 for (i = 0; i < qs.count; i++)
1380 if (MAPTST(&solv->multiversion, qs.elements[i]))
1384 /* filter out all multiversion packages as they don't update */
1385 d = pool_queuetowhatprovides(pool, &qs); /* save qs away */
1386 for (j = i; i < qs.count; i++)
1388 if (MAPTST(&solv->multiversion, qs.elements[i]))
1390 Solvable *ps = pool->solvables + qs.elements[i];
1391 /* if keepexplicitobsoletes is set and the name is different,
1392 * we assume that there is an obsoletes. XXX: not 100% correct */
1393 if (solv->keepexplicitobsoletes && ps->name != s->name)
1395 qs.elements[j++] = qs.elements[i];
1398 /* it's ok if they have same nevra */
1399 if (ps->name != s->name || ps->evr != s->evr || ps->arch != s->arch)
1402 qs.elements[j++] = qs.elements[i];
1405 if (j == 0 && dupinvolved && !dup_maykeepinstalled(solv, s))
1407 /* this is a multiversion orphan */
1408 queue_push(&solv->orphaned, p);
1409 set_specialupdaters(solv, s, d);
1410 if (solv->keep_orphans && !(solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - solv->installed->start))))
1412 /* we need to keep the orphan */
1414 solver_addrule(solv, p, 0, 0);
1417 /* we can drop it as long as we update */
1421 if (j < qs.count) /* filtered at least one package? */
1423 if (d && (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, p - solv->installed->start))))
1425 /* non-orphan multiversion package, set special updaters if we want an update */
1426 set_specialupdaters(solv, s, d);
1432 /* could fallthrough, but then we would do pool_queuetowhatprovides twice */
1434 solver_addrule(solv, p, 0, d); /* allow update of s */
1441 d = pool_queuetowhatprovides(pool, &qs);
1443 solver_addrule(solv, p, 0, d); /* allow update of s */
1447 d = qs.count ? qs.elements[0] : 0;
1449 solver_addrule(solv, p, d, 0); /* allow update of s */
1454 disableupdaterule(Solver *solv, Id p)
1458 MAPSET(&solv->noupdate, p - solv->installed->start);
1459 r = solv->rules + solv->updaterules + (p - solv->installed->start);
1460 if (r->p && r->d >= 0)
1461 solver_disablerule(solv, r);
1462 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1463 if (r->p && r->d >= 0)
1464 solver_disablerule(solv, r);
1465 if (solv->bestrules_pkg)
1468 ni = solv->bestrules_end - solv->bestrules;
1469 for (i = solv->bestrules_up - solv->bestrules; i < ni; i++)
1470 if (solv->bestrules_pkg[i] == p)
1471 solver_disablerule(solv, solv->rules + solv->bestrules + i);
1476 reenableupdaterule(Solver *solv, Id p)
1478 Pool *pool = solv->pool;
1481 MAPCLR(&solv->noupdate, p - solv->installed->start);
1482 r = solv->rules + solv->updaterules + (p - solv->installed->start);
1487 solver_enablerule(solv, r);
1488 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1490 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1491 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1497 r = solv->rules + solv->featurerules + (p - solv->installed->start);
1498 if (r->p && r->d < 0)
1500 solver_enablerule(solv, r);
1501 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1503 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1504 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1508 if (solv->bestrules_pkg)
1511 ni = solv->bestrules_end - solv->bestrules;
1512 for (i = solv->bestrules_up - solv->bestrules; i < ni; i++)
1513 if (solv->bestrules_pkg[i] == p)
1514 solver_enablerule(solv, solv->rules + solv->bestrules + i);
1519 /***********************************************************************
1521 *** Infarch rule part
1523 *** Infarch rules make sure the solver uses the best architecture of
1524 *** a package if multiple archetectures are available
1529 solver_addinfarchrules(Solver *solv, Map *addedmap)
1531 Pool *pool = solv->pool;
1532 Repo *installed = pool->installed;
1534 Id p, pp, a, aa, bestarch;
1535 Solvable *s, *ps, *bests;
1536 Queue badq, allowedarchs;
1540 queue_init(&allowedarchs);
1542 solv->infarchrules = solv->nrules;
1543 for (i = 1; i < pool->nsolvables; i++)
1545 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1547 s = pool->solvables + i;
1551 queue_empty(&allowedarchs);
1552 FOR_PROVIDES(p, pp, s->name)
1554 ps = pool->solvables + p;
1555 if (ps->name != s->name || !MAPTST(addedmap, p))
1562 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1563 if (a != 1 && installed && ps->repo == installed)
1565 if (solv->dupinvolvedmap_all || (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
1567 queue_pushunique(&allowedarchs, ps->arch); /* also ok to keep this architecture */
1568 continue; /* but ignore installed solvables when calculating the best arch */
1570 if (a && a != 1 && (!bestarch || a < bestarch))
1579 /* speed up common case where installed package already has best arch */
1580 if (allowedarchs.count == 1 && bests && allowedarchs.elements[0] == bests->arch)
1581 allowedarchs.count--; /* installed arch is best */
1583 if (allowedarchs.count && pool->implicitobsoleteusescolors && installed && bestarch)
1585 /* need an extra pass for lockstep checking: we only allow to keep an inferior arch
1586 * if the corresponding installed package is not lock-stepped */
1587 queue_empty(&allowedarchs);
1588 FOR_PROVIDES(p, pp, s->name)
1591 ps = pool->solvables + p;
1592 if (ps->name != s->name || ps->repo != installed || !MAPTST(addedmap, p))
1594 if (solv->dupinvolvedmap_all || (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
1597 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1600 queue_pushunique(&allowedarchs, ps->arch); /* strange arch, allow */
1603 if (a == 1 || ((a ^ bestarch) & 0xffff0000) == 0)
1605 /* have installed package with inferior arch, check if lock-stepped */
1606 FOR_PROVIDES(p2, pp2, s->name)
1608 Solvable *s2 = pool->solvables + p2;
1610 if (p2 == p || s2->name != s->name || s2->evr != pool->solvables[p].evr || s2->arch == pool->solvables[p].arch)
1613 a2 = (a2 <= pool->lastarch) ? pool->id2arch[a2] : 0;
1614 if (a2 && (a2 == 1 || ((a2 ^ bestarch) & 0xffff0000) == 0))
1618 queue_pushunique(&allowedarchs, ps->arch);
1622 /* find all bad packages */
1624 FOR_PROVIDES(p, pp, s->name)
1626 ps = pool->solvables + p;
1627 if (ps->name != s->name || !MAPTST(addedmap, p))
1630 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1631 if (a != 1 && bestarch && ((a ^ bestarch) & 0xffff0000) != 0)
1633 if (installed && ps->repo == installed)
1635 if (pool->implicitobsoleteusescolors)
1636 queue_push(&badq, p); /* special lock-step handling, see below */
1637 continue; /* always ok to keep an installed package */
1639 for (j = 0; j < allowedarchs.count; j++)
1641 aa = allowedarchs.elements[j];
1644 aa = (aa <= pool->lastarch) ? pool->id2arch[aa] : 0;
1645 if (aa && ((a ^ aa) & 0xffff0000) == 0)
1646 break; /* compatible */
1648 if (j == allowedarchs.count)
1649 queue_push(&badq, p);
1653 /* block all solvables in the badq! */
1654 for (j = 0; j < badq.count; j++)
1656 p = badq.elements[j];
1658 if (pool->implicitobsoleteusescolors)
1661 int haveinstalled = 0;
1663 FOR_PROVIDES(p2, pp, s->name)
1665 Solvable *s2 = pool->solvables + p2;
1666 if (p2 == p || s2->name != s->name || s2->evr != pool->solvables[p].evr || s2->arch == pool->solvables[p].arch)
1669 a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
1670 if (a && (a == 1 || ((a ^ bestarch) & 0xffff000) == 0))
1672 queue_push(&lsq, p2);
1673 if (installed && s2->repo == installed)
1677 if (installed && pool->solvables[p].repo == installed && !haveinstalled)
1678 continue; /* installed package not in lock-step */
1681 solver_addrule(solv, -p, lsq.count ? lsq.elements[0] : 0, 0);
1683 solver_addrule(solv, -p, 0, pool_queuetowhatprovides(pool, &lsq));
1688 queue_free(&allowedarchs);
1689 solv->infarchrules_end = solv->nrules;
1693 disableinfarchrule(Solver *solv, Id name)
1695 Pool *pool = solv->pool;
1698 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1700 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
1701 solver_disablerule(solv, r);
1706 reenableinfarchrule(Solver *solv, Id name)
1708 Pool *pool = solv->pool;
1711 for (i = solv->infarchrules, r = solv->rules + i; i < solv->infarchrules_end; i++, r++)
1713 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
1715 solver_enablerule(solv, r);
1716 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
1718 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
1719 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
1726 /***********************************************************************
1730 *** Dup rules make sure a package is selected from the specified dup
1731 *** repositories if an update candidate is included in one of them.
1736 add_cleandeps_updatepkg(Solver *solv, Id p)
1738 if (!solv->cleandeps_updatepkgs)
1740 solv->cleandeps_updatepkgs = solv_calloc(1, sizeof(Queue));
1741 queue_init(solv->cleandeps_updatepkgs);
1743 queue_pushunique(solv->cleandeps_updatepkgs, p);
1747 solver_addtodupmaps(Solver *solv, Id p, Id how, int targeted)
1749 Pool *pool = solv->pool;
1750 Solvable *ps, *s = pool->solvables + p;
1751 Repo *installed = solv->installed;
1752 Id pi, pip, obs, *obsp;
1754 if (!solv->dupinvolvedmap.size)
1755 map_grow(&solv->dupinvolvedmap, pool->nsolvables);
1757 MAPSET(&solv->dupinvolvedmap, p);
1759 MAPSET(&solv->dupmap, p);
1760 FOR_PROVIDES(pi, pip, s->name)
1762 ps = pool->solvables + pi;
1763 if (ps->name != s->name)
1765 MAPSET(&solv->dupinvolvedmap, pi);
1766 if (targeted && ps->repo == installed && solv->obsoletes && solv->obsoletes[pi - installed->start])
1769 for (opp = solv->obsoletes_data + solv->obsoletes[pi - installed->start]; (pi2 = *opp++) != 0;)
1770 if (pool->solvables[pi2].repo != installed)
1771 MAPSET(&solv->dupinvolvedmap, pi2);
1773 if (ps->repo == installed && (how & SOLVER_FORCEBEST) != 0 && !solv->bestupdatemap_all)
1775 if (!solv->bestupdatemap.size)
1776 map_grow(&solv->bestupdatemap, installed->end - installed->start);
1777 MAPSET(&solv->bestupdatemap, pi - installed->start);
1779 if (ps->repo == installed && (how & SOLVER_CLEANDEPS) != 0)
1780 add_cleandeps_updatepkg(solv, pi);
1781 if (!targeted && ps->repo != installed)
1782 MAPSET(&solv->dupmap, pi);
1784 if (s->repo == installed && solv->obsoletes && solv->obsoletes[p - installed->start])
1787 for (opp = solv->obsoletes_data + solv->obsoletes[p - installed->start]; (pi = *opp++) != 0;)
1789 ps = pool->solvables + pi;
1790 if (ps->repo == installed)
1792 MAPSET(&solv->dupinvolvedmap, pi);
1794 MAPSET(&solv->dupmap, pi);
1797 if (targeted && s->repo != installed && s->obsoletes)
1799 /* XXX: check obsoletes/provides combination */
1800 obsp = s->repo->idarraydata + s->obsoletes;
1801 while ((obs = *obsp++) != 0)
1803 FOR_PROVIDES(pi, pip, obs)
1805 Solvable *ps = pool->solvables + pi;
1806 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, ps, obs))
1808 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
1810 MAPSET(&solv->dupinvolvedmap, pi);
1811 if (targeted && ps->repo == installed && solv->obsoletes && solv->obsoletes[pi - installed->start])
1814 for (opp = solv->obsoletes_data + solv->obsoletes[pi - installed->start]; (pi2 = *opp++) != 0;)
1815 if (pool->solvables[pi2].repo != installed)
1816 MAPSET(&solv->dupinvolvedmap, pi2);
1818 if (ps->repo == installed && (how & SOLVER_FORCEBEST) != 0 && !solv->bestupdatemap_all)
1820 if (!solv->bestupdatemap.size)
1821 map_grow(&solv->bestupdatemap, installed->end - installed->start);
1822 MAPSET(&solv->bestupdatemap, pi - installed->start);
1824 if (ps->repo == installed && (how & SOLVER_CLEANDEPS) != 0)
1825 add_cleandeps_updatepkg(solv, pi);
1831 /* create the two dupmaps:
1832 * - dupmap: packages in that map are good to install/keep
1833 * - dupinvolvedmap: packages are subject to dup mode
1836 solver_createdupmaps(Solver *solv)
1838 Queue *job = &solv->job;
1839 Pool *pool = solv->pool;
1840 Repo *installed = solv->installed;
1841 Id select, how, what, p, pp;
1845 map_init(&solv->dupmap, pool->nsolvables);
1846 solv->dupinvolvedmap_all = 0;
1847 map_init(&solv->dupinvolvedmap, 0);
1848 for (i = 0; i < job->count; i += 2)
1850 how = job->elements[i];
1851 select = job->elements[i] & SOLVER_SELECTMASK;
1852 what = job->elements[i + 1];
1853 switch (how & SOLVER_JOBMASK)
1855 case SOLVER_DISTUPGRADE:
1856 if (select == SOLVER_SOLVABLE_REPO)
1859 if (what <= 0 || what > pool->nrepos)
1861 repo = pool_id2repo(pool, what);
1864 if (repo != installed && !(how & SOLVER_TARGETED) && solv->noautotarget)
1866 targeted = repo != installed || (how & SOLVER_TARGETED) != 0;
1867 FOR_REPO_SOLVABLES(repo, p, s)
1869 if (repo != installed && !pool_installable(pool, s))
1871 solver_addtodupmaps(solv, p, how, targeted);
1874 else if (select == SOLVER_SOLVABLE_ALL)
1876 solv->dupinvolvedmap_all = 1;
1877 FOR_POOL_SOLVABLES(p)
1879 Solvable *s = pool->solvables + p;
1880 if (!s->repo || s->repo == installed)
1882 if (!pool_installable(pool, s))
1884 MAPSET(&solv->dupmap, p);
1886 if ((how & SOLVER_FORCEBEST) != 0)
1887 solv->bestupdatemap_all = 1;
1888 if ((how & SOLVER_CLEANDEPS) != 0 && installed)
1890 FOR_REPO_SOLVABLES(installed, p, s)
1891 add_cleandeps_updatepkg(solv, p);
1896 targeted = how & SOLVER_TARGETED ? 1 : 0;
1897 if (installed && !targeted && !solv->noautotarget)
1899 FOR_JOB_SELECT(p, pp, select, what)
1900 if (pool->solvables[p].repo == installed)
1904 else if (!installed && !solv->noautotarget)
1906 FOR_JOB_SELECT(p, pp, select, what)
1908 Solvable *s = pool->solvables + p;
1911 if (s->repo != installed && !targeted)
1913 if (s->repo != installed && !pool_installable(pool, s))
1915 solver_addtodupmaps(solv, p, how, targeted);
1923 if (solv->dupinvolvedmap.size)
1924 MAPCLR(&solv->dupinvolvedmap, SYSTEMSOLVABLE);
1925 /* set update for all involved installed packages. We need to do
1926 * this before creating the update rules */
1927 if (solv->dupinvolvedmap_all)
1928 solv->updatemap_all = 1;
1929 else if (installed && !solv->updatemap_all && solv->dupinvolvedmap.size)
1931 FOR_REPO_SOLVABLES(installed, p, s)
1933 if (!MAPTST(&solv->dupinvolvedmap, p))
1935 if (!solv->updatemap.size)
1936 map_grow(&solv->updatemap, installed->end - installed->start);
1937 MAPSET(&solv->updatemap, p - installed->start);
1943 solver_freedupmaps(Solver *solv)
1945 map_free(&solv->dupmap);
1946 /* we no longer free solv->dupinvolvedmap as we need it in
1947 * policy's priority pruning code. sigh. */
1951 solver_addduprules(Solver *solv, Map *addedmap)
1953 Pool *pool = solv->pool;
1954 Repo *installed = solv->installed;
1960 solv->duprules = solv->nrules;
1961 for (i = 1; i < pool->nsolvables; i++)
1963 if (i == SYSTEMSOLVABLE || !MAPTST(addedmap, i))
1965 s = pool->solvables + i;
1967 FOR_PROVIDES(p, pp, s->name)
1969 ps = pool->solvables + p;
1970 if (ps->name != s->name || !MAPTST(addedmap, p))
1976 if (!solv->dupinvolvedmap_all && !MAPTST(&solv->dupinvolvedmap, p))
1978 if (installed && ps->repo == installed)
1980 if (!MAPTST(&solv->dupmap, p))
1983 /* is installed identical to a good one? */
1984 FOR_PROVIDES(ip, ipp, ps->name)
1986 Solvable *is = pool->solvables + ip;
1987 if (!MAPTST(&solv->dupmap, ip))
1989 if (is->evr == ps->evr && solvable_identical(ps, is))
1994 /* ok, identical to a good one. we may keep this package. */
1995 MAPSET(&solv->dupmap, p); /* for best rules processing */
1998 /* check if it's orphaned. If yes, we may keep it */
1999 r = solv->rules + solv->updaterules + (p - installed->start);
2001 r = solv->rules + solv->featurerules + (p - installed->start);
2004 /* no update/feature rule, this is an orphan */
2005 MAPSET(&solv->dupmap, p); /* for best rules processing */
2008 if (solv->specialupdaters && solv->specialupdaters[p - installed->start])
2010 /* this is a multiversion orphan, we're good if an update is installed */
2011 solver_addrule(solv, -p, 0, solv->specialupdaters[p - installed->start]);
2014 if (r->p == p && !r->d && !r->w2)
2016 r = solv->rules + solv->featurerules + (p - installed->start);
2017 if (!r->p || (!r->d && !r->w2))
2019 /* this is an orphan */
2020 MAPSET(&solv->dupmap, p); /* for best rules processing */
2024 solver_addrule(solv, -p, 0, 0); /* no match, sorry */
2027 else if (!MAPTST(&solv->dupmap, p))
2028 solver_addrule(solv, -p, 0, 0);
2031 solv->duprules_end = solv->nrules;
2036 disableduprule(Solver *solv, Id name)
2038 Pool *pool = solv->pool;
2041 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
2043 if (r->p < 0 && r->d >= 0 && pool->solvables[-r->p].name == name)
2044 solver_disablerule(solv, r);
2049 reenableduprule(Solver *solv, Id name)
2051 Pool *pool = solv->pool;
2054 for (i = solv->duprules, r = solv->rules + i; i < solv->duprules_end; i++, r++)
2056 if (r->p < 0 && r->d < 0 && pool->solvables[-r->p].name == name)
2058 solver_enablerule(solv, r);
2059 IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
2061 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
2062 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
2069 /***********************************************************************
2071 *** Policy rule disabling/reenabling
2073 *** Disable all policy rules that conflict with our jobs. If a job
2074 *** gets disabled later on, reenable the involved policy rules again.
2078 #define DISABLE_UPDATE 1
2079 #define DISABLE_INFARCH 2
2080 #define DISABLE_DUP 3
2083 jobtodisablelist(Solver *solv, Id how, Id what, Queue *q)
2085 Pool *pool = solv->pool;
2089 int i, j, set, qstart;
2092 installed = solv->installed;
2093 select = how & SOLVER_SELECTMASK;
2094 switch (how & SOLVER_JOBMASK)
2096 case SOLVER_INSTALL:
2097 set = how & SOLVER_SETMASK;
2098 if (!(set & SOLVER_NOAUTOSET))
2100 /* automatically add set bits by analysing the job */
2101 if (select == SOLVER_SOLVABLE_NAME)
2102 set |= SOLVER_SETNAME;
2103 if (select == SOLVER_SOLVABLE)
2104 set |= SOLVER_SETNAME | SOLVER_SETARCH | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_SETEVR;
2105 else if ((select == SOLVER_SOLVABLE_NAME || select == SOLVER_SOLVABLE_PROVIDES) && ISRELDEP(what))
2107 Reldep *rd = GETRELDEP(pool, what);
2108 if (rd->flags == REL_EQ && select == SOLVER_SOLVABLE_NAME)
2110 if (pool->disttype != DISTTYPE_DEB)
2112 const char *rel = strrchr(pool_id2str(pool, rd->evr), '-');
2113 set |= rel ? SOLVER_SETEVR : SOLVER_SETEV;
2116 set |= SOLVER_SETEVR;
2118 if (rd->flags <= 7 && ISRELDEP(rd->name))
2119 rd = GETRELDEP(pool, rd->name);
2120 if (rd->flags == REL_ARCH)
2121 set |= SOLVER_SETARCH;
2125 set &= ~SOLVER_NOAUTOSET;
2128 if ((set & SOLVER_SETARCH) != 0 && solv->infarchrules != solv->infarchrules_end)
2130 if (select == SOLVER_SOLVABLE)
2131 queue_push2(q, DISABLE_INFARCH, pool->solvables[what].name);
2134 int qcnt = q->count;
2135 /* does not work for SOLVER_SOLVABLE_ALL and SOLVER_SOLVABLE_REPO, but
2136 they are not useful for SOLVER_INSTALL jobs anyway */
2137 FOR_JOB_SELECT(p, pp, select, what)
2139 s = pool->solvables + p;
2141 for (i = qcnt; i < q->count; i += 2)
2142 if (q->elements[i + 1] == s->name)
2146 queue_push2(q, DISABLE_INFARCH, s->name);
2150 if ((set & SOLVER_SETREPO) != 0 && solv->duprules != solv->duprules_end)
2152 if (select == SOLVER_SOLVABLE)
2153 queue_push2(q, DISABLE_DUP, pool->solvables[what].name);
2156 int qcnt = q->count;
2157 FOR_JOB_SELECT(p, pp, select, what)
2159 s = pool->solvables + p;
2161 for (i = qcnt; i < q->count; i += 2)
2162 if (q->elements[i + 1] == s->name)
2166 queue_push2(q, DISABLE_DUP, s->name);
2170 if (!installed || installed->end == installed->start)
2172 /* now the hard part: disable some update rules */
2174 /* first check if we have installed or multiversion packages in the job */
2175 FOR_JOB_SELECT(p, pp, select, what)
2177 if (pool->solvables[p].repo == installed)
2179 if (solv->multiversion.size && MAPTST(&solv->multiversion, p) && !solv->keepexplicitobsoletes)
2184 FOR_JOB_SELECT(p, pp, select, what)
2186 solver_intersect_obsoleted(solv, p, q, qstart, &omap);
2187 if (q->count == qstart)
2193 if (qstart == q->count)
2194 return; /* nothing to prune */
2196 /* convert result to (DISABLE_UPDATE, p) pairs */
2198 for (j = qstart; j < i; j++)
2199 queue_push(q, q->elements[j]);
2200 for (j = qstart; j < q->count; j += 2)
2202 q->elements[j] = DISABLE_UPDATE;
2203 q->elements[j + 1] = q->elements[i++];
2206 /* now that we know which installed packages are obsoleted check each of them */
2207 if ((set & (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR)) == (SOLVER_SETEVR | SOLVER_SETARCH | SOLVER_SETVENDOR))
2208 return; /* all is set, nothing to do */
2210 for (i = j = qstart; i < q->count; i += 2)
2212 Solvable *is = pool->solvables + q->elements[i + 1];
2213 FOR_JOB_SELECT(p, pp, select, what)
2216 s = pool->solvables + p;
2217 if ((set & SOLVER_SETEVR) != 0)
2218 illegal |= POLICY_ILLEGAL_DOWNGRADE; /* ignore */
2219 if ((set & SOLVER_SETNAME) != 0)
2220 illegal |= POLICY_ILLEGAL_NAMECHANGE; /* ignore */
2221 if ((set & SOLVER_SETARCH) != 0)
2222 illegal |= POLICY_ILLEGAL_ARCHCHANGE; /* ignore */
2223 if ((set & SOLVER_SETVENDOR) != 0)
2224 illegal |= POLICY_ILLEGAL_VENDORCHANGE; /* ignore */
2225 illegal = policy_is_illegal(solv, is, s, illegal);
2226 if (illegal && illegal == POLICY_ILLEGAL_DOWNGRADE && (set & SOLVER_SETEV) != 0)
2228 /* it's ok if the EV is different */
2229 if (pool_evrcmp(pool, is->evr, s->evr, EVRCMP_COMPARE_EVONLY) != 0)
2237 /* no package conflicts with the update rule */
2238 /* thus keep the DISABLE_UPDATE */
2239 q->elements[j + 1] = q->elements[i + 1];
2243 queue_truncate(q, j);
2249 if (select == SOLVER_SOLVABLE_ALL || (select == SOLVER_SOLVABLE_REPO && what == installed->repoid))
2251 FOR_REPO_SOLVABLES(installed, p, s)
2252 queue_push2(q, DISABLE_UPDATE, p);
2254 FOR_JOB_SELECT(p, pp, select, what)
2255 if (pool->solvables[p].repo == installed)
2257 queue_push2(q, DISABLE_UPDATE, p);
2258 #ifdef ENABLE_LINKED_PKGS
2259 if (solv->instbuddy && solv->instbuddy[p - installed->start] > 1)
2260 queue_push2(q, DISABLE_UPDATE, solv->instbuddy[p - installed->start]);
2269 /* disable all policy rules that are in conflict with our job list */
2271 solver_disablepolicyrules(Solver *solv)
2273 Queue *job = &solv->job;
2280 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2282 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2284 r = solv->rules + i;
2285 if (r->d < 0) /* disabled? */
2287 j = solv->ruletojob.elements[i - solv->jobrules];
2291 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2293 if (solv->cleandepsmap.size)
2295 solver_createcleandepsmap(solv, &solv->cleandepsmap, 0);
2296 for (i = solv->installed->start; i < solv->installed->end; i++)
2297 if (MAPTST(&solv->cleandepsmap, i - solv->installed->start))
2298 queue_push2(&allq, DISABLE_UPDATE, i);
2300 MAPZERO(&solv->noupdate);
2301 for (i = 0; i < allq.count; i += 2)
2303 Id type = allq.elements[i], arg = allq.elements[i + 1];
2306 case DISABLE_UPDATE:
2307 disableupdaterule(solv, arg);
2309 case DISABLE_INFARCH:
2310 disableinfarchrule(solv, arg);
2313 disableduprule(solv, arg);
2322 /* we just disabled job #jobidx, now reenable all policy rules that were
2323 * disabled because of this job */
2325 solver_reenablepolicyrules(Solver *solv, int jobidx)
2327 Queue *job = &solv->job;
2332 Id qbuf[32], allqbuf[32];
2334 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
2335 jobtodisablelist(solv, job->elements[jobidx - 1], job->elements[jobidx], &q);
2341 /* now remove everything from q that is disabled by other jobs */
2343 /* first remove cleandeps packages, they count as DISABLE_UPDATE */
2344 if (solv->cleandepsmap.size)
2346 solver_createcleandepsmap(solv, &solv->cleandepsmap, 0);
2347 for (j = k = 0; j < q.count; j += 2)
2349 if (q.elements[j] == DISABLE_UPDATE)
2351 Id p = q.elements[j + 1];
2352 if (p >= solv->installed->start && p < solv->installed->end && MAPTST(&solv->cleandepsmap, p - solv->installed->start))
2353 continue; /* remove element from q */
2355 q.elements[k++] = q.elements[j];
2356 q.elements[k++] = q.elements[j + 1];
2366 /* now go through the disable list of all other jobs */
2367 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2368 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2370 r = solv->rules + i;
2371 if (r->d < 0) /* disabled? */
2373 j = solv->ruletojob.elements[i - solv->jobrules];
2377 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2380 /* remove all elements in allq from q */
2381 for (j = k = 0; j < q.count; j += 2)
2383 Id type = q.elements[j], arg = q.elements[j + 1];
2384 for (ai = 0; ai < allq.count; ai += 2)
2385 if (allq.elements[ai] == type && allq.elements[ai + 1] == arg)
2387 if (ai < allq.count)
2388 continue; /* found it in allq, remove element from q */
2389 q.elements[k++] = q.elements[j];
2390 q.elements[k++] = q.elements[j + 1];
2403 /* now re-enable anything that's left in q */
2404 for (j = 0; j < q.count; j += 2)
2406 Id type = q.elements[j], arg = q.elements[j + 1];
2409 case DISABLE_UPDATE:
2410 reenableupdaterule(solv, arg);
2412 case DISABLE_INFARCH:
2413 reenableinfarchrule(solv, arg);
2416 reenableduprule(solv, arg);
2423 /* we just removed a package from the cleandeps map, now reenable all policy rules that were
2424 * disabled because of this */
2426 solver_reenablepolicyrules_cleandeps(Solver *solv, Id pkg)
2428 Queue *job = &solv->job;
2435 queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf));
2436 for (i = solv->jobrules; i < solv->jobrules_end; i++)
2438 r = solv->rules + i;
2439 if (r->d < 0) /* disabled? */
2441 j = solv->ruletojob.elements[i - solv->jobrules];
2445 jobtodisablelist(solv, job->elements[j], job->elements[j + 1], &allq);
2447 for (i = 0; i < allq.count; i += 2)
2448 if (allq.elements[i] == DISABLE_UPDATE && allq.elements[i + 1] == pkg)
2450 if (i == allq.count)
2451 reenableupdaterule(solv, pkg);
2456 /***********************************************************************
2458 *** Rule info part, tell the user what the rule is about.
2463 addpkgruleinfo(Solver *solv, Id p, Id p2, Id d, int type, Id dep)
2465 Pool *pool = solv->pool;
2470 assert(!p2 && d > 0);
2471 if (!pool->whatprovidesdata[d])
2473 else if (!pool->whatprovidesdata[d + 1])
2475 p2 = pool->whatprovidesdata[d];
2480 /* check if this creates the rule we're searching for */
2481 r = solv->rules + solv->ruleinfoq->elements[0];
2484 /* three or more literals */
2485 Id od = r->d < 0 ? -r->d - 1 : r->d;
2486 if (p != r->p && !od)
2490 Id *dp = pool->whatprovidesdata + d;
2491 Id *odp = pool->whatprovidesdata + od;
2493 if (*dp++ != *odp++)
2498 if (p < 0 && pool->whatprovidesdata[d] < 0 && type == SOLVER_RULE_PKG_CONFLICTS)
2499 p2 = pool->whatprovidesdata[d];
2503 /* one or two literals */
2504 Id op = p, op2 = p2;
2505 if (op2 && op > op2) /* normalize */
2511 if (r->p != op || r->w2 != op2 || (r->d && r->d != -1))
2513 if (type == SOLVER_RULE_PKG_CONFLICTS && !p2)
2514 p2 = -SYSTEMSOLVABLE;
2515 if (type == SOLVER_RULE_PKG_SAME_NAME)
2517 p = op; /* we normalize same name order */
2521 /* yep, rule matches. record info */
2522 queue_push(solv->ruleinfoq, type);
2523 queue_push(solv->ruleinfoq, p < 0 ? -p : 0);
2524 queue_push(solv->ruleinfoq, p2 < 0 ? -p2 : 0);
2525 queue_push(solv->ruleinfoq, dep);
2529 solver_allruleinfos_cmp(const void *ap, const void *bp, void *dp)
2531 const Id *a = ap, *b = bp;
2550 getpkgruleinfos(Solver *solv, Rule *r, Queue *rq)
2552 Pool *pool = solv->pool;
2556 queue_push(rq, r - solv->rules); /* push the rule we're interested in */
2557 solv->ruleinfoq = rq;
2558 FOR_RULELITERALS(l, pp, r)
2562 solver_addpkgrulesforsolvable(solv, pool->solvables - l, 0);
2564 #ifdef ENABLE_LINKED_PKGS
2565 FOR_RULELITERALS(l, pp, r)
2573 if (!strchr(pool_id2str(pool, pool->solvables[l].name), ':') || !has_package_link(pool, pool->solvables + l))
2575 add_package_link(solv, pool->solvables + l, 0, 0);
2578 solv->ruleinfoq = 0;
2583 solver_allruleinfos(Solver *solv, Id rid, Queue *rq)
2585 Rule *r = solv->rules + rid;
2589 if (rid <= 0 || rid >= solv->pkgrules_end)
2591 Id type, from, to, dep;
2592 type = solver_ruleinfo(solv, rid, &from, &to, &dep);
2593 queue_push(rq, type);
2594 queue_push(rq, from);
2596 queue_push(rq, dep);
2599 getpkgruleinfos(solv, r, rq);
2600 /* now sort & unify em */
2603 solv_sort(rq->elements, rq->count / 4, 4 * sizeof(Id), solver_allruleinfos_cmp, 0);
2604 /* throw out identical entries */
2605 for (i = j = 0; i < rq->count; i += 4)
2609 if (rq->elements[i] == rq->elements[j - 4] &&
2610 rq->elements[i + 1] == rq->elements[j - 3] &&
2611 rq->elements[i + 2] == rq->elements[j - 2] &&
2612 rq->elements[i + 3] == rq->elements[j - 1])
2615 rq->elements[j++] = rq->elements[i];
2616 rq->elements[j++] = rq->elements[i + 1];
2617 rq->elements[j++] = rq->elements[i + 2];
2618 rq->elements[j++] = rq->elements[i + 3];
2625 solver_ruleinfo(Solver *solv, Id rid, Id *fromp, Id *top, Id *depp)
2627 Pool *pool = solv->pool;
2628 Rule *r = solv->rules + rid;
2629 SolverRuleinfo type = SOLVER_RULE_UNKNOWN;
2637 if (rid > 0 && rid < solv->pkgrules_end)
2643 return SOLVER_RULE_PKG;
2647 getpkgruleinfos(solv, r, &rq);
2648 type = SOLVER_RULE_PKG;
2649 for (i = 0; i < rq.count; i += 4)
2652 qt = rq.elements[i];
2653 qp = rq.elements[i + 1];
2654 qo = rq.elements[i + 2];
2655 qd = rq.elements[i + 3];
2656 if (type == SOLVER_RULE_PKG || type > qt)
2670 if (rid >= solv->jobrules && rid < solv->jobrules_end)
2672 Id jidx = solv->ruletojob.elements[rid - solv->jobrules];
2676 *top = solv->job.elements[jidx];
2678 *depp = solv->job.elements[jidx + 1];
2679 if ((r->d == 0 || r->d == -1) && r->w2 == 0 && r->p == -SYSTEMSOLVABLE)
2681 Id how = solv->job.elements[jidx];
2682 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_INSTALL|SOLVER_SOLVABLE_NAME))
2683 return SOLVER_RULE_JOB_UNKNOWN_PACKAGE;
2684 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES))
2685 return SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP;
2686 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_ERASE|SOLVER_SOLVABLE_NAME))
2687 return SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM;
2688 if ((how & (SOLVER_JOBMASK|SOLVER_SELECTMASK)) == (SOLVER_ERASE|SOLVER_SOLVABLE_PROVIDES))
2689 return SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM;
2690 return SOLVER_RULE_JOB_UNSUPPORTED;
2692 return SOLVER_RULE_JOB;
2694 if (rid >= solv->updaterules && rid < solv->updaterules_end)
2697 *fromp = solv->installed->start + (rid - solv->updaterules);
2698 return SOLVER_RULE_UPDATE;
2700 if (rid >= solv->featurerules && rid < solv->featurerules_end)
2703 *fromp = solv->installed->start + (rid - solv->featurerules);
2704 return SOLVER_RULE_FEATURE;
2706 if (rid >= solv->duprules && rid < solv->duprules_end)
2711 *depp = pool->solvables[-r->p].name;
2712 return SOLVER_RULE_DISTUPGRADE;
2714 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
2719 *depp = pool->solvables[-r->p].name;
2720 return SOLVER_RULE_INFARCH;
2722 if (rid >= solv->bestrules && rid < solv->bestrules_end)
2724 if (fromp && solv->bestrules_pkg[rid - solv->bestrules] > 0)
2725 *fromp = solv->bestrules_pkg[rid - solv->bestrules];
2726 return SOLVER_RULE_BEST;
2728 if (rid >= solv->yumobsrules && rid < solv->yumobsrules_end)
2734 /* first solvable is enough, we just need it for the name */
2735 if (!r->d || r->d == -1)
2738 *top = pool->whatprovidesdata[r->d < 0 ? -r->d : r->d];
2741 *depp = solv->yumobsrules_info[rid - solv->yumobsrules];
2742 return SOLVER_RULE_YUMOBS;
2744 if (rid >= solv->choicerules && rid < solv->choicerules_end)
2746 return SOLVER_RULE_CHOICE;
2748 if (rid >= solv->learntrules)
2750 return SOLVER_RULE_LEARNT;
2752 return SOLVER_RULE_UNKNOWN;
2756 solver_ruleclass(Solver *solv, Id rid)
2759 return SOLVER_RULE_UNKNOWN;
2760 if (rid > 0 && rid < solv->pkgrules_end)
2761 return SOLVER_RULE_PKG;
2762 if (rid >= solv->jobrules && rid < solv->jobrules_end)
2763 return SOLVER_RULE_JOB;
2764 if (rid >= solv->updaterules && rid < solv->updaterules_end)
2765 return SOLVER_RULE_UPDATE;
2766 if (rid >= solv->featurerules && rid < solv->featurerules_end)
2767 return SOLVER_RULE_FEATURE;
2768 if (rid >= solv->duprules && rid < solv->duprules_end)
2769 return SOLVER_RULE_DISTUPGRADE;
2770 if (rid >= solv->infarchrules && rid < solv->infarchrules_end)
2771 return SOLVER_RULE_INFARCH;
2772 if (rid >= solv->bestrules && rid < solv->bestrules_end)
2773 return SOLVER_RULE_BEST;
2774 if (rid >= solv->yumobsrules && rid < solv->yumobsrules_end)
2775 return SOLVER_RULE_YUMOBS;
2776 if (rid >= solv->choicerules && rid < solv->choicerules_end)
2777 return SOLVER_RULE_CHOICE;
2778 if (rid >= solv->learntrules && rid < solv->nrules)
2779 return SOLVER_RULE_LEARNT;
2780 return SOLVER_RULE_UNKNOWN;
2784 solver_ruleliterals(Solver *solv, Id rid, Queue *q)
2786 Pool *pool = solv->pool;
2791 r = solv->rules + rid;
2792 FOR_RULELITERALS(p, pp, r)
2793 if (p != -SYSTEMSOLVABLE)
2796 queue_push(q, -SYSTEMSOLVABLE); /* hmm, better to return an empty result? */
2800 solver_rule2jobidx(Solver *solv, Id rid)
2802 if (rid < solv->jobrules || rid >= solv->jobrules_end)
2804 return solv->ruletojob.elements[rid - solv->jobrules] + 1;
2807 /* job rule introspection */
2809 solver_rule2job(Solver *solv, Id rid, Id *whatp)
2812 if (rid < solv->jobrules || rid >= solv->jobrules_end)
2818 idx = solv->ruletojob.elements[rid - solv->jobrules];
2820 *whatp = solv->job.elements[idx + 1];
2821 return solv->job.elements[idx];
2824 /* update/feature rule introspection */
2826 solver_rule2solvable(Solver *solv, Id rid)
2828 if (rid >= solv->updaterules && rid < solv->updaterules_end)
2829 return rid - solv->updaterules;
2830 if (rid >= solv->featurerules && rid < solv->featurerules_end)
2831 return rid - solv->featurerules;
2836 solver_rule2pkgrule(Solver *solv, Id rid)
2838 if (rid >= solv->choicerules && rid < solv->choicerules_end)
2839 return solv->choicerules_ref[rid - solv->choicerules];
2844 solver_rule2rules_rec(Solver *solv, Id rid, Queue *q, Map *seen)
2851 for (i = solv->learnt_why.elements[rid - solv->learntrules]; (rid2 = solv->learnt_pool.elements[i]) != 0; i++)
2855 if (MAPTST(seen, rid2))
2857 if (rid2 >= solv->learntrules)
2858 solver_rule2rules_rec(solv, rid2, q, seen);
2861 queue_push(q, rid2);
2865 /* learnt rule introspection */
2867 solver_rule2rules(Solver *solv, Id rid, Queue *q, int recursive)
2870 if (rid < solv->learntrules || rid >= solv->nrules)
2875 map_init(&seen, solv->nrules);
2876 solver_rule2rules_rec(solv, rid, q, &seen);
2880 solver_rule2rules_rec(solv, rid, q, 0);
2884 /* check if the newest versions of pi still provides the dependency we're looking for */
2886 solver_choicerulecheck(Solver *solv, Id pi, Rule *r, Map *m, Queue *q)
2888 Pool *pool = solv->pool;
2893 if (!q->count || q->elements[0] != pi)
2897 ur = solv->rules + solv->updaterules + (pi - pool->installed->start);
2899 ur = solv->rules + solv->featurerules + (pi - pool->installed->start);
2902 queue_push2(q, pi, 0);
2903 FOR_RULELITERALS(p, pp, ur)
2912 return MAPTST(m, p) ? 0 : 1;
2914 if (!q->elements[1])
2916 for (i = 2; i < q->count; i++)
2917 if (!MAPTST(m, q->elements[i]))
2920 return 0; /* all provide it, no need to filter */
2921 /* some don't provide it, have to filter */
2922 queue_deleten(q, 0, 2);
2923 policy_filter_unwanted(solv, q, POLICY_MODE_CHOOSE);
2924 queue_unshift(q, 1); /* filter mark */
2925 queue_unshift(q, pi);
2927 for (i = 2; i < q->count; i++)
2928 if (MAPTST(m, q->elements[i]))
2929 return 0; /* at least one provides it */
2930 return 1; /* none of the new packages provided it */
2934 queue_removeelement(Queue *q, Id el)
2937 for (i = 0; i < q->count; i++)
2938 if (q->elements[i] == el)
2942 for (j = i++; i < q->count; i++)
2943 if (q->elements[i] != el)
2944 q->elements[j++] = q->elements[i];
2945 queue_truncate(q, j);
2950 solver_addchoicerules(Solver *solv)
2952 Pool *pool = solv->pool;
2955 Queue q, qi, qcheck;
2956 int i, j, rid, havechoice;
2960 Id lastaddedp, lastaddedd;
2964 solv->choicerules = solv->nrules;
2965 if (!pool->installed)
2967 solv->choicerules_end = solv->nrules;
2970 now = solv_timems(0);
2971 solv->choicerules_ref = solv_calloc(solv->pkgrules_end, sizeof(Id));
2974 queue_init(&qcheck);
2975 map_init(&m, pool->nsolvables);
2976 map_init(&mneg, pool->nsolvables);
2977 /* set up negative assertion map from infarch and dup rules */
2978 for (rid = solv->infarchrules, r = solv->rules + rid; rid < solv->infarchrules_end; rid++, r++)
2979 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
2980 MAPSET(&mneg, -r->p);
2981 for (rid = solv->duprules, r = solv->rules + rid; rid < solv->duprules_end; rid++, r++)
2982 if (r->p < 0 && !r->w2 && (r->d == 0 || r->d == -1))
2983 MAPSET(&mneg, -r->p);
2987 for (rid = 1; rid < solv->pkgrules_end ; rid++)
2989 r = solv->rules + rid;
2990 if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 <= 0))
2991 continue; /* only look at requires rules */
2992 /* solver_printrule(solv, SOLV_DEBUG_RESULT, r); */
2996 FOR_RULELITERALS(p, pp, r)
3000 s = pool->solvables + p;
3003 if (s->repo == pool->installed)
3008 /* check if this package is "blocked" by a installed package */
3010 FOR_PROVIDES(p2, pp2, s->name)
3012 s2 = pool->solvables + p2;
3013 if (s2->repo != pool->installed)
3015 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
3017 if (pool->implicitobsoleteusescolors && !pool_colormatch(pool, s, s2))
3023 /* found installed package p2 that we can update to p */
3024 if (MAPTST(&mneg, p))
3026 if (policy_is_illegal(solv, s2, s, 0))
3029 if (solver_choicerulecheck(solv, p2, r, &m))
3031 queue_push(&qi, p2);
3033 queue_push2(&qi, p2, p);
3040 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
3042 while ((obs = *obsp++) != 0)
3044 FOR_PROVIDES(p2, pp2, obs)
3046 s2 = pool->solvables + p2;
3047 if (s2->repo != pool->installed)
3049 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
3051 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
3060 /* found installed package p2 that we can update to p */
3061 if (MAPTST(&mneg, p))
3063 if (policy_is_illegal(solv, s2, s, 0))
3066 if (solver_choicerulecheck(solv, p2, r, &m))
3068 queue_push(&qi, p2);
3070 queue_push2(&qi, p2, p);
3076 /* package p is independent of the installed ones */
3079 if (!havechoice || !q.count || !qi.count)
3080 continue; /* no choice */
3082 FOR_RULELITERALS(p, pp, r)
3086 /* do extra checking */
3087 for (i = j = 0; i < qi.count; i += 2)
3089 p2 = qi.elements[i];
3092 if (solver_choicerulecheck(solv, p2, r, &m, &qcheck))
3094 /* oops, remove element p from q */
3095 queue_removeelement(&q, qi.elements[i + 1]);
3098 qi.elements[j++] = p2;
3100 queue_truncate(&qi, j);
3102 if (!q.count || !qi.count)
3104 FOR_RULELITERALS(p, pp, r)
3111 /* now check the update rules of the installed package.
3112 * if all packages of the update rules are contained in
3113 * the dependency rules, there's no need to set up the choice rule */
3114 for (i = 0; i < qi.count; i++)
3117 if (!qi.elements[i])
3119 ur = solv->rules + solv->updaterules + (qi.elements[i] - pool->installed->start);
3121 ur = solv->rules + solv->featurerules + (qi.elements[i] - pool->installed->start);
3124 FOR_RULELITERALS(p, pp, ur)
3129 for (j = i + 1; j < qi.count; j++)
3130 if (qi.elements[i] == qi.elements[j])
3133 /* empty map again */
3134 FOR_RULELITERALS(p, pp, r)
3140 printf("skipping choice ");
3141 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + rid);
3146 /* don't add identical rules */
3147 if (lastaddedp == r->p && lastaddedcnt == q.count)
3149 for (i = 0; i < q.count; i++)
3150 if (q.elements[i] != pool->whatprovidesdata[lastaddedd + i])
3153 continue; /* already added that one */
3155 d = q.count ? pool_queuetowhatprovides(pool, &q) : 0;
3159 lastaddedcnt = q.count;
3161 solver_addrule(solv, r->p, 0, d);
3162 queue_push(&solv->weakruleq, solv->nrules - 1);
3163 solv->choicerules_ref[solv->nrules - 1 - solv->choicerules] = rid;
3166 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + rid);
3167 printf("WEAK CHOICE ");
3168 solver_printrule(solv, SOLV_DEBUG_RESULT, solv->rules + solv->nrules - 1);
3173 queue_free(&qcheck);
3176 solv->choicerules_end = solv->nrules;
3177 /* shrink choicerules_ref */
3178 solv->choicerules_ref = solv_realloc2(solv->choicerules_ref, solv->choicerules_end - solv->choicerules, sizeof(Id));
3179 POOL_DEBUG(SOLV_DEBUG_STATS, "choice rule creation took %d ms\n", solv_timems(now));
3182 /* called when a choice rule is disabled by analyze_unsolvable. We also
3183 * have to disable all other choice rules so that the best packages get
3186 solver_disablechoicerules(Solver *solv, Rule *r)
3189 Pool *pool = solv->pool;
3193 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
3194 map_init(&m, pool->nsolvables);
3195 FOR_RULELITERALS(p, pp, or)
3198 FOR_RULELITERALS(p, pp, r)
3201 for (rid = solv->choicerules; rid < solv->choicerules_end; rid++)
3203 r = solv->rules + rid;
3206 or = solv->rules + solv->choicerules_ref[(r - solv->rules) - solv->choicerules];
3207 FOR_RULELITERALS(p, pp, or)
3208 if (p > 0 && MAPTST(&m, p))
3211 solver_disablerule(solv, r);
3216 prune_to_update_targets(Solver *solv, Id *cp, Queue *q)
3220 for (i = j = 0; i < q->count; i++)
3223 for (cp2 = cp; *cp2; cp2++)
3226 q->elements[j++] = p;
3230 queue_truncate(q, j);
3234 prune_to_dup_packages(Solver *solv, Id p, Queue *q)
3237 for (i = j = 0; i < q->count; i++)
3239 Id p = q->elements[i];
3240 if (MAPTST(&solv->dupmap, p))
3241 q->elements[j++] = p;
3243 queue_truncate(q, j);
3247 solver_addbestrules(Solver *solv, int havebestinstalljobs)
3249 Pool *pool = solv->pool;
3252 Repo *installed = solv->installed;
3258 solv->bestrules = solv->nrules;
3263 if (havebestinstalljobs)
3265 for (i = 0; i < solv->job.count; i += 2)
3267 Id how = solv->job.elements[i];
3268 if ((how & (SOLVER_JOBMASK | SOLVER_FORCEBEST)) == (SOLVER_INSTALL | SOLVER_FORCEBEST))
3272 for (j = 0; j < solv->ruletojob.count; j++)
3274 if (solv->ruletojob.elements[j] != i)
3276 r = solv->rules + solv->jobrules + j;
3279 FOR_RULELITERALS(p2, pp2, r)
3284 queue_push(&q2, p2);
3287 continue; /* orphaned */
3288 /* select best packages, just look at prio and version */
3290 policy_filter_unwanted(solv, &q, POLICY_MODE_RECOMMEND);
3291 if (q.count == oldcnt)
3292 continue; /* nothing filtered */
3294 queue_insertn(&q, 0, q2.count, q2.elements);
3295 p2 = queue_shift(&q);
3297 solver_addrule(solv, p2, q.count ? q.elements[0] : 0, 0);
3299 solver_addrule(solv, p2, 0, pool_queuetowhatprovides(pool, &q));
3300 if ((how & SOLVER_WEAK) != 0)
3301 queue_push(&solv->weakruleq, solv->nrules - 1);
3302 queue_push(&r2pkg, -(solv->jobrules + j));
3307 solv->bestrules_up = solv->nrules;
3309 if (installed && (solv->bestupdatemap_all || solv->bestupdatemap.size))
3313 if (solv->allowuninstall || solv->allowuninstall_all || solv->allowuninstallmap.size)
3314 map_init(&m, pool->nsolvables);
3317 FOR_REPO_SOLVABLES(installed, p, s)
3320 if (!solv->updatemap_all && (!solv->updatemap.size || !MAPTST(&solv->updatemap, p - installed->start)))
3322 if (!solv->bestupdatemap_all && (!solv->bestupdatemap.size || !MAPTST(&solv->bestupdatemap, p - installed->start)))
3325 if (solv->bestobeypolicy)
3326 r = solv->rules + solv->updaterules + (p - installed->start);
3329 r = solv->rules + solv->featurerules + (p - installed->start);
3330 if (!r->p) /* identical to update rule? */
3331 r = solv->rules + solv->updaterules + (p - installed->start);
3333 if (solv->specialupdaters && (d = solv->specialupdaters[p - installed->start]) != 0 && r == solv->rules + solv->updaterules + (p - installed->start))
3335 /* need to check specialupdaters */
3336 if (r->p == p) /* be careful with the dup case */
3338 while ((p2 = pool->whatprovidesdata[d++]) != 0)
3343 FOR_RULELITERALS(p2, pp2, r)
3347 if (solv->update_targets && solv->update_targets->elements[p - installed->start])
3348 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[p - installed->start], &q);
3349 if (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
3350 prune_to_dup_packages(solv, p, &q);
3351 /* select best packages, just look at prio and version */
3352 policy_filter_unwanted(solv, &q, POLICY_MODE_RECOMMEND);
3354 continue; /* orphaned */
3355 if (solv->bestobeypolicy)
3357 /* also filter the best of the feature rule packages and add them */
3358 r = solv->rules + solv->featurerules + (p - installed->start);
3363 FOR_RULELITERALS(p2, pp2, r)
3365 queue_push(&q2, p2);
3366 if (solv->update_targets && solv->update_targets->elements[p - installed->start])
3367 prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[p - installed->start], &q2);
3368 if (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
3369 prune_to_dup_packages(solv, p, &q2);
3370 policy_filter_unwanted(solv, &q2, POLICY_MODE_RECOMMEND);
3371 for (j = 0; j < q2.count; j++)
3372 queue_pushunique(&q, q2.elements[j]);
3375 if (solv->allowuninstall || solv->allowuninstall_all || (solv->allowuninstallmap.size && MAPTST(&solv->allowuninstallmap, p - installed->start)))
3377 /* package is flagged both for allowuninstall and best, add negative rules */
3378 d = q.count == 1 ? q.elements[0] : -pool_queuetowhatprovides(pool, &q);
3379 for (i = 0; i < q.count; i++)
3380 MAPSET(&m, q.elements[i]);
3381 r = solv->rules + solv->featurerules + (p - installed->start);
3382 if (!r->p) /* identical to update rule? */
3383 r = solv->rules + solv->updaterules + (p - installed->start);
3384 FOR_RULELITERALS(p2, pp2, r)
3389 solver_addrule(solv, -p2, d, 0);
3391 solver_addrule(solv, -p2, 0, -d);
3392 queue_push(&r2pkg, p);
3394 for (i = 0; i < q.count; i++)
3395 MAPCLR(&m, q.elements[i]);
3398 p2 = queue_shift(&q);
3400 solver_addrule(solv, p2, q.count ? q.elements[0] : 0, 0);
3402 solver_addrule(solv, p2, 0, pool_queuetowhatprovides(pool, &q));
3403 queue_push(&r2pkg, p);
3408 solv->bestrules_pkg = solv_memdup2(r2pkg.elements, r2pkg.count, sizeof(Id));
3409 solv->bestrules_end = solv->nrules;
3418 /* yumobs rule handling */
3419 /* note that we use pool->obsoleteusescolors || pool->implicitobsoleteusescolors
3420 * like in policy_findupdatepackages */
3423 find_obsolete_group(Solver *solv, Id obs, Queue *q)
3425 Pool *pool = solv->pool;
3427 Id p2, pp2, op, *opp, opp2;
3428 int i, j, qnc, ncnt;
3431 FOR_PROVIDES(p2, pp2, obs)
3433 Solvable *s2 = pool->solvables + p2;
3434 if (s2->repo != pool->installed)
3436 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
3438 /* we obsolete installed package s2 with obs. now find all other packages that have the same dep */
3439 for (opp = solv->obsoletes_data + solv->obsoletes[p2 - solv->installed->start]; (op = *opp++) != 0;)
3441 Solvable *os = pool->solvables + op;
3445 if ((pool->obsoleteusescolors || pool->implicitobsoleteusescolors) && !pool_colormatch(pool, s2, os))
3447 obsp2 = os->repo->idarraydata + os->obsoletes;
3448 while ((obs2 = *obsp2++) != 0)
3452 queue_pushunique(q, op);
3454 /* also search packages with the same name */
3455 FOR_PROVIDES(op, opp2, s2->name)
3457 Solvable *os = pool->solvables + op;
3459 if (os->name != s2->name)
3463 if ((pool->obsoleteusescolors || pool->implicitobsoleteusescolors) && !pool_colormatch(pool, s2, os))
3465 obsp2 = os->repo->idarraydata + os->obsoletes;
3466 while ((obs2 = *obsp2++) != 0)
3470 queue_pushunique(q, op);
3473 /* find names so that we can build groups */
3474 queue_init_clone(&qn, q);
3475 prune_to_best_version(solv->pool, &qn);
3478 for (i = 0; i < qn.count; i++)
3479 printf(" + %s\n", pool_solvid2str(pool, qn.elements[i]));
3482 /* filter into name groups */
3491 for (i = 0; i < qnc; i++)
3493 Id n = pool->solvables[qn.elements[i]].name;
3495 for (j = 0; j < q->count; j++)
3497 Id p = q->elements[j];
3498 if (pool->solvables[p].name == n)
3517 queue_insertn(q, 0, qn.count - qnc, qn.elements + qnc);
3523 solver_addyumobsrules(Solver *solv)
3525 Pool *pool = solv->pool;
3526 Repo *installed = solv->installed;
3529 Queue qo, qq, yumobsinfoq;
3533 solv->yumobsrules = solv->nrules;
3534 if (!installed || !solv->obsoletes)
3536 solv->yumobsrules_end = solv->nrules;
3539 now = solv_timems(0);
3541 FOR_REPO_SOLVABLES(installed, p, s)
3543 if (!solv->obsoletes[p - installed->start])
3546 printf("checking yumobs for %s\n", pool_solvable2str(pool, s));
3548 for (opp = solv->obsoletes_data + solv->obsoletes[p - installed->start]; (op = *opp++) != 0;)
3550 Solvable *os = pool->solvables + op;
3551 Id obs, *obsp = os->repo->idarraydata + os->obsoletes;
3553 while ((obs = *obsp++) != 0)
3555 FOR_PROVIDES(p2, pp2, obs)
3557 Solvable *s2 = pool->solvables + p2;
3558 if (s2->repo != installed)
3560 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
3562 if ((pool->obsoleteusescolors || pool->implicitobsoleteusescolors) && !pool_colormatch(pool, s, s2))
3564 queue_pushunique(&qo, obs);
3575 queue_init(&yumobsinfoq);
3577 for (i = 0; i < qo.count; i++)
3579 int group, groupk, groupstart;
3582 printf("investigating %s\n", pool_dep2str(pool, qo.elements[i]));
3584 find_obsolete_group(solv, qo.elements[i], &qq);
3586 printf("result:\n");
3587 for (j = 0; j < qq.count; j++)
3588 if (qq.elements[j] == 0)
3591 printf("%s\n", pool_solvid2str(pool, qq.elements[j]));
3596 /* at least two goups, build rules */
3598 for (j = 0; j < qq.count; j++)
3606 if (pool->solvables[p].repo == installed)
3610 for (k = 0; k < qq.count; k++)
3612 Id pk = qq.elements[k];
3615 if (group != groupk && k > groupstart)
3618 if (k - groupstart == 1)
3619 solver_addrule(solv, -p, qq.elements[groupstart], 0);
3621 solver_addrule(solv, -p, 0, pool_ids2whatprovides(pool, qq.elements + groupstart, k - groupstart));
3622 queue_push(&yumobsinfoq, qo.elements[i]);
3629 if (yumobsinfoq.count)
3630 solv->yumobsrules_info = solv_memdup2(yumobsinfoq.elements, yumobsinfoq.count, sizeof(Id));
3631 queue_free(&yumobsinfoq);
3634 solv->yumobsrules_end = solv->nrules;
3635 POOL_DEBUG(SOLV_DEBUG_STATS, "yumobs rule creation took %d ms\n", solv_timems(now));
3639 solver_breakorphans(Solver *solv)
3641 Pool *pool = solv->pool;
3642 Repo *installed = solv->installed;
3646 if (!installed || solv->droporphanedmap_all)
3648 solv->brokenorphanrules = solv_calloc(1, sizeof(Queue));
3649 queue_init(solv->brokenorphanrules);
3650 map_init(&m, installed->end - installed->start);
3651 for (i = 0; i < solv->orphaned.count; i++)
3653 Id p = solv->orphaned.elements[i];
3654 if (pool->solvables[p].repo != installed)
3656 if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - installed->start))
3658 MAPSET(&m, p - installed->start);
3660 for (rid = 1; rid < solv->pkgrules_end ; rid++)
3663 Rule *r = solv->rules + rid;
3664 /* ignore non-deps and simple conflicts */
3665 if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 < 0))
3668 if (p < installed->start || p >= installed->end || !MAPTST(&m, p - installed->start))
3670 /* need to check other literals */
3671 if (r->d == 0 || r->d == -1)
3673 for (dp = pool->whatprovidesdata + (r->d < 0 ? -r->d - 1 : r->d); *dp < 0; dp++)
3676 if (p >= installed->start && p < installed->end && MAPTST(&m, p - installed->start))
3682 /* ok, disable this rule */
3683 queue_push(solv->brokenorphanrules, rid);
3685 solver_disablerule(solv, r);
3688 if (!solv->brokenorphanrules->count)
3690 queue_free(solv->brokenorphanrules);
3691 solv->brokenorphanrules = solv_free(solv->brokenorphanrules);
3696 solver_check_brokenorphanrules(Solver *solv, Queue *dq)
3698 Pool *pool = solv->pool;
3703 if (!solv->brokenorphanrules)
3705 for (i = 0; i < solv->brokenorphanrules->count; i++)
3707 int rid = solv->brokenorphanrules->elements[i];
3708 Rule *r = solv->rules + rid;
3709 FOR_RULELITERALS(l, pp, r)
3713 if (solv->decisionmap[-l] <= 0)
3718 if (solv->decisionmap[l] > 0 && pool->solvables[l].repo != solv->installed)
3724 FOR_RULELITERALS(l, pp, r)
3725 if (l > 0 && solv->decisionmap[l] == 0 && pool->solvables[l].repo != solv->installed)
3726 queue_pushunique(dq, l);