rpm 5.2.1

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

- File List
- Globals

lib/poptI.c
Go to the documentation of this file.

    00001
    00006 #include "system.h"
    00007
    00008 #include <rpmio.h>
    00009 #include <rpmiotypes.h>
    00010 #include <rpmlog.h>
    00011
    00012 #include <rpmtag.h>
    00013 #include <rpmcli.h>
    00014
    00015 #include "debug.h"
    00016
    00017 /*@-redecl@*/
    00018 extern time_t get_date(const char * p, void * now);     /* XXX expedient lies */
    00019 /*@=redecl@*/
    00020
    00021 /*@-fullinitblock@*/
    00022 /*@unchecked@*/
    00023 struct rpmQVKArguments_s rpmIArgs = {
    00024 #if defined(RPM_VENDOR_MANDRIVA) /* dont-filter-install-file-conflicts */
    00025     .probFilter = RPMPROB_FILTER_NONE,
    00026 #else
    00027     .probFilter = (RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES),
    00028 #endif
    00029 };
    00030 /*@=fullinitblock@*/
    00031
    00032 #define POPT_RELOCATE           -1021
    00033 #define POPT_EXCLUDEPATH        -1022
    00034 #define POPT_ROLLBACK           -1023
    00035 #define POPT_ROLLBACK_EXCLUDE   -1024
    00036 /* -1025 thrugh -1033 are common in rpmcli.h. */
    00037 #define POPT_AUTOROLLBACK_GOAL  -1036
    00038
    00039 #define alloca_strdup(_s)       strcpy(alloca(strlen(_s)+1), (_s))
    00040
    00046 /*@exits@*/
    00047 static void argerror(const char * desc)
    00048         /*@globals stderr, fileSystem @*/
    00049         /*@modifies stderr, fileSystem @*/
    00050 {
    00051     /*@-modfilesys -globs @*/
    00052     fprintf(stderr, _("%s: %s\n"), __progname, desc);
    00053     /*@=modfilesys =globs @*/
    00054     exit(EXIT_FAILURE);
    00055 }
    00056
    00059 static void installArgCallback(/*@unused@*/ poptContext con,
    00060                 /*@unused@*/ enum poptCallbackReason reason,
    00061                 const struct poptOption * opt, const char * arg,
    00062                 /*@unused@*/ const void * data)
    00063         /*@globals rpmIArgs, stderr, fileSystem @*/
    00064         /*@modifies rpmIArgs, stderr, fileSystem @*/
    00065 {
    00066     QVA_t ia = &rpmIArgs;
    00067     int xx;
    00068
    00069     /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
    00070     if (opt->arg == NULL)
    00071     switch (opt->val) {
    00072
    00073     case 'i':
    00074         ia->installInterfaceFlags |= INSTALL_INSTALL;
    00075         break;
    00076
    00077     case POPT_EXCLUDEPATH:
    00078         if (arg == NULL || *arg != '/')
    00079             argerror(_("exclude paths must begin with a /"));
    00080         xx = rpmfiAddRelocation(&ia->relocations, &ia->nrelocations, arg, NULL);
    00081         break;
    00082     case POPT_RELOCATE:
    00083       { char * oldPath = NULL;
    00084         char * newPath = NULL;
    00085
    00086         if (arg == NULL)
    00087             argerror(_("Option --relocate needs /old/path=/new/path argument"));
    00088         if (*arg != '/')
    00089             argerror(_("relocations must begin with a /"));
    00090         oldPath = xstrdup(arg);
    00091         if (!(newPath = strchr(oldPath, '=')))
    00092             argerror(_("relocations must contain a ="));
    00093         *newPath++ = '\0';
    00094         if (*newPath != '/')
    00095             argerror(_("relocations must have a / following the ="));
    00096         xx = rpmfiAddRelocation(&ia->relocations, &ia->nrelocations,
    00097                         oldPath, newPath);
    00098         oldPath = _free(oldPath);
    00099       } break;
    00100
    00101     case POPT_ROLLBACK_EXCLUDE:
    00102     {   rpmuint32_t tid;
    00103         char *t, *te;
    00104
    00105         /* Make sure we were given the proper number of args */
    00106         if (arg == NULL)
    00107             argerror(_("Option --rbexclude needs transaction id argument(s)"));
    00108
    00109         te = alloca_strdup(arg);
    00110         while (*te != '\0' && strchr(" \t\n,", *te) != NULL)
    00111             *te++ = '\0';
    00112         while ((t = te++) != NULL && *t != '\0') {
    00113             /* Find next tid. */
    00114             while (*te != '\0' && strchr(" \t\n,", *te) == NULL)
    00115                 te++;
    00116             while (*te != '\0' && strchr(" \t\n,", *te) != NULL)
    00117                 *te++ = '\0';
    00118
    00119             /* Convert arg to TID which happens to be time_t */
    00120             /* XXX: Need check for arg to be an integer      */
    00121             tid = (rpmuint32_t) strtol(t, NULL, 0);
    00122
    00123             /* Allocate space for new exclude tid */
    00124             ia->rbtidExcludes = xrealloc(ia->rbtidExcludes,
    00125                 sizeof(*ia->rbtidExcludes) * (ia->numrbtidExcludes + 1));
    00126
    00127             /* Add it to the list and iterate count*/
    00128 /*@-temptrans@*/
    00129             ia->rbtidExcludes[ia->numrbtidExcludes] = tid;
    00130 /*@=temptrans@*/
    00131             ia->numrbtidExcludes++;
    00132         }
    00133     } break;
    00134
    00135     case POPT_ROLLBACK:
    00136       { time_t tid;
    00137         if (arg == NULL)
    00138             argerror(_("Option --rollback needs a time/date stamp argument"));
    00139
    00140         /*@-moduncon@*/
    00141         tid = get_date(arg, NULL);
    00142         rpmlog(RPMLOG_INFO, _("Rollback goal:  %-24.24s (0x%08x)\n"), ctime(&tid), (int)tid);
    00143         /*@=moduncon@*/
    00144
    00145         if (tid == (time_t)-1 || tid == (time_t)0)
    00146             argerror(_("malformed rollback time/date stamp argument"));
    00147         ia->rbtid = (rpmuint32_t)tid;
    00148       } break;
    00149
    00150     case POPT_AUTOROLLBACK_GOAL:
    00151       { time_t tid;
    00152         if (arg == NULL)
    00153             argerror(_("arbgoal takes a time/date stamp argument"));
    00154
    00155         /*@-moduncon@*/
    00156         tid = get_date(arg, NULL);
    00157         /*@=moduncon@*/
    00158
    00159         if (tid == (time_t)-1 || tid == (time_t)0)
    00160             argerror(_("malformed arbgoal time/date stamp argument"));
    00161         ia->arbtid = (rpmuint32_t)tid;
    00162       } break;
    00163
    00164     case RPMCLI_POPT_NODIGEST:
    00165         ia->qva_flags |= VERIFY_DIGEST;
    00166         break;
    00167
    00168     case RPMCLI_POPT_NOSIGNATURE:
    00169         ia->qva_flags |= VERIFY_SIGNATURE;
    00170         break;
    00171
    00172     case RPMCLI_POPT_NOHDRCHK:
    00173         ia->qva_flags |= VERIFY_HDRCHK;
    00174         break;
    00175
    00176     case RPMCLI_POPT_NODEPS:
    00177         ia->noDeps = 1;
    00178         break;
    00179
    00180     case RPMCLI_POPT_NOCONTEXTS:
    00181         ia->transFlags |= RPMTRANS_FLAG_NOCONTEXTS;
    00182         break;
    00183
    00184     case RPMCLI_POPT_NOSCRIPTS:
    00185         ia->transFlags |= (_noTransScripts|_noTransTriggers);
    00186         break;
    00187
    00188     case RPMCLI_POPT_NOFDIGESTS:
    00189         ia->transFlags |= RPMTRANS_FLAG_NOFDIGESTS;
    00190         break;
    00191
    00192     }
    00193 }
    00194
    00197 /*@-bitwisesigned -compmempass @*/
    00198 /*@unchecked@*/
    00199 struct poptOption rpmInstallPoptTable[] = {
    00200 /*@-type@*/ /* FIX: cast? */
    00201  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
    00202         installArgCallback, 0, NULL, NULL },
    00203 /*@=type@*/
    00204
    00205  { "allfiles", '\0', POPT_BIT_SET,
    00206         &rpmIArgs.transFlags, RPMTRANS_FLAG_ALLFILES,
    00207   N_("install all files, even configurations which might otherwise be skipped"),
    00208         NULL},
    00209  { "apply", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
    00210         (_noTransScripts|_noTransTriggers|
    00211                 RPMTRANS_FLAG_APPLYONLY|RPMTRANS_FLAG_PKGCOMMIT),
    00212         N_("do not execute package scriptlet(s)"), NULL },
    00213  { "dirstash", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
    00214         &rpmIArgs.transFlags, RPMTRANS_FLAG_DIRSTASH,
    00215         N_("save erased package files by renaming into sub-directory"), NULL},
    00216  { "excludeconfigs", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
    00217         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOCONFIGS,
    00218         N_("do not install configuration files"), NULL},
    00219  { "excludedocs", '\0', POPT_BIT_SET,
    00220         &rpmIArgs.transFlags, RPMTRANS_FLAG_NODOCS,
    00221         N_("do not install documentation"), NULL},
    00222  { "justdb", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_JUSTDB,
    00223         N_("update the database, but do not modify the filesystem"), NULL},
    00224  { "noconfigs", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
    00225         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOCONFIGS,
    00226         N_("do not install configuration files"), NULL},
    00227  { "nodocs", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
    00228         &rpmIArgs.transFlags, RPMTRANS_FLAG_NODOCS,
    00229         N_("do not install documentation"), NULL},
    00230 #ifdef  NOTYET  /* XXX multiple identical options forces popt callback. */
    00231  { "nocontexts", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
    00232         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOCONTEXTS,
    00233         N_("don't install file security contexts"), NULL},
    00234  { "nofdigests", '\0', POPT_BIT_SET,
    00235         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOFDIGESTS,
    00236         N_("don't verify file digests"), NULL },
    00237 #else
    00238   { "nocontexts", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NOCONTEXTS,
    00239         N_("don't verify file security contexts"), NULL },
    00240   { "nofdigests", '\0', 0, NULL, RPMCLI_POPT_NOFDIGESTS,
    00241         N_("don't verify file digests"), NULL },
    00242 #endif
    00243  { "norpmdb", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
    00244         &rpmIArgs.transFlags, RPMTRANS_FLAG_NORPMDB,
    00245         N_("don't register headers in rpmdb"), NULL},
    00246
    00247 #ifdef  NOTYET  /* XXX multiple identical options forces popt callback. */
    00248  { "noscripts", '\0', POPT_BIT_SET,
    00249         &rpmIArgs.transFlags, (_noTransScripts|_noTransTriggers),
    00250         N_("do not execute package scriptlet(s)"), NULL },
    00251 #else
    00252   { "noscripts", '\0', 0, NULL, RPMCLI_POPT_NOSCRIPTS,
    00253         N_("do not execute package scriptlet(s)"), NULL },
    00254 #endif
    00255  { "nopretrans", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
    00256         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOPRETRANS,
    00257         N_("do not execute %%pretrans scriptlet (if any)"), NULL },
    00258  { "nopre", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
    00259         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOPRE,
    00260         N_("do not execute %%pre scriptlet (if any)"), NULL },
    00261  { "nopost", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
    00262         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOPOST,
    00263         N_("do not execute %%post scriptlet (if any)"), NULL },
    00264  { "nopreun", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
    00265         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOPREUN,
    00266         N_("do not execute %%preun scriptlet (if any)"), NULL },
    00267  { "nopostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
    00268         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOPOSTUN,
    00269         N_("do not execute %%postun scriptlet (if any)"), NULL },
    00270  { "noposttrans", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
    00271         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOPOSTTRANS,
    00272         N_("do not execute %%postrans scriptlet (if any)"), NULL },
    00273
    00274  { "notriggers", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, _noTransTriggers,
    00275         N_("do not execute any scriptlet(s) triggered by this package"), NULL},
    00276  { "notriggerprein", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
    00277         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERPREIN,
    00278         N_("do not execute any %%triggerprein scriptlet(s)"), NULL},
    00279  { "notriggerin", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
    00280         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERIN,
    00281         N_("do not execute any %%triggerin scriptlet(s)"), NULL},
    00282  { "notriggerun", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
    00283         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERUN,
    00284         N_("do not execute any %%triggerun scriptlet(s)"), NULL},
    00285  { "notriggerpostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE|POPT_ARGFLAG_DOC_HIDDEN,
    00286         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERPOSTUN,
    00287         N_("do not execute any %%triggerpostun scriptlet(s)"), NULL},
    00288
    00289  { "repackage", '\0', POPT_BIT_SET|POPT_ARGFLAG_TOGGLE,
    00290         &rpmIArgs.transFlags, RPMTRANS_FLAG_REPACKAGE,
    00291         N_("save erased package files by repackaging"), NULL},
    00292  { "test", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_TEST,
    00293         N_("don't install, but tell if it would work or not"), NULL},
    00294
    00295  { "allmatches", '\0', POPT_BIT_SET,
    00296         &rpmIArgs.installInterfaceFlags, INSTALL_ALLMATCHES,
    00297         N_("remove all packages which match <package> (normally an error is generated if <package> specified multiple packages)"),
    00298         NULL},
    00299
    00300  { "badreloc", '\0', POPT_BIT_SET,
    00301         &rpmIArgs.probFilter, RPMPROB_FILTER_FORCERELOCATE,
    00302         N_("relocate files in non-relocatable package"), NULL},
    00303
    00304  { "erase", 'e', POPT_BIT_SET,
    00305         &rpmIArgs.installInterfaceFlags, INSTALL_ERASE,
    00306         N_("erase (uninstall) package"), N_("<package>+") },
    00307  { "excludepath", '\0', POPT_ARG_STRING, NULL, POPT_EXCLUDEPATH,
    00308         N_("skip files with leading component <path> "),
    00309         N_("<path>") },
    00310
    00311  { "fileconflicts", '\0', POPT_BIT_CLR, &rpmIArgs.probFilter,
    00312         (RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES),
    00313         N_("detect file conflicts between packages"), NULL},
    00314
    00315  { "freshen", 'F', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags,
    00316         (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL),
    00317         N_("upgrade package(s) if already installed"),
    00318         N_("<packagefile>+") },
    00319  { "hash", 'h', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags, INSTALL_HASH,
    00320         N_("print hash marks as package installs (good with -v)"), NULL},
    00321 #ifndef DIEDIEDIE
    00322  { "ignorearch", '\0', POPT_BIT_SET,
    00323         &rpmIArgs.probFilter, RPMPROB_FILTER_IGNOREARCH,
    00324         N_("don't verify package architecture"), NULL},
    00325  { "ignoreos", '\0', POPT_BIT_SET,
    00326         &rpmIArgs.probFilter, RPMPROB_FILTER_IGNOREOS,
    00327         N_("don't verify package operating system"), NULL},
    00328 #endif
    00329  { "ignoresize", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
    00330         (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES),
    00331         N_("don't check disk space before installing"), NULL},
    00332  { "includedocs", '\0', POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.incldocs, 0,
    00333         N_("install documentation"), NULL},
    00334
    00335  { "install", 'i', 0, NULL, 'i',
    00336         N_("install package(s)"), N_("<packagefile>+") },
    00337
    00338  { "nodeps", '\0', 0, NULL, RPMCLI_POPT_NODEPS,
    00339         N_("do not verify package dependencies"), NULL },
    00340
    00341  { "noorder", '\0', POPT_BIT_SET,
    00342         &rpmIArgs.installInterfaceFlags, INSTALL_NOORDER,
    00343         N_("do not reorder package installation to satisfy dependencies"),
    00344         NULL},
    00345
    00346  { "nodigest", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NODIGEST,
    00347         N_("don't verify package digest(s)"), NULL },
    00348  { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NOHDRCHK,
    00349         N_("don't verify database header(s) when retrieved"), NULL },
    00350  { "nosignature", '\0', POPT_ARGFLAG_DOC_HIDDEN, NULL, RPMCLI_POPT_NOSIGNATURE,
    00351         N_("don't verify package signature(s)"), NULL },
    00352
    00353  { "oldpackage", '\0', POPT_BIT_SET,
    00354         &rpmIArgs.probFilter, RPMPROB_FILTER_OLDPACKAGE,
    00355         N_("upgrade to an old version of the package (--force on upgrades does this automatically)"),
    00356         NULL},
    00357  { "percent", '\0', POPT_BIT_SET,
    00358         &rpmIArgs.installInterfaceFlags, INSTALL_PERCENT,
    00359         N_("print percentages as package installs"), NULL},
    00360  { "prefix", '\0', POPT_ARG_STRING, &rpmIArgs.qva_prefix, 0,
    00361         N_("relocate the package to <dir>, if relocatable"),
    00362         N_("<dir>") },
    00363  { "relocate", '\0', POPT_ARG_STRING, NULL, POPT_RELOCATE,
    00364         N_("relocate files from path <old> to <new>"),
    00365         N_("<old>=<new>") },
    00366  { "replacefiles", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
    00367         (RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES),
    00368         N_("ignore file conflicts between packages"), NULL},
    00369  { "replacepkgs", '\0', POPT_BIT_SET,
    00370         &rpmIArgs.probFilter, RPMPROB_FILTER_REPLACEPKG,
    00371         N_("reinstall if the package is already present"), NULL},
    00372  { "rollback", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, NULL, POPT_ROLLBACK,
    00373         N_("deinstall new, reinstall old, package(s), back to <date>"),
    00374         N_("<date>") },
    00375  { "arbgoal", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, NULL, POPT_AUTOROLLBACK_GOAL,
    00376         N_("If transaction fails rollback to <date>"),
    00377         N_("<date>") },
    00378  { "rbexclude", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, NULL, POPT_ROLLBACK_EXCLUDE,
    00379         N_("Exclude Transaction I.D. from rollback"),
    00380         N_("<tid>") },
    00381  { "upgrade", 'U', POPT_BIT_SET,
    00382         &rpmIArgs.installInterfaceFlags, (INSTALL_UPGRADE|INSTALL_INSTALL),
    00383         N_("upgrade package(s)"),
    00384         N_("<packagefile>+") },
    00385
    00386    POPT_TABLEEND
    00387 };
    00388 /*@=bitwisesigned =compmempass @*/