rpmdb.c
Go to the documentation of this file.
#include "system.h"
#include <popt.h>
#include <rpm/rpmcli.h>
#include "cliutils.h"
#include "debug.h"
#if !defined(__GLIBC__) && !defined(__APPLE__)
char ** environ = NULL;
#endif
enum modes {
MODE_INITDB = (1 << 0),
MODE_REBUILDDB = (1 << 1),
MODE_VERIFYDB = (1 << 2),
};
static int mode = 0;
static struct poptOption dbOptsTable[] = {
{ "initdb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_INITDB,
N_("initialize database"), NULL},
{ "rebuilddb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_REBUILDDB,
N_("rebuild database inverted lists from installed package headers"),
NULL},
{ "verifydb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR|POPT_ARGFLAG_DOC_HIDDEN),
&mode, MODE_VERIFYDB, N_("verify database files"), NULL},
POPT_TABLEEND
};
static struct poptOption optionsTable[] = {
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, dbOptsTable, 0,
N_("Database options:"), NULL },
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
N_("Common options for all rpm modes and executables:"), NULL },
POPT_AUTOALIAS
POPT_AUTOHELP
POPT_TABLEEND
};
int main(int argc, char *argv[])
{
int ec = EXIT_FAILURE;
poptContext optCon = rpmcliInit(argc, argv, optionsTable);
rpmts ts = NULL;
if (argc < 2 || poptPeekArg(optCon)) {
printUsage(optCon, stderr, 0);
goto exit;
}
ts = rpmtsCreate();
rpmtsSetRootDir(ts, rpmcliRootDir);
switch (mode) {
case MODE_INITDB:
ec = rpmtsInitDB(ts, 0644);
break;
case MODE_REBUILDDB:
{ rpmVSFlags vsflags = rpmExpandNumeric("%{_vsflags_rebuilddb}");
rpmVSFlags ovsflags = rpmtsSetVSFlags(ts, vsflags);
ec = rpmtsRebuildDB(ts);
rpmtsSetVSFlags(ts, ovsflags);
} break;
case MODE_VERIFYDB:
ec = rpmtsVerifyDB(ts);
break;
default:
argerror(_("only one major mode may be specified"));
}
exit:
rpmtsFree(ts);
rpmcliFini(optCon);
return ec;
}
dbOptsTable
static struct poptOption dbOptsTable[]
Definition: rpmdb.c:20
printUsage
void printUsage(poptContext con, FILE *fp, int flags)
Definition: cliutils.c:36
MODE_VERIFYDB
Definition: rpmdb.c:15
optionsTable
static struct poptOption optionsTable[]
Definition: rpmdb.c:31
debug.h
rpmtsFree
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
main
int main(int argc, char *argv[])
Definition: rpmdb.c:42
rpmcliInit
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable)
Initialize most everything needed by an rpm CLI executable context.
rpmtsRebuildDB
int rpmtsRebuildDB(rpmts ts)
Rebuild the database used by the transaction.
cliutils.h
rpmts
struct rpmts_s * rpmts
The main types involved in transaction manipulation.
Definition: rpmtypes.h:63
_
#define _(Text)
Definition: system.h:135
rpmtsCreate
rpmts rpmtsCreate(void)
Create an empty transaction set.
rpmcliFini
poptContext rpmcliFini(poptContext optCon)
Destroy most everything needed by an rpm CLI executable context.
rpmtsInitDB
int rpmtsInitDB(rpmts ts, int dbmode)
Initialize the database used by the transaction.
argerror
void argerror(const char *desc)
Definition: cliutils.c:19
rpmtsVerifyDB
int rpmtsVerifyDB(rpmts ts)
Verify the database used by the transaction.
modes
modes
Definition: rpmbuild.c:204
rpmExpandNumeric
int rpmExpandNumeric(const char *arg)
Return macro expansion as a numeric value.
rpmVSFlags
rpmFlags rpmVSFlags
Definition: rpmts.h:107
environ
char ** environ
Definition: rpmdb.c:9
MODE_INITDB
Definition: rpmdb.c:13
rpmcliRootDir
const char * rpmcliRootDir
rpmtsSetVSFlags
rpmVSFlags rpmtsSetVSFlags(rpmts ts, rpmVSFlags vsflags)
Set verify signatures flag(s).
rpmcliAllPoptTable
struct poptOption rpmcliAllPoptTable[]
Popt option table for options shared by all modes and executables.
mode
static int mode
Definition: rpmdb.c:18
MODE_REBUILDDB
Definition: rpmdb.c:14
system.h
N_
#define N_(Text)
Definition: system.h:138
rpmtsSetRootDir
int rpmtsSetRootDir(rpmts ts, const char *rootDir)
Set transaction rootDir, i.e.