4 #include <rpm/rpmcli.h>
10 MODE_INITDB = (1 << 0),
11 MODE_REBUILDDB = (1 << 1),
12 MODE_VERIFYDB = (1 << 2),
13 MODE_EXPORTDB = (1 << 3),
14 MODE_IMPORTDB = (1 << 4),
19 static struct poptOption dbOptsTable[] = {
20 { "initdb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_INITDB,
21 N_("initialize database"), NULL},
22 { "rebuilddb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_REBUILDDB,
23 N_("rebuild database inverted lists from installed package headers"),
25 { "verifydb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR|POPT_ARGFLAG_DOC_HIDDEN),
26 &mode, MODE_VERIFYDB, N_("verify database files"), NULL},
27 { "exportdb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_EXPORTDB,
28 N_("export database to stdout header list"),
30 { "importdb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_IMPORTDB,
31 N_("import database from stdin header list"),
36 static struct poptOption optionsTable[] = {
37 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, dbOptsTable, 0,
38 N_("Database options:"), NULL },
39 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
40 N_("Common options for all rpm modes and executables:"), NULL },
47 static int exportDB(rpmts ts)
49 FD_t fd = fdDup(STDOUT_FILENO);
50 rpmtxn txn = rpmtxnBegin(ts, RPMTXN_READ);
55 rpmdbMatchIterator mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0);
56 while ((h = rpmdbNextIterator(mi))) {
57 rc += headerWrite(fd, h, HEADER_MAGIC_YES);
59 rpmdbFreeIterator(mi);
68 /* XXX: only allow this on empty db? */
69 static int importDB(rpmts ts)
71 FD_t fd = fdDup(STDIN_FILENO);
72 rpmtxn txn = rpmtxnBegin(ts, RPMTXN_WRITE);
77 while ((h = headerRead(fd, HEADER_MAGIC_YES))) {
78 rc += rpmtsImportHeader(txn, h, 0);
88 int main(int argc, char *argv[])
90 int ec = EXIT_FAILURE;
91 poptContext optCon = NULL;
94 xsetprogname(argv[0]); /* Portability call -- see system.h */
96 optCon = rpmcliInit(argc, argv, optionsTable);
98 if (argc < 2 || poptPeekArg(optCon)) {
99 printUsage(optCon, stderr, 0);
104 rpmtsSetRootDir(ts, rpmcliRootDir);
108 ec = rpmtsInitDB(ts, 0644);
111 { rpmVSFlags vsflags = rpmExpandNumeric("%{_vsflags_rebuilddb}");
112 rpmVSFlags ovsflags = rpmtsSetVSFlags(ts, vsflags);
113 ec = rpmtsRebuildDB(ts);
114 rpmtsSetVSFlags(ts, ovsflags);
117 ec = rpmtsVerifyDB(ts);
126 argerror(_("only one major mode may be specified"));