]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Add pool_dep_fulfilled_in_map function 592/head
authorAleš Matěj <amatej@redhat.com>
Tue, 1 Jul 2025 12:25:38 +0000 (14:25 +0200)
committerAleš Matěj <amatej@redhat.com>
Tue, 1 Jul 2025 12:29:32 +0000 (14:29 +0200)
This is can be used to determine dependency closure on a given set of
packages (even with complex dependencies).

doc/libsolv-pool.txt
src/libsolv.ver
src/pool.c
src/pool.h

index 2958437c379977a37681f9f505de2d25f3a81a57..92232ab1ac7da51baedaee1bfe88f3e0a4837d1c 100644 (file)
@@ -562,6 +562,10 @@ by the ``evr'' parts must overlap.
 Like pool_match_dep, but the provider is the "self-provides" dependency
 of the Solvable _s_, i.e. the dependency ``s->name = s->evr''.
 
+        int pool_dep_fulfilled_in_map(Pool *pool, const Map *map, Id dep);
+
+Returns ``1'' if the dependency _dep_ is provided by at least one package
+from _map_, otherwise ``0'' is returned.
 
 Whatprovides Index
 ------------------
index accb5aa7e7a28a95e303ca2f671b80ecf3ef26d9..6f72ae16a0bcb01b7ef08b727ebdf824cc84722a 100644 (file)
@@ -91,6 +91,7 @@ SOLV_1.0 {
                pool_lookup_str;
                pool_lookup_void;
                pool_match_dep;
+               pool_dep_fulfilled_in_map;
                pool_match_nevr_rel;
                pool_prepend_rootdir;
                pool_prepend_rootdir_tmp;
index 14511deffcd6b6b4ef758452e4c6aae222811ae9..350153e41749dea749a4acd15d5abd6a5f0a02a8 100644 (file)
@@ -2104,4 +2104,74 @@ int (*pool_get_custom_vendorcheck(Pool *pool))(Pool *, Solvable *, Solvable *)
   return pool->custom_vendorcheck;
 }
 
+static int
+pool_dep_fulfilled_in_map_cplx(Pool *pool, const Map *map, Reldep *rd)
+{
+  if (rd->flags == REL_COND)
+    {
+      if (ISRELDEP(rd->evr))
+       {
+         Reldep *rd2 = GETRELDEP(pool, rd->evr);
+         if (rd2->flags == REL_ELSE)
+           {
+             if (pool_dep_fulfilled_in_map(pool, map, rd2->name))
+               return pool_dep_fulfilled_in_map(pool, map, rd->name);
+             return pool_dep_fulfilled_in_map(pool, map, rd2->evr);
+           }
+       }
+      if (pool_dep_fulfilled_in_map(pool, map, rd->name))
+       return 1;
+      return !pool_dep_fulfilled_in_map(pool, map, rd->evr);
+    }
+  if (rd->flags == REL_UNLESS)
+    {
+      if (ISRELDEP(rd->evr))
+       {
+         Reldep *rd2 = GETRELDEP(pool, rd->evr);
+         if (rd2->flags == REL_ELSE)
+           {
+             if (!pool_dep_fulfilled_in_map(pool, map, rd2->name))
+               return pool_dep_fulfilled_in_map(pool, map, rd->name);
+             return pool_dep_fulfilled_in_map(pool, map, rd2->evr);
+           }
+       }
+      if (!pool_dep_fulfilled_in_map(pool, map, rd->name))
+       return 0;
+      return !pool_dep_fulfilled_in_map(pool, map, rd->evr);
+    }
+  if (rd->flags == REL_AND)
+    {
+      if (!pool_dep_fulfilled_in_map(pool, map, rd->name))
+       return 0;
+      return pool_dep_fulfilled_in_map(pool, map, rd->evr);
+    }
+  if (rd->flags == REL_OR)
+    {
+      if (pool_dep_fulfilled_in_map(pool, map, rd->name))
+       return 1;
+      return pool_dep_fulfilled_in_map(pool, map, rd->evr);
+    }
+  return 0;
+}
+
+
+int pool_dep_fulfilled_in_map(Pool *pool, const Map *map, Id dep)
+{
+  Id p, pp;
+
+  if (ISRELDEP(dep)) {
+    Reldep *rd = GETRELDEP(pool, dep);
+    if (rd->flags == REL_COND || rd->flags == REL_UNLESS ||
+        rd->flags == REL_AND || rd->flags == REL_OR)
+      return pool_dep_fulfilled_in_map_cplx(pool, map, rd);
+    if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
+      return 0;
+  }
+  FOR_PROVIDES(p, pp, dep) {
+    if (MAPTST(map, p))
+      return 1;
+  }
+  return 0;
+}
+
 /* EOF */
index d8c938e8823cea1c3240c484d41a15fe3a284d79..7c11e46373987459e611ceae735f2bcecf6ba97b 100644 (file)
@@ -305,6 +305,7 @@ Id pool_id2langid(Pool *pool, Id id, const char *lang, int create);
 
 int pool_intersect_evrs(Pool *pool, int pflags, Id pevr, int flags, Id evr);
 int pool_match_dep(Pool *pool, Id d1, Id d2);
+int pool_dep_fulfilled_in_map(Pool *pool, const Map *map, Id dep);
 
 /* semi private, used in pool_match_nevr */
 int pool_match_nevr_rel(Pool *pool, Solvable *s, Id d);