#include "policy.h"
#include "solverdebug.h"
#include "linkedpkg.h"
+#include "cplxdeps.h"
#define RULES_BLOCK 63
{
Reldep *rd = GETRELDEP(pool, dep);
if (rd->flags >= 8)
- {
- if (rd->flags == REL_AND)
+ {
+ if (rd->flags == REL_AND || rd->flags == REL_COND)
{
if (!dep_possible(solv, rd->name, m))
return 0;
return dep_possible(solv, rd->evr, m);
}
+ if (rd->flags == REL_OR)
+ {
+ if (dep_possible(solv, rd->name, m))
+ return 1;
+ return dep_possible(solv, rd->evr, m);
+ }
if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
return solver_splitprovides(solv, rd->evr);
if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
return 0;
}
+static inline int
+is_otherproviders_dep(Pool *pool, Id dep)
+{
+ if (ISRELDEP(dep))
+ {
+ Reldep *rd = GETRELDEP(pool, dep);
+ if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
+ return 1;
+ }
+ return 0;
+}
+
/********************************************************************
*
* Rule handling
* Install: p > 0, d = 0 (A) user requested install
* Remove: p < 0, d = 0 (-A) user requested remove (also: uninstallable)
* Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
+ * Requires: p > 0, d < 0 (B|-A) hack to save a whatprovides allocation, gets converted into (-A|B)
* Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
* Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
* also used for obsoletes
- * ?: p > 0, d < 0 (A|-B)
- * No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
+ * No-op ?: p = 0, d = 0 (null) (used as placeholder in update/feature rules)
*
* resulting watches:
* ------------------
* Direct assertion (no watch needed) --> d = 0, w1 = p, w2 = 0
* Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
* every other : w1 = p, w2 = whatprovidesdata[d];
- * Disabled rule: w1 = 0
*
* always returns a rule for non-rpm rules
*/
int n = 0; /* number of literals in rule - 1
0 = direct assertion (single literal)
1 = binary rule
- >1 =
+ >1 = multi-literal rule
*/
/* it often happenes that requires lead to adding the same rpm rule
return r;
}
- /*
- * compute number of literals (n) in rule
- */
-
+ /* compute number of literals (n) in rule */
if (d < 0)
{
- /* always a binary rule */
+ if (p == -d)
+ return 0; /* rule is self-fulfilling */
if (p == d)
- return 0; /* ignore self conflict */
- n = 1;
+ d = 0; /* normalize to assertion */
+ else
+ n = 1; /* binary rule */
}
else if (d > 0)
{
for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
if (*dp == -p)
return 0; /* rule is self-fulfilling */
-
if (n == 1) /* convert to binary rule */
d = dp[-1];
}
if (n == 1 && p > d && !solv->rpmrules_end)
{
- /* smallest literal first so we can find dups */
+ /* put smallest literal first so we can find dups */
n = p; p = d; d = n; /* p <-> d */
n = 1; /* re-set n, was used as temp var */
}
/*
- * check for duplicate
+ * check for duplicate (r is only set if we're adding rpm rules)
*/
-
- /* check if the last added rule (r) is exactly the same as what we're looking for. */
- if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
- return r; /* binary rule */
-
- /* have n-ary rule with same first literal, check other literals */
- if (r && n > 1 && r->d && r->p == p)
+ if (r)
{
- /* Rule where d is an offset in whatprovidesdata */
- Id *dp2;
- if (d == r->d)
- return r;
- dp2 = pool->whatprovidesdata + r->d;
- for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
- if (*dp != *dp2)
- break;
- if (*dp == *dp2)
+ /* check if the last added rule (r) is exactly the same as what we're looking for. */
+ if (n == 1 && !r->d && r->p == p && r->w2 == d)
return r;
- }
+ /* have n-ary rule with same first literal, check other literals */
+ if (n > 1 && r->d && r->p == p)
+ {
+ /* Rule where d is an offset in whatprovidesdata */
+ Id *dp2;
+ if (d == r->d)
+ return r;
+ dp2 = pool->whatprovidesdata + r->d;
+ for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
+ if (*dp != *dp2)
+ break;
+ if (*dp == *dp2)
+ return r;
+ }
+ }
/*
- * allocate new rule
+ * allocate new rule r
*/
-
- /* extend rule buffer */
solv->rules = solv_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
r = solv->rules + solv->nrules++; /* point to rule space */
- /*
- * r = new rule
- */
-
r->p = p;
if (n == 0)
{
solv->instbuddy = solv_calloc(installed->end - installed->start, sizeof(Id));
if (qr->count == 1)
solv->instbuddy[s - pool->solvables - installed->start] = qr->elements[0];
- for (i = 0; i < qp->count; i++)
+ for (i = 0; i < qr->count; i++)
{
- Id p = qp->elements[i];
+ Id p = qr->elements[i];
if (pool->solvables[p].repo != installed)
continue; /* huh? */
if (qp->count > 1 || (solv->instbuddy[p - installed->start] != 0 && solv->instbuddy[p - installed->start] != s - pool->solvables))
#endif
+#ifdef ENABLE_COMPLEX_DEPS
+
+static void
+add_complex_deprules(Solver *solv, Id p, Id dep, int type, int dontfix, Queue *workq, Map *m)
+{
+ Pool *pool = solv->pool;
+ Repo *installed = solv->installed;
+ int i, j;
+ Queue bq;
+
+ queue_init(&bq);
+
+ /* CNF expansion for requires, DNF + INVERT expansion for conflicts */
+ i = pool_normalize_complex_dep(pool, dep, &bq, type == SOLVER_RULE_RPM_PACKAGE_REQUIRES ? 0 : (CPLXDEPS_TODNF | CPLXDEPS_EXPAND | CPLXDEPS_INVERT));
+ /* handle special cases */
+ if (i == 0)
+ {
+ if (dontfix)
+ {
+ POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "ignoring broken dependency %s of installed package %s\n", pool_dep2str(pool, dep), pool_solvid2str(pool, p));
+ }
+ else
+ {
+ POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", pool_solvid2str(pool, p), p, pool_dep2str(pool, dep));
+ addrpmrule(solv, -p, 0, type == SOLVER_RULE_RPM_PACKAGE_REQUIRES ? SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP : type, dep);
+ }
+ queue_free(&bq);
+ return;
+ }
+ if (i == 1)
+ {
+ queue_free(&bq);
+ return;
+ }
+
+ /* go through all blocks and add a rule for each block */
+ for (i = 0; i < bq.count; i++)
+ {
+ if (!bq.elements[i])
+ continue; /* huh? */
+ if (bq.elements[i] == pool->nsolvables)
+ {
+ /* conventional requires (cannot be a conflicts as they have been expanded) */
+ Id *dp = pool->whatprovidesdata + bq.elements[i + 1];
+ i += 2;
+ if (dontfix)
+ {
+ for (j = 0; dp[j] != 0; j++)
+ if (pool->solvables[dp[j]].repo == installed)
+ break; /* provider was installed */
+ if (!dp[j])
+ {
+ POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", pool_dep2str(pool, dep), pool_solvid2str(pool, p));
+ continue;
+ }
+ }
+ if (!*dp)
+ {
+ /* nothing provides req! */
+ POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", pool_solvid2str(pool, p), p, pool_dep2str(pool, dep));
+ addrpmrule(solv, -p, 0, SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP, dep);
+ continue;
+ }
+ addrpmrule(solv, -p, dp - pool->whatprovidesdata, SOLVER_RULE_RPM_PACKAGE_REQUIRES, dep);
+ /* push all non-visited providers on the work queue */
+ if (m)
+ for (; *dp; dp++)
+ if (!MAPTST(m, *dp))
+ queue_push(workq, *dp);
+ continue;
+ }
+ if (!bq.elements[i + 1])
+ {
+ Id p2 = bq.elements[i];
+ /* simple rule with just two literals */
+ if (dontfix && p2 < 0 && pool->solvables[-p2].repo == installed)
+ continue;
+ if (dontfix && p2 > 0 && pool->solvables[p2].repo != installed)
+ continue;
+ if (p == p2)
+ continue;
+ if (-p == p2)
+ {
+ if (type == SOLVER_RULE_RPM_PACKAGE_CONFLICT)
+ {
+ if (pool->forbidselfconflicts && !is_otherproviders_dep(pool, dep))
+ addrpmrule(solv, -p, 0, SOLVER_RULE_RPM_SELF_CONFLICT, dep);
+ continue;
+ }
+ addrpmrule(solv, -p, 0, type, dep);
+ continue;
+ }
+ if (p2 > 0)
+ addrpmrule(solv, p2, -p, type, dep); /* hack so that we don't need pool_queuetowhatprovides */
+ else
+ addrpmrule(solv, -p, p2, type, dep);
+ if (m && p2 > 0 && !MAPTST(m, p2))
+ queue_push(workq, p2);
+ }
+ else
+ {
+ Id *qele;
+ int qcnt;
+
+ qele = bq.elements + i;
+ qcnt = i;
+ while (bq.elements[i])
+ i++;
+ qcnt = i - qcnt;
+ if (dontfix)
+ {
+ for (j = 0; j < qcnt; j++)
+ {
+ if (qele[j] > 0 && pool->solvables[qele[j]].repo == installed)
+ break;
+ if (qele[j] < 0 && pool->solvables[-qele[j]].repo != installed)
+ break;
+ }
+ if (j == qcnt)
+ continue;
+ }
+ /* add -p to (ordered) rule (overwriting the trailing zero) */
+ for (j = 0; ; j++)
+ {
+ if (j == qcnt || qele[j] > -p)
+ {
+ if (j < qcnt)
+ memmove(qele + j + 1, qele + j, (qcnt - j) * sizeof(Id));
+ qele[j] = -p;
+ qcnt++;
+ break;
+ }
+ if (qele[j] == -p)
+ break;
+ }
+ /* check if the rule contains both p and -p */
+ for (j = 0; j < qcnt; j++)
+ if (qele[j] == p)
+ break;
+ if (j == qcnt)
+ {
+ /* hack: create fake queue 'q' so that we can call pool_queuetowhatprovides */
+ Queue q;
+ memset(&q, 0, sizeof(q));
+ q.count = qcnt - 1;
+ q.elements = qele + 1;
+ addrpmrule(solv, qele[0], pool_queuetowhatprovides(pool, &q), type, dep);
+ if (m)
+ for (j = 0; j < qcnt; j++)
+ if (qele[j] > 0 && !MAPTST(m, qele[j]))
+ queue_push(workq, qele[j]);
+ }
+ }
+ }
+ queue_free(&bq);
+}
+
+#endif
+
/*-------------------------------------------------------------------
*
* add (install) rules for solvable
Pool *pool = solv->pool;
Repo *installed = solv->installed;
- /* 'work' queue. keeps Ids of solvables we still have to work on.
- And buffer for it. */
- Queue workq;
+ Queue workq; /* list of solvables we still have to work on */
Id workqbuf[64];
int i;
- /* if to add rules for broken deps ('rpm -V' functionality)
- * 0 = yes, 1 = no
- */
- int dontfix;
- /* Id var and pointer for each dependency
- * (not used in parallel)
- */
+ int dontfix; /* ignore dependency errors for installed solvables */
Id req, *reqp;
Id con, *conp;
Id obs, *obsp;
MAPSET(m, n); /* mark as visited */
}
- s = pool->solvables + n; /* s = Solvable in question */
+ s = pool->solvables + n;
dontfix = 0;
if (installed /* Installed system available */
? pool_disabled_solvable(pool, s)
: !pool_installable(pool, s))
{
- POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", pool_solvable2str(pool, s), (Id)(s - pool->solvables));
+ POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", pool_solvid2str(pool, n), n);
addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOT_INSTALLABLE, 0);
}
}
if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
continue;
+#ifdef ENABLE_COMPLEX_DEPS
+ if (pool_is_complex_dep(pool, req))
+ {
+ /* we have AND/COND deps, normalize */
+ add_complex_deprules(solv, n, req, SOLVER_RULE_RPM_PACKAGE_REQUIRES, dontfix, &workq, m);
+ continue;
+ }
+#endif
+
/* find list of solvables providing 'req' */
dp = pool_whatprovides_ptr(pool, req);
* that are already broken. so if we find one provider
* that was already installed, we know that the
* dependency was not broken before so we enforce it */
-
- /* check if any of the providers for 'req' is installed */
for (i = 0; (p = dp[i]) != 0; i++)
- {
- if (pool->solvables[p].repo == installed)
- break; /* provider was installed */
- }
- /* didn't find an installed provider: previously broken dependency */
+ if (pool->solvables[p].repo == installed)
+ break; /* found installed provider */
if (!p)
{
+ /* didn't find an installed provider: previously broken dependency */
POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", pool_dep2str(pool, req), pool_solvable2str(pool, s));
continue;
}
if (!*dp)
{
- /* nothing provides req! */
- POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", pool_solvable2str(pool, s), (Id)(s - pool->solvables), pool_dep2str(pool, req));
+ POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", pool_solvid2str(pool, n), n, pool_dep2str(pool, req));
addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP, req);
continue;
}
/* rule: (-requestor|provider1|provider2|...|providerN) */
addrpmrule(solv, -n, dp - pool->whatprovidesdata, SOLVER_RULE_RPM_PACKAGE_REQUIRES, req);
- /* descend the dependency tree
- push all non-visited providers on the work queue */
+ /* push all non-visited providers on the work queue */
if (m)
- {
- for (; *dp; dp++)
- {
- if (!MAPTST(m, *dp))
- queue_push(&workq, *dp);
- }
- }
-
- } /* while, requirements of n */
-
- } /* if, requirements */
+ for (; *dp; dp++)
+ if (!MAPTST(m, *dp))
+ queue_push(&workq, *dp);
+ }
+ }
/* that's all we check for src packages */
if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
/* foreach conflicts of 's' */
while ((con = *conp++) != 0)
{
+#ifdef ENABLE_COMPLEX_DEPS
+ if (!ispatch && pool_is_complex_dep(pool, con))
+ {
+ /* we have AND/COND deps, normalize */
+ add_complex_deprules(solv, n, con, SOLVER_RULE_RPM_PACKAGE_CONFLICT, dontfix, &workq, m);
+ continue;
+ }
+#endif
/* foreach providers of a conflict of 's' */
FOR_PROVIDES(p, pp, con)
{
/* dontfix: dont care about conflicts with already installed packs */
if (dontfix && pool->solvables[p].repo == installed)
continue;
- /* p == n: self conflict */
- if (p == n && pool->forbidselfconflicts)
+ if (p == n) /* p == n: self conflict */
{
- if (ISRELDEP(con))
- {
- Reldep *rd = GETRELDEP(pool, con);
- if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
- continue;
- }
- p = 0; /* make it a negative assertion, aka 'uninstallable' */
+ if (!pool->forbidselfconflicts || is_otherproviders_dep(pool, con))
+ continue;
+ addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_SELF_CONFLICT, con);
+ continue;
}
- if (p && ispatch && solv->multiversion.size && MAPTST(&solv->multiversion, p) && ISRELDEP(con))
+ if (ispatch && solv->multiversion.size && MAPTST(&solv->multiversion, p) && ISRELDEP(con))
{
/* our patch conflicts with a multiversion package */
p = -makemultiversionconflict(solv, p, con);
}
- /* rule: -n|-p: either solvable _or_ provider of conflict */
- addrpmrule(solv, -n, -p, p ? SOLVER_RULE_RPM_PACKAGE_CONFLICT : SOLVER_RULE_RPM_SELF_CONFLICT, con);
+ /* rule: -n|-p: either solvable _or_ provider of conflict */
+ addrpmrule(solv, -n, p == SYSTEMSOLVABLE ? 0 : -p, SOLVER_RULE_RPM_PACKAGE_CONFLICT, con);
}
}
}
}
}
+ if (m && pool->implicitobsoleteusescolors && (s->arch > pool->lastarch || pool->id2arch[s->arch] != 1))
+ {
+ int a = pool->id2arch[s->arch];
+ /* check lock-step candidates */
+ FOR_PROVIDES(p, pp, s->name)
+ {
+ Solvable *ps = pool->solvables + p;
+ if (s->name != ps->name || s->evr != ps->evr || MAPTST(m, p))
+ continue;
+ if (ps->arch > pool->lastarch || pool->id2arch[ps->arch] == 1 || pool->id2arch[ps->arch] >= a)
+ continue;
+ queue_push(&workq, p);
+ }
+ }
+
/*-----------------------------------------
* add recommends to the work queue
*/
if (solv->dupmap_all)
p = finddistupgradepackages(solv, s, &qs, allow_all);
else
- policy_findupdatepackages(solv, s, &qs, allow_all);
- if (!allow_all && !solv->dupmap_all && solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
- addduppackages(solv, s, &qs);
+ {
+ policy_findupdatepackages(solv, s, &qs, allow_all);
+ if (!allow_all && solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
+ addduppackages(solv, s, &qs);
+ }
+
+#ifdef ENABLE_LINKED_PKGS
+ if (solv->instbuddy && solv->instbuddy[s - pool->solvables - solv->installed->start])
+ {
+ const char *name = pool_id2str(pool, s->name);
+ if (strncmp(name, "pattern:", 8) == 0 || strncmp(name, "application:", 12) == 0)
+ {
+ /* a linked pseudo package. As it is linked, we do not need an update rule */
+ /* nevertheless we set specialupdaters so we can update */
+ solver_addrule(solv, 0, 0);
+ if (!allow_all && qs.count)
+ {
+ if (p != -SYSTEMSOLVABLE)
+ queue_unshift(&qs, p);
+ if (!solv->specialupdaters)
+ solv->specialupdaters = solv_calloc(solv->installed->end - solv->installed->start, sizeof(Id));
+ solv->specialupdaters[s - pool->solvables - solv->installed->start] = pool_queuetowhatprovides(pool, &qs);
+ }
+ queue_free(&qs);
+ return;
+ }
+ }
+#endif
+
+ if (!allow_all && !p && solv->dupmap_all)
+ {
+ queue_push(&solv->orphaned, s - pool->solvables); /* an orphaned package */
+ if (solv->keep_orphans && !(solv->droporphanedmap_all || (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, s - pool->solvables - solv->installed->start))))
+ p = s - pool->solvables; /* keep this orphaned package installed */
+ }
if (!allow_all && qs.count && solv->multiversion.size)
{
int i, j;
- d = pool_queuetowhatprovides(pool, &qs);
- /* filter out all multiversion packages as they don't update */
- for (i = j = 0; i < qs.count; i++)
+ for (i = 0; i < qs.count; i++)
+ if (MAPTST(&solv->multiversion, qs.elements[i]))
+ break;
+ if (i < qs.count)
{
- if (MAPTST(&solv->multiversion, qs.elements[i]))
- {
- Solvable *ps = pool->solvables + qs.elements[i];
- /* if keepexplicitobsoletes is set and the name is different,
- * we assume that there is an obsoletes. XXX: not 100% correct */
- if (solv->keepexplicitobsoletes && ps->name != s->name)
+ /* filter out all multiversion packages as they don't update */
+ d = pool_queuetowhatprovides(pool, &qs);
+ for (j = i; i < qs.count; i++)
+ {
+ if (MAPTST(&solv->multiversion, qs.elements[i]))
{
- qs.elements[j++] = qs.elements[i];
- continue;
+ Solvable *ps = pool->solvables + qs.elements[i];
+ /* if keepexplicitobsoletes is set and the name is different,
+ * we assume that there is an obsoletes. XXX: not 100% correct */
+ if (solv->keepexplicitobsoletes && ps->name != s->name)
+ {
+ qs.elements[j++] = qs.elements[i];
+ continue;
+ }
+ /* it's ok if they have same nevra */
+ if (ps->name != s->name || ps->evr != s->evr || ps->arch != s->arch)
+ continue;
}
- /* it's ok if they have same nevra */
- if (ps->name != s->name || ps->evr != s->evr || ps->arch != s->arch)
- continue;
+ qs.elements[j++] = qs.elements[i];
}
- qs.elements[j++] = qs.elements[i];
- }
- if (j < qs.count)
- {
- if (d && solv->installed && s->repo == solv->installed &&
- (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, s - pool->solvables - solv->installed->start))))
+ if (j < qs.count)
{
- if (!solv->multiversionupdaters)
- solv->multiversionupdaters = solv_calloc(solv->installed->end - solv->installed->start, sizeof(Id));
- solv->multiversionupdaters[s - pool->solvables - solv->installed->start] = d;
+ if (d && solv->installed && s->repo == solv->installed &&
+ (solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, s - pool->solvables - solv->installed->start))))
+ {
+ if (!solv->specialupdaters)
+ solv->specialupdaters = solv_calloc(solv->installed->end - solv->installed->start, sizeof(Id));
+ solv->specialupdaters[s - pool->solvables - solv->installed->start] = d;
+ }
+ if (j == 0 && p == -SYSTEMSOLVABLE && solv->dupmap_all)
+ {
+ queue_push(&solv->orphaned, s - pool->solvables); /* also treat as orphaned */
+ j = qs.count;
+ }
+ qs.count = j;
}
- if (j == 0 && p == -SYSTEMSOLVABLE && solv->dupmap_all)
+ else if (p != -SYSTEMSOLVABLE)
{
- queue_push(&solv->orphaned, s - pool->solvables); /* treat as orphaned */
- j = qs.count;
+ /* could fallthrough, but then we would do pool_queuetowhatprovides twice */
+ queue_free(&qs);
+ solver_addrule(solv, p, d); /* allow update of s */
+ return;
}
- qs.count = j;
- }
- else if (p != -SYSTEMSOLVABLE)
- {
- /* could fallthrough, but then we would do pool_queuetowhatprovides twice */
- queue_free(&qs);
- solver_addrule(solv, p, d); /* allow update of s */
- return;
}
}
if (qs.count && p == -SYSTEMSOLVABLE)
solver_addinfarchrules(Solver *solv, Map *addedmap)
{
Pool *pool = solv->pool;
+ Repo *installed = pool->installed;
int first, i, j;
Id p, pp, a, aa, bestarch;
Solvable *s, *ps, *bests;
Queue badq, allowedarchs;
+ Queue lsq;
queue_init(&badq);
queue_init(&allowedarchs);
+ queue_init(&lsq);
solv->infarchrules = solv->nrules;
for (i = 1; i < pool->nsolvables; i++)
{
break;
a = ps->arch;
a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
- if (a != 1 && pool->installed && ps->repo == pool->installed)
+ if (a != 1 && installed && ps->repo == installed)
{
if (!solv->dupmap_all && !(solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
queue_pushunique(&allowedarchs, ps->arch); /* also ok to keep this architecture */
}
if (first)
continue;
+
/* speed up common case where installed package already has best arch */
if (allowedarchs.count == 1 && bests && allowedarchs.elements[0] == bests->arch)
allowedarchs.count--; /* installed arch is best */
+
+ if (allowedarchs.count && pool->implicitobsoleteusescolors && installed && bestarch)
+ {
+ /* need an extra pass for lockstep checking: we only allow to keep an inferior arch
+ * if the corresponding installed package is not lock-stepped */
+ queue_empty(&allowedarchs);
+ FOR_PROVIDES(p, pp, s->name)
+ {
+ Id p2, pp2;
+ ps = pool->solvables + p;
+ if (ps->name != s->name || ps->repo != installed || !MAPTST(addedmap, p))
+ continue;
+ if (solv->dupmap_all || (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p)))
+ continue;
+ a = ps->arch;
+ a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
+ if (!a)
+ {
+ queue_pushunique(&allowedarchs, ps->arch); /* strange arch, allow */
+ continue;
+ }
+ if (a == 1 || ((a ^ bestarch) & 0xffff0000) == 0)
+ continue;
+ /* have installed package with inferior arch, check if lock-stepped */
+ FOR_PROVIDES(p2, pp2, s->name)
+ {
+ Solvable *s2 = pool->solvables + p2;
+ Id a2;
+ if (p2 == p || s2->name != s->name || s2->evr != pool->solvables[p].evr || s2->arch == pool->solvables[p].arch)
+ continue;
+ a2 = s2->arch;
+ a2 = (a2 <= pool->lastarch) ? pool->id2arch[a2] : 0;
+ if (a2 && (a2 == 1 || ((a2 ^ bestarch) & 0xffff0000) == 0))
+ break;
+ }
+ if (!p2)
+ queue_pushunique(&allowedarchs, ps->arch);
+ }
+ }
+
+ /* find all bad packages */
queue_empty(&badq);
FOR_PROVIDES(p, pp, s->name)
{
a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
if (a != 1 && bestarch && ((a ^ bestarch) & 0xffff0000) != 0)
{
- if (pool->installed && ps->repo == pool->installed)
- continue; /* always ok to keep an installed package */
+ if (installed && ps->repo == installed)
+ {
+ if (pool->implicitobsoleteusescolors)
+ queue_push(&badq, p); /* special lock-step handling, see below */
+ continue; /* always ok to keep an installed package */
+ }
for (j = 0; j < allowedarchs.count; j++)
{
aa = allowedarchs.elements[j];
queue_push(&badq, p);
}
}
- if (!badq.count)
- continue;
+
/* block all solvables in the badq! */
for (j = 0; j < badq.count; j++)
{
p = badq.elements[j];
- solver_addrule(solv, -p, 0);
+ /* lock-step */
+ if (pool->implicitobsoleteusescolors)
+ {
+ Id p2;
+ int haveinstalled = 0;
+ queue_empty(&lsq);
+ FOR_PROVIDES(p2, pp, s->name)
+ {
+ Solvable *s2 = pool->solvables + p2;
+ if (p2 == p || s2->name != s->name || s2->evr != pool->solvables[p].evr || s2->arch == pool->solvables[p].arch)
+ continue;
+ a = s2->arch;
+ a = (a <= pool->lastarch) ? pool->id2arch[a] : 0;
+ if (a && (a == 1 || ((a ^ bestarch) & 0xffff000) == 0))
+ {
+ queue_push(&lsq, p2);
+ if (installed && s2->repo == installed)
+ haveinstalled = 1;
+ }
+ }
+ if (installed && pool->solvables[p].repo == installed && !haveinstalled)
+ continue; /* installed package not in lock-step */
+ }
+ solver_addrule(solv, -p, lsq.count ? pool_queuetowhatprovides(pool, &lsq) : 0);
}
}
+ queue_free(&lsq);
queue_free(&badq);
queue_free(&allowedarchs);
solv->infarchrules_end = solv->nrules;
if (pool->solvables[p].repo == installed)
{
queue_push2(q, DISABLE_UPDATE, p);
+#ifdef ENABLE_LINKED_PKGS
if (solv->instbuddy && solv->instbuddy[p - installed->start] > 1)
queue_push2(q, DISABLE_UPDATE, solv->instbuddy[p - installed->start]);
+#endif
}
return;
default:
w2 = pool->whatprovidesdata[d];
d = 0;
}
- if (p > 0 && d < 0) /* this hack is used for buddy deps */
+ if (p > 0 && d < 0) /* this hack is used for package links and complex deps */
{
w2 = p;
p = d;
if (p != op || w2 != ow2)
return;
}
+ /* should use a different type instead */
+ if (type == SOLVER_RULE_RPM_PACKAGE_CONFLICT && !w2)
+ w2 = -SYSTEMSOLVABLE;
}
/* yep, rule matches. record info */
queue_push(solv->ruleinfoq, type);
getrpmruleinfos(Solver *solv, Rule *r, Queue *rq)
{
Pool *pool = solv->pool;
-#ifdef ENABLE_LINKED_PKGS
- Id l, d;
-#endif
+ Id l, pp;
if (r->p >= 0)
return;
queue_push(rq, r - solv->rules); /* push the rule we're interested in */
solv->ruleinfoq = rq;
- solver_addrpmrulesforsolvable(solv, pool->solvables - r->p, 0);
- /* also try reverse direction for conflicts */
- if ((r->d == 0 || r->d == -1) && r->w2 < 0)
- solver_addrpmrulesforsolvable(solv, pool->solvables - r->w2, 0);
-#ifdef ENABLE_LINKED_PKGS
- /* check linked packages */
- d = 0;
- if ((r->d == 0 || r->d == -1))
- l = r->w2;
- else
+ FOR_RULELITERALS(l, pp, r)
{
- d = r->d < 0 ? -r->d - 1 : r->d;
- l = pool->whatprovidesdata[d++];
+ if (l >= 0)
+ break;
+ solver_addrpmrulesforsolvable(solv, pool->solvables - l, 0);
}
- for (; l; l = (d ? pool->whatprovidesdata[d++] : 0))
+#ifdef ENABLE_LINKED_PKGS
+ FOR_RULELITERALS(l, pp, r)
{
- if (l <= 0 || !strchr(pool_id2str(pool, pool->solvables[l].name), ':'))
+ if (l < 0)
+ {
+ if (l == r->p)
+ continue;
+ break;
+ }
+ if (!strchr(pool_id2str(pool, pool->solvables[l].name), ':') || !has_package_link(pool, pool->solvables + l))
break;
- if (has_package_link(pool, pool->solvables + l))
- add_package_link(solv, pool->solvables + l, 0, 0);
+ add_package_link(solv, pool->solvables + l, 0, 0);
}
#endif
solv->ruleinfoq = 0;
for (rid = 1; rid < solv->rpmrules_end ; rid++)
{
r = solv->rules + rid;
- if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 < 0))
+ if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 <= 0))
continue; /* only look at requires rules */
/* solver_printrule(solv, SOLV_DEBUG_RESULT, r); */
queue_empty(&q);
if (!r->p) /* identical to update rule? */
r = solv->rules + solv->updaterules + (p - installed->start);
}
- if (solv->multiversionupdaters && (d = solv->multiversionupdaters[p - installed->start]) != 0 && r == solv->rules + solv->updaterules + (p - installed->start))
+ if (solv->specialupdaters && (d = solv->specialupdaters[p - installed->start]) != 0 && r == solv->rules + solv->updaterules + (p - installed->start))
{
- /* need to check multiversionupdaters */
+ /* need to check specialupdaters */
if (r->p == p) /* be careful with the dup case */
queue_push(&q, p);
while ((p2 = pool->whatprovidesdata[d++]) != 0)
if (solv->update_targets && solv->update_targets->elements[p - installed->start])
prune_to_update_targets(solv, solv->update_targets->elements + solv->update_targets->elements[p - installed->start], &q2);
if (solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
- prune_to_dup_packages(solv, p, &q);
+ prune_to_dup_packages(solv, p, &q2);
policy_filter_unwanted(solv, &q2, POLICY_MODE_RECOMMEND);
for (j = 0; j < q2.count; j++)
queue_pushunique(&q, q2.elements[j]);
return 0;
}
+#ifdef ENABLE_COMPLEX_DEPS
+static void
+complex_cleandeps_remove(Pool *pool, Id ip, Id req, Map *im, Map *installedm, Queue *iq)
+{
+ int i;
+ Queue dq;
+ Id p;
+
+ queue_init(&dq);
+ i = pool_normalize_complex_dep(pool, req, &dq, CPLXDEPS_EXPAND);
+ if (i == 0 || i == 1)
+ {
+ queue_free(&dq);
+ return;
+ }
+ for (i = 0; i < dq.count; i++)
+ {
+ for (; (p = dq.elements[i]) != 0; i++)
+ {
+ if (p < 0)
+ {
+ if (!MAPTST(installedm, -p))
+ break;
+ continue;
+ }
+ if (p != SYSTEMSOLVABLE && MAPTST(im, p))
+ {
+#ifdef CLEANDEPSDEBUG
+ printf("%s requires/recommends %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
+#endif
+ queue_push(iq, p);
+ }
+ }
+ while (dq.elements[i])
+ i++;
+ }
+ queue_free(&dq);
+}
+
+static void
+complex_cleandeps_addback(Pool *pool, Id ip, Id req, Map *im, Map *installedm, Queue *iq, Map *userinstalled)
+{
+ int i, blk;
+ Queue dq;
+ Id p;
+
+ queue_init(&dq);
+ i = pool_normalize_complex_dep(pool, req, &dq, CPLXDEPS_EXPAND);
+ if (i == 0 || i == 1)
+ {
+ queue_free(&dq);
+ return;
+ }
+ for (i = 0; i < dq.count; i++)
+ {
+ blk = i;
+ for (; (p = dq.elements[i]) != 0; i++)
+ {
+ if (p < 0)
+ {
+ if (!MAPTST(installedm, -p))
+ break;
+ continue;
+ }
+ if (MAPTST(im, p))
+ break;
+ }
+ if (!p)
+ {
+ for (i = blk; (p = dq.elements[i]) != 0; i++)
+ {
+ if (p < 0)
+ continue;
+ if (!MAPTST(installedm, p))
+ continue;
+ if (p == ip || MAPTST(userinstalled, p - pool->installed->start))
+ continue;
+#ifdef CLEANDEPSDEBUG
+ printf("%s requires/recommends %s\n", pool_solvid2str(pool, ip), pool_solvid2str(pool, p));
+#endif
+ MAPSET(im, p);
+ queue_push(iq, p);
+ }
+ }
+ while (dq.elements[i])
+ i++;
+ }
+ queue_free(&dq);
+}
+
+#endif
/*
* Find all installed packages that are no longer
if (!strncmp("product:", pool_id2str(pool, s->name), 8))
{
MAPSET(&userinstalled, p - installed->start);
- if (pool->nscallback)
+#ifdef ENABLE_LINKED_PKGS
+ if (solv->instbuddy && solv->instbuddy[p - installed->start] > 1)
{
- Id buddy = pool->nscallback(pool, pool->nscallbackdata, NAMESPACE_PRODUCTBUDDY, p);
- if (buddy >= installed->start && buddy < installed->end && pool->solvables[buddy].repo == installed)
+ Id buddy = solv->instbuddy[p - installed->start];
+ if (buddy >= installed->start && buddy < installed->end)
MAPSET(&userinstalled, buddy - installed->start);
}
+#endif
}
}
}
{
if (req == SOLVABLE_PREREQMARKER)
continue;
-#if 0
- /* count number of installed packages that match */
- count = 0;
- FOR_PROVIDES(p, pp, req)
- if (MAPTST(&installedm, p))
- count++;
- if (count > 1)
- continue;
+#ifdef ENABLE_COMPLEX_DEPS
+ if (pool_is_complex_dep(pool, req))
+ {
+ complex_cleandeps_remove(pool, ip, req, &im, &installedm, &iq);
+ continue;
+ }
#endif
FOR_PROVIDES(p, pp, req)
{
reqp = s->repo->idarraydata + s->recommends;
while ((req = *reqp++) != 0)
{
-#if 0
- count = 0;
- FOR_PROVIDES(p, pp, req)
- if (MAPTST(&installedm, p))
- count++;
- if (count > 1)
- continue;
+#ifdef ENABLE_COMPLEX_DEPS
+ if (pool_is_complex_dep(pool, req))
+ {
+ complex_cleandeps_remove(pool, ip, req, &im, &installedm, &iq);
+ continue;
+ }
#endif
FOR_PROVIDES(p, pp, req)
{
reqp = s->repo->idarraydata + s->requires;
while ((req = *reqp++) != 0)
{
+#ifdef ENABLE_COMPLEX_DEPS
+ if (pool_is_complex_dep(pool, req))
+ {
+ complex_cleandeps_addback(pool, ip, req, &im, &installedm, &iq, &userinstalled);
+ continue;
+ }
+#endif
FOR_PROVIDES(p, pp, req)
if (MAPTST(&im, p))
break;
continue;
FOR_PROVIDES(p, pp, req)
{
- if (!MAPTST(&im, p) && MAPTST(&installedm, p))
+ if (MAPTST(&installedm, p))
{
if (p == ip)
continue;
reqp = s->repo->idarraydata + s->recommends;
while ((req = *reqp++) != 0)
{
+#ifdef ENABLE_COMPLEX_DEPS
+ if (pool_is_complex_dep(pool, req))
+ {
+ complex_cleandeps_addback(pool, ip, req, &im, &installedm, &iq, &userinstalled);
+ continue;
+ }
+#endif
FOR_PROVIDES(p, pp, req)
if (MAPTST(&im, p))
break;
continue;
FOR_PROVIDES(p, pp, req)
{
- if (!MAPTST(&im, p) && MAPTST(&installedm, p))
+ if (MAPTST(&installedm, p))
{
if (p == ip)
continue;
}
}
+#ifdef ENABLE_COMPLEX_DEPS
+static void
+complex_unneeded(Pool *pool, Id ip, Id req, Queue *edges, Map *cleandepsmap, Queue *unneededq)
+{
+ int i, j;
+ Queue dq;
+ Id p;
+
+ queue_init(&dq);
+ i = pool_normalize_complex_dep(pool, req, &dq, CPLXDEPS_EXPAND);
+ if (i == 0 || i == 1)
+ {
+ queue_free(&dq);
+ return;
+ }
+ for (i = 0; i < dq.count; i++)
+ {
+ for (; (p = dq.elements[i]) != 0; i++)
+ {
+ if (p < 0)
+ {
+ if (pool->solvables[-p].repo != pool->installed)
+ break;
+ continue;
+ }
+ if (p == ip || pool->solvables[p].repo != pool->installed || !MAPTST(cleandepsmap, p - pool->installed->start))
+ continue;
+ for (j = 0; j < unneededq->count; j++)
+ if (p == unneededq->elements[j])
+ {
+ if (edges->elements[edges->count - 1] != j + 1)
+ queue_push(edges, j + 1);
+ break;
+ }
+ }
+ while (dq.elements[i])
+ i++;
+ }
+ queue_free(&dq);
+}
+#endif
void
solver_get_unneeded(Solver *solv, Queue *unneededq, int filtered)
for (i = 0; i < count; i++)
{
Solvable *s = pool->solvables + unneededq->elements[i];
- edges.elements[i + 1] = edges.count;
+ int oldcount = edges.count;
+ edges.elements[i + 1] = oldcount;
for (pass = 0; pass < 2; pass++)
{
- int num = 0;
unsigned int off = pass == 0 ? s->requires : s->recommends;
- Id p, pp, *dp;
+ Id p, pp, dep, *dp;
if (off)
- for (dp = s->repo->idarraydata + off; *dp; dp++)
- FOR_PROVIDES(p, pp, *dp)
- {
- Solvable *sp = pool->solvables + p;
- if (s == sp || sp->repo != installed || !MAPTST(&cleandepsmap, p - installed->start))
- continue;
- for (j = 0; j < count; j++)
- if (p == unneededq->elements[j])
- break;
- if (j == count)
- continue;
- if (num && edges.elements[edges.count - 1] == j + 1)
+ for (dp = s->repo->idarraydata + off; (dep = *dp) != 0; dp++)
+ {
+#ifdef ENABLE_COMPLEX_DEPS
+ if (pool_is_complex_dep(pool, dep))
+ {
+ complex_unneeded(pool, s - pool->solvables, dep, &edges, &cleandepsmap, unneededq);
continue;
- queue_push(&edges, j + 1);
- num++;
- }
- if (pass == 0)
- nrequires[i] = num;
+ }
+#endif
+ FOR_PROVIDES(p, pp, dep)
+ {
+ Solvable *sp = pool->solvables + p;
+ if (s == sp || sp->repo != installed || !MAPTST(&cleandepsmap, p - installed->start))
+ continue;
+ for (j = 0; j < count; j++)
+ if (p == unneededq->elements[j])
+ {
+ if (edges.elements[edges.count - 1] != j + 1)
+ queue_push(&edges, j + 1);
+ }
+ }
+ }
+ if (pass == 0)
+ nrequires[i] = edges.count - oldcount;
}
queue_push(&edges, 0);
}
/* now add edge from j + 1 to i + 1 */
queue_insert(&edges, edges.elements[j + 1] + nrequires[j], i + 1);
/* addapt following edge pointers */
- for (k = j + 2; k < count + 2; k++)
- edges.elements[k]++;
+ for (j = j + 2; j < count + 1; j++)
+ edges.elements[j]++;
}
queue_free(&iq);
}
printf(" %s (%d requires):\n", pool_solvid2str(pool, unneededq->elements[i]), nrequires[i]);
for (j = edges.elements[i + 1]; edges.elements[j]; j++)
printf(" - %s\n", pool_solvid2str(pool, unneededq->elements[edges.elements[j] - 1]));
- }
+ }
#endif
map_free(&installedm);
map_free(&cleandepsmap);
}
-/* EOF */
+
+void
+solver_breakorphans(Solver *solv)
+{
+ Pool *pool = solv->pool;
+ Repo *installed = solv->installed;
+ int i, rid;
+ Map m;
+
+ if (!installed || solv->droporphanedmap_all)
+ return;
+ solv->brokenorphanrules = solv_calloc(1, sizeof(Queue));
+ queue_init(solv->brokenorphanrules);
+ map_init(&m, installed->end - installed->start);
+ for (i = 0; i < solv->orphaned.count; i++)
+ {
+ Id p = solv->orphaned.elements[i];
+ if (pool->solvables[p].repo != installed)
+ continue;
+ if (solv->droporphanedmap.size && MAPTST(&solv->droporphanedmap, p - installed->start))
+ continue;
+ MAPSET(&m, p - installed->start);
+ }
+ for (rid = 1; rid < solv->rpmrules_end ; rid++)
+ {
+ Id p, *dp;
+ Rule *r = solv->rules + rid;
+ /* ignore non-deps and simple conflicts */
+ if (r->p >= 0 || ((r->d == 0 || r->d == -1) && r->w2 < 0))
+ continue;
+ p = -r->p;
+ if (p < installed->start || p >= installed->end || !MAPTST(&m, p - installed->start))
+ {
+ /* need to check other literals */
+ if (r->d == 0 || r->d == -1)
+ continue;
+ for (dp = pool->whatprovidesdata + (r->d < 0 ? -r->d - 1 : r->d); *dp < 0; dp++)
+ {
+ p = -*dp;
+ if (p >= installed->start && p < installed->end && MAPTST(&m, p - installed->start))
+ break;
+ }
+ if (*dp >= 0)
+ continue;
+ }
+ /* ok, disable this rule */
+ queue_push(solv->brokenorphanrules, rid);
+ if (r->d >= 0)
+ solver_disablerule(solv, r);
+ }
+ map_free(&m);
+ if (!solv->brokenorphanrules->count)
+ {
+ queue_free(solv->brokenorphanrules);
+ solv->brokenorphanrules = solv_free(solv->brokenorphanrules);
+ }
+}
+
+void
+solver_check_brokenorphanrules(Solver *solv, Queue *dq)
+{
+ Pool *pool = solv->pool;
+ int i;
+ Id l, pp;
+
+ queue_empty(dq);
+ if (!solv->brokenorphanrules)
+ return;
+ for (i = 0; i < solv->brokenorphanrules->count; i++)
+ {
+ int rid = solv->brokenorphanrules->elements[i];
+ Rule *r = solv->rules + rid;
+ FOR_RULELITERALS(l, pp, r)
+ {
+ if (l < 0)
+ {
+ if (solv->decisionmap[-l] <= 0)
+ break;
+ }
+ else
+ {
+ if (solv->decisionmap[l] > 0 && pool->solvables[l].repo != solv->installed)
+ break;
+ }
+ }
+ if (l)
+ continue;
+ FOR_RULELITERALS(l, pp, r)
+ if (l > 0 && solv->decisionmap[l] == 0 && pool->solvables[l].repo != solv->installed)
+ queue_pushunique(dq, l);
+ }
+}
+