rpm: rpmdb.c Source File

rpm 4.11.2-rc1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

rpmdb.c
Go to the documentation of this file.
1 #include "system.h"
2
3 #include <popt.h>
4 #include <rpm/rpmcli.h>
5 #include "cliutils.h"
6 #include "debug.h"
7
8 #if !defined(__GLIBC__) && !defined(__APPLE__)
9 char ** environ = NULL;
10 #endif
11
12 enum modes {
13 MODE_INITDB = (1 << 0),
14 MODE_REBUILDDB = (1 << 1),
15 MODE_VERIFYDB = (1 << 2),
16 };
17
18 static int mode = 0;
19
20 static struct poptOption dbOptsTable[] = {
21 { "initdb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_INITDB,
22 N_("initialize database"), NULL},
23 { "rebuilddb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_REBUILDDB,
24 N_("rebuild database inverted lists from installed package headers"),
25 NULL},
26 { "verifydb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR|POPT_ARGFLAG_DOC_HIDDEN),
27 &mode, MODE_VERIFYDB, N_("verify database files"), NULL},
28 POPT_TABLEEND
29 };
30
31 static struct poptOption optionsTable[] = {
32 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, dbOptsTable, 0,
33 N_("Database options:"), NULL },
34 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
35 N_("Common options for all rpm modes and executables:"), NULL },
36
37 POPT_AUTOALIAS
38 POPT_AUTOHELP
39 POPT_TABLEEND
40 };
41
42 int main(int argc, char *argv[])
43 {
44 int ec = EXIT_FAILURE;
45 poptContext optCon = rpmcliInit(argc, argv, optionsTable);
46 rpmts ts = NULL;
47
48 if (argc < 2 || poptPeekArg(optCon)) {
49 printUsage(optCon, stderr, 0);
50 goto exit;
51 }
52
53 ts = rpmtsCreate();
54 rpmtsSetRootDir(ts, rpmcliRootDir);
55
56 switch (mode) {
57 case MODE_INITDB:
58 ec = rpmtsInitDB(ts, 0644);
59 break;
60 case MODE_REBUILDDB:
61 { rpmVSFlags vsflags = rpmExpandNumeric("%{_vsflags_rebuilddb}");
62 rpmVSFlags ovsflags = rpmtsSetVSFlags(ts, vsflags);
63 ec = rpmtsRebuildDB(ts);
64 rpmtsSetVSFlags(ts, ovsflags);
65 } break;
66 case MODE_VERIFYDB:
67 ec = rpmtsVerifyDB(ts);
68 break;
69 default:
70 argerror(_("only one major mode may be specified"));
71 }
72
73 exit:
74 rpmtsFree(ts);
75 rpmcliFini(optCon);
76 return ec;
77 }
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.