Imported Upstream version 0.6.21
[platform/upstream/libsolv.git] / tools / mergesolv.c
index f770fbd..6719c8c 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include <sys/types.h>
+#include <unistd.h>
 #include <limits.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -20,6 +21,9 @@
 
 #include "pool.h"
 #include "repo_solv.h"
+#ifdef SUSE
+#include "repo_autopattern.h"
+#endif
 #include "common_write.h"
 
 static void
@@ -32,31 +36,88 @@ usage()
   exit(0);
 }
 
+static int
+loadcallback (Pool *pool, Repodata *data, void *vdata)
+{
+  FILE *fp;
+  const char *location = repodata_lookup_str(data, SOLVID_META, REPOSITORY_LOCATION);
+  int r;
+
+  if (!location)
+    return 0;
+  fprintf(stderr, "Loading SOLV file %s\n", location);
+  fp = fopen (location, "r");
+  if (!fp)
+    {
+      perror(location);
+      return 0;
+    }
+  r = repo_add_solv(data->repo, fp, REPO_USE_LOADING|REPO_LOCALPOOL);
+  fclose(fp);
+  return r ? 0 : 1;
+}
 
 int
 main(int argc, char **argv)
 {
-  Pool *pool = pool_create();
+  Pool *pool;
   Repo *repo;
+  const char *basefile = 0;
+  int with_attr = 0;
+#ifdef SUSE
+  int add_auto = 0;
+#endif
+  int c;
+
+  pool = pool_create();
+  repo = repo_create(pool, "<mergesolv>");
+  
+  while ((c = getopt(argc, argv, "ahb:X")) >= 0)
+    {
+      switch (c)
+      {
+       case 'h':
+         usage();
+         break;
+       case 'a':
+         with_attr = 1;
+         break;
+       case 'b':
+         basefile = optarg;
+         break;
+       case 'X':
+#ifdef SUSE
+         add_auto = 1;
+#endif
+         break;
+       default:
+         usage();
+         exit(1);
+      }
+    }
+  if (with_attr)
+    pool_setloadcallback(pool, loadcallback, 0);
 
-  repo = repo_create(pool, "");
-  while (argc-- > 1)
+  for (; optind < argc; optind++)
     {
       FILE *fp;
-      argv++;
-      if (!strcmp(*argv,"-h"))
-       usage();
-      if ((fp = fopen(*argv, "r")) == NULL)
+      if ((fp = fopen(argv[optind], "r")) == NULL)
+       {
+         perror(argv[optind]);
+         exit(1);
+       }
+      if (repo_add_solv(repo, fp, 0))
        {
-         perror(argv[1]);
-         exit(0);
+         fprintf(stderr, "repo %s: %s\n", argv[optind], pool_errstr(pool));
+         exit(1);
        }
-      repo_add_solv(repo, fp);
       fclose(fp);
     }
-
-  tool_write(repo, 0, 0);
+#ifdef SUSE
+  if (add_auto)
+    repo_add_autopattern(repo, 0);
+#endif
+  tool_write(repo, basefile, 0);
   pool_free(pool);
-
   return 0;
 }