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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
/*
* Copyright (c) 2007, Novell Inc.
*
* This program is licensed under the BSD license, read LICENSE.BSD
* for further information
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
static int with_attr = 0;
#include "pool.h"
#include "repo_solv.h"
static void
dump_repodata (Repo *repo)
{
unsigned i;
Repodata *data;
if (repo->nrepodata == 0)
return;
printf("repo refers to %d subfiles:\n", repo->nrepodata);
for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
{
unsigned int j;
printf("%s has %d keys, %d schemata\n", data->location ? data->location : "**EMBED**", data->nkeys, data->nschemata);
for (j = 1; j < data->nkeys; j++)
printf(" %s (type %s size %d storage %d)\n", id2str(repo->pool, data->keys[j].name), id2str(repo->pool, data->keys[j].type), data->keys[j].size, data->keys[j].storage);
if (data->localpool)
printf(" localpool has %d strings, size is %d\n", data->spool.nstrings, data->spool.sstrings);
if (data->dirpool.ndirs)
printf(" localpool has %d directories\n", data->dirpool.ndirs);
if (data->addedfileprovides)
{
printf(" added file provides:\n");
for (j = 0; data->addedfileprovides[j]; j++)
printf(" %s\n", id2str(repo->pool, data->addedfileprovides[j]));
}
printf("\n");
}
printf("\n");
}
static void
printids(Repo *repo, char *kind, Offset ido)
{
Pool *pool = repo->pool;
Id id, *ids;
if (!ido)
return;
printf("%s:\n", kind);
ids = repo->idarraydata + ido;
while((id = *ids++) != 0)
printf(" %s\n", dep2str(pool, id));
}
int
dump_attr(Repo *repo, Repodata *data, Repokey *key, KeyValue *kv)
{
const char *keyname;
keyname = id2str(repo->pool, key->name);
switch(key->type)
{
case REPOKEY_TYPE_ID:
if (data && data->localpool)
kv->str = stringpool_id2str(&data->spool, kv->id);
else
kv->str = id2str(repo->pool, kv->id);
printf("%s: %s\n", keyname, kv->str);
break;
case REPOKEY_TYPE_CONSTANTID:
printf("%s: %s\n", keyname, dep2str(repo->pool, kv->id));
break;
case REPOKEY_TYPE_IDARRAY:
if (data && data->localpool)
printf("%s: %s\n", keyname, stringpool_id2str(&data->spool, kv->id));
else
printf("%s: %s\n", keyname, dep2str(repo->pool, kv->id));
break;
case REPOKEY_TYPE_STR:
printf("%s: %s\n", keyname, kv->str);
break;
case REPOKEY_TYPE_MD5:
case REPOKEY_TYPE_SHA1:
case REPOKEY_TYPE_SHA256:
printf("%s: %s\n", keyname, repodata_chk2str(data, key->type, (unsigned char *)kv->str));
break;
case REPOKEY_TYPE_VOID:
printf("%s: (void)\n", keyname);
break;
case REPOKEY_TYPE_U32:
case REPOKEY_TYPE_NUM:
case REPOKEY_TYPE_CONSTANT:
printf("%s: %d\n", keyname, kv->num);
break;
case REPOKEY_TYPE_DIRNUMNUMARRAY:
printf("%s: %s %d %d\n", keyname, repodata_dir2str(data, kv->id, 0), kv->num, kv->num2);
break;
case REPOKEY_TYPE_DIRSTRARRAY:
printf("%s: %s\n", keyname, repodata_dir2str(data, kv->id, kv->str));
break;
default:
printf("%s: ?\n", keyname);
break;
}
return 0;
}
static int
dump_repoattrs_cb(void *vcbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
{
return dump_attr(s->repo, data, key, kv);
}
/*
* dump all attributes for Id <p>
*/
void
dump_repoattrs(Repo *repo, Id p)
{
#if 1
repo_search(repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE, dump_repoattrs_cb, 0);
#else
Dataiterator di;
dataiterator_init(&di, repo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE);
while (dataiterator_step(&di))
dump_attr(repo, di.data, di.key, &di.kv);
#endif
}
#if 0
void
dump_some_attrs(Repo *repo, Solvable *s)
{
const char *summary = 0;
unsigned int medianr = -1, downloadsize = -1;
unsigned int time = -1;
summary = repo_lookup_str(s, SOLVABLE_SUMMARY);
medianr = repo_lookup_num(s, SOLVABLE_MEDIANR);
downloadsize = repo_lookup_num (s, SOLVABLE_DOWNLOADSIZE);
time = repo_lookup_num(s, SOLVABLE_BUILDTIME);
printf (" XXX %d %d %u %s\n", medianr, downloadsize, time, summary);
}
#endif
static FILE *
loadcallback (Pool *pool, Repodata *data, void *vdata)
{
FILE *fp = 0;
if (data->location && with_attr)
{
fprintf (stderr, "Loading SOLV file %s\n", data->location);
fp = fopen (data->location, "r");
if (!fp)
perror(data->location);
}
return fp;
}
static void
usage( const char *err )
{
if (err)
fprintf (stderr, "\n** Error:\n %s\n", err);
fprintf( stderr, "\nUsage:\n"
"dumpsolv [-a] [<solvfile>]\n"
" -a read attributes.\n"
);
exit(0);
}
#if 0
static void
tryme (Repo *repo, Id p, Id keyname, const char *match, int flags)
{
Dataiterator di;
dataiterator_init(&di, repo, p, keyname, match, flags);
while (dataiterator_step(&di))
{
switch (di.key->type)
{
case REPOKEY_TYPE_ID:
case REPOKEY_TYPE_IDARRAY:
if (di.data && di.data->localpool)
di.kv.str = stringpool_id2str(&di.data->spool, di.kv.id);
else
di.kv.str = id2str(repo->pool, di.kv.id);
break;
case REPOKEY_TYPE_STR:
case REPOKEY_TYPE_DIRSTRARRAY:
break;
default:
di.kv.str = 0;
}
fprintf (stdout, "found: %d:%s %d %s %d %d %d\n",
di.solvid,
id2str(repo->pool, di.key->name),
di.kv.id,
di.kv.str, di.kv.num, di.kv.num2, di.kv.eof);
}
}
#endif
int main(int argc, char **argv)
{
Repo *repo;
Pool *pool;
int i, n;
Solvable *s;
argv++;
argc--;
while (argc--)
{
const char *s = argv[0];
if (*s++ == '-')
while (*s)
switch (*s++)
{
case 'h': usage(NULL); break;
case 'a': with_attr = 1; break;
default : break;
}
else
{
if (freopen (argv[0], "r", stdin) == 0)
{
perror(argv[0]);
exit(1);
}
break;
}
argv++;
}
pool = pool_create();
pool_setdebuglevel(pool, 1);
pool_setloadcallback(pool, loadcallback, 0);
repo = repo_create(pool, argc != 1 ? argv[1] : "<stdin>");
if (repo_add_solv(repo, stdin))
printf("could not read repository\n");
printf("pool contains %d strings, %d rels, string size is %d\n", pool->ss.nstrings, pool->nrels, pool->ss.sstrings);
dump_repodata(repo);
printf("repo contains %d solvables %d non-solvables\n", repo->nsolvables, repo->nextra);
for (i = repo->start, n = 1; i < repo->end; i++)
{
s = pool->solvables + i;
if (s->repo != repo)
continue;
printf("\n");
printf("solvable %d:\n", n);
if (s->name || s->evr || s->arch)
printf("name: %s %s %s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch));
if (s->vendor)
printf("vendor: %s\n", id2str(pool, s->vendor));
printids(repo, "provides", s->provides);
printids(repo, "obsoletes", s->obsoletes);
printids(repo, "conflicts", s->conflicts);
printids(repo, "requires", s->requires);
printids(repo, "recommends", s->recommends);
printids(repo, "suggests", s->suggests);
printids(repo, "supplements", s->supplements);
printids(repo, "enhances", s->enhances);
printids(repo, "freshens", s->freshens);
if (repo->rpmdbid)
printf("rpmdbid: %u\n", repo->rpmdbid[i - repo->start]);
#if 0
dump_attrs (repo, n - 1);
#endif
dump_repoattrs(repo, i);
#if 0
dump_some_attrs(repo, s);
#endif
n++;
}
for (i = 0; i < repo->nextra; i++)
{
printf("\nextra %d:\n", i);
Dataiterator di;
dataiterator_init(&di, repo, -1 - i, 0, 0, SEARCH_EXTRA | SEARCH_NO_STORAGE_SOLVABLE);
while (dataiterator_step(&di))
dump_attr(repo, di.data, di.key, &di.kv);
}
#if 0
tryme(repo, 0, SOLVABLE_MEDIANR, 0, 0);
printf("\n");
tryme(repo, 0, 0, 0, 0);
printf("\n");
tryme(repo, 0, 0, "*y*e*", SEARCH_GLOB);
#endif
pool_free(pool);
exit(0);
}
|