also simplify solvable_copy_cb's checksum handling
[platform/upstream/libsolv.git] / ext / repo_mdk.c
index 43b6f2e..1bf6f17 100644 (file)
@@ -95,7 +95,9 @@ repo_add_mdk(Repo *repo, FILE *fp, int flags)
   while (fgets(buf + bufl, bufa - bufl, fp) > 0)
     {
       bufl += strlen(buf + bufl);
-      if (bufl && buf[bufl - 1] != '\n')
+      if (!bufl)
+       continue;
+      if (buf[bufl - 1] != '\n')
        {
          if (bufa - bufl < 256)
            {
@@ -104,7 +106,7 @@ repo_add_mdk(Repo *repo, FILE *fp, int flags)
            }
          continue;
        }
-      buf[--bufl] = 0;
+      buf[bufl - 1] = 0;
       bufl = 0;
       if (buf[0] != '@')
        {
@@ -241,7 +243,7 @@ repo_add_mdk(Repo *repo, FILE *fp, int flags)
   if (s)
     {
       pool_debug(pool, SOLV_ERROR, "unclosed package at EOF\n");
-      repo_free_solvable_block(s->repo, s - pool->solvables, 1, 1);
+      repo_free_solvable(s->repo, s - pool->solvables, 1);
     }
   solv_free(buf);
   if (!(flags & REPO_NO_INTERNALIZE))
@@ -253,6 +255,7 @@ enum state {
   STATE_START,
   STATE_MEDIA_INFO,
   STATE_INFO,
+  STATE_FILES,
   NUMSTATES
 };
 
@@ -267,6 +270,7 @@ struct stateswitch {
 static struct stateswitch stateswitches[] = {
   { STATE_START, "media_info", STATE_MEDIA_INFO, 0 },
   { STATE_MEDIA_INFO, "info", STATE_INFO, 1 },
+  { STATE_MEDIA_INFO, "files", STATE_FILES, 1 },
   { NUMSTATES }
 };
 
@@ -285,7 +289,7 @@ struct parsedata {
   enum state sbtab[NUMSTATES];
   Solvable *solvable;
   Hashtable joinhash;
-  Hashmask joinhashmask;
+  Hashval joinhashmask;
 };
 
 static inline const char *
@@ -300,9 +304,9 @@ find_attr(const char *txt, const char **atts)
 }
 
 static Hashtable
-joinhash_init(Repo *repo, Hashmask *hmp)
+joinhash_init(Repo *repo, Hashval *hmp)
 {
-  Hashmask hm = mkmask(repo->nsolvables);
+  Hashval hm = mkmask(repo->nsolvables);
   Hashtable ht = solv_calloc(hm + 1, sizeof(*ht));
   Hashval h, hh;
   Solvable *s;
@@ -321,7 +325,7 @@ joinhash_init(Repo *repo, Hashmask *hmp)
 }
 
 static Solvable *
-joinhash_lookup(Repo *repo, Hashtable ht, Hashmask hm, const char *fn, const char *distepoch)
+joinhash_lookup(Repo *repo, Hashtable ht, Hashval hm, const char *fn, const char *distepoch)
 {
   Hashval h, hh;
   const char *p, *vrstart, *vrend;
@@ -389,51 +393,6 @@ joinhash_lookup(Repo *repo, Hashtable ht, Hashmask hm, const char *fn, const cha
   return 0;
 }
 
-static void
-set_sourcerpm(Repodata *data, Solvable *s, Id handle, const char *sourcerpm)
-{
-  const char *p, *sevr, *sarch, *name, *evr;
-  Pool *pool;
-
-  p = strrchr(sourcerpm, '.');
-  if (!p || strcmp(p, ".rpm") != 0)
-    return;
-  p--;
-  while (p > sourcerpm && *p != '.')
-    p--;
-  if (*p != '.' || p == sourcerpm)
-    return;
-  sarch = p-- + 1;
-  while (p > sourcerpm && *p != '-')
-    p--;
-  if (*p != '-' || p == sourcerpm)
-    return;
-  p--;
-  while (p > sourcerpm && *p != '-')
-    p--;
-  if (*p != '-' || p == sourcerpm)
-    return;
-  sevr = p + 1;
-  pool = s->repo->pool;
-  if (!strcmp(sarch, "src.rpm"))
-    repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, ARCH_SRC);
-  else if (!strcmp(sarch, "nosrc.rpm"))
-    repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, ARCH_NOSRC);
-  else
-    repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, pool_strn2id(pool, sarch, strlen(sarch) - 4, 1));
-  evr = pool_id2str(pool, s->evr);
-  if (evr && !strncmp(sevr, evr, sarch - sevr - 1) && evr[sarch - sevr - 1] == 0)
-    repodata_set_void(data, handle, SOLVABLE_SOURCEEVR);
-  else
-    repodata_set_id(data, handle, SOLVABLE_SOURCEEVR, pool_strn2id(pool, sevr, sarch - sevr - 1, 1));
-  name = pool_id2str(pool, s->name);
-  if (name && !strncmp(sourcerpm, name, sevr - sourcerpm - 1) && name[sevr - sourcerpm - 1] == 0)
-    repodata_set_void(data, handle, SOLVABLE_SOURCENAME);
-  else
-    repodata_set_id(data, handle, SOLVABLE_SOURCENAME, pool_strn2id(pool, sourcerpm, sevr - sourcerpm - 1, 1));
-}
-
-
 static void XMLCALL
 startElement(void *userData, const char *name, const char **atts)
 {
@@ -477,7 +436,14 @@ startElement(void *userData, const char *name, const char **atts)
          repodata_set_poolstr(pd->data, pd->solvable - pool->solvables, SOLVABLE_LICENSE, str);
        str = find_attr("sourcerpm", atts);
        if (str && *str)
-         set_sourcerpm(pd->data, pd->solvable, pd->solvable - pool->solvables, str);
+         repodata_set_sourcepkg(pd->data, pd->solvable - pool->solvables, str);
+        break;
+      }
+    case STATE_FILES:
+      {
+       const char *fn = find_attr("fn", atts);
+       const char *distepoch = find_attr("distepoch", atts);
+       pd->solvable = joinhash_lookup(pd->repo, pd->joinhash, pd->joinhashmask, fn, distepoch);
         break;
       }
     default:
@@ -503,6 +469,35 @@ endElement(void *userData, const char *name)
       if (s && *pd->content)
         repodata_set_str(pd->data, s - pd->pool->solvables, SOLVABLE_DESCRIPTION, pd->content);
       break;
+    case STATE_FILES:
+      if (s && *pd->content)
+       {
+         char *np, *p, *sl;
+         for (p = pd->content; p && *p; p = np)
+           {
+             Id id;
+             np = strchr(p, '\n');
+             if (np)
+               *np++ = 0;
+             if (!*p)
+               continue;
+             sl = strrchr(p, '/');
+             if (sl)
+               {
+                 *sl++ = 0;
+                 id = repodata_str2dir(pd->data, p, 1);
+               }
+             else
+               {
+                 sl = p;
+                 id = 0;
+               }
+             if (!id)
+               id = repodata_str2dir(pd->data, "/", 1);
+             repodata_add_dirstr(pd->data, s - pd->pool->solvables, SOLVABLE_FILELIST, id, sl);
+           }
+       }
+      break;
     default:
       break;
     }