- INCOMPATIBLE CHANGE: index with repoid (thus pool->repos[repoid] == repo->repoid)
[platform/upstream/libsolv.git] / tools / dumpsolv.c
index 3e95f0c..681e98b 100644 (file)
@@ -15,45 +15,33 @@ static int with_attr = 0;
 #include "pool.h"
 #include "repo_solv.h"
 
+static int dump_repoattrs_cb(void *vcbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv);
+
 static void
-dump_repodata (Repo *repo)
+dump_repodata(Repo *repo)
 {
   unsigned i;
   Repodata *data;
   if (repo->nrepodata == 0)
     return;
-  for (i = 0; i < 32; i++)
-    if (repo->rpmdbcookie[i])
-      break;
-  if (i < 32)
-    {
-      printf("rpmdb cookie: ");
-      for (i = 0; i < 32; i++)
-       printf("%02x", repo->rpmdbcookie[i]);
-      printf("\n");
-    }
-  printf("repo refers to %d subfiles:\n", repo->nrepodata);
-  for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
+  printf("repo contains %d repodata sections:\n", repo->nrepodata);
+  FOR_REPODATAS(repo, i, data)
     {
       unsigned int j;
-      printf("%s has %d keys, %d schemata\n", data->location ? data->location : "**EMBED**", data->nkeys, data->nschemata);
+      printf("\nrepodata %d has %d keys, %d schemata\n", i + 1, data->nkeys - 1, data->nschemata - 1);
       for (j = 1; j < data->nkeys; j++)
-        printf("  %s (type %s size %d storage %d)\n", id2str(repo->pool, data->keys[j].name), id2str(repo->pool, data->keys[j].type), data->keys[j].size, data->keys[j].storage);
+        printf("  %s (type %s size %d storage %d)\n", pool_id2str(repo->pool, data->keys[j].name), pool_id2str(repo->pool, data->keys[j].type), data->keys[j].size, data->keys[j].storage);
       if (data->localpool)
        printf("  localpool has %d strings, size is %d\n", data->spool.nstrings, data->spool.sstrings);
       if (data->dirpool.ndirs)
        printf("  localpool has %d directories\n", data->dirpool.ndirs);
-      if (data->addedfileprovides)
-       {
-         printf("  added file provides:\n");
-         for (j = 0; data->addedfileprovides[j]; j++)
-           printf("    %s\n", id2str(repo->pool, data->addedfileprovides[j]));
-       }
       printf("\n");
+      repodata_search(data, SOLVID_META, 0, SEARCH_ARRAYSENTINEL|SEARCH_SUB, dump_repoattrs_cb, 0);
     }
   printf("\n");
 }
 
+#if 0
 static void
 printids(Repo *repo, char *kind, Offset ido)
 {
@@ -64,32 +52,39 @@ printids(Repo *repo, char *kind, Offset ido)
   printf("%s:\n", kind);
   ids = repo->idarraydata + ido;
   while((id = *ids++) != 0)
-    printf("  %s\n", dep2str(pool, id));
+    printf("  %s\n", pool_dep2str(pool, id));
 }
