Imported Upstream version 0.7.19
[platform/upstream/libsolv.git] / tools / mergesolv.c
index 87a3295..a10c686 100644 (file)
 
 #include <sys/types.h>
 #include <unistd.h>
-#include <limits.h>
-#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <getopt.h>
 
 #include "pool.h"
 #include "repo_solv.h"
+#ifdef SUSE
+#include "repo_autopattern.h"
+#endif
 #include "common_write.h"
 
 static void
@@ -33,19 +35,25 @@ usage()
   exit(0);
 }
 
-static FILE *
+static int
 loadcallback (Pool *pool, Repodata *data, void *vdata)
 {
-  FILE *fp = 0;
+  FILE *fp;
   const char *location = repodata_lookup_str(data, SOLVID_META, REPOSITORY_LOCATION);
-  if (location)
+  int r;
+
+  if (!location)
+    return 0;
+  fprintf(stderr, "Loading SOLV file %s\n", location);
+  fp = fopen (location, "r");
+  if (!fp)
     {
-      fprintf(stderr, "Loading SOLV file %s\n", location);
-      fp = fopen (location, "r");
-      if (!fp)
-       perror(location);
+      perror(location);
+      return 0;
     }
-  return fp;
+  r = repo_add_solv(data->repo, fp, REPO_USE_LOADING|REPO_LOCALPOOL);
+  fclose(fp);
+  return r ? 0 : 1;
 }
 
 int
@@ -53,14 +61,16 @@ main(int argc, char **argv)
 {
   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:")) >= 0)
+  while ((c = getopt(argc, argv, "ahX")) >= 0)
     {
       switch (c)
       {
@@ -70,10 +80,13 @@ main(int argc, char **argv)
        case 'a':
          with_attr = 1;
          break;
-       case 'b':
-         basefile = optarg;
+       case 'X':
+#ifdef SUSE
+         add_auto = 1;
+#endif
          break;
        default:
+         usage();
          exit(1);
       }
     }
@@ -88,10 +101,18 @@ main(int argc, char **argv)
          perror(argv[optind]);
          exit(1);
        }
-      repo_add_solv(repo, fp);
+      if (repo_add_solv(repo, fp, 0))
+       {
+         fprintf(stderr, "repo %s: %s\n", argv[optind], pool_errstr(pool));
+         exit(1);
+       }
       fclose(fp);
     }
-  tool_write(repo, basefile, 0);
+#ifdef SUSE
+  if (add_auto)
+    repo_add_autopattern(repo, 0);
+#endif
+  tool_write(repo, stdout);
   pool_free(pool);
   return 0;
 }