summaryrefslogtreecommitdiff
path: root/src/policy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/policy.c')
-rw-r--r--src/policy.c202
1 files changed, 202 insertions, 0 deletions
diff --git a/src/policy.c b/src/policy.c
index 12ad771..3a0a737 100644
--- a/src/policy.c
+++ b/src/policy.c
@@ -453,6 +453,89 @@ prefer_suggested(Solver *solv, Queue *plist)
}
}
+static int
+sort_by_favorq_cmp(const void *ap, const void *bp, void *dp)
+{
+ const Id *a = ap, *b = bp, *d = dp;
+ return d[b[0]] - d[a[0]];
+}
+
+static void
+sort_by_favorq(Queue *favorq, Id *el, int cnt)
+{
+ int i;
+ /* map to offsets into favorq */
+ for (i = 0; i < cnt; i++)
+ {
+ Id p = el[i];
+ /* lookup p in sorted favorq */
+ int med = 0, low = 0;
+ int high = favorq->count / 2;
+ while (low != high)
+ {
+ med = (low + high) / 2;
+ Id pp = favorq->elements[2 * med];
+ if (pp < p)
+ low = med;
+ else if (pp > p)
+ high = med;
+ else
+ break;
+ }
+ while(med && favorq->elements[2 * med - 2] == p)
+ med--;
+ if (favorq->elements[2 * med] == p)
+ el[i] = 2 * med + 1;
+ else
+ el[i] = 0; /* hmm */
+ }
+ /* sort by position */
+ solv_sort(el, cnt, sizeof(Id), sort_by_favorq_cmp, favorq->elements);
+ /* map back */
+ for (i = 0; i < cnt; i++)
+ if (el[i])
+ el[i] = favorq->elements[el[i] - 1];
+}
+
+/* bring favored packages to front and disfavored packages to back */
+void
+policy_prefer_favored(Solver *solv, Queue *plist)
+{
+ int i, fav, disfav, count;
+ if (!solv->favormap.size)
+ return;
+ for (i = fav = disfav = 0, count = plist->count; i < count; i++)
+ {
+ Id p = plist->elements[i];
+ if (!MAPTST(&solv->favormap, p))
+ continue;
+ if (solv->isdisfavormap.size && MAPTST(&solv->isdisfavormap, p))
+ {
+ /* disfavored package. bring to back */
+ if (i < plist->count - 1)
+ {
+ memmove(plist->elements + i, plist->elements + i + 1, (plist->count - 1 - i) * sizeof(Id));
+ plist->elements[plist->count - 1] = p;
+ }
+ i--;
+ count--;
+ disfav++;
+ }
+ else
+ {
+ /* favored package. bring to front */
+ if (i > fav)
+ memmove(plist->elements + fav + 1, plist->elements + fav, (i - fav) * sizeof(Id));
+ plist->elements[fav++] = p;
+ }
+ }
+ /* if we have multiple favored/disfavored packages, sort by favorq index */
+ if (fav > 1)
+ sort_by_favorq(solv->favorq, plist->elements, fav);
+ if (disfav > 1)
+ sort_by_favorq(solv->favorq, plist->elements + plist->count - disfav, disfav);
+}
+
/*
* prune to recommended/suggested packages.
* does not prune installed packages (they are also somewhat recommended).
@@ -1112,6 +1195,111 @@ dislike_old_versions(Pool *pool, Queue *plist)
}
}
+
+/* special lang package handling for urpm */
+/* see https://bugs.mageia.org/show_bug.cgi?id=18315 */
+
+static int
+urpm_reorder_cmp(const void *ap, const void *bp, void *dp)
+{
+ return ((Id *)bp)[1] - ((Id *)ap)[1];
+}
+
+static void
+urpm_reorder(Solver *solv, Queue *plist)
+{
+ Pool *pool = solv->pool;
+ int i, count = plist->count;
+ /* add locale score to packages */
+ queue_insertn(plist, count, count, 0);
+ for (i = count - 1; i >= 0; i--)
+ {
+ Solvable *s = pool->solvables + plist->elements[i];
+ int score = 1;
+ const char *sn = pool_id2str(pool, s->name);
+
+ if (!strncmp(sn, "kernel-", 7))
+ {
+ const char *devel = strstr(sn, "-devel-");
+ if (devel && strlen(sn) < 256)
+ {
+ char kn[256];
+ Id p, pp, knid;
+ memcpy(kn, sn, devel - sn);
+ strcpy(kn + (devel - sn), devel + 6);
+ knid = pool_str2id(pool, kn, 0);
+ if (knid)
+ {
+ FOR_PROVIDES(p, pp, knid)
+ if (solv->decisionmap[p] > 0 || (pool->installed && pool->solvables[p].repo == pool->installed))
+ score = 3;
+ }
+ }
+ }
+ else if ((sn = strstr(sn, "-kernel-")) != 0)
+ {
+ sn += 8;
+ if (strlen(sn) < 256 - 8 && *sn >= '0' && *sn <= '9' && sn[1] == '.')
+ {
+ const char *flavor = strchr(sn, '-');
+ if (flavor)
+ {
+ const char *release = strchr(flavor + 1, '-');
+ if (release)
+ {
+ char kn[256];
+ Id p, pp, knid;
+ memcpy(kn, "kernel", 8);
+ memcpy(kn + 6, flavor, release - flavor + 1);
+ memcpy(kn + 6 + (release - flavor) + 1, sn, flavor - sn);
+ strcpy(kn + 6 + (release + 1 - sn), release);
+ knid = pool_str2id(pool, kn, 0);
+ if (knid)
+ {
+ FOR_PROVIDES(p, pp, knid)
+ if (solv->decisionmap[p] > 0 || (pool->installed && pool->solvables[p].repo == pool->installed))
+ score = 3;
+ }
+ }
+ }
+ }
+ }
+ if (score == 1 && s->requires)
+ {
+ Id id, *idp, p, pp;
+ const char *deps;
+ for (idp = s->repo->idarraydata + s->requires; (id = *idp) != 0; idp++)
+ {
+ while (ISRELDEP(id))
+ {
+ Reldep *rd = GETRELDEP(pool, id);
+ id = rd->name;
+ }
+ deps = strstr(pool_id2str(pool, id), "locales-");
+ if (!deps)
+ continue;
+ if (!strncmp(deps + 8, "en", 2))
+ score = 2;
+ else
+ {
+ score = 0;
+ FOR_PROVIDES(p, pp, id)
+ if (solv->decisionmap[p] > 0 || (pool->installed && pool->solvables[p].repo == pool->installed))
+ score = 3;
+ break;
+ }
+ }
+ }
+ plist->elements[i * 2] = plist->elements[i];
+ plist->elements[i * 2 + 1] = score;
+ }
+ solv_sort(plist->elements, count, sizeof(Id) * 2, urpm_reorder_cmp, pool);
+ for (i = 0; i < count; i++)
+ plist->elements[i] = plist->elements[2 * i];
+ queue_truncate(plist, count);
+}
+
+
/*
* POLICY_MODE_CHOOSE: default, do all pruning steps
* POLICY_MODE_RECOMMEND: leave out prune_to_recommended
@@ -1121,6 +1309,17 @@ void
policy_filter_unwanted(Solver *solv, Queue *plist, int mode)
{
Pool *pool = solv->pool;
+ if (mode == POLICY_MODE_SUPPLEMENT)
+ {
+ /* reorder only */
+ dislike_old_versions(pool, plist);
+ sort_by_common_dep(pool, plist);
+ if (solv->urpmreorder)
+ urpm_reorder(solv, plist);
+ prefer_suggested(solv, plist);
+ policy_prefer_favored(solv, plist);
+ return;
+ }
if (plist->count > 1)
{
if (mode != POLICY_MODE_SUGGEST)
@@ -1143,7 +1342,10 @@ policy_filter_unwanted(Solver *solv, Queue *plist, int mode)
#endif
dislike_old_versions(pool, plist);
sort_by_common_dep(pool, plist);
+ if (solv->urpmreorder)
+ urpm_reorder(solv, plist);
prefer_suggested(solv, plist);
+ policy_prefer_favored(solv, plist);
}
}
}