rpm  4.9.1.3
rpmdb.c
Go to the documentation of this file.
00001 #include "system.h"
00002 
00003 #include <popt.h>
00004 #include <rpm/rpmcli.h>
00005 #include "cliutils.h"
00006 #include "debug.h"
00007 
00008 #if !defined(__GLIBC__) && !defined(__APPLE__)
00009 char ** environ = NULL;
00010 #endif
00011 
00012 enum modes {
00013     MODE_INITDB         = (1 << 0),
00014     MODE_REBUILDDB      = (1 << 1),
00015     MODE_VERIFYDB       = (1 << 2),
00016 };
00017 
00018 static int mode = 0;
00019 
00020 static struct poptOption dbOptsTable[] = {
00021     { "initdb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_INITDB,
00022         N_("initialize database"), NULL},
00023     { "rebuilddb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_REBUILDDB,
00024         N_("rebuild database inverted lists from installed package headers"),
00025         NULL},
00026     { "verifydb", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR|POPT_ARGFLAG_DOC_HIDDEN),
00027         &mode, MODE_VERIFYDB, N_("verify database files"), NULL},
00028     POPT_TABLEEND
00029 };
00030 
00031 static struct poptOption optionsTable[] = {
00032     { NULL, '\0', POPT_ARG_INCLUDE_TABLE, dbOptsTable, 0,
00033         N_("Database options:"), NULL },
00034     { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
00035         N_("Common options for all rpm modes and executables:"), NULL },
00036 
00037     POPT_AUTOALIAS
00038     POPT_AUTOHELP
00039     POPT_TABLEEND
00040 };
00041 
00042 int main(int argc, char *argv[])
00043 {
00044     int ec = EXIT_FAILURE;
00045     poptContext optCon = rpmcliInit(argc, argv, optionsTable);
00046     rpmts ts = NULL;
00047     
00048     if (argc < 2 || poptPeekArg(optCon)) {
00049         printUsage(optCon, stderr, 0);
00050         goto exit;
00051     }
00052 
00053     ts = rpmtsCreate();
00054     rpmtsSetRootDir(ts, rpmcliRootDir);
00055 
00056     switch (mode) {
00057     case MODE_INITDB:
00058         ec = rpmtsInitDB(ts, 0644);
00059         break;
00060     case MODE_REBUILDDB:
00061     {   rpmVSFlags vsflags = rpmExpandNumeric("%{_vsflags_rebuilddb}");
00062         rpmVSFlags ovsflags = rpmtsSetVSFlags(ts, vsflags);
00063         ec = rpmtsRebuildDB(ts);
00064         vsflags = rpmtsSetVSFlags(ts, ovsflags);
00065     }   break;
00066     case MODE_VERIFYDB:
00067         ec = rpmtsVerifyDB(ts);
00068         break;
00069     default:
00070         argerror(_("only one major mode may be specified"));
00071     }
00072 
00073 exit:
00074     rpmtsFree(ts);
00075     rpmcliFini(optCon);
00076     return ec;
00077 }