rpm 5.2.1

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

- File List
- Globals

poptI.c
Go to the documentation of this file.
1
6 #include "system.h"
7
8 #include <rpmio.h>
9 #include <rpmiotypes.h>
10 #include <rpmlog.h>
11
12 #include <rpmtag.h>
13 #include <rpmcli.h>
14
15 #include "debug.h"
16
17 /*@-redecl@*/
18 extern time_t get_date(const char * p, void * now); /* XXX expedient lies */
19 /*@=redecl@*/
20
21 /*@-fullinitblock@*/
22 /*@unchecked@*/
23 struct rpmQVKArguments_s rpmIArgs = {
24 #if defined(RPM_VENDOR_MANDRIVA) /* dont-filter-install-file-conflicts */
25 .probFilter = RPMPROB_FILTER_NONE,
26 #else
27 .probFilter = (RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES),
28 #endif
29 };
30 /*@=fullinitblock@*/
31
32 #define POPT_RELOCATE -1021
33 #define POPT_EXCLUDEPATH -1022
34 #define POPT_ROLLBACK -1023
35 #define POPT_ROLLBACK_EXCLUDE -1024
36 /* -1025 thrugh -1033 are common in rpmcli.h. */
37 #define POPT_AUTOROLLBACK_GOAL -1036
38
39 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
40
46 /*@exits@*/
47 static void argerror(const char * desc)
48 /*@globals stderr, fileSystem @*/
49 /*@modifies stderr, fileSystem @*/
50 {
51 /*@-modfilesys -globs @*/
52 fprintf(stderr, _("%s: %s\n"), __progname, desc);
53 /*@=modfilesys =globs @*/
54 exit(EXIT_FAILURE);
55 }
56
59 static void installArgCallback(/*@unused@*/ poptContext con,
60 /*@unused@*/ enum poptCallbackReason reason,
61 const struct poptOption * opt, const char * arg,
62 /*@unused@*/ const void * data)
63 /*@globals rpmIArgs, stderr, fileSystem @*/
64 /*@modifies rpmIArgs, stderr, fileSystem @*/
65 {
66 QVA_t ia = &rpmIArgs;
67 int xx;
68
69 /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
70 if (opt->arg == NULL)
71 switch (opt->val) {
72
73 case 'i':
74 ia->installInterfaceFlags |= INSTALL_INSTALL;
75 break;
76
77 case POPT_EXCLUDEPATH:
78 if (arg == NULL || *arg != '/')
79 argerror(_("exclude paths must begin with a /"));
80 xx = rpmfiAddRelocation(&ia->relocations, &ia->nrelocations, arg, NULL);
81 break;
82 case POPT_RELOCATE:
83 { char * oldPath = NULL;
84 char * newPath = NULL;
85
86 if (arg == NULL)
87 argerror(_("Option --relocate needs /old/path=/new/path argument"));
88 if (*arg != '/')
89 argerror(_("relocations must begin with a /"));
90 oldPath = xstrdup(arg);
91 if (!(newPath = strchr(oldPath, '=')))
92 argerror(_("relocations must contain a ="));
93 *newPath++ = '\0';
94 if (*newPath != '/')
95 argerror(_("relocations must have a / following the ="));
96 xx = rpmfiAddRelocation(&ia->relocations, &ia->nrelocations,
97 oldPath, newPath);
98 oldPath = _free(oldPath);
99 } break;
100
101 case POPT_ROLLBACK_EXCLUDE:
102 { rpmuint32_t tid;
103 char *t, *te;
104
105 /* Make sure we were given the proper number of args */
106 if (arg == NULL)
107 argerror(_("Option --rbexclude needs transaction id argument(s)"));
108
109 te = alloca_strdup(arg);
110 while (*te != '\0' && strchr(" \t\n,", *te) != NULL)
111 *te++ = '\0';
112 while ((t = te++) != NULL && *t != '\0') {
113 /* Find next tid. */
114 while (*te != '\0' && strchr(" \t\n,", *te) == NULL)
115 te++;
116 while (*te != '\0' && strchr(" \t\n,", *te) != NULL)
117 *te++ = '\0';
118
119 /* Convert arg to TID which happens to be time_t */
120 /* XXX: Need check for arg to be an integer */
121 tid = (rpmuint32_t) strtol(t, NULL, 0);
122
123 /* Allocate space for new exclude tid */
124 ia->rbtidExcludes = xrealloc(ia->rbtidExcludes,
125 sizeof(*ia->rbtidExcludes) * (ia->numrbtidExcludes + 1));
126
127 /* Add it to the list and iterate count*/
128 /*@-temptrans@*/
129 ia->rbtidExcludes[ia->numrbtidExcludes] = tid;
130 /*@=temptrans@*/
131 ia->numrbtidExcludes++;
132 }
133 } break;
134
135 case POPT_ROLLBACK:
136 { time_t tid;
137 if (arg == NULL)
138 argerror(_("Option --rollback needs a time/date stamp argument"));
139
140 /*@-moduncon@*/
141 tid = get_date(arg, NULL);
142 rpmlog(RPMLOG_INFO, _("Rollback goal: %-24.24s (0x%08x)\n"), ctime(&tid), (int)tid);
143 /*@=moduncon@*/
144
145 if (tid == (time_t)-1 || tid == (time_t)0)
146 argerror(_("malformed rollback time/date stamp argument"));
147 ia->rbtid = (rpmuint32_t)tid;
148 } break;
149
150 case POPT_AUTOROLLBACK_GOAL:
151 { time_t tid;
152 if (arg == NULL)
153 argerror(_("arbgoal takes a time/date stamp argument"));
154
155 /*@-moduncon@*/
156 tid = get_date(arg, NULL);
157 /*@=moduncon@*/
158
159 if (tid == (time_t)-1 || tid == (time_t)0)
160 argerror(_("malformed arbgoal time/date stamp argument"));
161 ia->arbtid = (rpmuint32_t)tid;
162 } break;
163
164 case RPMCLI_POPT_NODIGEST:
165 ia->qva_flags |= VERIFY_DIGEST;
166 break;
167
168 case RPMCLI_POPT_NOSIGNATURE:
169 ia->qva_flags |= VERIFY_SIGNATURE;
170 break;
171
172 case RPMCLI_POPT_NOHDRCHK:
173 ia->qva_flags |= VERIFY_HDRCHK;
174 break;
175
176 case RPMCLI_POPT_NODEPS:
177 ia->noDeps = 1;
178 break;
179
180 case RPMCLI_POPT_NOCONTEXTS:
181 ia->transFlags |= RPMTRANS_FLAG_NOCONTEXTS;
182 break;
183
184 case RPMCLI_POPT_NOSCRIPTS:
185 ia->transFlags |= (_noTransScripts|_noTransTriggers);
186 break;
187
188 case RPMCLI_POPT_NOFDIGESTS:
189 ia->transFlags |= RPMTRANS_FLAG_NOFDIGESTS;
190 break;
191
192 }
193 }
194
197 /*@-bitwisesigned -compmempass @*/
198 /*@unchecked@*/
199 struct poptOption rpmInstallPoptTable[] = {
200 /*@-type@*/ /* FIX: cast? */
201 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
202 installArgCallback, 0, NULL, NULL },
203 /*@=type@*/
204
205 { "allfiles", '\0', POPT_BIT_SET,
206 &rpmIArgs.transFlags, RPMTRANS_FLAG_ALLFILES,
207 N_("install all files, even configurations which might otherwise be skipped"),
208 NULL},
209 { "apply", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
210 (_noTransScripts|_noTransTriggers|
211 RPMTRANS_FLAG_APPLYONLY|RPMTRANS_FLAG_PKGCOMMIT),
212 N_("do not execute package scriptlet(s)"), NULL },
213 { "dirstash", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
214 &rpmIArgs.transFlags, RPMTRANS_FLAG_DIRSTASH,
215 N_("save erased package files by renaming into sub-directory"), NULL},
216 { "excludeconfigs", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
217 &rpmIArgs.transFlags, RPMTRANS_FLAG_NOCONFIGS,
218 N_("do not install configuration files"), NULL},
219 { "excludedocs", '\0', POPT_BIT_SET,
220 &rpmIArgs.transFlags, RPMTRANS_FLAG_NODOCS,
221 N_("do not install documentation"), NULL},
222 { "justdb", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_JUSTDB,
223 N_("update the database, but do not modify the filesystem"), NULL},
224 { "noconfigs", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
225 &rpmIArgs.transFlags, RPMTRANS_FLAG_NOCONFIGS,
226 N_("do not install configuration files"), NULL},
227 { "nodocs", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
228 &rpmIArgs.transFlags, RPMTRANS_FLAG_NODOCS,
229 N_("do not install documentation"), NULL},
230 #ifdef NOTYET /* XXX multiple identical options forces popt callback. */
231 { "nocontexts", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
232 &rpmIArgs.transFlags, RPMTRANS_FLAG_NOCONTEXTS,
233 N_("don't install file security contexts"), NULL},
234 { "nofdigests", '\0', POPT_BIT_SET,
235 &rpmIArgs.transFlags, RPMTRANS_FLAG_NOFDIGESTS,
236 N_("don't verify file digests"), NULL },
237 #else
238 { "nocontexts", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NOCONTEXTS,
239 N_("don't verify file security contexts"), NULL },
240 { "nofdigests", '\0', 0, NULL, RPMCLI_POPT_NOFDIGESTS,
241 N_("don't verify file digests"), NULL },
242 #endif
243 { "norpmdb", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
244 &rpmIArgs.transFlags, RPMTRANS_FLAG_NORPMDB,
245 N_("don't register headers in rpmdb"), NULL},
246
247 #ifdef NOTYET /* XXX multiple identical options forces popt callback. */
248 { "noscripts", '\0', POPT_BIT_SET,
249 &rpmIArgs.transFlags, (_noTransScripts|_noTransTriggers),
250 N_("do not execute package scriptlet(s)"), NULL },
251 #else
252 { "noscripts", '\0', 0, NULL, RPMCLI_POPT_NOSCRIPTS,
253 N_("do not execute package scriptlet(s)"), NULL },
254 #endif
255 { "nopretrans", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
256 &rpmIArgs.transFlags, RPMTRANS_FLAG_NOPRETRANS,
257 N_("do not execute %%pretrans scriptlet (if any)"), NULL },
258 { "nopre", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
259 &rpmIArgs.transFlags, RPMTRANS_FLAG_NOPRE,
260 N_("do not execute %%pre scriptlet (if any)"), NULL },
261 { "nopost", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
262 &rpmIArgs.transFlags, RPMTRANS_FLAG_NOPOST,
263 N_("do not execute %%post scriptlet (if any)"), NULL },
264 { "nopreun", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
265 &rpmIArgs.transFlags, RPMTRANS_FLAG_NOPREUN,
266 N_("do not execute %%preun scriptlet (if any)"), NULL },
267 { "nopostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
268 &rpmIArgs.transFlags, RPMTRANS_FLAG_NOPOSTUN,
269 N_("do not execute %%postun scriptlet (if any)"), NULL },
270 { "noposttrans", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
271 &rpmIArgs.transFlags, RPMTRANS_FLAG_NOPOSTTRANS,
272 N_("do not execute %%postrans scriptlet (if any)"), NULL },
273
274 { "notriggers", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, _noTransTriggers,
275 N_("do not execute any scriptlet(s) triggered by this package"), NULL},
276 { "notriggerprein", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
277 &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERPREIN,
278 N_("do not execute any %%triggerprein scriptlet(s)"), NULL},
279 { "notriggerin", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
280 &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERIN,
281 N_("do not execute any %%triggerin scriptlet(s)"), NULL},
282 { "notriggerun", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
283 &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERUN,
284 N_("do not execute any %%triggerun scriptlet(s)"), NULL},
285 { "notriggerpostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
286 &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERPOSTUN,
287 N_("do not execute any %%triggerpostun scriptlet(s)"), NULL},
288
289 { "repackage", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE,
290 &rpmIArgs.transFlags, RPMTRANS_FLAG_REPACKAGE,
291 N_("save erased package files by repackaging"), NULL},
292 { "test", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_TEST,
293 N_("don't install, but tell if it would work or not"), NULL},
294
295 { "allmatches", '\0', POPT_BIT_SET,
296 &rpmIArgs.installInterfaceFlags, INSTALL_ALLMATCHES,
297 N_("remove all packages which match <package> (normally an error is generated if <package> specified multiple packages)"),
298 NULL},
299
300 { "badreloc", '\0', POPT_BIT_SET,
301 &rpmIArgs.probFilter, RPMPROB_FILTER_FORCERELOCATE,
302 N_("relocate files in non-relocatable package"), NULL},
303
304 { "erase", 'e', POPT_BIT_SET,
305 &rpmIArgs.installInterfaceFlags, INSTALL_ERASE,
306 N_("erase (uninstall) package"), N_("<package>+") },
307 { "excludepath", '\0', POPT_ARG_STRING, NULL, POPT_EXCLUDEPATH,
308 N_("skip files with leading component <path> "),
309 N_("<path>") },
310
311 { "fileconflicts", '\0', POPT_BIT_CLR, &rpmIArgs.probFilter,
312 (RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES),
313 N_("detect file conflicts between packages"), NULL},
314
315 { "freshen", 'F', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags,
316 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL),
317 N_("upgrade package(s) if already installed"),
318 N_("<packagefile>+") },
319 { "hash", 'h', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags, INSTALL_HASH,
320 N_("print hash marks as package installs (good with -v)"), NULL},
321 #ifndef DIEDIEDIE
322 { "ignorearch", '\0', POPT_BIT_SET,
323 &rpmIArgs.probFilter, RPMPROB_FILTER_IGNOREARCH,
324 N_("don't verify package architecture"), NULL},
325 { "ignoreos", '\0', POPT_BIT_SET,
326 &rpmIArgs.probFilter, RPMPROB_FILTER_IGNOREOS,
327 N_("don't verify package operating system"), NULL},
328 #endif
329 { "ignoresize", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
330 (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES),
331 N_("don't check disk space before installing"), NULL},
332 { "includedocs", '\0', POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.incldocs, 0,
333 N_("install documentation"), NULL},
334
335 { "install", 'i', 0, NULL, 'i',
336 N_("install package(s)"), N_("<packagefile>+") },
337
338 { "nodeps", '\0', 0, NULL, RPMCLI_POPT_NODEPS,
339 N_("do not verify package dependencies"), NULL },
340
341 { "noorder", '\0', POPT_BIT_SET,
342 &rpmIArgs.installInterfaceFlags, INSTALL_NOORDER,
343 N_("do not reorder package installation to satisfy dependencies"),
344 NULL},
345
346 { "nodigest", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NODIGEST,
347 N_("don't verify package digest(s)"), NULL },
348 { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NOHDRCHK,
349 N_("don't verify database header(s) when retrieved"), NULL },
350 { "nosignature", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NOSIGNATURE,
351 N_("don't verify package signature(s)"), NULL },
352
353 { "oldpackage", '\0', POPT_BIT_SET,
354 &rpmIArgs.probFilter, RPMPROB_FILTER_OLDPACKAGE,
355 N_("upgrade to an old version of the package (--force on upgrades does this automatically)"),
356 NULL},
357 { "percent", '\0', POPT_BIT_SET,
358 &rpmIArgs.installInterfaceFlags, INSTALL_PERCENT,
359 N_("print percentages as package installs"), NULL},
360 { "prefix", '\0', POPT_ARG_STRING, &rpmIArgs.qva_prefix, 0,
361 N_("relocate the package to <dir>, if relocatable"),
362 N_("<dir>") },
363 { "relocate", '\0', POPT_ARG_STRING, NULL, POPT_RELOCATE,
364 N_("relocate files from path <old> to <new>"),
365 N_("<old>=<new>") },
366 { "replacefiles", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
367 (RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES),
368 N_("ignore file conflicts between packages"), NULL},
369 { "replacepkgs", '\0', POPT_BIT_SET,
370 &rpmIArgs.probFilter, RPMPROB_FILTER_REPLACEPKG,
371 N_("reinstall if the package is already present"), NULL},
372 { "rollback", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, NULL, POPT_ROLLBACK,
373 N_("deinstall new, reinstall old, package(s), back to <date>"),
374 N_("<date>") },
375 { "arbgoal", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, NULL, POPT_AUTOROLLBACK_GOAL,
376 N_("If transaction fails rollback to <date>"),
377 N_("<date>") },
378 { "rbexclude", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, NULL, POPT_ROLLBACK_EXCLUDE,
379 N_("Exclude Transaction I.D. from rollback"),
380 N_("<tid>") },
381 { "upgrade", 'U', POPT_BIT_SET,
382 &rpmIArgs.installInterfaceFlags, (INSTALL_UPGRADE|INSTALL_INSTALL),
383 N_("upgrade package(s)"),
384 N_("<packagefile>+") },
385
386 POPT_TABLEEND
387 };
388 /*@=bitwisesigned =compmempass @*/