00001 #include "system.h"
00002
00003 #include <rpmio_internal.h>
00004 #include <rpmgi.h>
00005 #include <rpmcli.h>
00006
00007 #include <rpmte.h>
00008
00009 #include <rpmmacro.h>
00010 #include <rpmmessages.h>
00011 #include <popt.h>
00012
00013 #include "debug.h"
00014
00015 static const char * gitagstr = "packages";
00016 static const char * gikeystr = NULL;
00017 static rpmtransFlags transFlags = 0;
00018 #ifdef DYING
00019 static rpmgiFlags giFlags = 0;
00020 #endif
00021
00022 static const char * queryFormat = NULL;
00023 static const char * defaultQueryFormat =
00024 "%{name}-%{version}-%{release}.%|SOURCERPM?{%{arch}.rpm}:{%|ARCH?{src.rpm}:{pubkey}|}|";
00025
00026
00027 static const char * rpmgiPathOrQF(const rpmgi gi)
00028
00029 {
00030 const char * fmt = ((queryFormat != NULL)
00031 ? queryFormat : defaultQueryFormat);
00032 const char * val = NULL;
00033 Header h = rpmgiHeader(gi);
00034
00035 if (h != NULL)
00036 val = headerSprintf(h, fmt, rpmTagTable, rpmHeaderFormats, NULL);
00037 else {
00038 const char * fn = rpmgiHdrPath(gi);
00039 val = (fn != NULL ? xstrdup(fn) : NULL);
00040 }
00041
00042 return val;
00043 }
00044
00045 static struct poptOption optionsTable[] = {
00046 { "rpmgidebug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmgi_debug, -1,
00047 N_("debug generalized iterator"), NULL},
00048
00049 { "tag", '\0', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &gitagstr, 0,
00050 N_("iterate tag index"), NULL },
00051 { "key", '\0', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &gikeystr, 0,
00052 N_("tag value key"), NULL },
00053
00054 { "anaconda", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00055 &transFlags, RPMTRANS_FLAG_ANACONDA|RPMTRANS_FLAG_DEPLOOPS,
00056 N_("use anaconda \"presentation order\""), NULL},
00057
00058 { "transaction", 'T', POPT_BIT_SET, &giFlags, (RPMGI_TSADD|RPMGI_TSORDER),
00059 N_("create transaction set"), NULL},
00060 { "noorder", '\0', POPT_BIT_CLR, &giFlags, RPMGI_TSORDER,
00061 N_("do not order transaction set"), NULL},
00062 { "noglob", '\0', POPT_BIT_SET, &giFlags, RPMGI_NOGLOB,
00063 N_("do not glob arguments"), NULL},
00064 { "nomanifest", '\0', POPT_BIT_SET, &giFlags, RPMGI_NOMANIFEST,
00065 N_("do not process non-package files as manifests"), NULL},
00066 { "noheader", '\0', POPT_BIT_SET, &giFlags, RPMGI_NOHEADER,
00067 N_("do not read headers"), NULL},
00068
00069 { "qf", '\0', POPT_ARG_STRING, &queryFormat, 0,
00070 N_("use the following query format"), "QUERYFORMAT" },
00071 { "queryformat", '\0', POPT_ARG_STRING, &queryFormat, 0,
00072 N_("use the following query format"), "QUERYFORMAT" },
00073
00074 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliFtsPoptTable, 0,
00075 N_("File tree walk options for fts(3):"),
00076 NULL },
00077
00078 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
00079 N_("Common options for all rpm modes and executables:"),
00080 NULL },
00081
00082 POPT_AUTOALIAS
00083 POPT_AUTOHELP
00084 POPT_TABLEEND
00085 };
00086
00087 int
00088 main(int argc, char *const argv[])
00089 {
00090 poptContext optCon;
00091 rpmts ts = NULL;
00092 rpmVSFlags vsflags;
00093 rpmgi gi = NULL;
00094 int gitag = RPMDBI_PACKAGES;
00095 const char ** av;
00096 int ac;
00097 int rc = 0;
00098
00099 optCon = rpmcliInit(argc, argv, optionsTable);
00100 if (optCon == NULL)
00101 exit(EXIT_FAILURE);
00102
00103 if (ftsOpts == 0)
00104 ftsOpts = (FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT);
00105
00106 if (gitagstr != NULL) {
00107 gitag = tagValue(gitagstr);
00108 if (gitag < 0) {
00109 fprintf(stderr, _("unknown --tag argument: %s\n"), gitagstr);
00110 exit(EXIT_FAILURE);
00111 }
00112 }
00113
00114
00115
00116 ts = rpmtsCreate();
00117 (void) rpmtsSetFlags(ts, transFlags);
00118
00119 vsflags = rpmExpandNumeric("%{?_vsflags_query}");
00120 if (rpmcliQueryFlags & VERIFY_DIGEST)
00121 vsflags |= _RPMVSF_NODIGESTS;
00122 if (rpmcliQueryFlags & VERIFY_SIGNATURE)
00123 vsflags |= _RPMVSF_NOSIGNATURES;
00124 if (rpmcliQueryFlags & VERIFY_HDRCHK)
00125 vsflags |= RPMVSF_NOHDRCHK;
00126 (void) rpmtsSetVSFlags(ts, vsflags);
00127
00128 { int_32 tid = (int_32) time(NULL);
00129 (void) rpmtsSetTid(ts, tid);
00130 }
00131
00132 gi = rpmgiNew(ts, gitag, gikeystr, 0);
00133
00134 av = poptGetArgs(optCon);
00135 (void) rpmgiSetArgs(gi, av, ftsOpts, giFlags);
00136
00137 ac = 0;
00138 while (rpmgiNext(gi) == RPMRC_OK) {
00139 if (!(giFlags & RPMGI_TSADD)) {
00140 const char * arg = rpmgiPathOrQF(gi);
00141
00142 fprintf(stdout, "%5d %s\n", ac, arg);
00143 arg = _free(arg);
00144 }
00145 ac++;
00146 }
00147
00148 if (giFlags & RPMGI_TSORDER) {
00149 rpmtsi tsi;
00150 rpmte q;
00151 int i;
00152
00153 fprintf(stdout, "======================= %d transaction elements\n\
00154 # Tree Depth Degree Package\n\
00155 =======================\n", rpmtsNElements(ts));
00156
00157 i = 0;
00158 tsi = rpmtsiInit(ts);
00159 while((q = rpmtsiNext(tsi, 0)) != NULL) {
00160 char deptypechar;
00161
00162 if (i == rpmtsUnorderedSuccessors(ts, -1))
00163 fprintf(stdout, "======================= leaf nodes only:\n");
00164
00165 deptypechar = (rpmteType(q) == TR_REMOVED ? '-' : '+');
00166 fprintf(stdout, "%5d%5d%6d%7d %*s%c%s\n",
00167 i, rpmteTree(q), rpmteDepth(q), rpmteDegree(q),
00168 (2 * rpmteDepth(q)), "",
00169 deptypechar, rpmteNEVRA(q));
00170 i++;
00171 }
00172 tsi = rpmtsiFree(tsi);
00173 }
00174
00175 gi = rpmgiFree(gi);
00176 ts = rpmtsFree(ts);
00177 optCon = rpmcliFini(optCon);
00178
00179 return rc;
00180 }