]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Better support for SOLVABLE_BUILDFLAVOR
authorMichael Schroeder <mls@suse.de>
Tue, 9 Apr 2019 09:36:40 +0000 (11:36 +0200)
committerMichael Schroeder <mls@suse.de>
Tue, 9 Apr 2019 09:36:40 +0000 (11:36 +0200)
This changes pool_solvable2str, testcase_str2solvid and
testcase_solvid2str to append the build flavor.

ext/solv_jsonparser.h
ext/testcase.c
src/solvable.c

index e0274f9c9070d3af327196c6da0e19171c1a67e4..50d8b5334dc07ed1f16ed9b7394139e331d2930a 100644 (file)
@@ -20,7 +20,7 @@ struct solv_jsonparser {
   char *value;
   size_t valuelen;
 
-  int state;
+  int state;           /* START, END, OBJECT, ARRAY */
   Queue stateq;
   int nextc;
   int nextline;
index 650f594d2e28dfe49bf82f4711ef0d01f743da84..339610cd3ac1f878f699e1ea65b930a75570d259 100644 (file)
@@ -362,7 +362,21 @@ testcase_solvid2str(Pool *pool, Id p)
   e = pool_id2str(pool, s->evr);
   a = pool_id2str(pool, s->arch);
   str = pool_alloctmpspace(pool, strlen(n) + strlen(e) + strlen(a) + 3);
-  sprintf(str, "%s-%s.%s", n, e, a);
+  if (s->arch)
+    sprintf(str, "%s-%s.%s", n, e, a);
+  else
+    sprintf(str, "%s-%s", n, e);
+  if (solvable_lookup_type(s, SOLVABLE_BUILDFLAVOR))
+    {
+      Queue flavorq;
+      int i;
+
+      queue_init(&flavorq);
+      solvable_lookup_idarray(s, SOLVABLE_BUILDFLAVOR, &flavorq);
+      for (i = 0; i < flavorq.count; i++)
+       str = pool_tmpappend(pool, str, "-", pool_id2str(pool, flavorq.elements[i]));
+      queue_free(&flavorq);
+    }
   if (!s->repo)
     return pool_tmpappend(pool, str, "@", 0);
   if (s->repo->name)
@@ -417,6 +431,47 @@ testcase_str2repo(Pool *pool, const char *str)
   return repo;
 }
 
+/* check evr and buildflavors */
+static int
+str2solvid_check(Pool *pool, Solvable *s, const char *start, const char *end, Id evrid)
+{
+  if (!solvable_lookup_type(s, SOLVABLE_BUILDFLAVOR))
+    {
+      /* just check the evr */
+      return evrid && s->evr == evrid;
+    }
+  else
+    {
+      Queue flavorq;
+      int i;
+
+      queue_init(&flavorq);
+      solvable_lookup_idarray(s, SOLVABLE_BUILDFLAVOR, &flavorq);
+      queue_unshift(&flavorq, s->evr);
+      for (i = 0; i < flavorq.count; i++)
+       {
+         const char *part = pool_id2str(pool, flavorq.elements[i]);
+         size_t partl = strlen(part);
+         if (start + partl > end || strncmp(start, part, partl) != 0)
+           break;
+         start += partl;
+         if (i + 1 < flavorq.count)
+           {
+             if (start >= end || *start != '-')
+               break;
+             start++;
+           }
+       }
+      if (i < flavorq.count)
+       {
+         queue_free(&flavorq);
+         return 0;
+       }
+      queue_free(&flavorq);
+      return start == end;
+    }
+}
+
 Id
 testcase_str2solvid(Pool *pool, const char *str)
 {
@@ -456,19 +511,18 @@ testcase_str2solvid(Pool *pool, const char *str)
          if (!nid)
            continue;
          evrid = pool_strn2id(pool, str + i + 1, repostart - (i + 1), 0);
-         if (!evrid)
-           continue;
          /* first check whatprovides */
          FOR_PROVIDES(p, pp, nid)
            {
              Solvable *s = pool->solvables + p;
-             if (s->name != nid || s->evr != evrid)
+             if (s->name != nid)
                continue;
              if (repo && s->repo != repo)
                continue;
              if (arch && s->arch != arch)
                continue;
-             return p;
+             if (str2solvid_check(pool, s, str + i + 1, str + repostart, evrid))
+               return p;
            }
          /* maybe it's not installable and thus not in whatprovides. do a slow search */
          if (repo)
@@ -476,11 +530,12 @@ testcase_str2solvid(Pool *pool, const char *str)
              Solvable *s;
              FOR_REPO_SOLVABLES(repo, p, s)
                {
-                 if (s->name != nid || s->evr != evrid)
+                 if (s->name != nid)
                    continue;
                  if (arch && s->arch != arch)
                    continue;
-                 return p;
+                 if (str2solvid_check(pool, s, str + i + 1, str + repostart, evrid))
+                   return p;
                }
            }
          else
@@ -488,11 +543,12 @@ testcase_str2solvid(Pool *pool, const char *str)
              FOR_POOL_SOLVABLES(p)
                {
                  Solvable *s = pool->solvables + p;
-                 if (s->name != nid || s->evr != evrid)
+                 if (s->name != nid)
                    continue;
                  if (arch && s->arch != arch)
                    continue;
-                 return p;
+                 if (str2solvid_check(pool, s, str + i + 1, str + repostart, evrid))
+                   return p;
                }
            }
        }
index 1b781f2b057cd7331d4520fe6787598b6ebcf11b..bc03ac029031a20ea64b4546ac682cf1f82900d8 100644 (file)
@@ -32,7 +32,7 @@ pool_solvable2str(Pool *pool, Solvable *s)
   int nl, el, al;
   char *p;
   n = pool_id2str(pool, s->name);
-  e = s->evr ? pool_id2str(pool, s->evr) : 0;
+  e = s->evr ? pool_id2str(pool, s->evr) : "";
   /* XXX: may want to skip the epoch here */
   a = s->arch ? pool_id2str(pool, s->arch) : "";
   nl = strlen(n);
@@ -58,6 +58,16 @@ pool_solvable2str(Pool *pool, Solvable *s)
       p[nl + el] = pool->disttype == DISTTYPE_HAIKU ? '-' : '.';
       strcpy(p + nl + el + 1, a);
     }
+  if (pool->disttype == DISTTYPE_CONDA && solvable_lookup_type(s, SOLVABLE_BUILDFLAVOR))
+    {
+      Queue flavorq;
+      int i;
+      queue_init(&flavorq);
+      solvable_lookup_idarray(s, SOLVABLE_BUILDFLAVOR, &flavorq);
+      for (i = 0; i < flavorq.count; i++)
+       p = pool_tmpappend(pool, p, "-", pool_id2str(pool, flavorq.elements[i]));
+      queue_free(&flavorq);
+    }
   return p;
 }