1
0
mirror of https://github.com/openSUSE/libsolv.git synced 2026-02-05 12:45:46 +01:00

Add pool_whatcontainsdep, selection_make_containsdep, and SELECTION_MATCH_DEPSTR

This commit is contained in:
Michael Schroeder
2016-04-22 15:39:54 +02:00
parent 6410e96610
commit a5cc7c5488
6 changed files with 135 additions and 17 deletions

View File

@@ -236,6 +236,7 @@ main(int argc, char **argv)
int forcebest = 0;
char *rootdir = 0;
char *keyname = 0;
int keyname_depstr = 0;
int debuglevel = 0;
argc--;
@@ -323,7 +324,13 @@ main(int argc, char **argv)
argc--;
argv++;
}
if (argc > 2 && !strcmp(argv[1], "--keyname"))
else if (argc > 1 && !strcmp(argv[1], "--depstr"))
{
keyname_depstr = 1;
argc--;
argv++;
}
else if (argc > 2 && !strcmp(argv[1], "--keyname"))
{
keyname = argv[2];
argc -= 2;
@@ -529,7 +536,11 @@ main(int argc, char **argv)
if (!keyname)
rflags = selection_make(pool, &job2, argv[i], flags);
else
rflags = selection_make_matchdeps(pool, &job2, argv[i], flags, pool_str2id(pool, keyname, 1), 0);
{
if (keyname_depstr)
flags |= SELECTION_MATCH_DEPSTR;
rflags = selection_make_matchdeps(pool, &job2, argv[i], flags, pool_str2id(pool, keyname, 1), 0);
}
if (repofilter.count)
selection_filter(pool, &job2, &repofilter);
if (archfilter.count)

View File

@@ -120,6 +120,7 @@ SOLV_1.0 {
pool_trivial_installable_multiversionmap;
pool_vendor2mask;
pool_whatmatchesdep;
pool_whatcontainsdep;
queue_alloc_one;
queue_alloc_one_head;
queue_delete;
@@ -245,6 +246,7 @@ SOLV_1.0 {
selection_add;
selection_filter;
selection_make;
selection_make_containsdep;
selection_make_matchdeps;
selection_solvables;
solv_bin2hex;

View File

@@ -1331,8 +1331,11 @@ void
pool_whatmatchesdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker)
{
Id p;
Queue qq;
int i;
queue_empty(q);
queue_init(&qq);
FOR_POOL_SOLVABLES(p)
{
Solvable *s = pool->solvables + p;
@@ -1340,9 +1343,49 @@ pool_whatmatchesdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker)
continue;
if (s->repo != pool->installed && !pool_installable(pool, s))
continue;
if (solvable_matchesdep(s, keyname, dep, marker))
queue_push(q, p);
if (qq.count)
queue_empty(&qq);
solvable_lookup_deparray(s, keyname, &qq, marker);
for (i = 0; i < qq.count; i++)
if (pool_match_dep(pool, qq.elements[i], dep))
{
queue_push(q, p);
break;
}
}
queue_free(&qq);
}
/* check if keyname contains dep, return list of matching packages */
void
pool_whatcontainsdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker)
{
Id p;
Queue qq;
int i;
queue_empty(q);
if (!dep)
return;
queue_init(&qq);
FOR_POOL_SOLVABLES(p)
{
Solvable *s = pool->solvables + p;
if (s->repo->disabled)
continue;
if (s->repo != pool->installed && !pool_installable(pool, s))
continue;
if (qq.count)
queue_empty(&qq);
solvable_lookup_deparray(s, keyname, &qq, marker);
for (i = 0; i < qq.count; i++)
if (qq.elements[i] == dep)
{
queue_push(q, p);
break;
}
}
queue_free(&qq);
}
/*************************************************************************/

View File

