2000-08-28 03:27:03 +08:00
|
|
|
/** \ingroup rpmcli
|
|
|
|
* \file lib/query.c
|
2001-03-15 07:09:09 +08:00
|
|
|
* Display tag values from package metadata.
|
2000-08-28 03:27:03 +08:00
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1997-01-18 00:20:18 +08:00
|
|
|
|
1998-07-25 04:30:55 +08:00
|
|
|
#ifndef PATH_MAX
|
|
|
|
# define PATH_MAX 255
|
|
|
|
#endif
|
|
|
|
|
2001-06-09 04:45:59 +08:00
|
|
|
#include <rpmcli.h>
|
2001-10-24 21:48:55 +08:00
|
|
|
|
2002-05-17 00:55:21 +08:00
|
|
|
#include "rpmdb.h"
|
2002-07-03 22:01:49 +08:00
|
|
|
#include "rpmfi.h"
|
2004-10-26 02:10:48 +08:00
|
|
|
|
|
|
|
#define _RPMGI_INTERNAL /* XXX for gi->flags */
|
2004-10-25 03:36:30 +08:00
|
|
|
#include "rpmgi.h"
|
2002-04-12 00:55:19 +08:00
|
|
|
#include "rpmts.h"
|
|
|
|
|
2001-03-23 07:39:01 +08:00
|
|
|
#include "manifest.h"
|
2001-10-25 09:36:32 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
2007-09-10 16:55:17 +08:00
|
|
|
#include "misc.h"
|
1995-12-28 04:08:35 +08:00
|
|
|
|
2004-10-26 08:22:10 +08:00
|
|
|
|
2001-03-15 07:09:09 +08:00
|
|
|
/**
|
|
|
|
*/
|
2000-12-26 21:10:18 +08:00
|
|
|
static void printFileInfo(char * te, const char * name,
|
1999-07-18 03:00:45 +08:00
|
|
|
unsigned int size, unsigned short mode,
|
2000-05-17 02:32:49 +08:00
|
|
|
unsigned int mtime,
|
|
|
|
unsigned short rdev, unsigned int nlink,
|
1999-07-18 03:00:45 +08:00
|
|
|
const char * owner, const char * group,
|
2002-07-03 22:01:49 +08:00
|
|
|
const char * linkto)
|
1999-07-18 03:00:45 +08:00
|
|
|
{
|
|
|
|
char sizefield[15];
|
2002-07-03 22:01:49 +08:00
|
|
|
char ownerfield[8+1], groupfield[8+1];
|
2001-04-29 09:05:43 +08:00
|
|
|
char timefield[100];
|
1999-07-18 03:00:45 +08:00
|
|
|
time_t when = mtime; /* important if sizeof(int_32) ! sizeof(time_t) */
|
|
|
|
struct tm * tm;
|
|
|
|
static time_t now;
|
|
|
|
static struct tm nowtm;
|
|
|
|
const char * namefield = name;
|
2001-03-23 07:39:01 +08:00
|
|
|
char * perms = rpmPermsString(mode);
|
1998-10-27 13:41:02 +08:00
|
|
|
|
1999-07-18 03:00:45 +08:00
|
|
|
/* On first call, grab snapshot of now */
|
|
|
|
if (now == 0) {
|
|
|
|
now = time(NULL);
|
|
|
|
tm = localtime(&now);
|
2001-05-04 05:00:18 +08:00
|
|
|
if (tm) nowtm = *tm; /* structure assignment */
|
1999-07-18 03:00:45 +08:00
|
|
|
}
|
1998-10-27 13:41:02 +08:00
|
|
|
|
2002-07-03 22:01:49 +08:00
|
|
|
strncpy(ownerfield, owner, sizeof(ownerfield));
|
|
|
|
ownerfield[sizeof(ownerfield)-1] = '\0';
|
1999-07-18 03:00:45 +08:00
|
|
|
|
2002-07-03 22:01:49 +08:00
|
|
|
strncpy(groupfield, group, sizeof(groupfield));
|
|
|
|
groupfield[sizeof(groupfield)-1] = '\0';
|
1999-07-18 03:00:45 +08:00
|
|
|
|
|
|
|
/* this is normally right */
|
|
|
|
sprintf(sizefield, "%12u", size);
|
|
|
|
|
|
|
|
/* this knows too much about dev_t */
|
|
|
|
|
|
|
|
if (S_ISLNK(mode)) {
|
|
|
|
char *nf = alloca(strlen(name) + sizeof(" -> ") + strlen(linkto));
|
|
|
|
sprintf(nf, "%s -> %s", name, linkto);
|
|
|
|
namefield = nf;
|
|
|
|
} else if (S_ISCHR(mode)) {
|
|
|
|
perms[0] = 'c';
|
2000-10-29 01:16:25 +08:00
|
|
|
sprintf(sizefield, "%3u, %3u", ((unsigned)(rdev >> 8) & 0xff),
|
|
|
|
((unsigned)rdev & 0xff));
|
1999-07-18 03:00:45 +08:00
|
|
|
} else if (S_ISBLK(mode)) {
|
|
|
|
perms[0] = 'b';
|
2000-10-29 01:16:25 +08:00
|
|
|
sprintf(sizefield, "%3u, %3u", ((unsigned)(rdev >> 8) & 0xff),
|
|
|
|
((unsigned)rdev & 0xff));
|
1999-07-18 03:00:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert file mtime to display format */
|
|
|
|
tm = localtime(&when);
|
2001-05-04 05:00:18 +08:00
|
|
|
timefield[0] = '\0';
|
|
|
|
if (tm != NULL)
|
1999-07-18 03:00:45 +08:00
|
|
|
{ const char *fmt;
|
|
|
|
if (now > when + 6L * 30L * 24L * 60L * 60L || /* Old. */
|
|
|
|
now < when - 60L * 60L) /* In the future. */
|
|
|
|
{
|
|
|
|
/* The file is fairly old or in the future.
|
|
|
|
* POSIX says the cutoff is 6 months old;
|
|
|
|
* approximate this by 6*30 days.
|
|
|
|
* Allow a 1 hour slop factor for what is considered "the future",
|
|
|
|
* to allow for NFS server/client clock disagreement.
|
|
|
|
* Show the year instead of the time of day.
|
|
|
|
*/
|
|
|
|
fmt = "%b %e %Y";
|
1998-10-27 13:41:02 +08:00
|
|
|
} else {
|
1999-07-18 03:00:45 +08:00
|
|
|
fmt = "%b %e %H:%M";
|
1998-10-27 13:41:02 +08:00
|
|
|
}
|
1999-07-18 03:00:45 +08:00
|
|
|
(void)strftime(timefield, sizeof(timefield) - 1, fmt, tm);
|
1998-10-27 13:41:02 +08:00
|
|
|
}
|
|
|
|
|
2000-12-26 21:10:18 +08:00
|
|
|
sprintf(te, "%s %4d %-8s%-8s %10s %s %s", perms,
|
|
|
|
(int)nlink, ownerfield, groupfield, sizefield, timefield, namefield);
|
2001-03-23 07:39:01 +08:00
|
|
|
perms = _free(perms);
|
1999-07-18 03:00:45 +08:00
|
|
|
}
|
1999-05-08 02:33:35 +08:00
|
|
|
|
2001-03-15 07:09:09 +08:00
|
|
|
/**
|
|
|
|
*/
|
2007-09-12 01:07:39 +08:00
|
|
|
static inline const char * queryHeader(Header h, const char * qfmt)
|
1999-07-18 03:00:45 +08:00
|
|
|
{
|
2002-05-02 06:13:00 +08:00
|
|
|
const char * errstr = "(unkown error)";
|
2000-12-26 21:10:18 +08:00
|
|
|
const char * str;
|
1996-06-28 04:47:54 +08:00
|
|
|
|
2000-12-26 21:10:18 +08:00
|
|
|
str = headerSprintf(h, qfmt, rpmTagTable, rpmHeaderFormats, &errstr);
|
2000-12-28 05:19:53 +08:00
|
|
|
if (str == NULL)
|
2000-12-26 21:10:18 +08:00
|
|
|
rpmError(RPMERR_QFMT, _("incorrect format: %s\n"), errstr);
|
2000-12-28 05:19:53 +08:00
|
|
|
return str;
|
1996-04-02 11:36:00 +08:00
|
|
|
}
|
|
|
|
|
2007-06-18 13:29:01 +08:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
static void flushBuffer(char ** tp, char ** tep, int nonewline)
|
|
|
|
{
|
|
|
|
char *t, *te;
|
|
|
|
|
|
|
|
t = *tp;
|
|
|
|
te = *tep;
|
|
|
|
if (te > t) {
|
|
|
|
if (!nonewline) {
|
|
|
|
*te++ = '\n';
|
|
|
|
*te = '\0';
|
|
|
|
}
|
|
|
|
rpmMessage(RPMMESS_NORMAL, "%s", t);
|
|
|
|
te = t;
|
|
|
|
*t = '\0';
|
|
|
|
}
|
|
|
|
*tp = t;
|
|
|
|
*tep = te;
|
|
|
|
}
|
|
|
|
|
2003-01-18 01:43:04 +08:00
|
|
|
int showQueryPackage(QVA_t qva, rpmts ts, Header h)
|
1999-05-11 07:41:04 +08:00
|
|
|
{
|
2003-01-21 07:52:04 +08:00
|
|
|
int scareMem = 0;
|
2002-07-03 22:01:49 +08:00
|
|
|
rpmfi fi = NULL;
|
2007-06-18 13:50:52 +08:00
|
|
|
size_t tb = 2 * BUFSIZ;
|
|
|
|
size_t sb;
|
2000-12-26 21:10:18 +08:00
|
|
|
char * t, * te;
|
1995-12-28 04:08:35 +08:00
|
|
|
char * prefix = NULL;
|
2000-12-26 21:10:18 +08:00
|
|
|
int rc = 0; /* XXX FIXME: need real return code */
|
1995-12-28 04:08:35 +08:00
|
|
|
int i;
|
|
|
|
|
2007-06-18 13:50:52 +08:00
|
|
|
te = t = xmalloc(tb);
|
2000-12-26 21:10:18 +08:00
|
|
|
*te = '\0';
|
1995-12-28 04:08:35 +08:00
|
|
|
|
2002-03-09 06:24:58 +08:00
|
|
|
if (qva->qva_queryFormat != NULL) {
|
|
|
|
const char * str = queryHeader(h, qva->qva_queryFormat);
|
2000-12-28 05:19:53 +08:00
|
|
|
if (str) {
|
2007-06-18 13:50:52 +08:00
|
|
|
size_t tx = (te - t);
|
2000-12-28 05:19:53 +08:00
|
|
|
|
2007-06-18 13:50:52 +08:00
|
|
|
sb = strlen(str);
|
|
|
|
if (sb) {
|
|
|
|
tb += sb;
|
|
|
|
t = xrealloc(t, tb);
|
|
|
|
te = t + tx;
|
2000-12-28 05:19:53 +08:00
|
|
|
}
|
|
|
|
te = stpcpy(te, str);
|
2001-02-13 03:02:15 +08:00
|
|
|
str = _free(str);
|
2007-06-18 13:29:01 +08:00
|
|
|
flushBuffer(&t, &te, 1);
|
2000-12-28 05:19:53 +08:00
|
|
|
}
|
|
|
|
}
|
2000-12-26 21:10:18 +08:00
|
|
|
|
2002-03-09 06:24:58 +08:00
|
|
|
if (!(qva->qva_flags & QUERY_FOR_LIST))
|
2000-12-26 21:10:18 +08:00
|
|
|
goto exit;
|
1995-12-28 04:08:35 +08:00
|
|
|
|
2002-08-20 06:27:44 +08:00
|
|
|
fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, scareMem);
|
2002-07-03 22:01:49 +08:00
|
|
|
if (rpmfiFC(fi) <= 0) {
|
2000-12-26 21:10:18 +08:00
|
|
|
te = stpcpy(te, _("(contains no files)"));
|
|
|
|
goto exit;
|
|
|
|
}
|
2002-07-03 22:01:49 +08:00
|
|
|
|
|
|
|
fi = rpmfiInit(fi, 0);
|
|
|
|
if (fi != NULL)
|
|
|
|
while ((i = rpmfiNext(fi)) >= 0) {
|
|
|
|
rpmfileAttrs fflags;
|
|
|
|
unsigned short fmode;
|
|
|
|
unsigned short frdev;
|
|
|
|
unsigned int fmtime;
|
|
|
|
rpmfileState fstate;
|
|
|
|
size_t fsize;
|
|
|
|
const char * fn;
|
|
|
|
char fmd5[32+1];
|
|
|
|
const char * fuser;
|
|
|
|
const char * fgroup;
|
|
|
|
const char * flink;
|
|
|
|
int_32 fnlink;
|
|
|
|
|
|
|
|
fflags = rpmfiFFlags(fi);
|
|
|
|
fmode = rpmfiFMode(fi);
|
|
|
|
frdev = rpmfiFRdev(fi);
|
|
|
|
fmtime = rpmfiFMtime(fi);
|
|
|
|
fstate = rpmfiFState(fi);
|
|
|
|
fsize = rpmfiFSize(fi);
|
|
|
|
fn = rpmfiFN(fi);
|
|
|
|
{ static char hex[] = "0123456789abcdef";
|
2007-07-11 18:20:45 +08:00
|
|
|
unsigned const char * s = rpmfiMD5(fi);
|
2002-07-03 22:01:49 +08:00
|
|
|
char * p = fmd5;
|
|
|
|
int j;
|
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
unsigned k = *s++;
|
|
|
|
*p++ = hex[ (k >> 4) & 0xf ];
|
|
|
|
*p++ = hex[ (k ) & 0xf ];
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
fuser = rpmfiFUser(fi);
|
|
|
|
fgroup = rpmfiFGroup(fi);
|
|
|
|
flink = rpmfiFLink(fi);
|
|
|
|
fnlink = rpmfiFNlink(fi);
|
2001-06-12 12:10:21 +08:00
|
|
|
|
2000-12-26 21:10:18 +08:00
|
|
|
/* If querying only docs, skip non-doc files. */
|
2002-07-03 22:01:49 +08:00
|
|
|
if ((qva->qva_flags & QUERY_FOR_DOCS) && !(fflags & RPMFILE_DOC))
|
2000-12-26 21:10:18 +08:00
|
|
|
continue;
|
2001-06-12 12:10:21 +08:00
|
|
|
|
2000-12-26 21:10:18 +08:00
|
|
|
/* If querying only configs, skip non-config files. */
|
2002-07-03 22:01:49 +08:00
|
|
|
if ((qva->qva_flags & QUERY_FOR_CONFIG) && !(fflags & RPMFILE_CONFIG))
|
2000-12-26 21:10:18 +08:00
|
|
|
continue;
|
|
|
|
|
2001-06-21 05:20:16 +08:00
|
|
|
/* If not querying %ghost, skip ghost files. */
|
2007-04-16 20:19:39 +08:00
|
|
|
if ((qva->qva_fflags & RPMFILE_GHOST) && (fflags & RPMFILE_GHOST))
|
2001-06-21 05:20:16 +08:00
|
|
|
continue;
|
|
|
|
|
2007-06-18 13:50:52 +08:00
|
|
|
/* Insure space for header derived data */
|
|
|
|
sb = strlen(fn) + strlen(fmd5) + strlen(fuser) + strlen(fgroup) + strlen(flink);
|
|
|
|
if ((sb + BUFSIZ) > tb) {
|
|
|
|
size_t tx = (te - t);
|
|
|
|
tb += sb + BUFSIZ;
|
|
|
|
t = xrealloc(t, tb);
|
|
|
|
te = t + tx;
|
|
|
|
}
|
|
|
|
|
2000-12-26 21:10:18 +08:00
|
|
|
if (!rpmIsVerbose() && prefix)
|
|
|
|
te = stpcpy(te, prefix);
|
|
|
|
|
2002-03-09 06:24:58 +08:00
|
|
|
if (qva->qva_flags & QUERY_FOR_STATE) {
|
2002-07-03 22:01:49 +08:00
|
|
|
switch (fstate) {
|
|
|
|
case RPMFILE_STATE_NORMAL:
|
|
|
|
te = stpcpy(te, _("normal "));
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2002-07-03 22:01:49 +08:00
|
|
|
case RPMFILE_STATE_REPLACED:
|
|
|
|
te = stpcpy(te, _("replaced "));
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2002-07-03 22:01:49 +08:00
|
|
|
case RPMFILE_STATE_NOTINSTALLED:
|
|
|
|
te = stpcpy(te, _("not installed "));
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2002-07-03 22:01:49 +08:00
|
|
|
case RPMFILE_STATE_NETSHARED:
|
|
|
|
te = stpcpy(te, _("net shared "));
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2002-12-31 09:23:03 +08:00
|
|
|
case RPMFILE_STATE_WRONGCOLOR:
|
|
|
|
te = stpcpy(te, _("wrong color "));
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2002-07-03 22:01:49 +08:00
|
|
|
case RPMFILE_STATE_MISSING:
|
2000-12-26 21:10:18 +08:00
|
|
|
te = stpcpy(te, _("(no state) "));
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2002-07-03 22:01:49 +08:00
|
|
|
default:
|
|
|
|
sprintf(te, _("(unknown %3d) "), fstate);
|
|
|
|
te += strlen(te);
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2000-12-26 21:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
1997-02-18 04:18:54 +08:00
|
|
|
|
2002-03-09 06:24:58 +08:00
|
|
|
if (qva->qva_flags & QUERY_FOR_DUMPFILES) {
|
2002-10-10 03:07:43 +08:00
|
|
|
sprintf(te, "%s %d %d %s 0%o ", fn, (int)fsize, fmtime, fmd5, fmode);
|
2000-12-26 21:10:18 +08:00
|
|
|
te += strlen(te);
|
|
|
|
|
2002-07-03 22:01:49 +08:00
|
|
|
if (fuser && fgroup) {
|
|
|
|
sprintf(te, "%s %s", fuser, fgroup);
|
2000-12-26 21:10:18 +08:00
|
|
|
te += strlen(te);
|
|
|
|
} else {
|
|
|
|
rpmError(RPMERR_INTERNAL,
|
2002-07-03 22:01:49 +08:00
|
|
|
_("package has not file owner/group lists\n"));
|
2000-12-26 21:10:18 +08:00
|
|
|
}
|
1996-06-21 06:28:02 +08:00
|
|
|
|
2000-12-26 21:10:18 +08:00
|
|
|
sprintf(te, " %s %s %u ",
|
2002-07-03 22:01:49 +08:00
|
|
|
fflags & RPMFILE_CONFIG ? "1" : "0",
|
|
|
|
fflags & RPMFILE_DOC ? "1" : "0",
|
|
|
|
frdev);
|
2000-12-26 21:10:18 +08:00
|
|
|
te += strlen(te);
|
|
|
|
|
2002-07-03 22:01:49 +08:00
|
|
|
sprintf(te, "%s", (flink && *flink ? flink : "X"));
|
2000-12-26 21:10:18 +08:00
|
|
|
te += strlen(te);
|
2001-10-15 11:22:10 +08:00
|
|
|
} else
|
|
|
|
if (!rpmIsVerbose()) {
|
2002-07-03 22:01:49 +08:00
|
|
|
te = stpcpy(te, fn);
|
2001-10-15 11:22:10 +08:00
|
|
|
}
|
|
|
|
else {
|
2002-07-03 22:01:49 +08:00
|
|
|
|
|
|
|
/* XXX Adjust directory link count and size for display output. */
|
|
|
|
if (S_ISDIR(fmode)) {
|
|
|
|
fnlink++;
|
|
|
|
fsize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fuser && fgroup) {
|
|
|
|
printFileInfo(te, fn, fsize, fmode, fmtime, frdev, fnlink,
|
|
|
|
fuser, fgroup, flink);
|
2000-12-26 21:10:18 +08:00
|
|
|
te += strlen(te);
|
|
|
|
} else {
|
|
|
|
rpmError(RPMERR_INTERNAL,
|
2001-01-16 07:09:42 +08:00
|
|
|
_("package has neither file owner or id lists\n"));
|
1996-01-06 02:12:17 +08:00
|
|
|
}
|
2000-12-26 21:10:18 +08:00
|
|
|
}
|
2007-06-18 13:29:01 +08:00
|
|
|
flushBuffer(&t, &te, 0);
|
1996-04-16 06:21:30 +08:00
|
|
|
}
|
2000-12-26 21:10:18 +08:00
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
exit:
|
2007-06-18 13:29:01 +08:00
|
|
|
flushBuffer(&t, &te, 0);
|
2001-03-23 07:39:01 +08:00
|
|
|
t = _free(t);
|
2002-07-03 22:01:49 +08:00
|
|
|
|
2002-08-20 06:27:44 +08:00
|
|
|
fi = rpmfiFree(fi);
|
2000-12-26 21:10:18 +08:00
|
|
|
return rc;
|
1996-04-16 06:21:30 +08:00
|
|
|
}
|
|
|
|
|
2001-06-06 03:26:22 +08:00
|
|
|
void rpmDisplayQueryTags(FILE * fp)
|
2000-02-14 03:23:55 +08:00
|
|
|
{
|
2001-06-29 06:19:08 +08:00
|
|
|
const struct headerTagTableEntry_s * t;
|
2007-07-16 21:14:51 +08:00
|
|
|
int i, ttype;
|
2001-06-29 06:19:08 +08:00
|
|
|
const struct headerSprintfExtension_s * ext = rpmHeaderFormats;
|
1999-05-11 07:41:04 +08:00
|
|
|
|
2007-07-16 21:14:51 +08:00
|
|
|
for (i = 0, t = rpmTagTable; i < rpmTagTableSize; i++, t++) {
|
|
|
|
if (t->name == NULL)
|
|
|
|
continue;
|
|
|
|
if (rpmIsVerbose()) {
|
|
|
|
static const char * tagtypes[] = {
|
|
|
|
"", "char", "int8", "int16", "int32", "int64",
|
|
|
|
"string", "blob", "argv", "i18nstring"
|
|
|
|
};
|
2007-09-04 02:30:44 +08:00
|
|
|
fprintf(fp, "%-20s %6d", t->name + 7, t->val);
|
2007-07-16 21:14:51 +08:00
|
|
|
ttype = t->type & RPM_MASK_TYPE;
|
|
|
|
if (ttype > RPM_NULL_TYPE && ttype <= RPM_MAX_TYPE)
|
|
|
|
fprintf(fp, " %s", tagtypes[ttype]);
|
2007-09-04 02:30:44 +08:00
|
|
|
} else {
|
|
|
|
fprintf(fp, "%s", t->name + 7);
|
2007-07-16 21:14:51 +08:00
|
|
|
}
|
2007-09-04 02:30:44 +08:00
|
|
|
|
2007-07-16 21:14:51 +08:00
|
|
|
fprintf(fp, "\n");
|
|
|
|
}
|
1999-05-11 07:41:04 +08:00
|
|
|
|
2001-06-06 03:26:22 +08:00
|
|
|
while (ext->name != NULL) {
|
2000-02-17 03:10:42 +08:00
|
|
|
if (ext->type == HEADER_EXT_MORE) {
|
1999-05-11 07:41:04 +08:00
|
|
|
ext = ext->u.more;
|
2000-02-17 03:10:42 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* XXX don't print query tags twice. */
|
|
|
|
for (i = 0, t = rpmTagTable; i < rpmTagTableSize; i++, t++) {
|
2001-06-06 03:26:22 +08:00
|
|
|
if (t->name == NULL) /* XXX programmer error. */
|
2007-09-12 01:07:39 +08:00
|
|
|
continue;
|
2000-02-17 03:10:42 +08:00
|
|
|
if (!strcmp(t->name, ext->name))
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2000-02-17 03:10:42 +08:00
|
|
|
}
|
|
|
|
if (i >= rpmTagTableSize && ext->type == HEADER_EXT_TAG)
|
2001-06-06 03:26:22 +08:00
|
|
|
fprintf(fp, "%s\n", ext->name + 7);
|
2000-02-17 03:10:42 +08:00
|
|
|
ext++;
|
1999-05-11 07:41:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-25 06:25:32 +08:00
|
|
|
static int rpmgiShowMatches(QVA_t qva, rpmts ts)
|
|
|
|
{
|
|
|
|
rpmgi gi = qva->qva_gi;
|
|
|
|
int ec = 0;
|
|
|
|
|
|
|
|
while (rpmgiNext(gi) == RPMRC_OK) {
|
2004-10-25 08:34:08 +08:00
|
|
|
Header h;
|
2004-10-25 06:25:32 +08:00
|
|
|
int rc;
|
|
|
|
|
2004-10-25 08:34:08 +08:00
|
|
|
h = rpmgiHeader(gi);
|
|
|
|
if (h == NULL) /* XXX perhaps stricter break instead? */
|
|
|
|
continue;
|
|
|
|
if ((rc = qva->qva_showPackage(qva, ts, h)) != 0)
|
2004-10-25 06:25:32 +08:00
|
|
|
ec = rc;
|
|
|
|
if (qva->qva_source == RPMQV_DBOFFSET)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ec;
|
|
|
|
}
|
|
|
|
|
2002-08-09 00:06:13 +08:00
|
|
|
int rpmcliShowMatches(QVA_t qva, rpmts ts)
|
2000-04-12 21:42:57 +08:00
|
|
|
{
|
|
|
|
Header h;
|
|
|
|
int ec = 0;
|
|
|
|
|
2001-10-24 21:48:55 +08:00
|
|
|
while ((h = rpmdbNextIterator(qva->qva_mi)) != NULL) {
|
2000-04-12 21:42:57 +08:00
|
|
|
int rc;
|
2001-10-24 21:48:55 +08:00
|
|
|
if ((rc = qva->qva_showPackage(qva, ts, h)) != 0)
|
2000-04-12 21:42:57 +08:00
|
|
|
ec = rc;
|
2004-03-11 07:01:46 +08:00
|
|
|
if (qva->qva_source == RPMQV_DBOFFSET)
|
|
|
|
break;
|
2000-04-12 21:42:57 +08:00
|
|
|
}
|
2001-10-24 21:48:55 +08:00
|
|
|
qva->qva_mi = rpmdbFreeIterator(qva->qva_mi);
|
2000-04-12 21:42:57 +08:00
|
|
|
return ec;
|
|
|
|
}
|
1999-05-11 07:41:04 +08:00
|
|
|
|
2002-02-05 07:29:59 +08:00
|
|
|
/**
|
|
|
|
* Convert hex to binary nibble.
|
|
|
|
* @param c hex character
|
|
|
|
* @return binary nibble
|
|
|
|
*/
|
|
|
|
static inline unsigned char nibble(char c)
|
|
|
|
{
|
|
|
|
if (c >= '0' && c <= '9')
|
|
|
|
return (c - '0');
|
|
|
|
if (c >= 'A' && c <= 'F')
|
|
|
|
return (c - 'A') + 10;
|
|
|
|
if (c >= 'a' && c <= 'f')
|
|
|
|
return (c - 'a') + 10;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-12 01:07:39 +08:00
|
|
|
/* LCL: segfault (realpath annotation?) */
|
2002-05-20 02:42:25 +08:00
|
|
|
int rpmQueryVerify(QVA_t qva, rpmts ts, const char * arg)
|
1999-05-11 07:41:04 +08:00
|
|
|
{
|
2001-10-24 21:48:55 +08:00
|
|
|
int res = 0;
|
2002-02-05 07:29:59 +08:00
|
|
|
const char * s;
|
|
|
|
int i;
|
2003-01-14 04:58:21 +08:00
|
|
|
int provides_checked = 0;
|
2001-10-24 21:48:55 +08:00
|
|
|
|
2002-09-01 06:39:34 +08:00
|
|
|
(void) rpmdbCheckSignals();
|
|
|
|
|
2001-10-24 21:48:55 +08:00
|
|
|
if (qva->qva_showPackage == NULL)
|
|
|
|
return 1;
|
1995-12-28 04:08:35 +08:00
|
|
|
|
2001-10-24 21:48:55 +08:00
|
|
|
switch (qva->qva_source) {
|
1999-11-10 04:57:38 +08:00
|
|
|
case RPMQV_RPM:
|
2004-10-25 08:34:08 +08:00
|
|
|
res = rpmgiShowMatches(qva, ts);
|
|
|
|
break;
|
1995-12-28 04:08:35 +08:00
|
|
|
|
1999-11-10 04:57:38 +08:00
|
|
|
case RPMQV_ALL:
|
2004-10-25 06:25:32 +08:00
|
|
|
res = rpmgiShowMatches(qva, ts);
|
1995-12-28 04:08:35 +08:00
|
|
|
break;
|
|
|
|
|
2004-10-25 09:10:13 +08:00
|
|
|
case RPMQV_HDLIST:
|
|
|
|
res = rpmgiShowMatches(qva, ts);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RPMQV_FTSWALK:
|
|
|
|
res = rpmgiShowMatches(qva, ts);
|
|
|
|
break;
|
|
|
|
|
2004-10-25 23:26:51 +08:00
|
|
|
case RPMQV_SPECFILE:
|
|
|
|
res = ((qva->qva_specQuery != NULL)
|
|
|
|
? qva->qva_specQuery(ts, qva, arg) : 1);
|
|
|
|
break;
|
|
|
|
|
1999-11-10 04:57:38 +08:00
|
|
|
case RPMQV_GROUP:
|
2001-10-28 04:09:20 +08:00
|
|
|
qva->qva_mi = rpmtsInitIterator(ts, RPMTAG_GROUP, arg, 0);
|
2001-10-24 21:48:55 +08:00
|
|
|
if (qva->qva_mi == NULL) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_QUERYINFO,
|
2000-12-26 21:10:18 +08:00
|
|
|
_("group %s does not contain any packages\n"), arg);
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 1;
|
2003-01-14 04:58:21 +08:00
|
|
|
} else
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
1996-01-06 02:12:17 +08:00
|
|
|
break;
|
|
|
|
|
1999-11-10 04:57:38 +08:00
|
|
|
case RPMQV_TRIGGEREDBY:
|
2001-10-28 04:09:20 +08:00
|
|
|
qva->qva_mi = rpmtsInitIterator(ts, RPMTAG_TRIGGERNAME, arg, 0);
|
2001-10-24 21:48:55 +08:00
|
|
|
if (qva->qva_mi == NULL) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_QUERYINFO, _("no package triggers %s\n"), arg);
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 1;
|
2003-01-14 04:58:21 +08:00
|
|
|
} else
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
1998-03-28 00:46:39 +08:00
|
|
|
break;
|
|
|
|
|
2002-02-05 07:29:59 +08:00
|
|
|
case RPMQV_PKGID:
|
2002-07-22 06:06:19 +08:00
|
|
|
{ unsigned char MD5[16];
|
2002-02-05 07:29:59 +08:00
|
|
|
unsigned char * t;
|
|
|
|
|
|
|
|
for (i = 0, s = arg; *s && isxdigit(*s); s++, i++)
|
|
|
|
{};
|
|
|
|
if (i != 32) {
|
|
|
|
rpmError(RPMERR_QUERYINFO, _("malformed %s: %s\n"), "pkgid", arg);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-07-22 06:06:19 +08:00
|
|
|
MD5[0] = '\0';
|
|
|
|
for (i = 0, t = MD5, s = arg; i < 16; i++, t++, s += 2)
|
2002-02-05 07:29:59 +08:00
|
|
|
*t = (nibble(s[0]) << 4) | nibble(s[1]);
|
|
|
|
|
2002-07-22 06:06:19 +08:00
|
|
|
qva->qva_mi = rpmtsInitIterator(ts, RPMTAG_SIGMD5, MD5, sizeof(MD5));
|
2002-02-05 07:29:59 +08:00
|
|
|
if (qva->qva_mi == NULL) {
|
|
|
|
rpmError(RPMERR_QUERYINFO, _("no package matches %s: %s\n"),
|
|
|
|
"pkgid", arg);
|
|
|
|
res = 1;
|
2003-01-14 04:58:21 +08:00
|
|
|
} else
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2002-02-05 07:29:59 +08:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case RPMQV_HDRID:
|
|
|
|
for (i = 0, s = arg; *s && isxdigit(*s); s++, i++)
|
|
|
|
{};
|
|
|
|
if (i != 40) {
|
|
|
|
rpmError(RPMERR_QUERYINFO, _("malformed %s: %s\n"), "hdrid", arg);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
qva->qva_mi = rpmtsInitIterator(ts, RPMTAG_SHA1HEADER, arg, 0);
|
|
|
|
if (qva->qva_mi == NULL) {
|
|
|
|
rpmError(RPMERR_QUERYINFO, _("no package matches %s: %s\n"),
|
|
|
|
"hdrid", arg);
|
|
|
|
res = 1;
|
2003-01-14 04:58:21 +08:00
|
|
|
} else
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2002-02-05 07:29:59 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RPMQV_FILEID:
|
2002-07-22 06:06:19 +08:00
|
|
|
{ unsigned char MD5[16];
|
2002-04-08 03:52:42 +08:00
|
|
|
unsigned char * t;
|
|
|
|
|
2002-02-05 07:29:59 +08:00
|
|
|
for (i = 0, s = arg; *s && isxdigit(*s); s++, i++)
|
|
|
|
{};
|
|
|
|
if (i != 32) {
|
|
|
|
rpmError(RPMERR_QUERY, _("malformed %s: %s\n"), "fileid", arg);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-07-22 06:06:19 +08:00
|
|
|
MD5[0] = '\0';
|
|
|
|
for (i = 0, t = MD5, s = arg; i < 16; i++, t++, s += 2)
|
2002-04-08 03:52:42 +08:00
|
|
|
*t = (nibble(s[0]) << 4) | nibble(s[1]);
|
|
|
|
|
2002-07-22 06:06:19 +08:00
|
|
|
qva->qva_mi = rpmtsInitIterator(ts, RPMTAG_FILEMD5S, MD5, sizeof(MD5));
|
2002-02-05 07:29:59 +08:00
|
|
|
if (qva->qva_mi == NULL) {
|
|
|
|
rpmError(RPMERR_QUERYINFO, _("no package matches %s: %s\n"),
|
|
|
|
"fileid", arg);
|
|
|
|
res = 1;
|
2003-01-14 04:58:21 +08:00
|
|
|
} else
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2002-04-08 03:52:42 +08:00
|
|
|
} break;
|
2002-02-05 07:29:59 +08:00
|
|
|
|
|
|
|
case RPMQV_TID:
|
|
|
|
{ int mybase = 10;
|
|
|
|
const char * myarg = arg;
|
|
|
|
char * end = NULL;
|
2007-07-10 18:23:56 +08:00
|
|
|
unsigned long iid;
|
2002-02-05 07:29:59 +08:00
|
|
|
|
|
|
|
/* XXX should be in strtoul */
|
|
|
|
if (*myarg == '0') {
|
|
|
|
myarg++;
|
|
|
|
mybase = 8;
|
|
|
|
if (*myarg == 'x') {
|
|
|
|
myarg++;
|
|
|
|
mybase = 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
iid = strtoul(myarg, &end, mybase);
|
|
|
|
if ((*end) || (end == arg) || (iid == ULONG_MAX)) {
|
|
|
|
rpmError(RPMERR_QUERY, _("malformed %s: %s\n"), "tid", arg);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
qva->qva_mi = rpmtsInitIterator(ts, RPMTAG_INSTALLTID, &iid, sizeof(iid));
|
|
|
|
if (qva->qva_mi == NULL) {
|
|
|
|
rpmError(RPMERR_QUERYINFO, _("no package matches %s: %s\n"),
|
|
|
|
"tid", arg);
|
|
|
|
res = 1;
|
2003-01-14 04:58:21 +08:00
|
|
|
} else
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2002-02-05 07:29:59 +08:00
|
|
|
} break;
|
|
|
|
|
1999-11-10 04:57:38 +08:00
|
|
|
case RPMQV_WHATREQUIRES:
|
2001-10-28 04:09:20 +08:00
|
|
|
qva->qva_mi = rpmtsInitIterator(ts, RPMTAG_REQUIRENAME, arg, 0);
|
2001-10-24 21:48:55 +08:00
|
|
|
if (qva->qva_mi == NULL) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_QUERYINFO, _("no package requires %s\n"), arg);
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 1;
|
2003-01-14 04:58:21 +08:00
|
|
|
} else
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
1996-06-10 05:47:42 +08:00
|
|
|
break;
|
|
|
|
|
1999-12-03 00:31:35 +08:00
|
|
|
case RPMQV_WHATPROVIDES:
|
|
|
|
if (arg[0] != '/') {
|
2003-01-14 04:58:21 +08:00
|
|
|
provides_checked = 1;
|
2001-10-28 04:09:20 +08:00
|
|
|
qva->qva_mi = rpmtsInitIterator(ts, RPMTAG_PROVIDENAME, arg, 0);
|
2001-10-24 21:48:55 +08:00
|
|
|
if (qva->qva_mi == NULL) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_QUERYINFO, _("no package provides %s\n"), arg);
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 1;
|
2003-01-14 04:58:21 +08:00
|
|
|
} else
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
1999-12-03 00:31:35 +08:00
|
|
|
break;
|
|
|
|
}
|
1999-11-10 04:57:38 +08:00
|
|
|
case RPMQV_PATH:
|
2002-02-05 07:29:59 +08:00
|
|
|
{ char * fn;
|
2003-01-14 04:58:21 +08:00
|
|
|
int myerrno = 0;
|
2000-07-10 07:10:25 +08:00
|
|
|
|
2001-04-29 09:05:43 +08:00
|
|
|
for (s = arg; *s != '\0'; s++)
|
2001-06-06 03:26:22 +08:00
|
|
|
if (!(*s == '.' || *s == '/'))
|
2007-09-12 01:07:39 +08:00
|
|
|
break;
|
2000-07-10 07:10:25 +08:00
|
|
|
|
|
|
|
if (*s == '\0') {
|
|
|
|
char fnbuf[PATH_MAX];
|
2001-10-14 03:35:58 +08:00
|
|
|
fn = realpath(arg, fnbuf);
|
2001-05-04 05:00:18 +08:00
|
|
|
if (fn)
|
|
|
|
fn = xstrdup(fn);
|
|
|
|
else
|
|
|
|
fn = xstrdup(arg);
|
2004-04-14 00:34:40 +08:00
|
|
|
} else if (*arg != '/') {
|
|
|
|
const char *curDir = currentDirectory();
|
2004-10-10 05:58:33 +08:00
|
|
|
fn = (char *) rpmGetPath(curDir, "/", arg, NULL);
|
2004-04-19 20:06:30 +08:00
|
|
|
curDir = _free(curDir);
|
2000-07-10 07:10:25 +08:00
|
|
|
} else
|
|
|
|
fn = xstrdup(arg);
|
2000-10-29 01:16:25 +08:00
|
|
|
(void) rpmCleanPath(fn);
|
2000-07-10 07:10:25 +08:00
|
|
|
|
2001-10-28 04:09:20 +08:00
|
|
|
qva->qva_mi = rpmtsInitIterator(ts, RPMTAG_BASENAMES, fn, 0);
|
2001-10-24 21:48:55 +08:00
|
|
|
if (qva->qva_mi == NULL) {
|
2000-07-10 07:10:25 +08:00
|
|
|
if (access(fn, F_OK) != 0)
|
2000-04-12 21:42:57 +08:00
|
|
|
myerrno = errno;
|
2003-01-14 04:58:21 +08:00
|
|
|
else if (!provides_checked)
|
|
|
|
qva->qva_mi = rpmtsInitIterator(ts, RPMTAG_PROVIDENAME, fn, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (myerrno != 0) {
|
|
|
|
rpmError(RPMERR_QUERY, _("file %s: %s\n"), fn, strerror(myerrno));
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 1;
|
2003-01-14 04:58:21 +08:00
|
|
|
} else if (qva->qva_mi == NULL) {
|
|
|
|
rpmError(RPMERR_QUERYINFO,
|
|
|
|
_("file %s is not owned by any package\n"), fn);
|
|
|
|
res = 1;
|
|
|
|
} else
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2003-01-14 04:58:21 +08:00
|
|
|
|
2001-02-13 03:02:15 +08:00
|
|
|
fn = _free(fn);
|
2000-07-10 07:10:25 +08:00
|
|
|
} break;
|
1995-12-28 04:08:35 +08:00
|
|
|
|
1999-11-10 04:57:38 +08:00
|
|
|
case RPMQV_DBOFFSET:
|
2000-04-04 17:27:48 +08:00
|
|
|
{ int mybase = 10;
|
|
|
|
const char * myarg = arg;
|
2001-10-24 21:48:55 +08:00
|
|
|
char * end = NULL;
|
2007-07-10 18:23:56 +08:00
|
|
|
unsigned long recOffset;
|
2000-04-24 04:37:57 +08:00
|
|
|
|
|
|
|
/* XXX should be in strtoul */
|
2000-04-04 17:27:48 +08:00
|
|
|
if (*myarg == '0') {
|
|
|
|
myarg++;
|
|
|
|
mybase = 8;
|
|
|
|
if (*myarg == 'x') {
|
|
|
|
myarg++;
|
|
|
|
mybase = 16;
|
|
|
|
}
|
|
|
|
}
|
2000-04-24 04:37:57 +08:00
|
|
|
recOffset = strtoul(myarg, &end, mybase);
|
|
|
|
if ((*end) || (end == arg) || (recOffset == ULONG_MAX)) {
|
2002-02-05 07:29:59 +08:00
|
|
|
rpmError(RPMERR_QUERYINFO, _("invalid package number: %s\n"), arg);
|
1996-06-21 06:28:02 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2000-04-24 04:37:57 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("package record number: %u\n"), recOffset);
|
2000-04-20 06:15:02 +08:00
|
|
|
/* RPMDBI_PACKAGES */
|
2001-10-28 04:09:20 +08:00
|
|
|
qva->qva_mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, &recOffset, sizeof(recOffset));
|
2001-10-24 21:48:55 +08:00
|
|
|
if (qva->qva_mi == NULL) {
|
2002-02-05 07:29:59 +08:00
|
|
|
rpmError(RPMERR_QUERYINFO,
|
2001-04-29 09:05:43 +08:00
|
|
|
_("record %u could not be read\n"), recOffset);
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 1;
|
2003-01-14 04:58:21 +08:00
|
|
|
} else
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2000-04-04 17:27:48 +08:00
|
|
|
} break;
|
1996-06-21 06:28:02 +08:00
|
|
|
|
1999-11-10 04:57:38 +08:00
|
|
|
case RPMQV_PACKAGE:
|
2007-06-11 18:22:25 +08:00
|
|
|
{
|
|
|
|
int matches = 0;
|
2007-06-28 19:44:48 +08:00
|
|
|
rpmdbMatchIterator mi;
|
|
|
|
mi = rpmtsInitIterator(ts, RPMDBI_LABEL, arg, 0);
|
|
|
|
while (rpmdbNextIterator(mi) != NULL) {
|
2007-06-11 18:22:25 +08:00
|
|
|
matches++;
|
|
|
|
}
|
2007-06-28 19:44:48 +08:00
|
|
|
rpmdbFreeIterator(mi);
|
2007-06-11 18:22:25 +08:00
|
|
|
if (! matches) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_QUERYINFO, _("package %s is not installed\n"), arg);
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 1;
|
2007-06-11 18:22:25 +08:00
|
|
|
} else {
|
|
|
|
qva->qva_mi = rpmtsInitIterator(ts, RPMDBI_LABEL, arg, 0);
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2007-06-11 18:22:25 +08:00
|
|
|
}
|
1995-12-28 04:08:35 +08:00
|
|
|
break;
|
1999-12-13 01:46:22 +08:00
|
|
|
}
|
2007-06-11 18:22:25 +08:00
|
|
|
|
|
|
|
}
|
1995-12-28 04:08:35 +08:00
|
|
|
|
2001-10-24 21:48:55 +08:00
|
|
|
return res;
|
1999-05-11 07:41:04 +08:00
|
|
|
}
|
|
|
|
|
2004-10-25 03:36:30 +08:00
|
|
|
int rpmcliArgIter(rpmts ts, QVA_t qva, ARGV_t argv)
|
1999-05-11 07:41:04 +08:00
|
|
|
{
|
2004-10-27 07:29:28 +08:00
|
|
|
rpmRC rpmrc = RPMRC_NOTFOUND;
|
2004-10-25 03:36:30 +08:00
|
|
|
int ec = 0;
|
|
|
|
|
|
|
|
switch (qva->qva_source) {
|
|
|
|
case RPMQV_ALL:
|
2004-10-25 06:25:32 +08:00
|
|
|
qva->qva_gi = rpmgiNew(ts, RPMDBI_PACKAGES, NULL, 0);
|
2004-10-25 09:10:13 +08:00
|
|
|
qva->qva_rc = rpmgiSetArgs(qva->qva_gi, argv, ftsOpts, RPMGI_NONE);
|
2004-10-27 07:29:28 +08:00
|
|
|
|
|
|
|
if (qva->qva_gi != NULL && (qva->qva_gi->flags & RPMGI_TSADD)) /* Load the ts with headers. */
|
|
|
|
while ((rpmrc = rpmgiNext(qva->qva_gi)) == RPMRC_OK)
|
|
|
|
{};
|
|
|
|
if (rpmrc != RPMRC_NOTFOUND)
|
|
|
|
return 1; /* XXX should be no. of failures. */
|
|
|
|
|
2007-09-12 01:07:39 +08:00
|
|
|
/* FIX: argv can be NULL, cast to pass argv array */
|
2004-10-25 03:36:30 +08:00
|
|
|
ec = rpmQueryVerify(qva, ts, (const char *) argv);
|
2004-10-25 04:35:41 +08:00
|
|
|
rpmtsEmpty(ts);
|
2004-10-25 03:36:30 +08:00
|
|
|
break;
|
2004-10-25 08:34:08 +08:00
|
|
|
case RPMQV_RPM:
|
|
|
|
qva->qva_gi = rpmgiNew(ts, RPMDBI_ARGLIST, NULL, 0);
|
2004-10-26 02:10:48 +08:00
|
|
|
qva->qva_rc = rpmgiSetArgs(qva->qva_gi, argv, ftsOpts, giFlags);
|
2004-10-27 07:29:28 +08:00
|
|
|
|
|
|
|
if (qva->qva_gi != NULL && (qva->qva_gi->flags & RPMGI_TSADD)) /* Load the ts with headers. */
|
|
|
|
while ((rpmrc = rpmgiNext(qva->qva_gi)) == RPMRC_OK)
|
|
|
|
{};
|
|
|
|
if (rpmrc != RPMRC_NOTFOUND)
|
|
|
|
return 1; /* XXX should be no. of failures. */
|
|
|
|
|
2007-09-12 01:07:39 +08:00
|
|
|
/* FIX: argv can be NULL, cast to pass argv array */
|
2004-10-25 09:10:13 +08:00
|
|
|
ec = rpmQueryVerify(qva, ts, NULL);
|
|
|
|
rpmtsEmpty(ts);
|
|
|
|
break;
|
|
|
|
case RPMQV_HDLIST:
|
|
|
|
qva->qva_gi = rpmgiNew(ts, RPMDBI_HDLIST, NULL, 0);
|
2004-10-26 02:10:48 +08:00
|
|
|
qva->qva_rc = rpmgiSetArgs(qva->qva_gi, argv, ftsOpts, giFlags);
|
2004-10-27 07:29:28 +08:00
|
|
|
|
|
|
|
if (qva->qva_gi != NULL && (qva->qva_gi->flags & RPMGI_TSADD)) /* Load the ts with headers. */
|
|
|
|
while ((rpmrc = rpmgiNext(qva->qva_gi)) == RPMRC_OK)
|
|
|
|
{};
|
|
|
|
if (rpmrc != RPMRC_NOTFOUND)
|
|
|
|
return 1; /* XXX should be no. of failures. */
|
|
|
|
|
2007-09-12 01:07:39 +08:00
|
|
|
/* FIX: argv can be NULL, cast to pass argv array */
|
2004-10-25 09:10:13 +08:00
|
|
|
ec = rpmQueryVerify(qva, ts, NULL);
|
|
|
|
rpmtsEmpty(ts);
|
|
|
|
break;
|
|
|
|
case RPMQV_FTSWALK:
|
2004-10-25 23:26:51 +08:00
|
|
|
if (ftsOpts == 0)
|
2004-10-25 09:10:13 +08:00
|
|
|
ftsOpts = (FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT);
|
2004-10-26 02:10:48 +08:00
|
|
|
qva->qva_gi = rpmgiNew(ts, RPMDBI_FTSWALK, NULL, 0);
|
|
|
|
qva->qva_rc = rpmgiSetArgs(qva->qva_gi, argv, ftsOpts, giFlags);
|
2004-10-27 07:29:28 +08:00
|
|
|
|
|
|
|
if (qva->qva_gi != NULL && (qva->qva_gi->flags & RPMGI_TSADD)) /* Load the ts with headers. */
|
|
|
|
while ((rpmrc = rpmgiNext(qva->qva_gi)) == RPMRC_OK)
|
|
|
|
{};
|
|
|
|
if (rpmrc != RPMRC_NOTFOUND)
|
|
|
|
return 1; /* XXX should be no. of failures. */
|
|
|
|
|
2007-09-12 01:07:39 +08:00
|
|
|
/* FIX: argv can be NULL, cast to pass argv array */
|
2004-10-25 08:34:08 +08:00
|
|
|
ec = rpmQueryVerify(qva, ts, NULL);
|
|
|
|
rpmtsEmpty(ts);
|
|
|
|
break;
|
2004-10-25 03:36:30 +08:00
|
|
|
default:
|
2004-10-25 06:25:32 +08:00
|
|
|
qva->qva_gi = rpmgiNew(ts, RPMDBI_ARGLIST, NULL, 0);
|
2004-10-26 08:22:10 +08:00
|
|
|
qva->qva_rc = rpmgiSetArgs(qva->qva_gi, argv, ftsOpts,
|
|
|
|
(giFlags | (RPMGI_NOGLOB|RPMGI_NOHEADER)));
|
2004-10-25 04:35:41 +08:00
|
|
|
while (rpmgiNext(qva->qva_gi) == RPMRC_OK) {
|
|
|
|
ec += rpmQueryVerify(qva, ts, rpmgiHdrPath(qva->qva_gi));
|
2004-10-25 03:36:30 +08:00
|
|
|
rpmtsEmpty(ts);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
qva->qva_gi = rpmgiFree(qva->qva_gi);
|
|
|
|
|
|
|
|
return ec;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rpmcliQuery(rpmts ts, QVA_t qva, const char ** argv)
|
|
|
|
{
|
2002-08-06 09:41:44 +08:00
|
|
|
rpmVSFlags vsflags, ovsflags;
|
2001-10-24 21:48:55 +08:00
|
|
|
int ec = 0;
|
1999-05-11 07:41:04 +08:00
|
|
|
|
2001-10-28 04:09:20 +08:00
|
|
|
if (qva->qva_showPackage == NULL)
|
|
|
|
qva->qva_showPackage = showQueryPackage;
|
|
|
|
|
2003-02-03 19:46:52 +08:00
|
|
|
/* If --queryformat unspecified, then set default now. */
|
2003-02-01 06:55:28 +08:00
|
|
|
if (!(qva->qva_flags & _QUERY_FOR_BITS) && qva->qva_queryFormat == NULL) {
|
|
|
|
qva->qva_queryFormat = rpmExpand("%{?_query_all_fmt}\n", NULL);
|
|
|
|
if (!(qva->qva_queryFormat != NULL && *qva->qva_queryFormat != '\0')) {
|
|
|
|
qva->qva_queryFormat = _free(qva->qva_queryFormat);
|
2007-09-20 19:39:24 +08:00
|
|
|
qva->qva_queryFormat = xstrdup("%{name}-%{version}-%{release}.%{arch}\n");
|
2003-02-01 06:55:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-03 05:52:01 +08:00
|
|
|
vsflags = rpmExpandNumeric("%{?_vsflags_query}");
|
2002-05-17 00:55:21 +08:00
|
|
|
if (qva->qva_flags & VERIFY_DIGEST)
|
2002-08-06 09:41:44 +08:00
|
|
|
vsflags |= _RPMVSF_NODIGESTS;
|
2002-05-17 00:55:21 +08:00
|
|
|
if (qva->qva_flags & VERIFY_SIGNATURE)
|
2002-08-06 09:41:44 +08:00
|
|
|
vsflags |= _RPMVSF_NOSIGNATURES;
|
2002-07-25 00:21:23 +08:00
|
|
|
if (qva->qva_flags & VERIFY_HDRCHK)
|
2002-08-06 09:41:44 +08:00
|
|
|
vsflags |= RPMVSF_NOHDRCHK;
|
2002-03-09 06:24:58 +08:00
|
|
|
|
2002-08-06 09:41:44 +08:00
|
|
|
ovsflags = rpmtsSetVSFlags(ts, vsflags);
|
2004-10-25 03:36:30 +08:00
|
|
|
ec = rpmcliArgIter(ts, qva, argv);
|
2002-08-06 09:41:44 +08:00
|
|
|
vsflags = rpmtsSetVSFlags(ts, ovsflags);
|
2001-10-24 21:48:55 +08:00
|
|
|
|
|
|
|
if (qva->qva_showPackage == showQueryPackage)
|
|
|
|
qva->qva_showPackage = NULL;
|
|
|
|
|
|
|
|
return ec;
|
1996-04-03 11:45:27 +08:00
|
|
|
}
|