- supply transitive closure for CLI packages from rpmdb-redhat database.
[platform/upstream/rpm.git] / lib / poptI.c
1 /** \ingroup rpmcli
2  * \file lib/poptI.c
3  *  Popt tables for install modes.
4  */
5
6 #include "system.h"
7
8 #include <rpmcli.h>
9
10 #include "debug.h"
11
12 /*@-redecl@*/
13 extern time_t get_date(const char * p, void * now);     /* XXX expedient lies */
14 /*@=redecl@*/
15
16 /*@unchecked@*/
17 struct rpmInstallArguments_s rpmIArgs;
18
19 #define POPT_RELOCATE           -1021
20 #define POPT_EXCLUDEPATH        -1022
21 #define POPT_ROLLBACK           -1023
22
23 /*@exits@*/
24 static void argerror(const char * desc)
25         /*@globals stderr, fileSystem @*/
26         /*@modifies stderr, fileSystem @*/
27 {
28     /*@-modfilesys -globs @*/
29     fprintf(stderr, _("%s: %s\n"), __progname, desc);
30     /*@=modfilesys =globs @*/
31     exit(EXIT_FAILURE);
32 }
33
34 /**
35  */
36 /*@-bounds@*/
37 static void installArgCallback( /*@unused@*/ poptContext con,
38                 /*@unused@*/ enum poptCallbackReason reason,
39                 const struct poptOption * opt, const char * arg,
40                 /*@unused@*/ const void * data)
41         /*@globals rpmIArgs, stderr, fileSystem @*/
42         /*@modifies rpmIArgs, stderr, fileSystem @*/
43 {
44     struct rpmInstallArguments_s * ia = &rpmIArgs;
45
46     /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
47     /*@-branchstate@*/
48     if (opt->arg == NULL)
49     switch (opt->val) {
50
51     case 'i':
52         ia->installInterfaceFlags |= INSTALL_INSTALL;
53         break;
54
55     case POPT_EXCLUDEPATH:
56         if (arg == NULL || *arg != '/') 
57             argerror(_("exclude paths must begin with a /"));
58         ia->relocations = xrealloc(ia->relocations, 
59                         sizeof(*ia->relocations) * (ia->numRelocations + 1));
60 /*@-temptrans@*/
61         ia->relocations[ia->numRelocations].oldPath = xstrdup(arg);
62 /*@=temptrans@*/
63         ia->relocations[ia->numRelocations].newPath = NULL;
64         ia->numRelocations++;
65         break;
66     case POPT_RELOCATE:
67       { char * oldPath = NULL;
68         char * newPath = NULL;
69         
70         if (arg == NULL || *arg != '/') 
71             argerror(_("relocations must begin with a /"));
72         oldPath = xstrdup(arg);
73         if (!(newPath = strchr(oldPath, '=')))
74             argerror(_("relocations must contain a ="));
75         *newPath++ = '\0';
76         if (*newPath != '/') 
77             argerror(_("relocations must have a / following the ="));
78         ia->relocations = xrealloc(ia->relocations, 
79                         sizeof(*ia->relocations) * (ia->numRelocations + 1));
80 /*@-temptrans@*/
81         ia->relocations[ia->numRelocations].oldPath = oldPath;
82 /*@=temptrans@*/
83 /*@-kepttrans -usereleased @*/
84         ia->relocations[ia->numRelocations].newPath = newPath;
85 /*@=kepttrans =usereleased @*/
86         ia->numRelocations++;
87       } break;
88
89     case POPT_ROLLBACK:
90       { time_t tid;
91         if (arg == NULL)
92             argerror(_("rollback takes a time/date stamp argument"));
93
94         /*@-moduncon@*/
95         tid = get_date(arg, NULL);
96         /*@=moduncon@*/
97
98         if (tid == (time_t)-1 || tid == (time_t)0)
99             argerror(_("malformed rollback time/date stamp argument"));
100         ia->rbtid = tid;
101       } break;
102
103     case RPMCLI_POPT_NODIGEST:
104         ia->qva_flags |= VERIFY_DIGEST;
105         break;
106
107     case RPMCLI_POPT_NOSIGNATURE:
108         ia->qva_flags |= VERIFY_SIGNATURE;
109         break;
110
111     case RPMCLI_POPT_NOHDRCHK:
112         ia->qva_flags |= VERIFY_HDRCHK;
113         break;
114
115     case RPMCLI_POPT_NODEPS:
116         ia->noDeps = 1;
117         break;
118
119     case RPMCLI_POPT_NOMD5:
120         ia->transFlags |= RPMTRANS_FLAG_NOMD5;
121         break;
122
123     case RPMCLI_POPT_FORCE:
124         ia->probFilter |=
125                 ( RPMPROB_FILTER_REPLACEPKG
126                 | RPMPROB_FILTER_REPLACEOLDFILES
127                 | RPMPROB_FILTER_REPLACENEWFILES
128                 | RPMPROB_FILTER_OLDPACKAGE );
129         break;
130
131     case RPMCLI_POPT_NOSCRIPTS:
132         ia->transFlags |= (_noTransScripts | _noTransTriggers);
133         break;
134
135     }
136     /*@=branchstate@*/
137 }
138 /*@=bounds@*/
139
140 /**
141  */
142 /*@-bitwisesigned -compmempass @*/
143 /*@unchecked@*/
144 struct poptOption rpmInstallPoptTable[] = {
145 /*@-type@*/ /* FIX: cast? */
146  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
147         installArgCallback, 0, NULL, NULL },
148 /*@=type@*/
149
150  { "aid", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
151         &rpmIArgs.transFlags, RPMTRANS_FLAG_ADDINDEPS,
152         N_("add suggested packages to transaction"), NULL },
153
154  { "allfiles", '\0', POPT_BIT_SET,
155         &rpmIArgs.transFlags, RPMTRANS_FLAG_ALLFILES,
156   N_("install all files, even configurations which might otherwise be skipped"),
157         NULL},
158  { "allmatches", '\0', POPT_BIT_SET,
159         &rpmIArgs.eraseInterfaceFlags, UNINSTALL_ALLMATCHES,
160         N_("remove all packages which match <package> (normally an error is generated if <package> specified multiple packages)"),
161         NULL},
162
163  { "apply", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
164         (_noTransScripts|_noTransTriggers|
165                 RPMTRANS_FLAG_APPLYONLY|RPMTRANS_FLAG_PKGCOMMIT),
166         N_("do not execute package scriptlet(s)"), NULL },
167
168  { "badreloc", '\0', POPT_BIT_SET,
169         &rpmIArgs.probFilter, RPMPROB_FILTER_FORCERELOCATE,
170         N_("relocate files in non-relocateable package"), NULL},
171  { "dirstash", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
172         &rpmIArgs.transFlags, RPMTRANS_FLAG_DIRSTASH,
173         N_("save erased package files by renaming into sub-directory"), NULL},
174  { "erase", 'e', POPT_BIT_SET,
175         &rpmIArgs.installInterfaceFlags, INSTALL_ERASE,
176         N_("erase (uninstall) package"), N_("<package>+") },
177  { "excludedocs", '\0', POPT_BIT_SET,
178         &rpmIArgs.transFlags, RPMTRANS_FLAG_NODOCS,
179         N_("do not install documentation"), NULL},
180  { "excludepath", '\0', POPT_ARG_STRING, 0, POPT_EXCLUDEPATH,
181         N_("skip files with leading component <path> "),
182         N_("<path>") },
183
184 #ifdef  DYING
185  { "force", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
186         (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES | RPMPROB_FILTER_OLDPACKAGE),
187         N_("short hand for --replacepkgs --replacefiles"), NULL},
188 #else
189  { "force", '\0', 0, NULL, RPMCLI_POPT_FORCE,
190         N_("short hand for --replacepkgs --replacefiles"), NULL},
191 #endif
192
193  { "freshen", 'F', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags,
194         (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL),
195         N_("upgrade package(s) if already installed"),
196         N_("<packagefile>+") },
197  { "hash", 'h', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags, INSTALL_HASH,
198         N_("print hash marks as package installs (good with -v)"), NULL},
199  { "ignorearch", '\0', POPT_BIT_SET,
200         &rpmIArgs.probFilter, RPMPROB_FILTER_IGNOREARCH,
201         N_("don't verify package architecture"), NULL},
202  { "ignoreos", '\0', POPT_BIT_SET,
203         &rpmIArgs.probFilter, RPMPROB_FILTER_IGNOREOS,
204         N_("don't verify package operating system"), NULL},
205  { "ignoresize", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
206         (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES),
207         N_("don't check disk space before installing"), NULL},
208  { "includedocs", '\0', POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.incldocs, 0,
209         N_("install documentation"), NULL},
210
211 #ifdef  DYING
212  { "install", '\0', POPT_BIT_SET,
213         &rpmIArgs.installInterfaceFlags, INSTALL_INSTALL,
214         N_("install package(s)"), N_("<packagefile>+") },
215 #else
216  { "install", 'i', 0, NULL, 'i',
217         N_("install package(s)"), N_("<packagefile>+") },
218 #endif
219
220  { "justdb", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_JUSTDB,
221         N_("update the database, but do not modify the filesystem"), NULL},
222
223 #ifdef  DYING
224  { "nodeps", '\0', 0, &rpmIArgs.noDeps, 0,
225         N_("do not verify package dependencies"), NULL },
226 #else
227  { "nodeps", '\0', 0, NULL, RPMCLI_POPT_NODEPS,
228         N_("do not verify package dependencies"), NULL },
229 #endif
230
231  { "nomd5", '\0', 0, NULL, RPMCLI_POPT_NOMD5,
232         N_("don't verify MD5 digest of files"), NULL },
233  { "noorder", '\0', POPT_BIT_SET,
234         &rpmIArgs.installInterfaceFlags, INSTALL_NOORDER,
235         N_("do not reorder package installation to satisfy dependencies"),
236         NULL},
237
238  { "nosuggest", '\0', POPT_BIT_SET, &rpmIArgs.transFlags,
239         RPMTRANS_FLAG_NOSUGGEST,
240         N_("do not suggest missing dependency resolution(s)"), NULL},
241
242 #ifdef  DYING
243  { "noscripts", '\0', POPT_BIT_SET, &rpmIArgs.transFlags,
244         (_noTransScripts|_noTransTriggers),
245         N_("do not execute package scriptlet(s)"), NULL },
246 #else
247  { "noscripts", '\0', 0, NULL, RPMCLI_POPT_NOSCRIPTS,
248         N_("do not execute package scriptlet(s)"), NULL },
249 #endif
250  { "nopre", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
251         RPMTRANS_FLAG_NOPRE,
252         N_("do not execute %%pre scriptlet (if any)"), NULL },
253  { "nopost", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
254         RPMTRANS_FLAG_NOPOST,
255         N_("do not execute %%post scriptlet (if any)"), NULL },
256  { "nopreun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
257         RPMTRANS_FLAG_NOPREUN,
258         N_("do not execute %%preun scriptlet (if any)"), NULL },
259  { "nopostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
260         RPMTRANS_FLAG_NOPOSTUN,
261         N_("do not execute %%postun scriptlet (if any)"), NULL },
262
263 #ifdef  DYING
264  { "nodigest", '\0', POPT_BIT_SET, &rpmIArgs.qva_flags, VERIFY_DIGEST,
265         N_("don't verify package digest(s)"), NULL },
266  { "nohdrchk", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.qva_flags, VERIFY_HDRCHK,
267         N_("don't verify database header(s) when retrieved"), NULL },
268  { "nosignature", '\0', POPT_BIT_SET, &rpmIArgs.qva_flags, VERIFY_SIGNATURE,
269         N_("don't verify package signature(s)"), NULL },
270 #else
271  { "nodigest", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NODIGEST,
272         N_("don't verify package digest(s)"), NULL },
273  { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOHDRCHK,
274         N_("don't verify database header(s) when retrieved"), NULL },
275  { "nosignature", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOSIGNATURE,
276         N_("don't verify package signature(s)"), NULL },
277 #endif
278
279  { "notriggers", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, _noTransTriggers,
280         N_("do not execute any scriptlet(s) triggered by this package"), NULL},
281  { "notriggerprein", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
282         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERPREIN,
283         N_("do not execute any %%triggerprein scriptlet(s)"), NULL},
284  { "notriggerin", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
285         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERIN,
286         N_("do not execute any %%triggerin scriptlet(s)"), NULL},
287  { "notriggerun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
288         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERUN,
289         N_("do not execute any %%triggerun scriptlet(s)"), NULL},
290  { "notriggerpostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
291         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERPOSTUN,
292         N_("do not execute any %%triggerpostun scriptlet(s)"), NULL},
293
294  { "oldpackage", '\0', POPT_BIT_SET,
295         &rpmIArgs.probFilter, RPMPROB_FILTER_OLDPACKAGE,
296         N_("upgrade to an old version of the package (--force on upgrades does this automatically)"),
297         NULL},
298  { "percent", '\0', POPT_BIT_SET,
299         &rpmIArgs.installInterfaceFlags, INSTALL_PERCENT,
300         N_("print percentages as package installs"), NULL},
301  { "prefix", '\0', POPT_ARG_STRING, &rpmIArgs.prefix, 0,
302         N_("relocate the package to <dir>, if relocatable"),
303         N_("<dir>") },
304  { "relocate", '\0', POPT_ARG_STRING, 0, POPT_RELOCATE,
305         N_("relocate files from path <old> to <new>"),
306         N_("<old>=<new>") },
307  { "repackage", '\0', POPT_BIT_SET,
308         &rpmIArgs.transFlags, RPMTRANS_FLAG_REPACKAGE,
309         N_("save erased package files by repackaging"), NULL},
310  { "replacefiles", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
311         (RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES),
312         N_("install even if the package replaces installed files"), NULL},
313  { "replacepkgs", '\0', POPT_BIT_SET,
314         &rpmIArgs.probFilter, RPMPROB_FILTER_REPLACEPKG,
315         N_("reinstall if the package is already present"), NULL},
316  { "rollback", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_ROLLBACK,
317         N_("deinstall new, reinstall old, package(s), back to <date>"),
318         N_("<date>") },
319  { "test", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_TEST,
320         N_("don't install, but tell if it would work or not"), NULL},
321  { "upgrade", 'U', POPT_BIT_SET,
322         &rpmIArgs.installInterfaceFlags, (INSTALL_UPGRADE|INSTALL_INSTALL),
323         N_("upgrade package(s)"),
324         N_("<packagefile>+") },
325
326    POPT_TABLEEND
327 };
328 /*@=bitwisesigned =compmempass @*/