@@ -347,6 +347,7 @@ static inline Id *pool_whatprovides_ptr(Pool *pool, Id d)
}
void pool_whatmatchesdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker);
void pool_whatcontainsdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker);
/* search the pool. the following filters are available:
* p - search just this solvable

View File

@@ -867,6 +867,19 @@ selection_make(Pool *pool, Queue *selection, const char *name, int flags)
return ret;
}
static inline int
matchdep_str(const char *pattern, const char *string, int flags)
{
if (flags & SELECTION_GLOB)
{
int globflags = (flags & SELECTION_NOCASE) != 0 ? FNM_CASEFOLD : 0;
return fnmatch(pattern, string, globflags) == 0 ? 1 : 0;
}
if (flags & SELECTION_NOCASE)
return strcasecmp(pattern, string) == 0 ? 1 : 0;
return strcmp(pattern, string) == 0 ? 1 : 0;
}
static int
matchdep(Pool *pool, Id id, char *rname, int rflags, char *revr, int flags)
{
@@ -899,14 +912,7 @@ matchdep(Pool *pool, Id id, char *rname, int rflags, char *revr, int flags)
}
return 1;
}
if (flags & SELECTION_GLOB)
{
int globflags = (flags & SELECTION_NOCASE) != 0 ? FNM_CASEFOLD : 0;
return fnmatch(rname, pool_id2str(pool, id), globflags) == 0 ? 1 : 0;
}
if (flags & SELECTION_NOCASE)
return strcasecmp(rname, pool_id2str(pool, id)) == 0 ? 1 : 0;
return strcmp(rname, pool_id2str(pool, id)) == 0 ? 1 : 0;
return matchdep_str(rname, pool_id2str(pool, id), flags);
}
/*
@@ -924,15 +930,18 @@ selection_make_matchdeps(Pool *pool, Queue *selection, const char *name, int fla
queue_empty(selection);
rname = solv_strdup(name);
if ((r = strpbrk(rname, "<=>")) != 0)
if (!(flags & SELECTION_MATCH_DEPSTR))
{
if ((r = splitrel(rname, r, &rflags)) == 0)
if ((r = strpbrk(rname, "<=>")) != 0)
{
solv_free(rname);
return 0;
if ((r = splitrel(rname, r, &rflags)) == 0)
{
solv_free(rname);
return 0;
}
}
}
if ((flags & SELECTION_GLOB) != 0 && !strpbrk(name, "[*?") != 0)
if ((flags & SELECTION_GLOB) != 0 && !strpbrk(rname, "[*?") != 0)
flags &= ~SELECTION_GLOB;
queue_init(&q);
@@ -957,6 +966,12 @@ selection_make_matchdeps(Pool *pool, Queue *selection, const char *name, int fla
for (i = 0; i < q.count; i++)
{
Id id = q.elements[i];
if ((flags & SELECTION_MATCH_DEPSTR) != 0)
{
if (matchdep_str(rname, pool_dep2str(pool, id), flags))
break;
continue;
}
if (matchdep(pool, id, rname, rflags, r, flags))
break;
}
@@ -972,6 +987,50 @@ selection_make_matchdeps(Pool *pool, Queue *selection, const char *name, int fla
return SELECTION_PROVIDES;
}
int
selection_make_containsdep(Pool *pool, Queue *selection, Id dep, int flags, int keyname, int marker)
{
Id p;
Queue q;
queue_empty(selection);
if (!dep)
return 0;
queue_init(&q);
FOR_POOL_SOLVABLES(p)
{
Solvable *s = pool->solvables + p;
int i;
if (s->repo != pool->installed && !pool_installable(pool, s))
{
if (!(flags & SELECTION_SOURCE_ONLY) || (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC))
continue;
if (pool_disabled_solvable(pool, s))
continue;
}
if ((flags & SELECTION_INSTALLED_ONLY) != 0 && s->repo != pool->installed)
continue;
if ((s->arch == ARCH_SRC || s->arch == ARCH_NOSRC) && !(flags & SELECTION_SOURCE_ONLY) && !(flags & SELECTION_WITH_SOURCE))
continue;
queue_empty(&q);
repo_lookup_deparray(s->repo, p, keyname, &q, marker);
for (i = 0; i < q.count; i++)
{
if (q.elements[i] == dep)
break;
}
if (i < q.count)
queue_push2(selection, SOLVER_SOLVABLE | SOLVER_NOAUTOSET, p);
}
queue_free(&q);
if (!selection->count)
return 0;
if ((flags & SELECTION_FLAT) != 0)
selection_flatten(pool, selection);
return SELECTION_PROVIDES;
}
static inline int
pool_is_kind(Pool *pool, Id name, Id kind)
{

View File

@@ -33,9 +33,11 @@ extern "C" {
#define SELECTION_SOURCE_ONLY (1 << 12)
#define SELECTION_WITH_SOURCE (1 << 13)
#define SELECTION_SKIP_KIND (1 << 14)
#define SELECTION_MATCH_DEPSTR (1 << 15)
extern int selection_make(Pool *pool, Queue *selection, const char *name, int flags);
extern int selection_make_matchdeps(Pool *pool, Queue *selection, const char *name, int flags, int keyname, int marker);
extern int selection_make_containsdep(Pool *pool, Queue *selection, Id dep, int flags, int keyname, int marker);
extern void selection_filter(Pool *pool, Queue *sel1, Queue *sel2);
extern void selection_add(Pool *pool, Queue *sel1, Queue *sel2);