1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*
* Copyright (c) 2007, Novell Inc.
*
* This program is licensed under the BSD license, read LICENSE.BSD
* for further information
*/
/*
* mergesolv
*
*/
#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 "pool.h"
#include "repo_solv.h"
#include "common_write.h"
static void
usage()
{
fprintf(stderr, "\nUsage:\n"
"mergesolv [file] [file] [...]\n"
" merges multiple solv files into one and writes it to stdout\n"
);
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;
Repo *repo;
const char *basefile = 0;
int with_attr = 0;
int c;
pool = pool_create();
repo = repo_create(pool, "<mergesolv>");
while ((c = getopt(argc, argv, "ahb:")) >= 0)
{
switch (c)
{
case 'h':
usage();
break;
case 'a':
with_attr = 1;
break;
case 'b':
basefile = optarg;
break;
default:
exit(1);
}
}
if (with_attr)
pool_setloadcallback(pool, loadcallback, 0);
for (; optind < argc; optind++)
{
FILE *fp;
if ((fp = fopen(argv[optind], "r")) == NULL)
{
perror(argv[optind]);
exit(1);
}
repo_add_solv(repo, fp, 0);
fclose(fp);
}
tool_write(repo, basefile, 0);
pool_free(pool);
return 0;
}
|