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
|
/*
* Copyright (c) 2004 Michael Schroeder (mls@suse.de)
*
* This program is licensed under the BSD license, read LICENSE.BSD
* for further information
*/
#include <fcntl.h>
#include <string.h>
#include <rpm/rpmlib.h>
#include <rpm/rpmts.h>
#include <rpm/rpmdb.h>
int main(int argc, char **argv)
{
FD_t fdo;
rpmts ts = NULL;
rpmdbMatchIterator mi;
Header h;
int ret = 0;
char *n;
char *e;
char *v;
char *r;
char *a = NULL;
if (argc > 2 && !strcmp(argv[1], "-a"))
{
a = argv[2];
argc -= 2;
argv += 2;
}
if (argc != 2)
{
fprintf(stderr, "usage: rpmdumpheader package\n");
exit(1);
}
n = argv[1];
r = strrchr(n, '-');
if (r == 0 || r == n)
{
fprintf(stderr, "package name must be in n-(e:)v-r format\n");
exit(1);
}
*r++ = 0;
v = strrchr(n, '-');
if (v == 0 || v == n)
{
fprintf(stderr, "package name must be in n-(e:)v-r format\n");
exit(1);
}
*v++ = 0;
e = strchr(v, ':');
if (e)
{
char *t;
*e++ = 0;
t = e;
e = v;
v = t;
}
rpmReadConfigFiles(NULL, NULL);
ts = rpmtsCreate();
mi = rpmtsInitIterator(ts, RPMTAG_NAME, n, 0);
rpmdbSetIteratorRE(mi, RPMTAG_EPOCH, RPMMIRE_STRCMP, e);
rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_STRCMP, v);
rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_STRCMP, r);
if (a)
rpmdbSetIteratorRE(mi, RPMTAG_ARCH, RPMMIRE_STRCMP, a);
if ((h = rpmdbNextIterator(mi)) != NULL)
{
fdo = Fopen("-", "w.ufdio");
headerWrite(fdo, h, HEADER_MAGIC_YES);
}
else
{
if (e)
fprintf(stderr, "%s-%s:%s-%s%s%s is not installed\n", n, e, v, r, a ? "." : "", a ? a : "");
else
fprintf(stderr, "%s-%s-%s%s%s is not installed\n", n, v, r, a ? "." : "", a ? a : "");
ret = 1;
}
mi = rpmdbFreeIterator(mi);
ts = rpmtsFree(ts);
exit(ret);
}
|