summaryrefslogtreecommitdiff
path: root/tools/dumpdb.c
blob: 745c81ba3c9fcd1b6a74b2e3438c6eb1bdb5ded9 (plain)
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
#include "system.h"

#include <rpmlib.h>
#include "header_internal.h"

#include "rpmdb.h"

#include "debug.h"

int main(int argc, char ** argv)
{
    unsigned int dspBlockNum = 0;		/* default to all */
    rpmdb db;

    setprogname(argv[0]);	/* Retrofit glibc __progname */
    rpmReadConfigFiles(NULL, NULL);

    if (argc == 2) {
	dspBlockNum = atoi(argv[1]);
    } else if (argc != 1) {
	fprintf(stderr, _("dumpdb <block num>\n"));
	exit(1);
    }

    if (rpmdbOpen("", &db, O_RDONLY, 0644)) {
	fprintf(stderr, _("cannot open Packages\n"));
	exit(1);
    }

    {	Header h = NULL;
	unsigned int blockNum = 0;
	rpmdbMatchIterator mi;
#define	_RECNUM	rpmdbGetIteratorOffset(mi)

	mi = rpmdbInitIterator(db, RPMDBI_PACKAGES, NULL, 0);

	while ((h = rpmdbNextIterator(mi)) != NULL) {

	    blockNum++;
	    if (!(dspBlockNum != 0 && dspBlockNum != blockNum))
		continue;

	    headerDump(h, stdout, HEADER_DUMP_INLINE, rpmTagTable);
	    fprintf(stdout, "Offset: %d\n", _RECNUM);
    
	    if (dspBlockNum && blockNum > dspBlockNum)
		exit(0);
	}

	mi = rpmdbFreeIterator(mi);

    }

    rpmdbClose(db);

    return 0;
}