add repodata_set_deltalocation and use it in the parsers
[platform/upstream/libsolv.git] / src / repodata.c
index d64a00b..a812ba8 100644 (file)
@@ -1593,6 +1593,11 @@ dataiterator_step(Dataiterator *di)
          if (!datamatcher_match(&di->matcher, di->kv.str))
            continue;
        }
+      else
+       {
+         if (di->keyname == SOLVABLE_FILELIST && di->key->type == REPOKEY_TYPE_DIRSTRARRAY && (di->flags & SEARCH_FILES) != 0)
+           repodata_stringify(di->pool, di->data, di->key, &di->kv, di->flags);
+       }
       /* found something! */
       return 1;
     }
@@ -2299,6 +2304,86 @@ repodata_set_location(Repodata *data, Id solvid, int medianr, const char *dir, c
   repodata_set_str(data, solvid, SOLVABLE_MEDIAFILE, file);
 }
 
+static inline void repodata_set_poolstrn(Repodata *data, Id solvid, Id keyname, const char *str, int l)
+{
+  Id id;
+  if (data->localpool)
+    id = stringpool_strn2id(&data->spool, str, l, 1);
+  else
+    id = pool_strn2id(data->repo->pool, str, l, 1);
+  repodata_set_id(data, solvid, keyname, id);
+}
+
+/* XXX: medianr is currently not stored */
+void
+repodata_set_deltalocation(Repodata *data, Id handle, int medianr, const char *dir, const char *file)
+{
+  int l = 0;
+  const char *evr, *suf, *s;
+
+  if (!dir)
+    {
+      if ((dir = strrchr(file, '/')) != 0)
+       {
+          l = dir - file;
+         dir = file;
+         file = dir + l + 1;
+         if (!l)
+           l++;
+       }
+    }
+  else
+    l = strlen(dir);
+  if (l >= 2 && dir[0] == '.' && dir[1] == '/' && (l == 2 || dir[2] != '/'))
+    {
+      dir += 2;
+      l -= 2;
+    }
+  if (l == 1 && dir[0] == '.')
+    l = 0;
+  if (dir && l)
+    repodata_set_poolstrn(data, handle, DELTA_LOCATION_DIR, dir, l);
+  evr = strchr(file, '-');
+  if (evr)
+    {
+      for (s = evr - 1; s > file; s--)
+       if (*s == '-')
+         {
+           evr = s;
+           break;
+         }
+    }
+  suf = strrchr(file, '.');
+  if (suf)
+    {
+      for (s = suf - 1; s > file; s--)
+       if (*s == '.')
+         {
+           suf = s;
+           break;
+         }
+      if (!strcmp(suf, ".delta.rpm") || !strcmp(suf, ".patch.rpm"))
+       {
+         /* We accept one more item as suffix.  */
+         for (s = suf - 1; s > file; s--)
+           if (*s == '.')
+             {
+               suf = s;
+               break;
+             }
+       }
+    }
+  if (!evr)
+    suf = 0;
+  if (suf && evr && suf < evr)
+    suf = 0;
+  repodata_set_poolstrn(data, handle, DELTA_LOCATION_NAME, file, evr ? evr - file : strlen(file));
+  if (evr)
+    repodata_set_poolstrn(data, handle, DELTA_LOCATION_EVR, evr + 1, suf ? suf - evr - 1: strlen(evr + 1));
+  if (suf)
+    repodata_set_poolstr(data, handle, DELTA_LOCATION_SUFFIX, suf + 1);
+}
+
 void
 repodata_set_sourcepkg(Repodata *data, Id solvid, const char *sourcepkg)
 {
@@ -2444,7 +2529,7 @@ repodata_add_flexarray(Repodata *data, Id solvid, Id keyname, Id ghandle)
 }
 
 void
-repodata_delete_uninternalized(Repodata *data, Id solvid, Id keyname)
+repodata_set_deleted_uninternalized(Repodata *data, Id solvid, Id keyname)
 {
   Id *pp, *ap, **app;
   app = repodata_get_attrp(data, solvid);
@@ -2470,7 +2555,7 @@ repodata_delete_uninternalized(Repodata *data, Id solvid, Id keyname)
 
 /* XXX: does not work correctly, needs fix in iterators! */
 void
-repodata_delete(Repodata *data, Id solvid, Id keyname)
+repodata_set_deleted(Repodata *data, Id solvid, Id keyname)
 {
   Repokey key;
   key.name = keyname;