rpm: rpmqv.c Source File

rpm 4.11.2-rc1

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

- File List
- Globals

rpmqv.c
Go to the documentation of this file.
1 #include "system.h"
2 const char *__progname;
3
4 #include <rpm/rpmcli.h>
5 #include <rpm/rpmlib.h> /* RPMSIGTAG, rpmReadPackageFile .. */
6 #include <rpm/rpmlog.h>
7 #include <rpm/rpmps.h>
8 #include <rpm/rpmts.h>
9
10 #include "cliutils.h"
11
12 #include "debug.h"
13
14 #if defined(IAM_RPMQ) || defined(IAM_RPMV)
15 #define IAM_RPMQV
16 #endif
17
18 enum modes {
19
20 MODE_QUERY = (1 << 0),
21 MODE_VERIFY = (1 << 3),
22 #define MODES_QV (MODE_QUERY | MODE_VERIFY)
23
24 MODE_INSTALL = (1 << 1),
25 MODE_ERASE = (1 << 2),
26 #define MODES_IE (MODE_INSTALL | MODE_ERASE)
27
28 MODE_UNKNOWN = 0
29 };
30
31 #define MODES_FOR_NODEPS (MODES_IE | MODE_VERIFY)
32 #define MODES_FOR_TEST (MODES_IE)
33
34 static int quiet;
35
36 /* the structure describing the options we take and the defaults */
37 static struct poptOption optionsTable[] = {
38
39 #ifdef IAM_RPMQV
40 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQVSourcePoptTable, 0,
41 N_("Query/Verify package selection options:"),
42 NULL },
43 #endif
44 #ifdef IAM_RPMQ
45 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,
46 N_("Query options (with -q or --query):"),
47 NULL },
48 #endif
49 #ifdef IAM_RPMV
50 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0,
51 N_("Verify options (with -V or --verify):"),
52 NULL },
53 #endif
54
55 #ifdef IAM_RPMEIU
56 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0,
57 N_("Install/Upgrade/Erase options:"),
58 NULL },
59 #endif /* IAM_RPMEIU */
60
61 { "quiet", '\0', POPT_ARGFLAG_DOC_HIDDEN, &quiet, 0, NULL, NULL},
62
63 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
64 N_("Common options for all rpm modes and executables:"),
65 NULL },
66
67 POPT_AUTOALIAS
68 POPT_AUTOHELP
69 POPT_TABLEEND
70 };
71
72 int main(int argc, char *argv[])
73 {
74 rpmts ts = NULL;
75 enum modes bigMode = MODE_UNKNOWN;
76
77 #if defined(IAM_RPMQV)
78 QVA_t qva = &rpmQVKArgs;
79 #endif
80
81 #ifdef IAM_RPMEIU
82 struct rpmInstallArguments_s * ia = &rpmIArgs;
83 #endif
84
85 poptContext optCon;
86 int ec = 0;
87 #ifdef IAM_RPMEIU
88 int i;
89 #endif
90
91 optCon = rpmcliInit(argc, argv, optionsTable);
92
93 /* Set the major mode based on argv[0] */
94 #ifdef IAM_RPMQV
95 if (rstreq(__progname, "rpmquery")) bigMode = MODE_QUERY;
96 if (rstreq(__progname, "rpmverify")) bigMode = MODE_VERIFY;
97 #endif
98
99 #if defined(IAM_RPMQV)
100 /* Jumpstart option from argv[0] if necessary. */
101 switch (bigMode) {
102 case MODE_QUERY: qva->qva_mode = 'q'; break;
103 case MODE_VERIFY: qva->qva_mode = 'V'; break;
104 case MODE_INSTALL:
105 case MODE_ERASE:
106 case MODE_UNKNOWN:
107 default:
108 break;
109 }
110 #endif
111
112 #ifdef IAM_RPMQV
113 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) {
114 switch (qva->qva_mode) {
115 case 'q': bigMode = MODE_QUERY; break;
116 case 'V': bigMode = MODE_VERIFY; break;
117 }
118
119 if (qva->qva_sourceCount) {
120 if (qva->qva_sourceCount > 1)
121 argerror(_("one type of query/verify may be performed at a "
122 "time"));
123 }
124 if (qva->qva_flags && (bigMode & ~MODES_QV))
125 argerror(_("unexpected query flags"));
126
127 if (qva->qva_queryFormat && (bigMode & ~MODES_QV))
128 argerror(_("unexpected query format"));
129
130 if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV))
131 argerror(_("unexpected query source"));
132 }
133 #endif /* IAM_RPMQV */
134
135 #ifdef IAM_RPMEIU
136 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
137 { int iflags = (ia->installInterfaceFlags &
138 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL));
139 int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
140
141 if (iflags & eflags)
142 argerror(_("only one major mode may be specified"));
143 else if (iflags)
144 bigMode = MODE_INSTALL;
145 else if (eflags)
146 bigMode = MODE_ERASE;
147 }
148 #endif /* IAM_RPMEIU */
149
150 #if defined(IAM_RPMEIU)
151 if (!( bigMode == MODE_INSTALL ) &&
152 (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_OLDPACKAGE)))
153 argerror(_("only installation and upgrading may be forced"));
154 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
155 argerror(_("files may only be relocated during package installation"));
156
157 if (ia->relocations && ia->prefix)
158 argerror(_("cannot use --prefix with --relocate or --excludepath"));
159
160 if (bigMode != MODE_INSTALL && ia->relocations)
161 argerror(_("--relocate and --excludepath may only be used when installing new packages"));
162
163 if (bigMode != MODE_INSTALL && ia->prefix)
164 argerror(_("--prefix may only be used when installing new packages"));
165
166 if (ia->prefix && ia->prefix[0] != '/')
167 argerror(_("arguments to --prefix must begin with a /"));
168
169 if (!(bigMode & MODES_IE) && (ia->installInterfaceFlags & INSTALL_HASH))
170 argerror(_("--hash (-h) may only be specified during package "
171 "installation and erasure"));
172
173 if (!(bigMode & MODES_IE) && (ia->installInterfaceFlags & INSTALL_PERCENT))
174 argerror(_("--percent may only be specified during package "
175 "installation and erasure"));
176
177 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
178 argerror(_("--replacepkgs may only be specified during package "
179 "installation"));
180
181 if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
182 argerror(_("--excludedocs may only be specified during package "
183 "installation"));
184
185 if (bigMode != MODE_INSTALL && ia->incldocs)
186 argerror(_("--includedocs may only be specified during package "
187 "installation"));
188
189 if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
190 argerror(_("only one of --excludedocs and --includedocs may be "
191 "specified"));
192
193 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
194 argerror(_("--ignorearch may only be specified during package "
195 "installation"));
196
197 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
198 argerror(_("--ignoreos may only be specified during package "
199 "installation"));
200
201 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
202 (ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES)))
203 argerror(_("--ignoresize may only be specified during package "
204 "installation"));
205
206 if ((ia->installInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
207 argerror(_("--allmatches may only be specified during package "
208 "erasure"));
209
210 if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
211 argerror(_("--allfiles may only be specified during package "
212 "installation"));
213
214 if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
215 bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
216 argerror(_("--justdb may only be specified during package "
217 "installation and erasure"));
218
219 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY &&
220 (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers)))
221 argerror(_("script disabling options may only be specified during "
222 "package installation and erasure"));
223
224 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE && bigMode != MODE_VERIFY &&
225 (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers)))
226 argerror(_("trigger disabling options may only be specified during "
227 "package installation and erasure"));
228
229 if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
230 argerror(_("--nodeps may only be specified during package "
231 "installation, erasure, and verification"));
232
233 if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
234 argerror(_("--test may only be specified during package installation "
235 "and erasure"));
236 #endif /* IAM_RPMEIU */
237
238 if (rpmcliRootDir && rpmcliRootDir[0] != '/') {
239 argerror(_("arguments to --root (-r) must begin with a /"));
240 }
241
242 if (quiet)
243 rpmSetVerbosity(RPMLOG_WARNING);
244
245 if (rpmcliPipeOutput && initPipe())
246 exit(EXIT_FAILURE);
247
248 ts = rpmtsCreate();
249 (void) rpmtsSetRootDir(ts, rpmcliRootDir);
250 switch (bigMode) {
251 #ifdef IAM_RPMEIU
252 case MODE_ERASE:
253 if (ia->noDeps) ia->installInterfaceFlags |= UNINSTALL_NODEPS;
254
255 if (!poptPeekArg(optCon)) {
256 argerror(_("no packages given for erase"));
257 } else {
258 ec += rpmErase(ts, ia, (ARGV_const_t) poptGetArgs(optCon));
259 }
260 break;
261
262 case MODE_INSTALL:
263
264 /* RPMTRANS_FLAG_KEEPOBSOLETE */
265
266 if (!ia->incldocs) {
267 if (ia->transFlags & RPMTRANS_FLAG_NODOCS) {
268 ;
269 } else if (rpmExpandNumeric("%{_excludedocs}"))
270 ia->transFlags |= RPMTRANS_FLAG_NODOCS;
271 }
272
273 if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS;
274
275 /* we've already ensured !(!ia->prefix && !ia->relocations) */
276 if (ia->prefix) {
277 ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
278 ia->relocations[0].oldPath = NULL; /* special case magic */
279 ia->relocations[0].newPath = ia->prefix;
280 ia->relocations[1].oldPath = NULL;
281 ia->relocations[1].newPath = NULL;
282 } else if (ia->relocations) {
283 ia->relocations = xrealloc(ia->relocations,
284 sizeof(*ia->relocations) * (ia->numRelocations + 1));
285 ia->relocations[ia->numRelocations].oldPath = NULL;
286 ia->relocations[ia->numRelocations].newPath = NULL;
287 }
288
289 if (!poptPeekArg(optCon)) {
290 argerror(_("no packages given for install"));
291 } else {
292 /* FIX: ia->relocations[0].newPath undefined */
293 ec += rpmInstall(ts, ia, (ARGV_t) poptGetArgs(optCon));
294 }
295 break;
296
297 #endif /* IAM_RPMEIU */
298
299 #ifdef IAM_RPMQV
300 case MODE_QUERY:
301 if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL))
302 argerror(_("no arguments given for query"));
303
304 ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
305 break;
306
307 case MODE_VERIFY:
308 { rpmVerifyFlags verifyFlags = VERIFY_ALL;
309
310 verifyFlags &= ~qva->qva_flags;
311 qva->qva_flags = (rpmQueryFlags) verifyFlags;
312
313 if (!poptPeekArg(optCon) && !(qva->qva_source == RPMQV_ALL))
314 argerror(_("no arguments given for verify"));
315 ec = rpmcliVerify(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
316 } break;
317 #endif /* IAM_RPMQV */
318
319 #if !defined(IAM_RPMQV)
320 case MODE_QUERY:
321 case MODE_VERIFY:
322 #endif
323 #if !defined(IAM_RPMEIU)
324 case MODE_INSTALL:
325 case MODE_ERASE:
326 #endif
327 case MODE_UNKNOWN:
328 if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
329 printUsage(optCon, stderr, 0);
330 ec = argc;
331 }
332 break;
333 }
334
335 rpmtsFree(ts);
336 if (finishPipe())
337 ec = EXIT_FAILURE;
338
339 #ifdef IAM_RPMQV
340 free(qva->qva_queryFormat);
341 #endif
342
343 #ifdef IAM_RPMEIU
344 if (ia->relocations != NULL) {
345 for (i = 0; i < ia->numRelocations; i++)
346 free(ia->relocations[i].oldPath);
347 free(ia->relocations);
348 }
349 #endif
350
351 rpmcliFini(optCon);
352
353 return RETVAL(ec);
354 }
RPMTRANS_FLAG_NODOCS
Definition: rpmts.h:35
RETVAL
#define RETVAL(rc)
Definition: cliutils.h:9
INSTALL_HASH
Definition: rpmcli.h:277
printUsage
void printUsage(poptContext con, FILE *fp, int flags)
Definition: cliutils.c:36
rpmVerifyFlags
rpmFlags rpmVerifyFlags
Definition: rpmvf.h:77
rpmQVKArguments_s::qva_sourceCount
int qva_sourceCount
Definition: rpmcli.h:170
rpmInstallArguments_s::numRelocations
int numRelocations
Definition: rpmcli.h:338
xmalloc
#define xmalloc(_size)
Definition: system.h:108
ARGV_t
char ** ARGV_t
Definition: argv.h:15
rpmInstallArguments_s::incldocs
int incldocs
Definition: rpmcli.h:340
RPMPROB_FILTER_DISKNODES
Definition: rpmprob.h:31
rpmRelocation_s::oldPath
char * oldPath
Definition: rpmfi.h:95
main
int main(int argc, char *argv[])
Definition: rpmqv.c:72
rpmInstallArguments_s::probFilter
rpmprobFilterFlags probFilter
Definition: rpmcli.h:336
debug.h
RPMPROB_FILTER_REPLACEPKG
Definition: rpmprob.h:25
INSTALL_PERCENT
Definition: rpmcli.h:276
optionsTable
static struct poptOption optionsTable[]
Definition: rpmqv.c:37
rpmtsFree
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
rpmErase
int rpmErase(rpmts ts, struct rpmInstallArguments_s *ia, ARGV_const_t argv)
Erase binary rpm package.
rpmQVKArguments_s::qva_flags
rpmQueryFlags qva_flags
Definition: rpmcli.h:171
rpmRelocation_s::newPath
char * newPath
Definition: rpmfi.h:96
MODES_FOR_NODEPS
#define MODES_FOR_NODEPS
Definition: rpmqv.c:31
rpmcliInit
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable)
Initialize most everything needed by an rpm CLI executable context.
rpmcliQuery
int rpmcliQuery(rpmts ts, QVA_t qva, ARGV_const_t argv)
Display package information.
rpmInstallArguments_s::relocations
rpmRelocation * relocations
Definition: rpmcli.h:341
cliutils.h
MODE_ERASE
Definition: rpmqv.c:25
RPMTRANS_FLAG_NOSCRIPTS
Definition: rpmts.h:32
rpmts
struct rpmts_s * rpmts
The main types involved in transaction manipulation.
Definition: rpmtypes.h:63
MODE_INSTALL
Definition: rpmqv.c:24
_noTransScripts
#define _noTransScripts
Definition: rpmts.h:59
finishPipe
int finishPipe(void)
Definition: cliutils.c:73
INSTALL_INSTALL
Definition: rpmcli.h:283
_
#define _(Text)
Definition: system.h:135
rpmQVKArguments_s
Describe query/verify/signature command line operation.
Definition: rpmcli.h:168
rpmIsVerbose
#define rpmIsVerbose()
Definition: rpmlog.h:272
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:66
rpmQVKArgs
struct rpmQVKArguments_s rpmQVKArgs
rpmtsCreate
rpmts rpmtsCreate(void)
Create an empty transaction set.
rpmInstallPoptTable
struct poptOption rpmInstallPoptTable[]
rpmcliFini
poptContext rpmcliFini(poptContext optCon)
Destroy most everything needed by an rpm CLI executable context.
RPMPROB_FILTER_DISKSPACE
Definition: rpmprob.h:30
rpmcliPipeOutput
const char * rpmcliPipeOutput
rpmQVKArguments_s::qva_mode
char qva_mode
Definition: rpmcli.h:177
argerror
void argerror(const char *desc)
Definition: cliutils.c:19
rpmQueryPoptTable
struct poptOption rpmQueryPoptTable[]
rpmQueryFlags
rpmFlags rpmQueryFlags
Definition: rpmcli.h:130
RPMLOG_WARNING
Definition: rpmlog.h:34
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:335
RPMPROB_FILTER_OLDPACKAGE
Definition: rpmprob.h:29
INSTALL_NODEPS
Definition: rpmcli.h:278
modes
modes
Definition: rpmbuild.c:204
VERIFY_ALL
#define VERIFY_ALL
Definition: rpmvf.h:82
rpmQVSourcePoptTable
struct poptOption rpmQVSourcePoptTable[]
rpmQVKArguments_s::qva_source
rpmQVSources qva_source
Definition: rpmcli.h:169
MODE_UNKNOWN
Definition: rpmqv.c:28
rpmcliVerify
int rpmcliVerify(rpmts ts, QVA_t qva, ARGV_const_t argv)
Verify package install.
initPipe
int initPipe(void)
Definition: cliutils.c:48
INSTALL_ERASE
Definition: rpmcli.h:284
rpmExpandNumeric
int rpmExpandNumeric(const char *arg)
Return macro expansion as a numeric value.
rpmInstallArguments_s::installInterfaceFlags
rpmInstallFlags installInterfaceFlags
Definition: rpmcli.h:337
RPMTRANS_FLAG_ALLFILES
Definition: rpmts.h:36
rpmIArgs
struct rpmInstallArguments_s rpmIArgs
quiet
static int quiet
Definition: rpmqv.c:34
rpmInstallArguments_s::noDeps
int noDeps
Definition: rpmcli.h:339
rpmcliRootDir
const char * rpmcliRootDir
RPMTRANS_FLAG_NOTRIGGERS
Definition: rpmts.h:34
MODE_VERIFY
Definition: rpmqv.c:21
rpmcliAllPoptTable
struct poptOption rpmcliAllPoptTable[]
Popt option table for options shared by all modes and executables.
rpmQVKArguments_s::qva_queryFormat
char * qva_queryFormat
Definition: rpmcli.h:176
RPMPROB_FILTER_IGNOREOS
Definition: rpmprob.h:23
ARGV_const_t
char *const * ARGV_const_t
Definition: argv.h:16
RPMQV_PACKAGE
Definition: rpmcli.h:79
MODE_QUERY
Definition: rpmqv.c:20
UNINSTALL_ALLMATCHES
#define UNINSTALL_ALLMATCHES
Definition: rpmcli.h:295
system.h
rpmInstallArguments_s
Describe database command line requests.
Definition: rpmcli.h:334
RPMPROB_FILTER_FORCERELOCATE
Definition: rpmprob.h:26
rpmVerifyPoptTable
struct poptOption rpmVerifyPoptTable[]
rpmInstallArguments_s::prefix
char * prefix
Definition: rpmcli.h:342
RPMTRANS_FLAG_TEST
Definition: rpmts.h:30
__progname
#define __progname
Definition: system.h:121
rpmInstall
int rpmInstall(rpmts ts, struct rpmInstallArguments_s *ia, ARGV_t fileArgv)
Install/upgrade/freshen binary rpm package.
N_
#define N_(Text)
Definition: system.h:138
INSTALL_UPGRADE
Definition: rpmcli.h:281
rpmSetVerbosity
#define rpmSetVerbosity(_lvl)
Definition: rpmlog.h:264
UNINSTALL_NODEPS
#define UNINSTALL_NODEPS
Definition: rpmcli.h:294
MODES_IE
#define MODES_IE
Definition: rpmqv.c:26
INSTALL_FRESHEN
Definition: rpmcli.h:282
RPMQV_ALL
Definition: rpmcli.h:81
rpmtsSetRootDir
int rpmtsSetRootDir(rpmts ts, const char *rootDir)
Set transaction rootDir, i.e.
xrealloc
#define xrealloc(_ptr, _size)
Definition: system.h:110
RPMTRANS_FLAG_JUSTDB
Definition: rpmts.h:33
RPMPROB_FILTER_IGNOREARCH
Definition: rpmprob.h:24