]> git.ipfire.org Git - thirdparty/libsolv.git/blame - tools/mergesolv.c
build: use GNUInstallDirs
[thirdparty/libsolv.git] / tools / mergesolv.c
CommitLineData
13127796
MS
1/*
2 * Copyright (c) 2007, Novell Inc.
3 *
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
6 */
7
50d2c054
MM
8/*
9 * mergesolv
10 *
11 */
12
13#include <sys/types.h>
a043c8ca 14#include <unistd.h>
50d2c054
MM
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
18#include <assert.h>
19
20#include "pool.h"
a00b22fc 21#include "repo_solv.h"
3c1f4d97
MS
22#ifdef SUSE
23#include "repo_autopattern.h"
24#endif
b33428b8 25#include "common_write.h"
227309d1 26
fd1cbd24
KK
27static void
28usage()
29{
30 fprintf(stderr, "\nUsage:\n"
31 "mergesolv [file] [file] [...]\n"
32 " merges multiple solv files into one and writes it to stdout\n"
33 );
34 exit(0);
35}
36
560f2046 37static int
a043c8ca
MS
38loadcallback (Pool *pool, Repodata *data, void *vdata)
39{
560f2046 40 FILE *fp;
b4385f9f 41 const char *location = repodata_lookup_str(data, SOLVID_META, REPOSITORY_LOCATION);
560f2046
MS
42 int r;
43
44 if (!location)
45 return 0;
46 fprintf(stderr, "Loading SOLV file %s\n", location);
47 fp = fopen (location, "r");
48 if (!fp)
a043c8ca 49 {
560f2046
MS
50 perror(location);
51 return 0;
a043c8ca 52 }
03c154a6 53 r = repo_add_solv(data->repo, fp, REPO_USE_LOADING|REPO_LOCALPOOL);
560f2046
MS
54 fclose(fp);
55 return r ? 0 : 1;
a043c8ca 56}
fd1cbd24 57
50d2c054
MM
58int
59main(int argc, char **argv)
60{
a043c8ca 61 Pool *pool;
227309d1 62 Repo *repo;
a043c8ca 63 int with_attr = 0;
3c1f4d97
MS
64#ifdef SUSE
65 int add_auto = 0;
66#endif
a043c8ca 67 int c;
50d2c054 68
a043c8ca
MS
69 pool = pool_create();
70 repo = repo_create(pool, "<mergesolv>");
71
63491bc9 72 while ((c = getopt(argc, argv, "ahX")) >= 0)
a043c8ca
MS
73 {
74 switch (c)
75 {
76 case 'h':
77 usage();
78 break;
79 case 'a':
80 with_attr = 1;
81 break;
3c1f4d97
MS
82 case 'X':
83#ifdef SUSE
84 add_auto = 1;
85#endif
86 break;
a043c8ca 87 default:
3c1f4d97 88 usage();
a043c8ca
MS
89 exit(1);
90 }
91 }
92 if (with_attr)
93 pool_setloadcallback(pool, loadcallback, 0);
94
95 for (; optind < argc; optind++)
50d2c054
MM
96 {
97 FILE *fp;
a043c8ca 98 if ((fp = fopen(argv[optind], "r")) == NULL)
50d2c054 99 {
a043c8ca 100 perror(argv[optind]);
b2fa614d 101 exit(1);
50d2c054 102 }
5702cc43
MS
103 if (repo_add_solv(repo, fp, 0))
104 {
105 fprintf(stderr, "repo %s: %s\n", argv[optind], pool_errstr(pool));
106 exit(1);
107 }
50d2c054
MM
108 fclose(fp);
109 }
3c1f4d97
MS
110#ifdef SUSE
111 if (add_auto)
112 repo_add_autopattern(repo, 0);
113#endif
63491bc9 114 tool_write(repo, stdout);
50d2c054 115 pool_free(pool);
50d2c054
MM
116 return 0;
117}