/*
- * Copyright (c) 2007, Novell Inc.
+ * Copyright (c) 2012, Novell Inc.
*
* This program is licensed under the BSD license, read LICENSE.BSD
* for further information
}
static void
-selection_limit_rel(Pool *pool, Queue *selection, Id relflags, Id relevr)
+selection_filter_rel(Pool *pool, Queue *selection, Id relflags, Id relevr)
{
int i;
for (i = 0; i < selection->count; i += 2)
}
}
queue_free(&q);
- continue;
}
- if (select != SOLVER_SOLVABLE_NAME && select != SOLVER_SOLVABLE_PROVIDES)
- continue; /* actually internal error */
- if (relflags == REL_ARCH && (relevr == ARCH_SRC || relevr == ARCH_NOSRC) && ISRELDEP(id))
+ else if (select == SOLVER_SOLVABLE_NAME && select == SOLVER_SOLVABLE_PROVIDES)
{
- Reldep *rd = GETRELDEP(pool, id);
- if (rd->flags == REL_ARCH && rd->evr == ARCH_SRC)
- id = rd->name;
+ /* don't stack src reldeps */
+ if (relflags == REL_ARCH && (relevr == ARCH_SRC || relevr == ARCH_NOSRC) && ISRELDEP(id))
+ {
+ Reldep *rd = GETRELDEP(pool, id);
+ if (rd->flags == REL_ARCH && rd->evr == ARCH_SRC)
+ id = rd->name;
+ }
+ selection->elements[i + 1] = pool_rel2id(pool, id, relevr, relflags, 1);
}
- selection->elements[i + 1] = pool_rel2id(pool, id, relevr, relflags, 1);
+ else
+ continue; /* actually internal error */
if (relflags == REL_ARCH)
selection->elements[i] |= SOLVER_SETARCH;
- if (relflags == REL_EQ && select == SOLVER_SOLVABLE_NAME && selection->elements[i])
+ if (relflags == REL_EQ && select != SOLVER_SOLVABLE_PROVIDES)
{
if (pool->disttype == DISTTYPE_DEB)
selection->elements[i] |= SOLVER_SETEVR; /* debian can't match version only like rpm */
continue;
if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
havesrc = 1;
- else if (!pool_installable(pool, s))
+ else if (s->repo != pool->installed && !pool_installable(pool, s))
continue;
queue_push(&q, p);
}
if (doglob && (flags & SELECTION_NOCASE) != 0)
globflags = FNM_CASEFOLD;
-#if 0 /* doesn't work with selection_limit_rel yet */
+#if 0 /* doesn't work with selection_filter_rel yet */
if (doglob && !strcmp(name, "*") && (flags & SELECTION_FLAT) != 0)
{
/* can't do this for SELECTION_PROVIDES, as src rpms don't provide anything */
FOR_POOL_SOLVABLES(p)
{
Solvable *s = pool->solvables + p;
- if (!pool_installable(pool, s))
+ if (s->repo != pool->installed && !pool_installable(pool, s))
if (!(flags & SELECTION_SOURCE_ONLY) || (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC))
continue;
if ((flags & SELECTION_INSTALLED_ONLY) != 0 && s->repo != pool->installed)
if ((ret = selection_depglob(pool, selection, name, flags)) != 0)
return ret;
- /* check if theres an .arch suffix */
+ if (!(flags & SELECTION_DOTARCH))
+ return 0;
+ /* check if there is an .arch suffix */
if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
{
char *rname = solv_strdup(name);
flags |= SELECTION_SOURCE_ONLY;
if ((ret = selection_depglob(pool, selection, rname, flags)) != 0)
{
- selection_limit_rel(pool, selection, REL_ARCH, archid);
+ selection_filter_rel(pool, selection, REL_ARCH, archid);
solv_free(rname);
- return ret;
+ return ret | SELECTION_DOTARCH;
}
solv_free(rname);
}
Solvable *s = pool->solvables + di.solvid;
if (!s->repo)
continue;
- if (!pool_installable(pool, s))
+ if (s->repo != pool->installed && !pool_installable(pool, s))
if (!(flags & SELECTION_SOURCE_ONLY) || (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC))
continue;
if ((flags & SELECTION_INSTALLED_ONLY) != 0 && s->repo != pool->installed)
if ((ret = selection_depglob_arch(pool, selection, rname, flags)) != 0)
{
if (rflags)
- selection_limit_rel(pool, selection, rflags, pool_str2id(pool, r, 1));
+ selection_filter_rel(pool, selection, rflags, pool_str2id(pool, r, 1));
solv_free(rname);
- return ret;
+ return ret | SELECTION_REL;
}
solv_free(rname);
return 0;
/* magic epoch promotion code, works only for SELECTION_NAME selections */
static void
-selection_limit_evr(Pool *pool, Queue *selection, char *evr)
+selection_filter_evr(Pool *pool, Queue *selection, char *evr)
{
int i, j;
+ Queue q;
+ Id qbuf[10];
+
+ queue_init(&q);
+ queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
for (i = j = 0; i < selection->count; i += 2)
{
Id select = selection->elements[i] & SOLVER_SELECTMASK;
Id id = selection->elements[i + 1];
Id p, pp;
- Queue tmpq;
- Id tmpqb[2];
- const char *highest = 0;
- int highestlen = 0;
+ const char *lastepoch = 0;
+ int lastepochlen = 0;
+ queue_empty(&q);
FOR_JOB_SELECT(p, pp, select, id)
{
Solvable *s = pool->solvables + p;
const char *sp;
for (sp = sevr; *sp >= '0' && *sp <= '9'; sp++)
;
- if (sp == sevr || *sp != ':')
- continue;
- /* found epoch, compare vr */
- if (strcmp(sp + 1, evr) != 0)
+ if (*sp != ':')
+ sp = sevr;
+ /* compare vr part */
+ if (strcmp(evr, sp != sevr ? sp + 1 : sevr) != 0)
{
- int r = pool_evrcmp_str(pool, sp + 1, evr, EVRCMP_DEPCMP);
+ int r = pool_evrcmp_str(pool, sp != sevr ? sp + 1 : sevr, evr, EVRCMP_DEPCMP);
if (r == -1 || r == 1)
- continue; /* no match */
+ continue; /* solvable does not match vr */
}
- if (highest)
+ queue_push(&q, p);
+ if (sp > sevr)
{
- if (highestlen == sp - sevr && !strncmp(highest, sevr, highestlen))
- continue;
- if (pool_evrcmp_str(pool, sevr, highest, EVRCMP_COMPARE) <= 0)
- continue;
+ while (sevr < sp && *sevr == '0') /* normalize epoch */
+ sevr++;
+ }
+ if (!lastepoch)
+ {
+ lastepoch = sevr;
+ lastepochlen = sp - sevr;
}
- highest = sevr;
- highestlen = sp - sevr;
+ else if (lastepochlen != sp - sevr || strncmp(lastepoch, sevr, lastepochlen) != 0)
+ lastepochlen = -1; /* multiple different epochs */
}
- if (highest)
+ if (!lastepoch || lastepochlen == 0)
+ id = pool_str2id(pool, evr, 1); /* no match at all or zero epoch */
+ else if (lastepochlen >= 0)
{
- /* found epoch, prepend */
- char *evrx = solv_malloc(strlen(evr) + highestlen + 2);
- strncpy(evrx, highest, highestlen + 1);
- strcpy(evrx + highestlen + 1, evr);
+ /* found exactly one epoch, simply prepend */
+ char *evrx = solv_malloc(strlen(evr) + lastepochlen + 2);
+ strncpy(evrx, lastepoch, lastepochlen + 1);
+ strcpy(evrx + lastepochlen + 1, evr);
id = pool_str2id(pool, evrx, 1);
solv_free(evrx);
}
else
- id = pool_str2id(pool, evr, 1);
- queue_init_buffer(&tmpq, tmpqb, sizeof(tmpqb)/sizeof(*tmpqb));
- queue_push2(&tmpq, selection->elements[i], selection->elements[i + 1]);
- selection_limit_rel(pool, &tmpq, REL_EQ, id);
- if (!tmpq.count)
{
- queue_free(&tmpq);
- continue; /* oops, no match */
+ /* multiple epochs in multiple solvables, convert to list of solvables */
+ selection->elements[j] = (selection->elements[i] & ~SOLVER_SELECTMASK) | SOLVER_SOLVABLE_ONE_OF;
+ selection->elements[j + 1] = pool_queuetowhatprovides(pool, &q);
+ j += 2;
+ continue;
}
- selection->elements[j] = tmpq.elements[0];
- selection->elements[j + 1] = tmpq.elements[1];
- queue_free(&tmpq);
+ queue_empty(&q);
+ queue_push2(&q, selection->elements[i], selection->elements[i + 1]);
+ selection_filter_rel(pool, &q, REL_EQ, id);
+ if (!q.count)
+ continue; /* oops, no match */
+ selection->elements[j] = q.elements[0];
+ selection->elements[j + 1] = q.elements[1];
j += 2;
}
queue_truncate(selection, j);
+ queue_free(&q);
}
+/* match the "canonical" name of the package */
static int
-selection_nevra(Pool *pool, Queue *selection, const char *name, int flags)
+selection_canon(Pool *pool, Queue *selection, const char *name, int flags)
{
char *rname, *r, *r2;
Id archid = 0;
if ((r2 = strchr(r, '_')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
{
*r2 = 0; /* split off */
- selection_limit_rel(pool, selection, REL_ARCH, archid);
+ selection_filter_rel(pool, selection, REL_ARCH, archid);
}
- selection_limit_rel(pool, selection, REL_EQ, pool_str2id(pool, r, 1));
+ selection_filter_rel(pool, selection, REL_EQ, pool_str2id(pool, r, 1));
solv_free(rname);
- return ret;
+ return ret | SELECTION_CANON;
}
if ((r = strrchr(name, '-')) == 0)
}
}
if (archid)
- selection_limit_rel(pool, selection, REL_ARCH, archid);
- selection_limit_evr(pool, selection, r + 1); /* magic epoch promotion */
+ selection_filter_rel(pool, selection, REL_ARCH, archid);
+ selection_filter_evr(pool, selection, r + 1); /* magic epoch promotion */
solv_free(rname);
- return ret;
+ return ret | SELECTION_CANON;
}
int
queue_empty(selection);
if (*name == '/' && (flags & SELECTION_FILELIST))
ret = selection_filelist(pool, selection, name, flags);
- if (!ret && (r = strpbrk(name, "<=>")) != 0)
+ if (!ret && (flags & SELECTION_REL) != 0 && (r = strpbrk(name, "<=>")) != 0)
ret = selection_rel(pool, selection, name, flags);
if (!ret)
ret = selection_depglob_arch(pool, selection, name, flags);
- if (!ret && (flags & SELECTION_NAME) != 0)
- ret = selection_nevra(pool, selection, name, flags);
+ if (!ret && (flags & SELECTION_CANON) != 0)
+ ret = selection_canon(pool, selection, name, flags);
+
if (ret && (flags & SELECTION_FLAT) != 0)
selection_flatten(pool, selection);
return ret;
}
void
-selection_limit(Pool *pool, Queue *sel1, Queue *sel2)
+selection_filter(Pool *pool, Queue *sel1, Queue *sel2)
{
int i, j, miss;
Id p, pp;