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>
|
2000-12-13 04:03:45 +08:00
|
|
|
#include <rpmbuild.h>
|
2001-03-23 07:39:01 +08:00
|
|
|
#include "manifest.h"
|
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 rpmdb@*/ /* 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,
|
|
|
|
int uid, int gid, const char * linkto)
|
|
|
|
{
|
|
|
|
char sizefield[15];
|
|
|
|
char ownerfield[9], groupfield[9];
|
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
|
|
|
|
1999-07-18 03:00:45 +08:00
|
|
|
if (owner)
|
|
|
|
strncpy(ownerfield, owner, 8);
|
|
|
|
else
|
|
|
|
sprintf(ownerfield, "%-8d", uid);
|
|
|
|
ownerfield[8] = '\0';
|
|
|
|
|
|
|
|
if (group)
|
|
|
|
strncpy(groupfield, group, 8);
|
|
|
|
else
|
|
|
|
sprintf(groupfield, "%-8d", gid);
|
|
|
|
groupfield[8] = '\0';
|
|
|
|
|
|
|
|
/* 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)
|
1999-07-18 03:00:45 +08:00
|
|
|
{
|
2000-02-24 01:34:41 +08:00
|
|
|
const char * errstr;
|
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
|
|
|
}
|
|
|
|
|
2001-03-15 07:09:09 +08:00
|
|
|
/**
|
|
|
|
*/
|
2000-05-17 02:32:49 +08:00
|
|
|
static int countLinks(int_16 * fileRdevList, int_32 * fileInodeList, int nfiles,
|
|
|
|
int xfile)
|
|
|
|
{
|
|
|
|
int nlink = 0;
|
|
|
|
|
2000-06-05 22:18:40 +08:00
|
|
|
/* XXX rpm-3.3.12 has not RPMTAG_FILEINODES */
|
|
|
|
if (!(fileRdevList && fileInodeList && nfiles > 0))
|
|
|
|
return 1;
|
2000-05-17 02:32:49 +08:00
|
|
|
while (nfiles-- > 0) {
|
|
|
|
if (fileRdevList[nfiles] != fileRdevList[xfile])
|
|
|
|
continue;
|
|
|
|
if (fileInodeList[nfiles] != fileInodeList[xfile])
|
|
|
|
continue;
|
|
|
|
nlink++;
|
|
|
|
}
|
|
|
|
return nlink;
|
|
|
|
}
|
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
int showQueryPackage(QVA_t qva, /*@unused@*/rpmdb rpmdb, Header h)
|
1999-05-11 07:41:04 +08:00
|
|
|
{
|
2001-05-01 06:32:22 +08:00
|
|
|
HGE_t hge = (HGE_t)headerGetEntryMinMemory;
|
|
|
|
HFD_t hfd = headerFreeData;
|
2000-12-26 21:10:18 +08:00
|
|
|
char * t, * te;
|
2001-06-09 04:45:59 +08:00
|
|
|
rpmQueryFlags queryFlags = qva->qva_flags;
|
|
|
|
const char * queryFormat = qva->qva_queryFormat;
|
2001-06-12 12:10:21 +08:00
|
|
|
rpmTagType type;
|
|
|
|
int_32 count;
|
1995-12-28 04:08:35 +08:00
|
|
|
char * prefix = NULL;
|
2000-12-26 21:10:18 +08:00
|
|
|
const char ** dirNames = NULL;
|
|
|
|
const char ** baseNames = NULL;
|
2001-06-12 12:10:21 +08:00
|
|
|
rpmTagType bnt, dnt;
|
2000-12-26 21:10:18 +08:00
|
|
|
const char ** fileMD5List = NULL;
|
1999-09-18 04:40:41 +08:00
|
|
|
const char ** fileOwnerList = NULL;
|
|
|
|
const char ** fileGroupList = NULL;
|
2000-12-26 21:10:18 +08:00
|
|
|
const char ** fileLinktoList = NULL;
|
2001-06-12 12:10:21 +08:00
|
|
|
rpmTagType m5t, fot, fgt, ltt;
|
2000-12-26 21:10:18 +08:00
|
|
|
const char * fileStatesList;
|
1996-02-19 12:50:33 +08:00
|
|
|
int_32 * fileFlagsList, * fileMTimeList, * fileSizeList;
|
1999-09-18 04:40:41 +08:00
|
|
|
int_32 * fileUIDList = NULL;
|
|
|
|
int_32 * fileGIDList = NULL;
|
2000-05-17 02:32:49 +08:00
|
|
|
int_32 * fileInodeList = NULL;
|
1996-06-21 06:28:02 +08:00
|
|
|
uint_16 * fileModeList;
|
|
|
|
uint_16 * fileRdevList;
|
1999-11-27 05:58:42 +08:00
|
|
|
int_32 * dirIndexes;
|
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);
|
2000-12-26 21:10:18 +08:00
|
|
|
*te = '\0';
|
1995-12-28 04:08:35 +08:00
|
|
|
|
2001-06-09 04:45:59 +08:00
|
|
|
if (queryFormat == NULL && queryFlags == QUERY_FOR_DEFAULT) {
|
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);
|
2000-12-26 21:10:18 +08:00
|
|
|
te = stpcpy(te, name);
|
|
|
|
te = stpcpy( stpcpy(te, "-"), version);
|
|
|
|
te = stpcpy( stpcpy(te, "-"), release);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2000-12-28 05:19:53 +08:00
|
|
|
if (queryFormat) {
|
|
|
|
const char * str = queryHeader(h, queryFormat);
|
|
|
|
nonewline = 1;
|
|
|
|
if (str) {
|
|
|
|
size_t tb = (te - t);
|
|
|
|
size_t sb = strlen(str);
|
|
|
|
|
|
|
|
if (sb >= (BUFSIZ - tb)) {
|
|
|
|
t = xrealloc(t, BUFSIZ+sb);
|
|
|
|
te = t + tb;
|
|
|
|
}
|
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@*/
|
2001-02-13 03:02:15 +08:00
|
|
|
str = _free(str);
|
2000-12-28 05:19:53 +08:00
|
|
|
}
|
|
|
|
}
|
2000-12-26 21:10:18 +08:00
|
|
|
|
|
|
|
if (!(queryFlags & QUERY_FOR_LIST))
|
|
|
|
goto exit;
|
1995-12-28 04:08:35 +08:00
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
if (!hge(h, RPMTAG_BASENAMES, &bnt, (void **) &baseNames, &count)) {
|
2000-12-26 21:10:18 +08:00
|
|
|
te = stpcpy(te, _("(contains no files)"));
|
|
|
|
goto exit;
|
|
|
|
}
|
2001-06-09 04:45:59 +08:00
|
|
|
if (!hge(h, RPMTAG_FILESTATES, &type, (void **) &fileStatesList, NULL))
|
2000-12-26 21:10:18 +08:00
|
|
|
fileStatesList = NULL;
|
2001-06-04 21:55:58 +08:00
|
|
|
if (!hge(h, RPMTAG_DIRNAMES, &dnt, (void **) &dirNames, NULL))
|
|
|
|
dirNames = NULL;
|
|
|
|
if (!hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &dirIndexes, NULL))
|
|
|
|
dirIndexes = NULL;
|
2001-06-09 04:45:59 +08:00
|
|
|
if (!hge(h, RPMTAG_FILEFLAGS, &type, (void **) &fileFlagsList, NULL))
|
2001-06-04 21:55:58 +08:00
|
|
|
fileFlagsList = NULL;
|
2001-06-09 04:45:59 +08:00
|
|
|
if (!hge(h, RPMTAG_FILESIZES, &type, (void **) &fileSizeList, NULL))
|
2001-06-04 21:55:58 +08:00
|
|
|
fileSizeList = NULL;
|
2001-06-09 04:45:59 +08:00
|
|
|
if (!hge(h, RPMTAG_FILEMODES, &type, (void **) &fileModeList, NULL))
|
2001-06-04 21:55:58 +08:00
|
|
|
fileModeList = NULL;
|
2001-06-09 04:45:59 +08:00
|
|
|
if (!hge(h, RPMTAG_FILEMTIMES, &type, (void **) &fileMTimeList, NULL))
|
2001-06-04 21:55:58 +08:00
|
|
|
fileMTimeList = NULL;
|
2001-06-09 04:45:59 +08:00
|
|
|
if (!hge(h, RPMTAG_FILERDEVS, &type, (void **) &fileRdevList, NULL))
|
2001-06-04 21:55:58 +08:00
|
|
|
fileRdevList = NULL;
|
2001-06-09 04:45:59 +08:00
|
|
|
if (!hge(h, RPMTAG_FILEINODES, &type, (void **) &fileInodeList, NULL))
|
2001-06-04 21:55:58 +08:00
|
|
|
fileInodeList = NULL;
|
|
|
|
if (!hge(h, RPMTAG_FILELINKTOS, <t, (void **) &fileLinktoList, NULL))
|
|
|
|
fileLinktoList = NULL;
|
|
|
|
if (!hge(h, RPMTAG_FILEMD5S, &m5t, (void **) &fileMD5List, NULL))
|
|
|
|
fileMD5List = NULL;
|
2001-06-09 04:45:59 +08:00
|
|
|
if (!hge(h, RPMTAG_FILEUIDS, &type, (void **) &fileUIDList, NULL))
|
2000-12-26 21:10:18 +08:00
|
|
|
fileUIDList = NULL;
|
2001-06-09 04:45:59 +08:00
|
|
|
if (!hge(h, RPMTAG_FILEGIDS, &type, (void **) &fileGIDList, NULL))
|
2000-12-26 21:10:18 +08:00
|
|
|
fileGIDList = NULL;
|
2001-06-04 21:55:58 +08:00
|
|
|
if (!hge(h, RPMTAG_FILEUSERNAME, &fot, (void **) &fileOwnerList, NULL))
|
2000-12-26 21:10:18 +08:00
|
|
|
fileOwnerList = NULL;
|
2001-06-04 21:55:58 +08:00
|
|
|
if (!hge(h, RPMTAG_FILEGROUPNAME, &fgt, (void **) &fileGroupList, NULL))
|
2000-12-26 21:10:18 +08:00
|
|
|
fileGroupList = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2001-06-12 12:10:21 +08:00
|
|
|
|
2000-12-26 21:10:18 +08:00
|
|
|
/* If querying only docs, skip non-doc files. */
|
|
|
|
if ((queryFlags & QUERY_FOR_DOCS)
|
|
|
|
&& !(fileFlagsList[i] & RPMFILE_DOC))
|
|
|
|
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. */
|
|
|
|
if ((queryFlags & QUERY_FOR_CONFIG)
|
|
|
|
&& !(fileFlagsList[i] & RPMFILE_CONFIG))
|
|
|
|
continue;
|
|
|
|
|
2001-06-21 05:20:16 +08:00
|
|
|
/* If not querying %ghost, skip ghost files. */
|
|
|
|
if (!(qva->qva_fflags & RPMFILE_GHOST)
|
|
|
|
&& (fileFlagsList[i] & RPMFILE_GHOST))
|
|
|
|
continue;
|
|
|
|
|
2000-12-26 21:10:18 +08:00
|
|
|
if (!rpmIsVerbose() && prefix)
|
|
|
|
te = stpcpy(te, prefix);
|
|
|
|
|
|
|
|
if (queryFlags & QUERY_FOR_STATE) {
|
|
|
|
if (fileStatesList) {
|
2001-06-12 12:10:21 +08:00
|
|
|
rpmfileState fstate = fileStatesList[i];
|
|
|
|
switch (fstate) {
|
2000-12-26 21:10:18 +08:00
|
|
|
case RPMFILE_STATE_NORMAL:
|
|
|
|
te = stpcpy(te, _("normal ")); break;
|
|
|
|
case RPMFILE_STATE_REPLACED:
|
|
|
|
te = stpcpy(te, _("replaced ")); break;
|
|
|
|
case RPMFILE_STATE_NOTINSTALLED:
|
|
|
|
te = stpcpy(te, _("not installed ")); break;
|
|
|
|
case RPMFILE_STATE_NETSHARED:
|
|
|
|
te = stpcpy(te, _("net shared ")); break;
|
|
|
|
default:
|
|
|
|
sprintf(te, _("(unknown %3d) "), (int)fileStatesList[i]);
|
|
|
|
te += strlen(te);
|
|
|
|
break;
|
1997-02-18 04:18:54 +08:00
|
|
|
}
|
2000-12-26 21:10:18 +08:00
|
|
|
} else {
|
|
|
|
te = stpcpy(te, _("(no state) "));
|
|
|
|
}
|
|
|
|
}
|
1997-02-18 04:18:54 +08:00
|
|
|
|
2000-12-26 21:10:18 +08:00
|
|
|
if (queryFlags & QUERY_FOR_DUMPFILES) {
|
|
|
|
sprintf(te, "%s%s %d %d %s 0%o ",
|
1999-11-27 05:58:42 +08:00
|
|
|
dirNames[dirIndexes[i]], baseNames[i],
|
1996-06-21 06:28:02 +08:00
|
|
|
fileSizeList[i], fileMTimeList[i],
|
2001-06-04 21:55:58 +08:00
|
|
|
fileMD5List[i], (unsigned) fileModeList[i]);
|
2000-12-26 21:10:18 +08:00
|
|
|
te += strlen(te);
|
|
|
|
|
|
|
|
if (fileOwnerList && fileGroupList) {
|
|
|
|
sprintf(te, "%s %s", fileOwnerList[i], fileGroupList[i]);
|
|
|
|
te += strlen(te);
|
|
|
|
} else if (fileUIDList && fileGIDList) {
|
|
|
|
sprintf(te, "%d %d", fileUIDList[i], fileGIDList[i]);
|
|
|
|
te += strlen(te);
|
|
|
|
} else {
|
|
|
|
rpmError(RPMERR_INTERNAL,
|
2001-01-16 07:09:42 +08:00
|
|
|
_("package has neither file owner or id 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 ",
|
1996-06-21 06:28:02 +08:00
|
|
|
fileFlagsList[i] & RPMFILE_CONFIG ? "1" : "0",
|
|
|
|
fileFlagsList[i] & RPMFILE_DOC ? "1" : "0",
|
2001-06-04 21:55:58 +08:00
|
|
|
(unsigned) fileRdevList[i]);
|
2000-12-26 21:10:18 +08:00
|
|
|
te += strlen(te);
|
|
|
|
|
|
|
|
if (strlen(fileLinktoList[i]))
|
|
|
|
sprintf(te, "%s", fileLinktoList[i]);
|
|
|
|
else
|
|
|
|
sprintf(te, "X");
|
|
|
|
te += strlen(te);
|
|
|
|
} else if (!rpmIsVerbose()) {
|
|
|
|
te = stpcpy(te, dirNames[dirIndexes[i]]);
|
|
|
|
te = stpcpy(te, baseNames[i]);
|
|
|
|
} else {
|
|
|
|
char * filespec;
|
|
|
|
int nlink;
|
2001-06-21 05:20:16 +08:00
|
|
|
size_t fileSize;
|
1996-06-21 06:28:02 +08:00
|
|
|
|
2000-12-26 21:10:18 +08:00
|
|
|
filespec = xmalloc(strlen(dirNames[dirIndexes[i]])
|
1999-11-27 05:58:42 +08:00
|
|
|
+ strlen(baseNames[i]) + 1);
|
2000-12-26 21:10:18 +08:00
|
|
|
strcpy(filespec, dirNames[dirIndexes[i]]);
|
|
|
|
strcat(filespec, baseNames[i]);
|
1999-10-06 23:51:14 +08:00
|
|
|
|
2001-06-21 05:20:16 +08:00
|
|
|
fileSize = fileSizeList[i];
|
2000-12-26 21:10:18 +08:00
|
|
|
nlink = countLinks(fileRdevList, fileInodeList, count, i);
|
2001-06-21 05:20:16 +08:00
|
|
|
|
|
|
|
if (S_ISDIR(fileModeList[i])) {
|
|
|
|
nlink++;
|
|
|
|
fileSize = 0;
|
|
|
|
}
|
2000-12-26 21:10:18 +08:00
|
|
|
if (fileOwnerList && fileGroupList) {
|
2001-06-21 05:20:16 +08:00
|
|
|
printFileInfo(te, filespec, fileSize,
|
1999-10-06 23:51:14 +08:00
|
|
|
fileModeList[i], fileMTimeList[i],
|
2000-05-17 02:32:49 +08:00
|
|
|
fileRdevList[i], nlink,
|
1999-10-06 23:51:14 +08:00
|
|
|
fileOwnerList[i],
|
|
|
|
fileGroupList[i], -1,
|
|
|
|
-1, fileLinktoList[i]);
|
2000-12-26 21:10:18 +08:00
|
|
|
te += strlen(te);
|
|
|
|
} else if (fileUIDList && fileGIDList) {
|
2001-06-21 05:20:16 +08:00
|
|
|
printFileInfo(te, filespec, fileSize,
|
1999-10-06 23:51:14 +08:00
|
|
|
fileModeList[i], fileMTimeList[i],
|
2000-05-17 02:32:49 +08:00
|
|
|
fileRdevList[i], nlink,
|
|
|
|
NULL, NULL, fileUIDList[i],
|
1999-10-06 23:51:14 +08:00
|
|
|
fileGIDList[i],
|
|
|
|
fileLinktoList[i]);
|
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
|
|
|
|
2001-03-23 07:39:01 +08:00
|
|
|
filespec = _free(filespec);
|
2000-12-26 21:10:18 +08:00
|
|
|
}
|
|
|
|
if (te > t) {
|
|
|
|
*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';
|
1995-12-28 04:08:35 +08:00
|
|
|
}
|
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) {
|
|
|
|
*te++ = '\n';
|
|
|
|
*te = '\0';
|
|
|
|
}
|
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);
|
2001-05-01 06:32:22 +08:00
|
|
|
dirNames = hfd(dirNames, dnt);
|
|
|
|
baseNames = hfd(baseNames, bnt);
|
2001-06-04 21:55:58 +08:00
|
|
|
fileLinktoList = hfd(fileLinktoList, ltt);
|
|
|
|
fileMD5List = hfd(fileMD5List, m5t);
|
|
|
|
fileOwnerList = hfd(fileOwnerList, fot);
|
|
|
|
fileGroupList = hfd(fileGroupList, fgt);
|
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
|
|
|
/**
|
|
|
|
*/
|
1999-02-23 01:44:57 +08:00
|
|
|
static void
|
|
|
|
printNewSpecfile(Spec spec)
|
|
|
|
{
|
2000-02-24 01:34:41 +08:00
|
|
|
Header h = spec->packages->header;
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
char fmt[128];
|
|
|
|
|
|
|
|
fmt[0] = '\0';
|
|
|
|
(void) stpcpy( stpcpy( stpcpy( fmt, "%{"), tn), "}\n");
|
2001-02-13 03:02:15 +08:00
|
|
|
msgstr = _free(msgstr);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
1999-02-23 01:44:57 +08:00
|
|
|
break;
|
|
|
|
case RPMTAG_DESCRIPTION:
|
1999-09-18 04:40:41 +08:00
|
|
|
for (j = 1; j < t->t_nlines; j++) {
|
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");
|
1999-02-23 01:44:57 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-02-13 03:02:15 +08:00
|
|
|
msgstr = _free(msgstr);
|
1999-02-23 01:44:57 +08:00
|
|
|
|
|
|
|
for (i = 0; i < sl->sl_nlines; i++) {
|
|
|
|
if (sl->sl_lines[i] == NULL)
|
|
|
|
continue;
|
|
|
|
printf("%s", sl->sl_lines[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-06 03:26:22 +08:00
|
|
|
void rpmDisplayQueryTags(FILE * fp)
|
2000-02-14 03:23:55 +08:00
|
|
|
{
|
1999-05-11 07:41:04 +08:00
|
|
|
const struct headerTagTableEntry * t;
|
|
|
|
int i;
|
|
|
|
const struct headerSprintfExtension * ext = rpmHeaderFormats;
|
|
|
|
|
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. */
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
int showMatches(QVA_t qva, rpmdbMatchIterator mi, QVF_t showPackage)
|
2000-04-12 21:42:57 +08:00
|
|
|
{
|
|
|
|
Header h;
|
|
|
|
int ec = 0;
|
|
|
|
|
|
|
|
while ((h = rpmdbNextIterator(mi)) != NULL) {
|
|
|
|
int rc;
|
2001-05-11 12:01:04 +08:00
|
|
|
/*@-nullpass@*/
|
2000-05-17 01:10:13 +08:00
|
|
|
if ((rc = showPackage(qva, rpmdbGetIteratorRpmDB(mi), h)) != 0)
|
2000-04-12 21:42:57 +08:00
|
|
|
ec = rc;
|
2001-05-11 12:01:04 +08:00
|
|
|
/*@=nullpass@*/
|
2000-04-12 21:42:57 +08:00
|
|
|
}
|
2001-04-30 06:43:01 +08:00
|
|
|
mi = rpmdbFreeIterator(mi);
|
2000-04-12 21:42:57 +08:00
|
|
|
return ec;
|
|
|
|
}
|
1999-05-11 07:41:04 +08:00
|
|
|
|
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
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
int rpmQueryVerify(QVA_t qva, rpmQVSources source, const char * arg,
|
2000-05-07 08:53:11 +08:00
|
|
|
rpmdb rpmdb, QVF_t showPackage)
|
1999-05-11 07:41:04 +08:00
|
|
|
{
|
2000-04-12 21:42:57 +08:00
|
|
|
rpmdbMatchIterator mi = NULL;
|
1995-12-28 04:08:35 +08:00
|
|
|
Header h;
|
1996-01-06 02:12:17 +08:00
|
|
|
int rc;
|
|
|
|
int isSource;
|
1996-04-03 11:45:27 +08:00
|
|
|
int retcode = 0;
|
2001-06-14 04:57:06 +08:00
|
|
|
const char ** av = NULL;
|
2001-06-12 12:10:21 +08:00
|
|
|
char * end = NULL;
|
1995-12-28 04:08:35 +08:00
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
switch (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;
|
1999-12-13 01:46:22 +08:00
|
|
|
int i;
|
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);
|
1999-12-13 01:46:22 +08:00
|
|
|
retcode = 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-06-06 03:26:22 +08:00
|
|
|
/*@-mustmod@*/ /* LCL: segfault. */
|
2001-02-13 03:02:15 +08:00
|
|
|
rpmrc = rpmReadPackageHeader(fd, &h, &isSource, NULL, NULL);
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@=mustmod@*/
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(fd);
|
1996-10-15 11:14:50 +08:00
|
|
|
|
2001-03-23 07:39:01 +08:00
|
|
|
if (!(rpmrc == RPMRC_OK || rpmrc == RPMRC_BADMAGIC)) {
|
|
|
|
rpmError(RPMERR_QUERY, _("query of %s failed\n"), fileURL);
|
|
|
|
retcode = 1;
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@loopbreak@*/ break;
|
2001-03-23 07:39:01 +08:00
|
|
|
}
|
|
|
|
if (rpmrc == RPMRC_OK && h == NULL) {
|
|
|
|
rpmError(RPMERR_QUERY,
|
2000-12-26 21:10:18 +08:00
|
|
|
_("old format source packages cannot be queried\n"));
|
2001-03-23 07:39:01 +08:00
|
|
|
retcode = 1;
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@loopbreak@*/ break;
|
2001-03-23 07:39:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Query a package file. */
|
|
|
|
if (rpmrc == RPMRC_OK) {
|
2000-05-07 08:53:11 +08:00
|
|
|
retcode = showPackage(qva, rpmdb, h);
|
2001-05-23 22:25:19 +08:00
|
|
|
h = headerFree(h);
|
2001-03-23 07:39:01 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
1999-05-11 07:41:04 +08:00
|
|
|
retcode = 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-03-24 04:27:48 +08:00
|
|
|
retcode = rpmReadPackageManifest(fd, &ac, &av);
|
2001-03-23 07:39:01 +08:00
|
|
|
if (retcode) {
|
2001-04-10 20:36:45 +08:00
|
|
|
rpmError(RPMERR_MANIFEST, _("%s: read manifest failed: %s\n"),
|
|
|
|
fileURL, Fstrerror(fd));
|
2001-03-23 07:39:01 +08:00
|
|
|
retcode = 1;
|
|
|
|
}
|
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. */
|
|
|
|
if (retcode == 0)
|
|
|
|
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:
|
1999-05-11 07:41:04 +08:00
|
|
|
if (showPackage != showQueryPackage)
|
|
|
|
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-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);
|
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);
|
1998-11-20 08:29:46 +08:00
|
|
|
retcode = 1;
|
|
|
|
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);
|
1999-02-23 01:44:57 +08:00
|
|
|
retcode = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-05-07 03:17:14 +08:00
|
|
|
for (pkg = spec->packages; pkg != NULL; pkg = pkg->next)
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) showPackage(qva, NULL, 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:
|
2000-04-20 06:15:02 +08:00
|
|
|
/* RPMDBI_PACKAGES */
|
2000-05-07 08:53:11 +08:00
|
|
|
mi = rpmdbInitIterator(rpmdb, RPMDBI_PACKAGES, NULL, 0);
|
2000-04-12 21:42:57 +08:00
|
|
|
if (mi == NULL) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_QUERYINFO, _("no packages\n"));
|
2000-04-12 21:42:57 +08:00
|
|
|
retcode = 1;
|
|
|
|
} else {
|
2001-06-14 04:57:06 +08:00
|
|
|
for (av = (const char **) arg; av && *av; av++) {
|
2001-06-15 12:56:33 +08:00
|
|
|
if (!rpmdbSetIteratorRE(mi, RPMTAG_NAME, RPMMIRE_DEFAULT, *av))
|
2001-06-14 04:57:06 +08:00
|
|
|
continue;
|
|
|
|
mi = rpmdbFreeIterator(mi);
|
|
|
|
retcode = 1;
|
|
|
|
/*@loopbreak@*/ break;
|
|
|
|
}
|
|
|
|
if (!retcode)
|
|
|
|
retcode = showMatches(qva, mi, showPackage);
|
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:
|
2000-05-07 08:53:11 +08:00
|
|
|
mi = rpmdbInitIterator(rpmdb, RPMTAG_GROUP, arg, 0);
|
2000-04-12 21:42:57 +08:00
|
|
|
if (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);
|
2000-04-12 21:42:57 +08:00
|
|
|
retcode = 1;
|
|
|
|
} else {
|
2000-04-27 08:10:28 +08:00
|
|
|
retcode = showMatches(qva, mi, showPackage);
|
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:
|
2000-05-07 08:53:11 +08:00
|
|
|
mi = rpmdbInitIterator(rpmdb, RPMTAG_TRIGGERNAME, arg, 0);
|
2000-04-12 21:42:57 +08:00
|
|
|
if (mi == NULL) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_QUERYINFO, _("no package triggers %s\n"), arg);
|
2000-04-12 21:42:57 +08:00
|
|
|
retcode = 1;
|
|
|
|
} else {
|
2000-04-27 08:10:28 +08:00
|
|
|
retcode = showMatches(qva, mi, showPackage);
|
2000-04-12 21:42:57 +08:00
|
|
|
}
|
1998-03-28 00:46:39 +08:00
|
|
|
break;
|
|
|
|
|
1999-11-10 04:57:38 +08:00
|
|
|
case RPMQV_WHATREQUIRES:
|
2000-05-07 08:53:11 +08:00
|
|
|
mi = rpmdbInitIterator(rpmdb, RPMTAG_REQUIRENAME, arg, 0);
|
2000-04-12 21:42:57 +08:00
|
|
|
if (mi == NULL) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_QUERYINFO, _("no package requires %s\n"), arg);
|
2000-04-12 21:42:57 +08:00
|
|
|
retcode = 1;
|
|
|
|
} else {
|
2000-04-27 08:10:28 +08:00
|
|
|
retcode = showMatches(qva, mi, showPackage);
|
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] != '/') {
|
2000-05-07 08:53:11 +08:00
|
|
|
mi = rpmdbInitIterator(rpmdb, RPMTAG_PROVIDENAME, arg, 0);
|
2000-04-12 21:42:57 +08:00
|
|
|
if (mi == NULL) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_QUERYINFO, _("no package provides %s\n"), arg);
|
2000-04-12 21:42:57 +08:00
|
|
|
retcode = 1;
|
|
|
|
} else {
|
2000-04-27 08:10:28 +08:00
|
|
|
retcode = showMatches(qva, mi, showPackage);
|
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:
|
2000-07-10 07:10:25 +08:00
|
|
|
{ const char * s;
|
|
|
|
char * fn;
|
|
|
|
|
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];
|
|
|
|
fn = /*@-unrecog@*/ realpath(arg, fnbuf) /*@=unrecog@*/;
|
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
|
|
|
|
|
|
|
mi = rpmdbInitIterator(rpmdb, RPMTAG_BASENAMES, fn, 0);
|
2000-04-12 21:42:57 +08:00
|
|
|
if (mi == NULL) {
|
|
|
|
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));
|
2000-04-12 21:42:57 +08:00
|
|
|
break;
|
|
|
|
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);
|
2000-04-12 21:42:57 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
retcode = 1;
|
|
|
|
} else {
|
2000-04-27 08:10:28 +08:00
|
|
|
retcode = showMatches(qva, mi, showPackage);
|
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-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)) {
|
2000-12-26 21:10:18 +08:00
|
|
|
rpmError(RPMERR_QUERY, _("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 */
|
2000-05-07 08:53:11 +08:00
|
|
|
mi = rpmdbInitIterator(rpmdb, RPMDBI_PACKAGES, &recOffset, sizeof(recOffset));
|
2000-04-12 21:42:57 +08:00
|
|
|
if (mi == NULL) {
|
2000-12-26 21:10:18 +08:00
|
|
|
rpmError(RPMERR_QUERY,
|
2001-04-29 09:05:43 +08:00
|
|
|
_("record %u could not be read\n"), recOffset);
|
2000-04-12 21:42:57 +08:00
|
|
|
retcode = 1;
|
|
|
|
} else {
|
2000-04-27 08:10:28 +08:00
|
|
|
retcode = showMatches(qva, mi, showPackage);
|
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 */
|
2000-05-07 08:53:11 +08:00
|
|
|
mi = rpmdbInitIterator(rpmdb, RPMDBI_LABEL, arg, 0);
|
2000-04-27 08:10:28 +08:00
|
|
|
if (mi == NULL) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_QUERYINFO, _("package %s is not installed\n"), arg);
|
2000-04-27 08:10:28 +08:00
|
|
|
retcode = 1;
|
|
|
|
} else {
|
|
|
|
retcode = showMatches(qva, mi, showPackage);
|
|
|
|
}
|
1995-12-28 04:08:35 +08:00
|
|
|
break;
|
1999-12-13 01:46:22 +08:00
|
|
|
}
|
1995-12-28 04:08:35 +08:00
|
|
|
|
1999-05-11 07:41:04 +08:00
|
|
|
return retcode;
|
|
|
|
}
|
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
int rpmQuery(QVA_t qva, rpmQVSources source, const char * arg)
|
1999-05-11 07:41:04 +08:00
|
|
|
{
|
2000-05-07 08:53:11 +08:00
|
|
|
rpmdb rpmdb = NULL;
|
1999-05-11 07:41:04 +08:00
|
|
|
int rc;
|
|
|
|
|
1998-11-20 08:29:46 +08:00
|
|
|
switch (source) {
|
1999-05-08 02:33:35 +08:00
|
|
|
case RPMQV_RPM:
|
|
|
|
case RPMQV_SPECFILE:
|
1998-11-20 08:29:46 +08:00
|
|
|
break;
|
1999-05-11 07:41:04 +08:00
|
|
|
default:
|
2000-05-07 08:53:11 +08:00
|
|
|
if (rpmdbOpen(qva->qva_prefix, &rpmdb, O_RDONLY, 0644))
|
1999-05-11 07:41:04 +08:00
|
|
|
return 1;
|
|
|
|
break;
|
1996-01-09 03:44:29 +08:00
|
|
|
}
|
1996-04-03 11:45:27 +08:00
|
|
|
|
2000-05-07 08:53:11 +08:00
|
|
|
rc = rpmQueryVerify(qva, source, arg, rpmdb, showQueryPackage);
|
1996-02-15 04:56:22 +08:00
|
|
|
|
2001-04-29 09:05:43 +08:00
|
|
|
if (rpmdb != NULL)
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) rpmdbClose(rpmdb);
|
1998-08-16 22:06:19 +08:00
|
|
|
|
1999-05-11 07:41:04 +08:00
|
|
|
return rc;
|
1996-04-03 11:45:27 +08:00
|
|
|
}
|