+#endif
 
 int
 dump_attr(Repo *repo, Repodata *data, Repokey *key, KeyValue *kv)
 {
   const char *keyname;
+  KeyValue *kvp;
+  int indent = 0;
 
-  keyname = id2str(repo->pool, key->name);
+  keyname = pool_id2str(repo->pool, key->name);
+  for (kvp = kv; (kvp = kvp->parent) != 0; indent += 2)
+    printf("  ");
   switch(key->type)
     {
     case REPOKEY_TYPE_ID:
       if (data && data->localpool)
        kv->str = stringpool_id2str(&data->spool, kv->id);
       else
-        kv->str = id2str(repo->pool, kv->id);
+        kv->str = pool_id2str(repo->pool, kv->id);
       printf("%s: %s\n", keyname, kv->str);
       break;
     case REPOKEY_TYPE_CONSTANTID:
-      printf("%s: %s\n", keyname, dep2str(repo->pool, kv->id));
+      printf("%s: %s\n", keyname, pool_dep2str(repo->pool, kv->id));
       break;
     case REPOKEY_TYPE_IDARRAY:
+      if (!kv->entry)
+        printf("%s:\n%*s", keyname, indent, "");
       if (data && data->localpool)
-        printf("%s: %s\n", keyname, stringpool_id2str(&data->spool, kv->id));
+        printf("  %s\n", stringpool_id2str(&data->spool, kv->id));
       else
-        printf("%s: %s\n", keyname, dep2str(repo->pool, kv->id));
+        printf("  %s\n", pool_dep2str(repo->pool, kv->id));
       break;
     case REPOKEY_TYPE_STR:
       printf("%s: %s\n", keyname, kv->str);
@@ -97,7 +92,7 @@ dump_attr(Repo *repo, Repodata *data, Repokey *key, KeyValue *kv)
     case REPOKEY_TYPE_MD5:
     case REPOKEY_TYPE_SHA1:
     case REPOKEY_TYPE_SHA256:
-      printf("%s: %s\n", keyname, repodata_chk2str(data, key->type, (unsigned char *)kv->str));
+      printf("%s: %s (%s)\n", keyname, repodata_chk2str(data, key->type, (unsigned char *)kv->str), pool_id2str(repo->pool, key->type));
       break;
     case REPOKEY_TYPE_VOID:
       printf("%s: (void)\n", keyname);
@@ -107,14 +102,28 @@ dump_attr(Repo *repo, Repodata *data, Repokey *key, KeyValue *kv)
     case REPOKEY_TYPE_CONSTANT:
       printf("%s: %d\n", keyname, kv->num);
       break;
+    case REPOKEY_TYPE_BINARY:
+      if (kv->num)
+        printf("%s: %02x..%02x len %d\n", keyname, (unsigned char)kv->str[0], (unsigned char)kv->str[kv->num - 1], kv->num);
+      else
+        printf("%s: len 0\n", keyname);
+      break;
     case REPOKEY_TYPE_DIRNUMNUMARRAY:
-      printf("%s: %s %d %d\n", keyname, repodata_dir2str(data, kv->id, 0), kv->num, kv->num2);
+      if (!kv->entry)
+        printf("%s:\n%*s", keyname, indent, "");
+      printf("  %s %d %d\n", repodata_dir2str(data, kv->id, 0), kv->num, kv->num2);
       break;
     case REPOKEY_TYPE_DIRSTRARRAY:
-      printf("%s: %s\n", keyname, repodata_dir2str(data, kv->id, kv->str));
+      if (!kv->entry)
+        printf("%s:\n%*s", keyname, indent, "");
+      printf("  %s\n", repodata_dir2str(data, kv->id, kv->str));
       break;
-    case REPOKEY_TYPE_COUNTED:
-      printf("%s: %s\n", keyname, kv->eof == 0 ? "open" : kv->eof == 1 ? "next" : "close");
+    case REPOKEY_TYPE_FIXARRAY:
+    case REPOKEY_TYPE_FLEXARRAY:
+      if (!kv->entry)
+        printf("%s:\n", keyname);
+      else
+        printf("\n");
       break;
     default:
       printf("%s: ?\n", keyname);
@@ -123,11 +132,15 @@ dump_attr(Repo *repo, Repodata *data, Repokey *key, KeyValue *kv)
   return 0;
 }
 
-/*static int
+#if 1
+static int
 dump_repoattrs_cb(void *vcbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
 {
-  return dump_attr(s->repo, data, key, kv);
-}*/
+  if (key->name == REPOSITORY_SOLVABLES)
+    return SEARCH_NEXT_SOLVABLE;
+  return dump_attr(data->repo, data, key, kv);
+}
+#endif
 
 /*
  * dump all attributes for Id <p>
@@ -137,10 +150,10 @@ void
 dump_repoattrs(Repo *repo, Id p)
 {
 #if 0
-  repo_search(repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE, dump_repoattrs_cb, 0);
+  repo_search(repo, p, 0, 0, SEARCH_ARRAYSENTINEL|SEARCH_SUB, dump_repoattrs_cb, 0);
 #else
   Dataiterator di;
-  dataiterator_init(&di, repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE);
+  dataiterator_init(&di, repo->pool, repo, p, 0, 0, SEARCH_ARRAYSENTINEL|SEARCH_SUB);
   while (dataiterator_step(&di))
     dump_attr(repo, di.data, di.key, &di.kv);
 #endif
@@ -162,31 +175,38 @@ dump_some_attrs(Repo *repo, Solvable *s)
 #endif
 
 
-static FILE *
+static int
 loadcallback (Pool *pool, Repodata *data, void *vdata)
 {
   FILE *fp = 0;
-  if (data->location && with_attr)
+  int r;
+
+printf("LOADCALLBACK\n");
+  const char *location = repodata_lookup_str(data, SOLVID_META, REPOSITORY_LOCATION);
+printf("loc %s\n", location);
+  if (!location || !with_attr)
+    return 0;
+  fprintf (stderr, "Loading SOLV file %s\n", location);
+  fp = fopen (location, "r");
+  if (!fp)
     {
-      fprintf (stderr, "Loading SOLV file %s\n", data->location);
-      fp = fopen (data->location, "r");
-      if (!fp)
-       perror(data->location);
+      perror(location);
+      return 0;
     }
-  return fp;
+  r = repo_add_solv_flags(data->repo, fp, REPO_USE_LOADING|REPO_LOCALPOOL);
+  fclose(fp);
+  return !r ? 1 : 0;
 }
 
 
 static void
-usage( const char *err )
+usage(int status)
 {
-  if (err)
-    fprintf (stderr, "\n** Error:\n  %s\n", err);
   fprintf( stderr, "\nUsage:\n"
           "dumpsolv [-a] [<solvfile>]\n"
           "  -a  read attributes.\n"
           );
-  exit(0);
+  exit(status);
 }
 
 #if 0
@@ -204,7 +224,7 @@ tryme (Repo *repo, Id p, Id keyname, const char *match, int flags)
              if (di.data && di.data->localpool)
                di.kv.str = stringpool_id2str(&di.data->spool, di.kv.id);
              else
-               di.kv.str = id2str(repo->pool, di.kv.id);
+               di.kv.str = pool_id2str(repo->pool, di.kv.id);
              break;
          case REPOKEY_TYPE_STR:
          case REPOKEY_TYPE_DIRSTRARRAY:
@@ -214,7 +234,7 @@ tryme (Repo *repo, Id p, Id keyname, const char *match, int flags)
        }
       fprintf (stdout, "found: %d:%s %d %s %d %d %d\n",
               di.solvid,
-              id2str(repo->pool, di.key->name),
+              pool_id2str(repo->pool, di.key->name),
               di.kv.id,
               di.kv.str, di.kv.num, di.kv.num2, di.kv.eof);
     }
@@ -225,64 +245,74 @@ int main(int argc, char **argv)
 {
   Repo *repo;
   Pool *pool;
-  int i, j, n;
+  int c, i, j, n;
   Solvable *s;
   
   pool = pool_create();
   pool_setdebuglevel(pool, 1);
   pool_setloadcallback(pool, loadcallback, 0);
 
-  argv++;
-  argc--;
-  while (argc--)
+  while ((c = getopt(argc, argv, "ha")) >= 0)
     {
-      const char *s = argv[0];
-      if (*s++ == '-')
-        while (*s)
-          switch (*s++)
-           {
-             case 'h': usage(NULL); break;
-             case 'a': with_attr = 1; break;
-             default : break;
-           }
-      else
+      switch(c)
        {
-         if (freopen (argv[0], "r", stdin) == 0)
-           {
-             perror(argv[0]);
-             exit(1);
-           }
-         repo = repo_create(pool, argv[0]);
-         if (repo_add_solv(repo, stdin))
-           printf("could not read repository\n");
+       case 'h':
+         usage(0);
+         break;
+       case 'a':
+         with_attr = 1;
+         break;
+       default:
+          usage(1);
+          break;
        }
-      argv++;
     }
-
-  if (!pool->nrepos)
+  for (; optind < argc; optind++)
+    {
+      if (freopen(argv[optind], "r", stdin) == 0)
+       {
+         perror(argv[optind]);
+         exit(1);
+       }
+      repo = repo_create(pool, argv[optind]);
+      if (repo_add_solv(repo, stdin))
+       printf("could not read repository\n");
+    }
+  if (!pool->urepos)
     {
       repo = repo_create(pool, argc != 1 ? argv[1] : "<stdin>");
       if (repo_add_solv(repo, stdin))
        printf("could not read repository\n");
     }
   printf("pool contains %d strings, %d rels, string size is %d\n", pool->ss.nstrings, pool->nrels, pool->ss.sstrings);
-  for (j = 0; 1 && j < pool->nrepos; j++)
+
+#if 0
+{
+  Dataiterator di;
+  dataiterator_init(&di, repo, -1, 0, "oo", DI_SEARCHSUB|SEARCH_SUBSTRING);
+  while (dataiterator_step(&di))
+    dump_attr(di.repo, di.data, di.key, &di.kv);
+  exit(0);
+}
+#endif
+
+  n = 0;
+  FOR_REPOS(j, repo)
     {
-      repo = pool->repos[j];
       dump_repodata(repo);
-      printf("repo %d contains %d solvables %d non-solvables\n", j, repo->nsolvables, repo->nextra);
+
+      printf("repo %d contains %d solvables\n", j, repo->nsolvables);
       printf("repo start: %d end: %d\n", repo->start, repo->end);
-      for (i = repo->start, n = 1; i < repo->end; i++)
+      FOR_REPO_SOLVABLES(repo, i, s)
        {
-         s = pool->solvables + i;
-         if (s->repo != repo)
-           continue;
+         n++;
          printf("\n");
          printf("solvable %d (%d):\n", n, i);
+#if 0
          if (s->name || s->evr || s->arch)
-           printf("name: %s %s %s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
+           printf("name: %s %s %s\n", pool_id2str(pool, s->name), pool_id2str(pool, s->evr), pool_id2str(pool, s->arch));
          if (s->vendor)
-           printf("vendor: %s\n", id2str(pool, s->vendor));
+           printf("vendor: %s\n", pool_id2str(pool, s->vendor));
          printids(repo, "provides", s->provides);
          printids(repo, "obsoletes", s->obsoletes);
          printids(repo, "conflicts", s->conflicts);
@@ -293,22 +323,11 @@ int main(int argc, char **argv)
          printids(repo, "enhances", s->enhances);
          if (repo->rpmdbid)
            printf("rpmdbid: %u\n", repo->rpmdbid[i - repo->start]);
-#if 0
-         dump_attrs (repo, n - 1);
 #endif
          dump_repoattrs(repo, i);
 #if 0
          dump_some_attrs(repo, s);
 #endif
-         n++;
-       }
-      for (i = 0; i < repo->nextra; i++)
-       {
-         printf("\nextra %d:\n", i);
-         Dataiterator di;
-         dataiterator_init(&di, repo, -1 - i, 0, 0, SEARCH_EXTRA | SEARCH_NO_STORAGE_SOLVABLE);
-         while (dataiterator_step(&di))
-           dump_attr(repo, di.data, di.key, &di.kv);
        }
 #if 0
       tryme(repo, 0, SOLVABLE_MEDIANR, 0, 0);
@@ -321,7 +340,7 @@ int main(int argc, char **argv)
 #if 0
   printf ("\nSearchresults:\n");
   Dataiterator di;
-  dataiterator_init(&di, pool->repos[0], 0, 0, "3", SEARCH_EXTRA | SEARCH_SUBSTRING | SEARCH_ALL_REPOS | SEARCH_FILES);
+  dataiterator_init(&di, pool, 0, 0, 0, "3", SEARCH_SUB | SEARCH_SUBSTRING | SEARCH_FILES);
   //int count = 0;
   while (dataiterator_step(&di))
     {