2004-10-10 13:30:48 +08:00
|
|
|
#include "system.h"
|
|
|
|
|
|
|
|
#include <rpmio_internal.h>
|
|
|
|
#include <rpmgi.h>
|
|
|
|
#include <rpmcli.h>
|
|
|
|
|
2004-10-20 10:34:17 +08:00
|
|
|
#include <rpmte.h>
|
|
|
|
|
2004-10-10 13:30:48 +08:00
|
|
|
#include <rpmmacro.h>
|
|
|
|
#include <rpmmessages.h>
|
2007-09-18 12:19:57 +08:00
|
|
|
#include <fts.h>
|
2004-10-10 13:30:48 +08:00
|
|
|
#include <popt.h>
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
2004-10-20 00:39:36 +08:00
|
|
|
static const char * gitagstr = "packages";
|
|
|
|
static const char * gikeystr = NULL;
|
2004-10-20 10:34:17 +08:00
|
|
|
static rpmtransFlags transFlags = 0;
|
2004-10-26 02:10:48 +08:00
|
|
|
#ifdef DYING
|
|
|
|
static rpmgiFlags giFlags = 0;
|
|
|
|
#endif
|
2004-10-10 13:30:48 +08:00
|
|
|
|
2004-10-11 04:55:11 +08:00
|
|
|
static const char * queryFormat = NULL;
|
2004-10-25 03:36:30 +08:00
|
|
|
static const char * defaultQueryFormat =
|
|
|
|
"%{name}-%{version}-%{release}.%|SOURCERPM?{%{arch}.rpm}:{%|ARCH?{src.rpm}:{pubkey}|}|";
|
2004-10-11 04:55:11 +08:00
|
|
|
|
2004-10-19 10:30:25 +08:00
|
|
|
static const char * rpmgiPathOrQF(const rpmgi gi)
|
|
|
|
{
|
|
|
|
const char * fmt = ((queryFormat != NULL)
|
2004-10-25 03:36:30 +08:00
|
|
|
? queryFormat : defaultQueryFormat);
|
2004-10-19 10:30:25 +08:00
|
|
|
const char * val = NULL;
|
|
|
|
Header h = rpmgiHeader(gi);
|
|
|
|
|
|
|
|
if (h != NULL)
|
|
|
|
val = headerSprintf(h, fmt, rpmTagTable, rpmHeaderFormats, NULL);
|
|
|
|
else {
|
|
|
|
const char * fn = rpmgiHdrPath(gi);
|
|
|
|
val = (fn != NULL ? xstrdup(fn) : NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2004-10-10 13:30:48 +08:00
|
|
|
static struct poptOption optionsTable[] = {
|
|
|
|
{ "rpmgidebug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmgi_debug, -1,
|
|
|
|
N_("debug generalized iterator"), NULL},
|
|
|
|
|
2004-10-20 00:39:36 +08:00
|
|
|
{ "tag", '\0', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &gitagstr, 0,
|
|
|
|
N_("iterate tag index"), NULL },
|
|
|
|
{ "key", '\0', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &gikeystr, 0,
|
|
|
|
N_("tag value key"), NULL },
|
2004-10-10 13:30:48 +08:00
|
|
|
|
2004-10-20 10:34:17 +08:00
|
|
|
{ "anaconda", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
|
|
|
|
&transFlags, RPMTRANS_FLAG_ANACONDA|RPMTRANS_FLAG_DEPLOOPS,
|
|
|
|
N_("use anaconda \"presentation order\""), NULL},
|
|
|
|
|
2004-10-26 02:10:48 +08:00
|
|
|
{ "transaction", 'T', POPT_BIT_SET, &giFlags, (RPMGI_TSADD|RPMGI_TSORDER),
|
|
|
|
N_("create transaction set"), NULL},
|
|
|
|
{ "noorder", '\0', POPT_BIT_CLR, &giFlags, RPMGI_TSORDER,
|
2004-10-25 03:36:30 +08:00
|
|
|
N_("do not order transaction set"), NULL},
|
2004-10-26 02:10:48 +08:00
|
|
|
{ "noglob", '\0', POPT_BIT_SET, &giFlags, RPMGI_NOGLOB,
|
2004-10-25 03:36:30 +08:00
|
|
|
N_("do not glob arguments"), NULL},
|
2004-10-26 02:10:48 +08:00
|
|
|
{ "nomanifest", '\0', POPT_BIT_SET, &giFlags, RPMGI_NOMANIFEST,
|
|
|
|
N_("do not process non-package files as manifests"), NULL},
|
|
|
|
{ "noheader", '\0', POPT_BIT_SET, &giFlags, RPMGI_NOHEADER,
|
2004-10-25 03:36:30 +08:00
|
|
|
N_("do not read headers"), NULL},
|
|
|
|
|
2004-10-11 04:55:11 +08:00
|
|
|
{ "qf", '\0', POPT_ARG_STRING, &queryFormat, 0,
|
|
|
|
N_("use the following query format"), "QUERYFORMAT" },
|
|
|
|
{ "queryformat", '\0', POPT_ARG_STRING, &queryFormat, 0,
|
|
|
|
N_("use the following query format"), "QUERYFORMAT" },
|
|
|
|
|
2004-10-25 23:26:51 +08:00
|
|
|
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliFtsPoptTable, 0,
|
|
|
|
N_("File tree walk options for fts(3):"),
|
|
|
|
NULL },
|
2004-10-10 13:30:48 +08:00
|
|
|
|
|
|
|
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
|
|
|
|
N_("Common options for all rpm modes and executables:"),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
POPT_AUTOALIAS
|
|
|
|
POPT_AUTOHELP
|
|
|
|
POPT_TABLEEND
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
2007-09-18 11:53:37 +08:00
|
|
|
main(int argc, char *argv[])
|
2004-10-10 13:30:48 +08:00
|
|
|
{
|
|
|
|
poptContext optCon;
|
|
|
|
rpmts ts = NULL;
|
2004-10-15 08:14:29 +08:00
|
|
|
rpmVSFlags vsflags;
|
2004-10-10 13:30:48 +08:00
|
|
|
rpmgi gi = NULL;
|
2004-10-20 00:39:36 +08:00
|
|
|
int gitag = RPMDBI_PACKAGES;
|
2004-10-18 07:32:55 +08:00
|
|
|
const char ** av;
|
2004-10-10 13:30:48 +08:00
|
|
|
int ac;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
optCon = rpmcliInit(argc, argv, optionsTable);
|
|
|
|
if (optCon == NULL)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
if (ftsOpts == 0)
|
|
|
|
ftsOpts = (FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT);
|
|
|
|
|
2004-10-20 00:39:36 +08:00
|
|
|
if (gitagstr != NULL) {
|
2007-09-20 20:09:52 +08:00
|
|
|
gitag = rpmTagGetValue(gitagstr);
|
2004-10-20 00:39:36 +08:00
|
|
|
if (gitag < 0) {
|
|
|
|
fprintf(stderr, _("unknown --tag argument: %s\n"), gitagstr);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX ftswalk segfault with no args. */
|
|
|
|
|
2004-10-10 13:30:48 +08:00
|
|
|
ts = rpmtsCreate();
|
2004-10-20 10:34:17 +08:00
|
|
|
(void) rpmtsSetFlags(ts, transFlags);
|
|
|
|
|
2004-10-15 08:14:29 +08:00
|
|
|
vsflags = rpmExpandNumeric("%{?_vsflags_query}");
|
|
|
|
if (rpmcliQueryFlags & VERIFY_DIGEST)
|
|
|
|
vsflags |= _RPMVSF_NODIGESTS;
|
|
|
|
if (rpmcliQueryFlags & VERIFY_SIGNATURE)
|
|
|
|
vsflags |= _RPMVSF_NOSIGNATURES;
|
|
|
|
if (rpmcliQueryFlags & VERIFY_HDRCHK)
|
|
|
|
vsflags |= RPMVSF_NOHDRCHK;
|
|
|
|
(void) rpmtsSetVSFlags(ts, vsflags);
|
|
|
|
|
|
|
|
{ int_32 tid = (int_32) time(NULL);
|
|
|
|
(void) rpmtsSetTid(ts, tid);
|
|
|
|
}
|
|
|
|
|
2004-10-20 00:39:36 +08:00
|
|
|
gi = rpmgiNew(ts, gitag, gikeystr, 0);
|
2004-10-19 23:54:38 +08:00
|
|
|
|
2004-10-18 07:32:55 +08:00
|
|
|
av = poptGetArgs(optCon);
|
2004-10-26 02:10:48 +08:00
|
|
|
(void) rpmgiSetArgs(gi, av, ftsOpts, giFlags);
|
2004-10-10 13:30:48 +08:00
|
|
|
|
|
|
|
ac = 0;
|
2004-10-19 10:30:25 +08:00
|
|
|
while (rpmgiNext(gi) == RPMRC_OK) {
|
2004-10-26 02:10:48 +08:00
|
|
|
if (!(giFlags & RPMGI_TSADD)) {
|
2004-10-20 10:34:17 +08:00
|
|
|
const char * arg = rpmgiPathOrQF(gi);
|
2004-10-25 08:34:08 +08:00
|
|
|
|
|
|
|
fprintf(stdout, "%5d %s\n", ac, arg);
|
2004-10-20 10:34:17 +08:00
|
|
|
arg = _free(arg);
|
|
|
|
}
|
2004-10-10 13:30:48 +08:00
|
|
|
ac++;
|
2004-10-20 10:34:17 +08:00
|
|
|
}
|
2004-10-20 06:52:33 +08:00
|
|
|
|
2004-10-26 02:10:48 +08:00
|
|
|
if (giFlags & RPMGI_TSORDER) {
|
2004-10-20 10:34:17 +08:00
|
|
|
rpmtsi tsi;
|
|
|
|
rpmte q;
|
|
|
|
int i;
|
|
|
|
|
2004-10-25 03:36:30 +08:00
|
|
|
fprintf(stdout, "======================= %d transaction elements\n\
|
2004-10-20 10:34:17 +08:00
|
|
|
# Tree Depth Degree Package\n\
|
|
|
|
=======================\n", rpmtsNElements(ts));
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
tsi = rpmtsiInit(ts);
|
|
|
|
while((q = rpmtsiNext(tsi, 0)) != NULL) {
|
|
|
|
char deptypechar;
|
|
|
|
|
|
|
|
if (i == rpmtsUnorderedSuccessors(ts, -1))
|
2004-10-25 03:36:30 +08:00
|
|
|
fprintf(stdout, "======================= leaf nodes only:\n");
|
2004-10-20 10:34:17 +08:00
|
|
|
|
|
|
|
deptypechar = (rpmteType(q) == TR_REMOVED ? '-' : '+');
|
2004-10-25 03:36:30 +08:00
|
|
|
fprintf(stdout, "%5d%5d%6d%7d %*s%c%s\n",
|
2004-10-20 10:34:17 +08:00
|
|
|
i, rpmteTree(q), rpmteDepth(q), rpmteDegree(q),
|
|
|
|
(2 * rpmteDepth(q)), "",
|
|
|
|
deptypechar, rpmteNEVRA(q));
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
tsi = rpmtsiFree(tsi);
|
2004-10-10 13:30:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gi = rpmgiFree(gi);
|
|
|
|
ts = rpmtsFree(ts);
|
|
|
|
optCon = rpmcliFini(optCon);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|