rpmqv.c
Go to the documentation of this file.
#include "system.h"
const char *__progname;
#include <rpm/rpmcli.h>
#include <rpm/rpmlib.h> /* RPMSIGTAG, rpmReadPackageFile .. */
#include <rpm/rpmlog.h>
#include <rpm/rpmps.h>
#include <rpm/rpmts.h>
#include "cliutils.h"
#include "debug.h"
#if defined(IAM_RPMQ) || defined(IAM_RPMV)
#define IAM_RPMQV
#endif
enum modes {
MODE_QUERY = (1 << 0),
MODE_VERIFY = (1 << 3),
#define MODES_QV (MODE_QUERY | MODE_VERIFY)
MODE_INSTALL = (1 << 1),
MODE_ERASE = (1 << 2),
#define MODES_IE (MODE_INSTALL | MODE_ERASE)
MODE_UNKNOWN = 0
};
#define MODES_FOR_NODEPS (MODES_IE | MODE_VERIFY)
#define MODES_FOR_TEST (MODES_IE)
static int quiet;
/* the structure describing the options we take and the defaults */
static struct poptOption optionsTable[] = {
#ifdef IAM_RPMQV
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQVSourcePoptTable, 0,
N_("Query/Verify package selection options:"),
NULL },
#endif
#ifdef IAM_RPMQ
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,
N_("Query options (with -q or --query):"),
NULL },
#endif
#ifdef IAM_RPMV
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0,
N_("Verify options (with -V or --verify):"),
NULL },
#endif
#ifdef IAM_RPMEIU
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0,
N_("Install/Upgrade/Erase options:"),
NULL },
#endif /* IAM_RPMEIU */
{ "quiet", '\0', POPT_ARGFLAG_DOC_HIDDEN, &quiet, 0, NULL, 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[])
{
rpmts ts = NULL;
enum modes bigMode = MODE_UNKNOWN;
#if defined(IAM_RPMQV)
QVA_t qva = &rpmQVKArgs;
#endif
#ifdef IAM_RPMEIU
struct rpmInstallArguments_s * ia = &rpmIArgs;
#endif
poptContext optCon;
int ec = 0;
#ifdef IAM_RPMEIU
int i;
#endif
optCon = rpmcliInit(argc, argv, optionsTable);
/* Set the major mode based on argv[0] */
#ifdef IAM_RPMQV
if (rstreq(__progname, "rpmquery")) bigMode = MODE_QUERY;
if (rstreq(__progname, "rpmverify")) bigMode = MODE_VERIFY;
#endif
#if defined(IAM_RPMQV)
/* Jumpstart option from argv[0] if necessary. */
switch (bigMode) {
case MODE_QUERY: qva->qva_mode = 'q'; break;
case MODE_VERIFY: qva->qva_mode = 'V'; break;
case MODE_INSTALL:
case MODE_ERASE:
case MODE_UNKNOWN:
default:
break;
}
#endif
#ifdef IAM_RPMQV
if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) {
switch (qva->qva_mode) {
case 'q': bigMode = MODE_QUERY; break;
case 'V': bigMode = MODE_VERIFY; break;
}
if (qva->qva_sourceCount) {
if (qva->qva_sourceCount > 1)
argerror(_("one type of query/verify may be performed at a "
"time"));
}
if (qva->qva_flags && (bigMode & ~MODES_QV))
argerror(_("unexpected query flags"));
if (qva->qva_queryFormat && (bigMode & ~MODES_QV))
argerror(_("unexpected query format"));
if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV))
argerror(_("unexpected query source"));
}
#endif /* IAM_RPMQV */
#ifdef IAM_RPMEIU
if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
{ int iflags = (ia->installInterfaceFlags &
(INSTALL_UPGRADE|INSTALL_FRESHEN|
INSTALL_INSTALL|INSTALL_REINSTALL));
int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
if (iflags & eflags)
argerror(_("only one major mode may be specified"));
else if (iflags)
bigMode = MODE_INSTALL;
else if (eflags)
bigMode = MODE_ERASE;
}
#endif /* IAM_RPMEIU */
#if defined(IAM_RPMEIU)
if (!( bigMode == MODE_INSTALL ) &&
(ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_OLDPACKAGE)))
argerror(_("only installation and upgrading may be forced"));
if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
argerror(_("files may only be relocated during package installation"));
if (ia->relocations && ia->prefix)
argerror(_("cannot use --prefix with --relocate or --excludepath"));
if (bigMode != MODE_INSTALL && ia->relocations)
argerror(_("--relocate and --excludepath may only be used when installing new packages"));
if (bigMode != MODE_INSTALL && ia->prefix)
argerror(_("--prefix may only be used when installing new packages"));
if (ia->prefix && ia->prefix[0] != '/')
argerror(_("arguments to --prefix must begin with a /"));
if (!(bigMode & MODES_IE) && (ia->installInterfaceFlags & INSTALL_HASH))
argerror(_("--hash (-h) may only be specified during package "
"installation and erasure"));
if (!(bigMode & MODES_IE) && (ia->installInterfaceFlags & INSTALL_PERCENT))
argerror(_("--percent may only be specified during package "
"installation and erasure"));
if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
argerror(_("--replacepkgs may only be specified during package "
"installation"));
if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
argerror(_("--excludedocs may only be specified during package "
"installation"));
if (bigMode != MODE_INSTALL && ia->incldocs)
argerror(_("--includedocs may only be specified during package "
"installation"));
if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
argerror(_("only one of --excludedocs and --includedocs may be "
"specified"));
if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
argerror(_("--ignorearch may only be specified during package "
"installation"));
if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
argerror(_("--ignoreos may only be specified during package "
"installation"));
if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
(ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES)))
argerror(_("--ignoresize may only be specified during package "
"installation"));
if ((ia->installInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
argerror(_("--allmatches may only be specified during package "
"erasure"));
if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
argerror(_("--allfiles may only be specified during package "
"installation"));
if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
argerror(_("--justdb may only be specified during package "
"installation and erasure"));
if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY &&
(ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers)))
argerror(_("script disabling options may only be specified during "
"package installation and erasure"));
if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY &&
(ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers)))
argerror(_("trigger disabling options may only be specified during "
"package installation and erasure"));
if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
argerror(_("--nodeps may only be specified during package "
"installation, erasure, and verification"));
if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
argerror(_("--test may only be specified during package installation "
"and erasure"));
#endif /* IAM_RPMEIU */
if (rpmcliRootDir && rpmcliRootDir[0] != '/') {
argerror(_("arguments to --root (-r) must begin with a /"));
}
if (quiet)
rpmSetVerbosity(RPMLOG_WARNING);
if (rpmcliPipeOutput && initPipe())
exit(EXIT_FAILURE);
ts = rpmtsCreate();
(void) rpmtsSetRootDir(ts, rpmcliRootDir);
switch (bigMode) {
#ifdef IAM_RPMEIU
case MODE_ERASE:
if (ia->noDeps) ia->installInterfaceFlags |= UNINSTALL_NODEPS;
if (!poptPeekArg(optCon)) {
argerror(_("no packages given for erase"));
} else {
ec += rpmErase(ts, ia, (ARGV_const_t) poptGetArgs(optCon));
}
break;
case MODE_INSTALL:
/* RPMTRANS_FLAG_KEEPOBSOLETE */
if (!ia->incldocs) {
if (ia->transFlags & RPMTRANS_FLAG_NODOCS) {
;
} else if (rpmExpandNumeric("%{_excludedocs}"))
ia->transFlags |= RPMTRANS_FLAG_NODOCS;
}
if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS;
/* we've already ensured !(!ia->prefix && !ia->relocations) */
if (ia->prefix) {
ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
ia->relocations[0].oldPath = NULL; /* special case magic */
ia->relocations[0].newPath = ia->prefix;
ia->relocations[1].oldPath = NULL;
ia->relocations[1].newPath = NULL;
} else if (ia->relocations) {
ia->relocations = xrealloc(ia->relocations,
sizeof(*ia->relocations) * (ia->numRelocations + 1));
ia->relocations[ia->numRelocations].oldPath = NULL;
ia->relocations[ia->numRelocations].newPath = NULL;
}
if (!poptPeekArg(optCon)) {
argerror(_("no packages given for install"));
} else {
/* FIX: ia->relocations[0].newPath undefined */
ec += rpmInstall(ts, ia, (ARGV_t) poptGetArgs(optCon));
}
break;
#endif /* IAM_RPMEIU */
#ifdef IAM_RPMQV
case MODE_QUERY:
if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL))
argerror(_("no arguments given for query"));
ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
break;
case MODE_VERIFY:
{ rpmVerifyFlags verifyFlags = VERIFY_ALL;
verifyFlags &= ~qva->qva_flags;
qva->qva_flags = (rpmQueryFlags) verifyFlags;
if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL))
argerror(_("no arguments given for verify"));
ec = rpmcliVerify(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
} break;
#endif /* IAM_RPMQV */
#if !defined(IAM_RPMQV)
case MODE_QUERY:
case MODE_VERIFY:
#endif
#if !defined(IAM_RPMEIU)
case MODE_INSTALL:
case MODE_ERASE:
#endif
case MODE_UNKNOWN:
if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
printUsage(optCon, stderr, 0);
ec = argc;
}
break;
}
rpmtsFree(ts);
if (finishPipe())
ec = EXIT_FAILURE;
#ifdef IAM_RPMQV
free(qva->qva_queryFormat);
#endif
#ifdef IAM_RPMEIU
if (ia->relocations != NULL) {
for (i = 0; i < ia->numRelocations; i++)
free(ia->relocations[i].oldPath);
free(ia->relocations);
}
#endif
rpmcliFini(optCon);
return RETVAL(ec);
}
RPMPROB_FILTER_DISKNODES
Definition: rpmprob.h:31
RETVAL
#define RETVAL(rc)
Definition: cliutils.h:14
rpmtsSetRootDir
int rpmtsSetRootDir(rpmts ts, const char *rootDir)
Set transaction rootDir, i.e.
RPMLOG_WARNING
Definition: rpmlog.h:34
rpmInstall
int rpmInstall(rpmts ts, struct rpmInstallArguments_s *ia, ARGV_t fileArgv)
Install/upgrade/freshen/reinstall binary rpm package.
printUsage
void printUsage(poptContext con, FILE *fp, int flags)
Definition: cliutils.c:36
rpmVerifyFlags
rpmFlags rpmVerifyFlags
Definition: rpmvf.h:79
rpmQVKArguments_s::qva_sourceCount
int qva_sourceCount
Definition: rpmcli.h:176
rpmInstallArguments_s::numRelocations
int numRelocations
Definition: rpmcli.h:345
xmalloc
#define xmalloc(_size)
Definition: system.h:85
ARGV_t
char ** ARGV_t
Definition: argv.h:17
rpmInstallArguments_s::incldocs
int incldocs
Definition: rpmcli.h:347
rpmRelocation_s::oldPath
char * oldPath
Definition: rpmfiles.h:95
main
int main(int argc, char *argv[])
Definition: rpmqv.c:72
rpmInstallArguments_s::probFilter
rpmprobFilterFlags probFilter
Definition: rpmcli.h:343
debug.h
INSTALL_UPGRADE
Definition: rpmcli.h:287
rpmcliQuery
int rpmcliQuery(rpmts ts, QVA_t qva, ARGV_const_t argv)
Display package information.
optionsTable
static struct poptOption optionsTable[]
Definition: rpmqv.c:37
rpmQVKArguments_s::qva_flags
rpmQueryFlags qva_flags
Definition: rpmcli.h:177
RPMPROB_FILTER_DISKSPACE
Definition: rpmprob.h:30
rpmInstallPoptTable
struct poptOption rpmInstallPoptTable[]
rpmcliInit
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable)
Initialize most everything needed by an rpm CLI executable context.
rpmRelocation_s::newPath
char * newPath
Definition: rpmfiles.h:96
MODES_FOR_NODEPS
#define MODES_FOR_NODEPS
Definition: rpmqv.c:31
rpmcliFini
poptContext rpmcliFini(poptContext optCon)
Destroy most everything needed by an rpm CLI executable context.
rpmInstallArguments_s::relocations
rpmRelocation * relocations
Definition: rpmcli.h:348
cliutils.h
Misc helpers for RPM CLI tools.
rpmQVKArgs
struct rpmQVKArguments_s rpmQVKArgs
MODE_ERASE
Definition: rpmqv.c:25
rpmVerifyPoptTable
struct poptOption rpmVerifyPoptTable[]
RPMPROB_FILTER_FORCERELOCATE
Definition: rpmprob.h:26
RPMPROB_FILTER_REPLACEPKG
Definition: rpmprob.h:25
rpmcliVerify
int rpmcliVerify(rpmts ts, QVA_t qva, ARGV_const_t argv)
Verify package install.
MODE_INSTALL
Definition: rpmqv.c:24
_noTransScripts
#define _noTransScripts
Definition: rpmts.h:60
finishPipe
int finishPipe(void)
Definition: cliutils.c:73
INSTALL_REINSTALL
Definition: rpmcli.h:292
_
#define _(Text)
Definition: system.h:112
rpmQVKArguments_s
Describe query/verify/signature command line operation.
Definition: rpmcli.h:174
rpmIsVerbose
#define rpmIsVerbose()
Definition: rpmlog.h:272
RPMTRANS_FLAG_JUSTDB
Definition: rpmts.h:33
rpmQueryPoptTable
struct poptOption rpmQueryPoptTable[]
MODES_QV
#define MODES_QV
Definition: rpmqv.c:22
MODES_FOR_TEST
#define MODES_FOR_TEST
Definition: rpmqv.c:32
_noTransTriggers
#define _noTransTriggers
Definition: rpmts.h:69
INSTALL_HASH
Definition: rpmcli.h:283
RPMTRANS_FLAG_NOSCRIPTS
Definition: rpmts.h:32
rpmErase
int rpmErase(rpmts ts, struct rpmInstallArguments_s *ia, ARGV_const_t argv)
Erase binary rpm package.
RPMTRANS_FLAG_NOTRIGGERS
Definition: rpmts.h:34
rpmcliPipeOutput
const char * rpmcliPipeOutput
RPMPROB_FILTER_OLDPACKAGE
Definition: rpmprob.h:29
rpmQVKArguments_s::qva_mode
char qva_mode
Definition: rpmcli.h:183
argerror
void argerror(const char *desc)
Definition: cliutils.c:19
INSTALL_FRESHEN
Definition: rpmcli.h:288
rpmQueryFlags
rpmFlags rpmQueryFlags
Definition: rpmcli.h:136
rstreq
static int rstreq(const char *s1, const char *s2)
Test for string equality.
Definition: rpmstring.h:113
rpmInstallArguments_s::transFlags
rpmtransFlags transFlags
Definition: rpmcli.h:342
modes
modes
Definition: rpmbuild.c:250
VERIFY_ALL
#define VERIFY_ALL
Definition: rpmvf.h:84
rpmExpandNumeric
int rpmExpandNumeric(const char *arg)
Return macro expansion as a numeric value.
rpmQVKArguments_s::qva_source
rpmQVSources qva_source
Definition: rpmcli.h:175
MODE_UNKNOWN
Definition: rpmqv.c:28
INSTALL_PERCENT
Definition: rpmcli.h:282
initPipe
int initPipe(void)
Definition: cliutils.c:48
RPMTRANS_FLAG_ALLFILES
Definition: rpmts.h:36
RPMTRANS_FLAG_TEST
Definition: rpmts.h:30
rpmInstallArguments_s::installInterfaceFlags
rpmInstallFlags installInterfaceFlags
Definition: rpmcli.h:344
UNINSTALL_ALLMATCHES
#define UNINSTALL_ALLMATCHES
Definition: rpmcli.h:302
quiet
static int quiet
Definition: rpmqv.c:34
rpmInstallArguments_s::noDeps
int noDeps
Definition: rpmcli.h:346
rpmcliRootDir
const char * rpmcliRootDir
RPMPROB_FILTER_IGNOREARCH
Definition: rpmprob.h:24
RPMPROB_FILTER_IGNOREOS
Definition: rpmprob.h:23
MODE_VERIFY
Definition: rpmqv.c:21
RPMQV_PACKAGE
Definition: rpmcli.h:81
rpmQVKArguments_s::qva_queryFormat
char * qva_queryFormat
Definition: rpmcli.h:182
INSTALL_ERASE
Definition: rpmcli.h:290
ARGV_const_t
char *const * ARGV_const_t
Definition: argv.h:18
rpmtsFree
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
INSTALL_NODEPS
Definition: rpmcli.h:284
rpmts
struct rpmts_s * rpmts
The main types involved in transaction manipulation.
Definition: rpmtypes.h:63
MODE_QUERY
Definition: rpmqv.c:20
system.h
Some misc low-level API.
rpmInstallArguments_s
Describe database command line requests.
Definition: rpmcli.h:341
UNINSTALL_NODEPS
#define UNINSTALL_NODEPS
Definition: rpmcli.h:301
rpmInstallArguments_s::prefix
char * prefix
Definition: rpmcli.h:349
__progname
#define __progname
Definition: system.h:98
rpmIArgs
struct rpmInstallArguments_s rpmIArgs
N_
#define N_(Text)
Definition: system.h:115
rpmQVSourcePoptTable
struct poptOption rpmQVSourcePoptTable[]
rpmSetVerbosity
#define rpmSetVerbosity(_lvl)
Definition: rpmlog.h:264
MODES_IE
#define MODES_IE
Definition: rpmqv.c:26
rpmtsCreate
rpmts rpmtsCreate(void)
Create an empty transaction set.
RPMTRANS_FLAG_NODOCS
Definition: rpmts.h:35
xrealloc
#define xrealloc(_ptr, _size)
Definition: system.h:87
INSTALL_INSTALL
Definition: rpmcli.h:289
RPMQV_ALL
Definition: rpmcli.h:83
rpmcliAllPoptTable
struct poptOption rpmcliAllPoptTable[]
Popt option table for options shared by all modes and executables.