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
|
2001-09-21 23:07:11 +08:00
|
|
|
/*@-incondefs@*/ /* FIX: long int? */
|
1998-07-25 04:30:55 +08:00
|
|
|
# define PATH_MAX 255
|
2001-09-21 23:07:11 +08:00
|
|
|
/*@=incondefs@*/
|
1998-07-25 04:30:55 +08:00
|
|
|
#endif
|
|
|
|
|
2001-06-09 04:45:59 +08:00
|
|
|
#include <rpmcli.h>
|
2000-12-13 04:03:45 +08:00
|
|
|
#include <rpmbuild.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"
|
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"
|
1995-12-28 04:08:35 +08:00
|
|
|
|
2000-10-29 01:16:25 +08:00
|
|
|
/*@access rpmdbMatchIterator@*/ /* XXX compared with NULL */
|
2001-04-29 09:05:43 +08:00
|
|
|
/*@access Header@*/ /* XXX compared with NULL */
|
|
|
|
/*@access FD_t@*/ /* XXX compared with NULL */
|
2001-02-13 03:02:15 +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)
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@modifies *te @*/
|
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);
|
2002-06-23 02:51:56 +08:00
|
|
|
/*@-boundsread@*/
|
2001-05-04 05:00:18 +08:00
|
|
|
if (tm) nowtm = *tm; /* structure assignment */
|
2002-06-23 02:51:56 +08:00
|
|
|
/*@=boundsread@*/
|
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
|
|
|
/**
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
static inline /*@null@*/ const char * queryHeader(Header h, const char * qfmt)
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@*/
|
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
|
|
|
|
2002-05-03 06:16:30 +08:00
|
|
|
/*@-modobserver@*/
|
2000-12-26 21:10:18 +08:00
|
|
|
str = headerSprintf(h, qfmt, rpmTagTable, rpmHeaderFormats, &errstr);
|
2002-05-03 06:16:30 +08:00
|
|
|
/*@=modobserver@*/
|
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
|
|
|
}
|
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
int showQueryPackage(QVA_t qva, /*@unused@*/ rpmts ts, Header h)
|
1999-05-11 07:41:04 +08:00
|
|
|
{
|
2002-07-03 22:01:49 +08:00
|
|
|
int scareMem = 1;
|
|
|
|
rpmfi fi = NULL;
|
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 */
|
2000-12-28 05:19:53 +08:00
|
|
|
int nonewline = 0;
|
1995-12-28 04:08:35 +08:00
|
|
|
int i;
|
|
|
|
|
2000-12-28 05:19:53 +08:00
|
|
|
te = t = xmalloc(BUFSIZ);
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@-boundswrite@*/
|
2000-12-26 21:10:18 +08:00
|
|
|
*te = '\0';
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@=boundswrite@*/
|
1995-12-28 04:08:35 +08:00
|
|
|
|
2002-03-09 06:24:58 +08:00
|
|
|
if (!(qva->qva_flags & _QUERY_FOR_BITS) && qva->qva_queryFormat == NULL)
|
|
|
|
{
|
2000-12-26 21:10:18 +08:00
|
|
|
const char * name, * version, * release;
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerNVR(h, &name, &version, &release);
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@-boundswrite@*/
|
2000-12-26 21:10:18 +08:00
|
|
|
te = stpcpy(te, name);
|
|
|
|
te = stpcpy( stpcpy(te, "-"), version);
|
|
|
|
te = stpcpy( stpcpy(te, "-"), release);
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@=boundswrite@*/
|
2000-12-26 21:10:18 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
nonewline = 1;
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@-branchstate@*/
|
2000-12-28 05:19:53 +08:00
|
|
|
if (str) {
|
|
|
|
size_t tb = (te - t);
|
|
|
|
size_t sb = strlen(str);
|
|
|
|
|
|
|
|
if (sb >= (BUFSIZ - tb)) {
|
|
|
|
t = xrealloc(t, BUFSIZ+sb);
|
|
|
|
te = t + tb;
|
|
|
|
}
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@-boundswrite@*/
|
2001-04-29 09:05:43 +08:00
|
|
|
/*@-usereleased@*/
|
2000-12-28 05:19:53 +08:00
|
|
|
te = stpcpy(te, str);
|
2001-04-29 09:05:43 +08:00
|
|
|
/*@=usereleased@*/
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@=boundswrite@*/
|
2001-02-13 03:02:15 +08:00
|
|
|
str = _free(str);
|
2000-12-28 05:19:53 +08:00
|
|
|
}
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@=branchstate@*/
|
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) {
|
|
|
|
/*@-boundswrite@*/
|
2000-12-26 21:10:18 +08:00
|
|
|
te = stpcpy(te, _("(contains no files)"));
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@=boundswrite@*/
|
2000-12-26 21:10:18 +08:00
|
|
|
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);
|
|
|
|
/*@-bounds@*/
|
|
|
|
{ static char hex[] = "0123456789abcdef";
|
|
|
|
const char * s = rpmfiMD5(fi);
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
/*@=bounds@*/
|
|
|
|
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. */
|
2002-07-03 22:01:49 +08:00
|
|
|
if (!(qva->qva_fflags & RPMFILE_GHOST) && (fflags & RPMFILE_GHOST))
|
2001-06-21 05:20:16 +08:00
|
|
|
continue;
|
|
|
|
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@-boundswrite@*/
|
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 "));
|
|
|
|
/*@switchbreak@*/ break;
|
|
|
|
case RPMFILE_STATE_REPLACED:
|
|
|
|
te = stpcpy(te, _("replaced "));
|
|
|
|
/*@switchbreak@*/ break;
|
|
|
|
case RPMFILE_STATE_NOTINSTALLED:
|
|
|
|
te = stpcpy(te, _("not installed "));
|
|
|
|
/*@switchbreak@*/ break;
|
|
|
|
case RPMFILE_STATE_NETSHARED:
|
|
|
|
te = stpcpy(te, _("net shared "));
|
|
|
|
/*@switchbreak@*/ break;
|
|
|
|
case RPMFILE_STATE_MISSING:
|
2000-12-26 21:10:18 +08:00
|
|
|
te = stpcpy(te, _("(no state) "));
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@switchbreak@*/ break;
|
|
|
|
default:
|
|
|
|
sprintf(te, _("(unknown %3d) "), fstate);
|
|
|
|
te += strlen(te);
|
|
|
|
/*@switchbreak@*/ break;
|
2000-12-26 21:10:18 +08:00
|
|
|
}
|
|
|
|
}
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@=boundswrite@*/
|
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) {
|
|
|
|
/*@-nullpass@*/
|
|
|
|
sprintf(te, "%s %s", fuser, fgroup);
|
|
|
|
/*@=nullpass@*/
|
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
|
|
|
/*@-boundswrite@*/
|
|
|
|
te = stpcpy(te, fn);
|
|
|
|
/*@=boundswrite@*/
|
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) {
|
|
|
|
/*@-nullpass@*/
|
|
|
|
printFileInfo(te, fn, fsize, fmode, fmtime, frdev, fnlink,
|
|
|
|
fuser, fgroup, flink);
|
|
|
|
/*@=nullpass@*/
|
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
|
|
|
}
|
2002-09-17 23:21:03 +08:00
|
|
|
/*@-branchstate@*/
|
2000-12-26 21:10:18 +08:00
|
|
|
if (te > t) {
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@-boundswrite@*/
|
2000-12-26 21:10:18 +08:00
|
|
|
*te++ = '\n';
|
|
|
|
*te = '\0';
|
|
|
|
rpmMessage(RPMMESS_NORMAL, "%s", t);
|
2000-12-28 05:19:53 +08:00
|
|
|
te = t;
|
2000-12-26 21:10:18 +08:00
|
|
|
*t = '\0';
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@=boundswrite@*/
|
1995-12-28 04:08:35 +08:00
|
|
|
}
|
2002-09-17 23:21:03 +08:00
|
|
|
/*@=branchstate@*/
|
1996-04-16 06:21:30 +08:00
|
|
|
}
|
2000-12-26 21:10:18 +08:00
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
exit:
|
2000-12-28 05:19:53 +08:00
|
|
|
if (te > t) {
|
|
|
|
if (!nonewline) {
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@-boundswrite@*/
|
2000-12-28 05:19:53 +08:00
|
|
|
*te++ = '\n';
|
|
|
|
*te = '\0';
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@=boundswrite@*/
|
2000-12-28 05:19:53 +08:00
|
|
|
}
|
2000-12-26 21:10:18 +08:00
|
|
|
rpmMessage(RPMMESS_NORMAL, "%s", t);
|
2000-12-28 05:19:53 +08:00
|
|
|
}
|
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-03-15 07:09:09 +08:00
|
|
|
/**
|
2002-07-12 05:47:51 +08:00
|
|
|
* Print copy of spec file, filling in Group/Description/Summary from specspo.
|
|
|
|
* @param spec spec file control structure
|
2001-03-15 07:09:09 +08:00
|
|
|
*/
|
1999-02-23 01:44:57 +08:00
|
|
|
static void
|
|
|
|
printNewSpecfile(Spec spec)
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@globals fileSystem @*/
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@modifies spec->sl->sl_lines[], fileSystem @*/
|
1999-02-23 01:44:57 +08:00
|
|
|
{
|
2001-07-19 07:03:27 +08:00
|
|
|
Header h;
|
2001-05-07 03:17:14 +08:00
|
|
|
speclines sl = spec->sl;
|
|
|
|
spectags st = spec->st;
|
2000-02-24 01:34:41 +08:00
|
|
|
const char * msgstr = NULL;
|
1999-02-23 01:44:57 +08:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
if (sl == NULL || st == NULL)
|
|
|
|
return;
|
|
|
|
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@-branchstate@*/
|
1999-02-23 01:44:57 +08:00
|
|
|
for (i = 0; i < st->st_ntags; i++) {
|
2001-05-07 03:17:14 +08:00
|
|
|
spectag t = st->st_t + i;
|
2000-02-24 01:34:41 +08:00
|
|
|
const char * tn = tagName(t->t_tag);
|
|
|
|
const char * errstr;
|
2001-07-19 07:03:27 +08:00
|
|
|
char fmt[1024];
|
2000-02-24 01:34:41 +08:00
|
|
|
|
|
|
|
fmt[0] = '\0';
|
2001-07-19 07:03:27 +08:00
|
|
|
if (t->t_msgid == NULL)
|
|
|
|
h = spec->packages->header;
|
|
|
|
else {
|
|
|
|
Package pkg;
|
|
|
|
char *fe;
|
|
|
|
|
2002-06-23 02:51:56 +08:00
|
|
|
/*@-bounds@*/
|
2001-07-19 07:03:27 +08:00
|
|
|
strcpy(fmt, t->t_msgid);
|
|
|
|
for (fe = fmt; *fe && *fe != '('; fe++)
|
|
|
|
{} ;
|
|
|
|
if (*fe == '(') *fe = '\0';
|
2002-06-23 02:51:56 +08:00
|
|
|
/*@=bounds@*/
|
2001-07-19 07:03:27 +08:00
|
|
|
h = NULL;
|
|
|
|
for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
|
|
|
|
const char *pkgname;
|
|
|
|
h = pkg->header;
|
2001-07-20 05:14:05 +08:00
|
|
|
(void) headerNVR(h, &pkgname, NULL, NULL);
|
2001-07-19 07:03:27 +08:00
|
|
|
if (!strcmp(pkgname, fmt))
|
2001-07-20 05:14:05 +08:00
|
|
|
/*@innerbreak@*/ break;
|
2001-07-19 07:03:27 +08:00
|
|
|
}
|
|
|
|
if (pkg == NULL || h == NULL)
|
|
|
|
h = spec->packages->header;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fmt[0] = '\0';
|
2002-06-23 02:51:56 +08:00
|
|
|
/*@-boundswrite@*/
|
2001-07-19 07:03:27 +08:00
|
|
|
(void) stpcpy( stpcpy( stpcpy( fmt, "%{"), tn), "}");
|
2002-06-23 02:51:56 +08:00
|
|
|
/*@=boundswrite@*/
|
2001-02-13 03:02:15 +08:00
|
|
|
msgstr = _free(msgstr);
|
2001-07-19 07:03:27 +08:00
|
|
|
|
2002-05-02 06:13:00 +08:00
|
|
|
/* XXX this should use queryHeader(), but prints out tn as well. */
|
2000-02-24 01:34:41 +08:00
|
|
|
msgstr = headerSprintf(h, fmt, rpmTagTable, rpmHeaderFormats, &errstr);
|
|
|
|
if (msgstr == NULL) {
|
2000-12-26 21:10:18 +08:00
|
|
|
rpmError(RPMERR_QFMT, _("can't query %s: %s\n"), tn, errstr);
|
2000-02-24 01:34:41 +08:00
|
|
|
return;
|
1999-02-23 01:44:57 +08:00
|
|
|
}
|
|
|
|
|
2002-06-23 02:51:56 +08:00
|
|
|
/*@-boundswrite@*/
|
1999-02-23 01:44:57 +08:00
|
|
|
switch(t->t_tag) {
|
|
|
|
case RPMTAG_SUMMARY:
|
|
|
|
case RPMTAG_GROUP:
|
2001-04-30 06:43:01 +08:00
|
|
|
/*@-unqualifiedtrans@*/
|
2001-03-23 07:39:01 +08:00
|
|
|
sl->sl_lines[t->t_startx] = _free(sl->sl_lines[t->t_startx]);
|
2001-04-30 06:43:01 +08:00
|
|
|
/*@=unqualifiedtrans@*/
|
1999-02-23 01:44:57 +08:00
|
|
|
if (t->t_lang && strcmp(t->t_lang, RPMBUILD_DEFAULT_LANG))
|
|
|
|
continue;
|
2000-02-24 01:34:41 +08:00
|
|
|
{ char *buf = xmalloc(strlen(tn) + sizeof(": ") + strlen(msgstr));
|
|
|
|
(void) stpcpy( stpcpy( stpcpy(buf, tn), ": "), msgstr);
|
|
|
|
sl->sl_lines[t->t_startx] = buf;
|
|
|
|
}
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
1999-02-23 01:44:57 +08:00
|
|
|
case RPMTAG_DESCRIPTION:
|
1999-09-18 04:40:41 +08:00
|
|
|
for (j = 1; j < t->t_nlines; j++) {
|
2001-07-19 07:03:27 +08:00
|
|
|
if (*sl->sl_lines[t->t_startx + j] == '%')
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@innercontinue@*/ continue;
|
2001-04-30 06:43:01 +08:00
|
|
|
/*@-unqualifiedtrans@*/
|
2001-03-23 07:39:01 +08:00
|
|
|
sl->sl_lines[t->t_startx + j] =
|
|
|
|
_free(sl->sl_lines[t->t_startx + j]);
|
2001-04-30 06:43:01 +08:00
|
|
|
/*@=unqualifiedtrans@*/
|
1999-09-18 04:40:41 +08:00
|
|
|
}
|
1999-02-23 01:44:57 +08:00
|
|
|
if (t->t_lang && strcmp(t->t_lang, RPMBUILD_DEFAULT_LANG)) {
|
2001-03-23 07:39:01 +08:00
|
|
|
sl->sl_lines[t->t_startx] = _free(sl->sl_lines[t->t_startx]);
|
1999-02-23 01:44:57 +08:00
|
|
|
continue;
|
|
|
|
}
|
1999-09-21 11:22:53 +08:00
|
|
|
sl->sl_lines[t->t_startx + 1] = xstrdup(msgstr);
|
1999-02-23 01:44:57 +08:00
|
|
|
if (t->t_nlines > 2)
|
1999-09-21 11:22:53 +08:00
|
|
|
sl->sl_lines[t->t_startx + 2] = xstrdup("\n\n");
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
1999-02-23 01:44:57 +08:00
|
|
|
}
|
2002-06-23 02:51:56 +08:00
|
|
|
/*@=boundswrite@*/
|
1999-02-23 01:44:57 +08:00
|
|
|
}
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@=branchstate@*/
|
2001-02-13 03:02:15 +08:00
|
|
|
msgstr = _free(msgstr);
|
1999-02-23 01:44:57 +08:00
|
|
|
|
2002-06-23 02:51:56 +08:00
|
|
|
/*@-boundsread@*/
|
1999-02-23 01:44:57 +08:00
|
|
|
for (i = 0; i < sl->sl_nlines; i++) {
|
2001-07-19 07:03:27 +08:00
|
|
|
const char * s = sl->sl_lines[i];
|
|
|
|
if (s == NULL)
|
1999-02-23 01:44:57 +08:00
|
|
|
continue;
|
2001-07-19 07:03:27 +08:00
|
|
|
printf("%s", s);
|
|
|
|
if (strchr(s, '\n') == NULL && s[strlen(s)-1] != '\n')
|
|
|
|
printf("\n");
|
1999-02-23 01:44:57 +08:00
|
|
|
}
|
2002-06-23 02:51:56 +08:00
|
|
|
/*@=boundsread@*/
|
1999-02-23 01:44:57 +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;
|
1999-05-11 07:41:04 +08:00
|
|
|
int i;
|
2001-06-29 06:19:08 +08:00
|
|
|
const struct headerSprintfExtension_s * ext = rpmHeaderFormats;
|
1999-05-11 07:41:04 +08:00
|
|
|
|
2001-06-06 03:26:22 +08:00
|
|
|
for (i = 0, t = rpmTagTable; i < rpmTagTableSize; i++, t++)
|
|
|
|
if (t->name) fprintf(fp, "%s\n", t->name + 7);
|
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. */
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@innercontinue@*/ continue;
|
2000-02-17 03:10:42 +08:00
|
|
|
if (!strcmp(t->name, ext->name))
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@innerbreak@*/ 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@-redecl@*/
|
2000-04-27 09:11:48 +08:00
|
|
|
/**
|
2000-08-30 06:04:33 +08:00
|
|
|
* @todo Eliminate linkage loop into librpmbuild.a
|
2000-04-27 09:11:48 +08:00
|
|
|
*/
|
1999-11-01 05:38:21 +08:00
|
|
|
int (*parseSpecVec) (Spec *specp, const char *specFile, const char *rootdir,
|
2001-05-07 03:17:14 +08:00
|
|
|
const char *buildRoot, int recursing, const char *passPhrase,
|
1999-11-01 05:38:21 +08:00
|
|
|
char *cookie, int anyarch, int force) = NULL;
|
2000-04-27 09:11:48 +08:00
|
|
|
/**
|
2000-08-30 06:04:33 +08:00
|
|
|
* @todo Eliminate linkage loop into librpmbuild.a
|
2000-04-27 09:11:48 +08:00
|
|
|
*/
|
2001-05-07 03:17:14 +08:00
|
|
|
/*@null@*/ Spec (*freeSpecVec) (Spec spec) = NULL;
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@=redecl@*/
|
1999-07-01 05:18:43 +08:00
|
|
|
|
2002-07-12 05:47:51 +08:00
|
|
|
/*@-bounds@*/ /* 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
|
|
|
const char ** av = NULL;
|
|
|
|
int res = 0;
|
1995-12-28 04:08:35 +08:00
|
|
|
Header h;
|
1996-01-06 02:12:17 +08:00
|
|
|
int rc;
|
2001-11-13 06:54:39 +08:00
|
|
|
int xx;
|
2002-02-05 07:29:59 +08:00
|
|
|
const char * s;
|
|
|
|
int i;
|
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-16 01:53:34 +08:00
|
|
|
/*@-branchstate@*/
|
2001-10-24 21:48:55 +08:00
|
|
|
switch (qva->qva_source) {
|
1999-11-10 04:57:38 +08:00
|
|
|
case RPMQV_RPM:
|
2001-03-24 04:27:48 +08:00
|
|
|
{ int ac = 0;
|
2001-03-23 07:39:01 +08:00
|
|
|
const char * fileURL = NULL;
|
2001-02-13 03:02:15 +08:00
|
|
|
rpmRC rpmrc;
|
1998-12-01 08:10:18 +08:00
|
|
|
|
2001-03-24 04:27:48 +08:00
|
|
|
rc = rpmGlob(arg, &ac, &av);
|
2001-03-23 07:39:01 +08:00
|
|
|
if (rc) return 1;
|
|
|
|
|
|
|
|
restart:
|
2001-03-24 04:27:48 +08:00
|
|
|
for (i = 0; i < ac; i++) {
|
1999-12-13 01:46:22 +08:00
|
|
|
FD_t fd;
|
2001-03-23 07:39:01 +08:00
|
|
|
|
|
|
|
fileURL = _free(fileURL);
|
2001-03-24 04:27:48 +08:00
|
|
|
fileURL = av[i];
|
|
|
|
av[i] = NULL;
|
2001-03-23 07:39:01 +08:00
|
|
|
|
|
|
|
/* Try to read the header from a package file. */
|
|
|
|
fd = Fopen(fileURL, "r.ufdio");
|
2001-03-24 04:27:48 +08:00
|
|
|
if (fd == NULL || Ferror(fd)) {
|
2001-03-23 07:39:01 +08:00
|
|
|
rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), fileURL,
|
|
|
|
Fstrerror(fd));
|
2001-05-01 06:32:22 +08:00
|
|
|
if (fd) (void) Fclose(fd);
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 1;
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@loopbreak@*/ break;
|
1999-12-13 01:46:22 +08:00
|
|
|
}
|
1996-10-15 11:14:50 +08:00
|
|
|
|
2001-10-28 04:09:20 +08:00
|
|
|
rpmrc = rpmReadPackageFile(ts, fd, fileURL, &h);
|
2001-10-25 09:36:32 +08:00
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(fd);
|
1996-10-15 11:14:50 +08:00
|
|
|
|
2002-08-24 05:01:59 +08:00
|
|
|
res = 0;
|
|
|
|
switch (rpmrc) {
|
|
|
|
default:
|
2002-09-17 04:10:20 +08:00
|
|
|
#ifdef DYING
|
2001-03-23 07:39:01 +08:00
|
|
|
rpmError(RPMERR_QUERY, _("query of %s failed\n"), fileURL);
|
2002-09-17 04:10:20 +08:00
|
|
|
#endif
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 1;
|
2002-08-24 05:01:59 +08:00
|
|
|
/*@switchbreak@*/ break;
|
2002-08-28 04:50:21 +08:00
|
|
|
case RPMRC_NOTTRUSTED:
|
|
|
|
case RPMRC_NOKEY:
|
2002-08-24 05:01:59 +08:00
|
|
|
case RPMRC_OK:
|
|
|
|
if (h == NULL) {
|
2002-09-17 04:10:20 +08:00
|
|
|
#ifdef DYING
|
2002-08-24 05:01:59 +08:00
|
|
|
rpmError(RPMERR_QUERY,
|
2000-12-26 21:10:18 +08:00
|
|
|
_("old format source packages cannot be queried\n"));
|
2002-09-17 04:10:20 +08:00
|
|
|
#endif
|
2002-08-24 05:01:59 +08:00
|
|
|
res = 1;
|
|
|
|
/*@switchbreak@*/ break;
|
|
|
|
}
|
2001-03-23 07:39:01 +08:00
|
|
|
|
2002-08-24 05:01:59 +08:00
|
|
|
/* Query a package file. */
|
2001-10-24 21:48:55 +08:00
|
|
|
res = qva->qva_showPackage(qva, ts, h);
|
2002-07-14 03:08:51 +08:00
|
|
|
h = headerFree(h);
|
2002-08-16 02:50:46 +08:00
|
|
|
rpmtsEmpty(ts);
|
2001-03-23 07:39:01 +08:00
|
|
|
continue;
|
2002-08-24 05:01:59 +08:00
|
|
|
/*@notreached@*/ /*@switchbreak@*/ break;
|
|
|
|
case RPMRC_NOTFOUND:
|
|
|
|
res = 0;
|
|
|
|
/*@switchbreak@*/ break;
|
2001-03-23 07:39:01 +08:00
|
|
|
}
|
2002-08-24 05:01:59 +08:00
|
|
|
if (res)
|
|
|
|
/*@loopbreak@*/ break;
|
2001-03-23 07:39:01 +08:00
|
|
|
|
|
|
|
/* Try to read a package manifest. */
|
|
|
|
fd = Fopen(fileURL, "r.fpio");
|
2001-04-10 20:36:45 +08:00
|
|
|
if (fd == NULL || Ferror(fd)) {
|
2001-03-23 07:39:01 +08:00
|
|
|
rpmError(RPMERR_OPEN, _("open of %s failed: %s\n"), fileURL,
|
|
|
|
Fstrerror(fd));
|
2001-05-01 06:32:22 +08:00
|
|
|
if (fd) (void) Fclose(fd);
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 1;
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@loopbreak@*/ break;
|
1996-01-06 02:12:17 +08:00
|
|
|
}
|
2001-03-23 07:39:01 +08:00
|
|
|
|
|
|
|
/* Read list of packages from manifest. */
|
2001-10-24 21:48:55 +08:00
|
|
|
res = rpmReadPackageManifest(fd, &ac, &av);
|
2002-05-14 06:34:25 +08:00
|
|
|
if (res != RPMRC_OK) {
|
2002-09-17 04:10:20 +08:00
|
|
|
rpmError(RPMERR_MANIFEST,
|
|
|
|
_("%s: not an rpm package (or package manifest): %s\n"),
|
2001-04-10 20:36:45 +08:00
|
|
|
fileURL, Fstrerror(fd));
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 1;
|
2001-03-23 07:39:01 +08:00
|
|
|
}
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(fd);
|
2001-03-23 07:39:01 +08:00
|
|
|
|
|
|
|
/* If successful, restart the query loop. */
|
2001-10-24 21:48:55 +08:00
|
|
|
if (res == 0)
|
2001-03-23 07:39:01 +08:00
|
|
|
goto restart;
|
|
|
|
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@loopbreak@*/ break;
|
1996-01-06 02:12:17 +08:00
|
|
|
}
|
2001-03-23 07:39:01 +08:00
|
|
|
|
|
|
|
fileURL = _free(fileURL);
|
2001-03-24 04:27:48 +08:00
|
|
|
if (av) {
|
|
|
|
for (i = 0; i < ac; i++)
|
|
|
|
av[i] = _free(av[i]);
|
|
|
|
av = _free(av);
|
1999-12-13 01:46:22 +08:00
|
|
|
}
|
1999-11-10 04:57:38 +08:00
|
|
|
} break;
|
1995-12-28 04:08:35 +08:00
|
|
|
|
1999-11-10 04:57:38 +08:00
|
|
|
case RPMQV_SPECFILE:
|
2001-10-24 21:48:55 +08:00
|
|
|
if (qva->qva_showPackage != showQueryPackage)
|
1999-05-11 07:41:04 +08:00
|
|
|
return 1;
|
1999-07-01 05:18:43 +08:00
|
|
|
|
|
|
|
/* XXX Eliminate linkage dependency loop */
|
|
|
|
if (parseSpecVec == NULL || freeSpecVec == NULL)
|
|
|
|
return 1;
|
|
|
|
|
1998-11-20 08:29:46 +08:00
|
|
|
{ Spec spec = NULL;
|
|
|
|
Package pkg;
|
|
|
|
char * buildRoot = NULL;
|
2001-05-07 03:17:14 +08:00
|
|
|
int recursing = 0;
|
1998-11-20 08:29:46 +08:00
|
|
|
char * passPhrase = "";
|
|
|
|
char *cookie = NULL;
|
|
|
|
int anyarch = 1;
|
|
|
|
int force = 1;
|
1999-07-01 05:18:43 +08:00
|
|
|
|
2001-11-13 06:54:39 +08:00
|
|
|
/*@-mods@*/ /* FIX: make spec abstract */
|
2001-05-07 03:17:14 +08:00
|
|
|
rc = parseSpecVec(&spec, arg, "/", buildRoot, recursing, passPhrase,
|
1999-07-01 05:18:43 +08:00
|
|
|
cookie, anyarch, force);
|
2001-10-18 00:43:36 +08:00
|
|
|
/*@=mods@*/
|
1998-11-20 08:29:46 +08:00
|
|
|
if (rc || spec == NULL) {
|
2000-12-26 21:10:18 +08:00
|
|
|
rpmError(RPMERR_QUERY,
|
|
|
|
_("query of specfile %s failed, can't parse\n"), arg);
|
2001-05-07 03:17:14 +08:00
|
|
|
spec = freeSpecVec(spec);
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 1;
|
1998-11-20 08:29:46 +08:00
|
|
|
break;
|
|
|
|
}
|
1999-02-23 01:44:57 +08:00
|
|
|
|
2000-02-24 01:34:41 +08:00
|
|
|
if (specedit) {
|
1999-02-23 01:44:57 +08:00
|
|
|
printNewSpecfile(spec);
|
2001-05-07 03:17:14 +08:00
|
|
|
spec = freeSpecVec(spec);
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 0;
|
1999-02-23 01:44:57 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-11-13 06:54:39 +08:00
|
|
|
for (pkg = spec->packages; pkg != NULL; pkg = pkg->next)
|
|
|
|
xx = qva->qva_showPackage(qva, ts, pkg->header);
|
2001-05-07 03:17:14 +08:00
|
|
|
spec = freeSpecVec(spec);
|
1998-11-20 08:29:46 +08:00
|
|
|
} break;
|
|
|
|
|
1999-11-10 04:57:38 +08:00
|
|
|
case RPMQV_ALL:
|
2001-10-28 04:09:20 +08:00
|
|
|
qva->qva_mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 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 packages\n"));
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 1;
|
2000-04-12 21:42:57 +08:00
|
|
|
} else {
|
2001-10-24 21:48:55 +08:00
|
|
|
if (arg != NULL)
|
|
|
|
for (av = (const char **) arg; *av; av++) {
|
|
|
|
if (!rpmdbSetIteratorRE(qva->qva_mi, RPMTAG_NAME, RPMMIRE_DEFAULT, *av))
|
2001-06-14 04:57:06 +08:00
|
|
|
continue;
|
2001-10-24 21:48:55 +08:00
|
|
|
qva->qva_mi = rpmdbFreeIterator(qva->qva_mi);
|
|
|
|
res = 1;
|
2001-06-14 04:57:06 +08:00
|
|
|
/*@loopbreak@*/ break;
|
|
|
|
}
|
2001-10-24 21:48:55 +08:00
|
|
|
if (!res)
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2000-04-12 21:42:57 +08:00
|
|
|
}
|
1995-12-28 04:08:35 +08:00
|
|
|
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;
|
2000-04-12 21:42:57 +08:00
|
|
|
} else {
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2000-04-12 21:42:57 +08:00
|
|
|
}
|
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;
|
2000-04-12 21:42:57 +08:00
|
|
|
} else {
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2000-04-12 21:42:57 +08:00
|
|
|
}
|
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;
|
|
|
|
} 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;
|
|
|
|
} 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;
|
|
|
|
} else {
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2002-02-05 07:29:59 +08:00
|
|
|
}
|
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;
|
|
|
|
unsigned iid;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
} 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;
|
2000-04-12 21:42:57 +08:00
|
|
|
} else {
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2000-04-12 21:42:57 +08:00
|
|
|
}
|
1996-06-10 05:47:42 +08:00
|
|
|
break;
|
|
|
|
|
1999-12-03 00:31:35 +08:00
|
|
|
case RPMQV_WHATPROVIDES:
|
|
|
|
if (arg[0] != '/') {
|
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;
|
2000-04-12 21:42:57 +08:00
|
|
|
} else {
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2000-04-12 21:42:57 +08:00
|
|
|
}
|
1999-12-03 00:31:35 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*@fallthrough@*/
|
1999-11-10 04:57:38 +08:00
|
|
|
case RPMQV_PATH:
|
2002-02-05 07:29:59 +08:00
|
|
|
{ char * fn;
|
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 == '/'))
|
|
|
|
/*@loopbreak@*/ 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);
|
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-04-12 21:42:57 +08:00
|
|
|
int myerrno = 0;
|
2000-07-10 07:10:25 +08:00
|
|
|
if (access(fn, F_OK) != 0)
|
2000-04-12 21:42:57 +08:00
|
|
|
myerrno = errno;
|
|
|
|
switch (myerrno) {
|
|
|
|
default:
|
2000-12-26 21:10:18 +08:00
|
|
|
rpmError(RPMERR_QUERY,
|
|
|
|
_("file %s: %s\n"), fn, strerror(myerrno));
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@innerbreak@*/ break;
|
2000-04-12 21:42:57 +08:00
|
|
|
case 0:
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_QUERYINFO,
|
2000-12-26 21:10:18 +08:00
|
|
|
_("file %s is not owned by any package\n"), fn);
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@innerbreak@*/ break;
|
2000-04-12 21:42:57 +08:00
|
|
|
}
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 1;
|
2000-04-12 21:42:57 +08:00
|
|
|
} else {
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2000-04-12 21:42:57 +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;
|
2001-04-29 09:05:43 +08:00
|
|
|
unsigned 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;
|
2000-04-12 21:42:57 +08:00
|
|
|
} else {
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2000-04-12 21:42:57 +08:00
|
|
|
}
|
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:
|
2000-04-27 08:10:28 +08:00
|
|
|
/* XXX HACK to get rpmdbFindByLabel out of the API */
|
2001-10-28 04:09:20 +08:00
|
|
|
qva->qva_mi = rpmtsInitIterator(ts, RPMDBI_LABEL, 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, _("package %s is not installed\n"), arg);
|
2001-10-24 21:48:55 +08:00
|
|
|
res = 1;
|
2000-04-27 08:10:28 +08:00
|
|
|
} else {
|
2002-08-09 00:06:13 +08:00
|
|
|
res = rpmcliShowMatches(qva, ts);
|
2000-04-27 08:10:28 +08:00
|
|
|
}
|
1995-12-28 04:08:35 +08:00
|
|
|
break;
|
1999-12-13 01:46:22 +08:00
|
|
|
}
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@=branchstate@*/
|
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
|
|
|
}
|
2002-06-23 02:51:56 +08:00
|
|
|
/*@=bounds@*/
|
1999-05-11 07:41:04 +08:00
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
int rpmcliQuery(rpmts ts, QVA_t qva, const char ** argv)
|
1999-05-11 07:41:04 +08:00
|
|
|
{
|
2001-10-26 12:16:19 +08:00
|
|
|
const char * arg;
|
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;
|
|
|
|
|
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);
|
2001-10-24 21:48:55 +08:00
|
|
|
if (qva->qva_source == RPMQV_ALL) {
|
|
|
|
/*@-nullpass@*/ /* FIX: argv can be NULL, cast to pass argv array */
|
|
|
|
ec = rpmQueryVerify(qva, ts, (const char *) argv);
|
|
|
|
/*@=nullpass@*/
|
|
|
|
} else {
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@-boundsread@*/
|
2001-10-24 21:48:55 +08:00
|
|
|
if (argv != NULL)
|
|
|
|
while ((arg = *argv++) != NULL) {
|
|
|
|
ec += rpmQueryVerify(qva, ts, arg);
|
2002-08-16 02:50:46 +08:00
|
|
|
rpmtsEmpty(ts);
|
2001-10-24 21:48:55 +08:00
|
|
|
}
|
2002-07-03 22:01:49 +08:00
|
|
|
/*@=boundsread@*/
|
2001-10-24 21:48:55 +08:00
|
|
|
}
|
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
|
|
|
}
|