Imported Upstream version 0.7.4
[platform/upstream/libsolv.git] / tools / rpmdb2solv.c
index e6ed72a..1a04adf 100644 (file)
@@ -15,8 +15,6 @@
  */
 
 #include <sys/types.h>
-#include <limits.h>
-#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "repo_products.h"
 #include "repo_solv.h"
 #include "common_write.h"
+#ifdef ENABLE_APPDATA
+#include "repo_appdata.h"
+#endif
+#ifdef SUSE
+#include "repo_autopattern.h"
+#endif
+
 
 static void
 usage(int status)
 {
   fprintf(stderr, "\nUsage:\n"
-         "rpmdb2solv [-n] [-b <basefile>] [-p <productsdir>] [-r <root>]\n"
+         "rpmdb2solv [-P] [-C] [-n] [-b <basefile>] [-p <productsdir>] [-r <root>]\n"
          " -n : No packages, do not read rpmdb, useful to only parse products\n"
-         " -b <basefile> : Write .solv to <basefile>.solv instead of stdout\n"
          " -p <productsdir> : Scan <productsdir> for .prod files, representing installed products\n"
          " -r <root> : Prefix rpmdb path and <productsdir> with <root>\n"
          " -o <solv> : Write .solv to file instead of stdout\n"
+          " -P : print percentage done\n"
+          " -C : include the changelog\n"
         );
   exit(status);
 }
@@ -56,8 +62,8 @@ main(int argc, char **argv)
   Repodata *data;
   int c, percent = 0;
   int nopacks = 0;
+  int add_changelog = 0;
   const char *root = 0;
-  const char *basefile = 0;
   const char *refname = 0;
 #ifdef ENABLE_SUSEREPO
   char *proddir = 0;
@@ -66,12 +72,18 @@ main(int argc, char **argv)
 #ifdef ENABLE_PUBKEY
   int pubkeys = 0;
 #endif
+#ifdef ENABLE_APPDATA
+  int add_appdata = 0;
+#endif
+#ifdef SUSE
+  int add_auto = 0;
+#endif
 
   /*
    * parse arguments
    */
   
-  while ((c = getopt(argc, argv, "Phnkxb:r:p:o:")) >= 0)
+  while ((c = getopt(argc, argv, "ACPhnkxXr:p:o:")) >= 0)
     switch (c)
       {
       case 'h':
@@ -80,9 +92,6 @@ main(int argc, char **argv)
       case 'r':
         root = optarg;
         break;
-      case 'b':
-        basefile = optarg;
-        break;
       case 'n':
        nopacks = 1;
        break;
@@ -95,7 +104,17 @@ main(int argc, char **argv)
 #endif
        break;
       case 'x':
-        break;
+        break; /* extrapool no longer supported */
+      case 'X':
+#ifdef SUSE
+       add_auto = 1;
+#endif
+       break;
+      case 'A':
+#ifdef ENABLE_APPDATA
+       add_appdata = 1;
+#endif
+       break;
       case 'o':
         outfile = optarg;
         break;
@@ -105,6 +124,9 @@ main(int argc, char **argv)
         pubkeys = 1;
         break;
 #endif
+      case 'C':
+       add_changelog = 1;
+       break;
       default:
        usage(1);
       }
@@ -144,7 +166,12 @@ main(int argc, char **argv)
 
   if (!nopacks)
     {
-      if (repo_add_rpmdb_reffp(repo, reffp, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | (percent ? RPMDB_REPORT_PROGRESS : 0)))
+      int flags = REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE;
+      if (percent)
+       flags |= RPMDB_REPORT_PROGRESS;
+      if (add_changelog)
+       flags |= RPM_ADD_WITH_CHANGELOG;
+      if (repo_add_rpmdb_reffp(repo, reffp, flags))
        {
          fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
          exit(1);
@@ -153,7 +180,7 @@ main(int argc, char **argv)
 #ifdef ENABLE_PUBKEY
   if (pubkeys)
     {
-      if (repo_add_rpmdb_pubkeys(repo, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
+      if (repo_add_rpmdb_pubkeys(repo, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | ADD_WITH_KEYSIGNATURES))
        {
          fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
          exit(1);
@@ -181,12 +208,25 @@ main(int argc, char **argv)
        }
     }
 #endif
+
+#ifdef ENABLE_APPDATA
+  if (add_appdata)
+    {
+      repo_add_appdata_dir(repo, "/usr/share/metainfo", REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | APPDATA_SEARCH_UNINTERNALIZED_FILELIST);
+      repo_add_appdata_dir(repo, "/usr/share/appdata", REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | APPDATA_SEARCH_UNINTERNALIZED_FILELIST);
+    }
+#endif
   repodata_internalize(data);
 
   if (reffp)
     fclose(reffp);
 
-  tool_write(repo, basefile, 0);
+#ifdef SUSE
+  if (add_auto)
+    repo_add_autopattern(repo, ADD_NO_AUTOPRODUCTS);
+#endif
+
+  tool_write(repo, stdout);
   pool_free(pool);
   exit(0);
 }