2000-08-28 03:27:03 +08:00
|
|
|
/** \ingroup rpmcli
|
|
|
|
* \file lib/query.c
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
#include <rpmbuild.h>
|
1999-07-14 05:37:57 +08:00
|
|
|
#include <rpmurl.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 Header@*/ /* XXX compared with NULL */
|
|
|
|
/*@access rpmdbMatchIterator@*/ /* XXX compared with NULL */
|
|
|
|
|
1999-07-18 03:00:45 +08:00
|
|
|
/* ======================================================================== */
|
|
|
|
static char * permsString(int mode)
|
|
|
|
{
|
1999-09-21 11:22:53 +08:00
|
|
|
char *perms = xstrdup("----------");
|
1999-07-18 03:00:45 +08:00
|
|
|
|
|
|
|
if (S_ISDIR(mode))
|
|
|
|
perms[0] = 'd';
|
|
|
|
else if (S_ISLNK(mode))
|
|
|
|
perms[0] = 'l';
|
|
|
|
else if (S_ISFIFO(mode))
|
|
|
|
perms[0] = 'p';
|
|
|
|
else if (S_ISSOCK(mode))
|
|
|
|
perms[0] = 's';
|
|
|
|
else if (S_ISCHR(mode))
|
|
|
|
perms[0] = 'c';
|
|
|
|
else if (S_ISBLK(mode))
|
|
|
|
perms[0] = 'b';
|
1996-01-06 02:12:17 +08:00
|
|
|
|
2000-10-29 01:16:25 +08:00
|
|
|
/*@-unrecog@*/
|
1999-07-18 03:00:45 +08:00
|
|
|
if (mode & S_IRUSR) perms[1] = 'r';
|
|
|
|
if (mode & S_IWUSR) perms[2] = 'w';
|
|
|
|
if (mode & S_IXUSR) perms[3] = 'x';
|
|
|
|
|
|
|
|
if (mode & S_IRGRP) perms[4] = 'r';
|
|
|
|
if (mode & S_IWGRP) perms[5] = 'w';
|
|
|
|
if (mode & S_IXGRP) perms[6] = 'x';
|
1998-10-27 13:41:02 +08:00
|
|
|
|
1999-07-18 03:00:45 +08:00
|
|
|
if (mode & S_IROTH) perms[7] = 'r';
|
|
|
|
if (mode & S_IWOTH) perms[8] = 'w';
|
|
|
|
if (mode & S_IXOTH) perms[9] = 'x';
|
1999-05-08 02:33:35 +08:00
|
|
|
|
1999-07-18 03:00:45 +08:00
|
|
|
if (mode & S_ISUID)
|
|
|
|
perms[3] = ((mode & S_IXUSR) ? 's' : 'S');
|
1999-05-08 02:33:35 +08:00
|
|
|
|
1999-07-18 03:00:45 +08:00
|
|
|
if (mode & S_ISGID)
|
|
|
|
perms[6] = ((mode & S_IXGRP) ? 's' : 'S');
|
|
|
|
|
|
|
|
if (mode & S_ISVTX)
|
|
|
|
perms[9] = ((mode & S_IXOTH) ? 't' : 'T');
|
2000-10-29 01:16:25 +08:00
|
|
|
/*@=unrecog@*/
|
1999-07-18 03:00:45 +08:00
|
|
|
|
|
|
|
return perms;
|
1999-05-08 02:33:35 +08:00
|
|
|
}
|
1998-10-27 13:41:02 +08:00
|
|
|
|
1999-07-18 03:00:45 +08:00
|
|
|
static void printFileInfo(FILE *fp, const char * name,
|
|
|
|
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];
|
|
|
|
char timefield[100] = "";
|
|
|
|
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;
|
|
|
|
char * perms;
|
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);
|
|
|
|
nowtm = *tm; /* structure assignment */
|
|
|
|
}
|
1998-10-27 13:41:02 +08:00
|
|
|
|
1999-07-18 03:00:45 +08:00
|
|
|
perms = permsString(mode);
|
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);
|
|
|
|
{ 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-10-29 01:16:25 +08:00
|
|
|
fprintf(fp, "%s %4d %-8s%-8s %10s %s %s\n", perms, (int)nlink,
|
2000-05-17 02:32:49 +08:00
|
|
|
ownerfield, groupfield, sizefield, timefield, namefield);
|
1999-07-18 03:00:45 +08:00
|
|
|
if (perms) free(perms);
|
|
|
|
}
|
1999-05-08 02:33:35 +08:00
|
|
|
|
1999-07-18 03:00:45 +08:00
|
|
|
static int queryHeader(FILE *fp, Header h, const char * chptr)
|
|
|
|
{
|
1997-05-30 04:09:45 +08:00
|
|
|
char * str;
|
2000-02-24 01:34:41 +08:00
|
|
|
const char * errstr;
|
1996-06-28 04:47:54 +08:00
|
|
|
|
2000-02-24 01:34:41 +08:00
|
|
|
str = headerSprintf(h, chptr, rpmTagTable, rpmHeaderFormats, &errstr);
|
|
|
|
if (str == NULL) {
|
|
|
|
fprintf(stderr, _("error in format: %s\n"), errstr);
|
1997-05-30 04:09:45 +08:00
|
|
|
return 1;
|
1996-04-02 11:36:00 +08:00
|
|
|
}
|
1996-06-09 01:27:10 +08:00
|
|
|
|
1999-07-18 03:00:45 +08:00
|
|
|
fputs(str, fp);
|
1996-06-28 04:47:54 +08:00
|
|
|
|
|
|
|
return 0;
|
1996-04-02 11:36:00 +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;
|
|
|
|
}
|
|
|
|
|
2000-05-07 08:53:11 +08:00
|
|
|
int showQueryPackage(QVA_t *qva, /*@unused@*/rpmdb rpmdb, Header h)
|
1999-05-11 07:41:04 +08:00
|
|
|
{
|
1999-07-18 03:00:45 +08:00
|
|
|
FILE *fp = stdout; /* XXX FIXME: pass as arg */
|
1999-05-11 07:41:04 +08:00
|
|
|
int queryFlags = qva->qva_flags;
|
|
|
|
const char *queryFormat = qva->qva_queryFormat;
|
|
|
|
|
1999-08-07 06:52:49 +08:00
|
|
|
const char * name, * version, * release;
|
1995-12-28 04:08:35 +08:00
|
|
|
int_32 count, type;
|
|
|
|
char * prefix = NULL;
|
1999-11-27 05:58:42 +08:00
|
|
|
const char ** dirNames, ** baseNames;
|
1999-09-18 04:40:41 +08:00
|
|
|
const char ** fileMD5List;
|
|
|
|
const char * fileStatesList;
|
|
|
|
const char ** fileOwnerList = NULL;
|
|
|
|
const char ** fileGroupList = NULL;
|
|
|
|
const char ** fileLinktoList;
|
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;
|
1995-12-28 04:08:35 +08:00
|
|
|
int i;
|
|
|
|
|
1999-08-07 06:52:49 +08:00
|
|
|
headerNVR(h, &name, &version, &release);
|
1995-12-28 04:08:35 +08:00
|
|
|
|
1997-02-18 04:18:54 +08:00
|
|
|
if (!queryFormat && !queryFlags) {
|
1999-07-18 03:00:45 +08:00
|
|
|
fprintf(fp, "%s-%s-%s\n", name, version, release);
|
1995-12-28 04:08:35 +08:00
|
|
|
} else {
|
1997-02-18 04:18:54 +08:00
|
|
|
if (queryFormat)
|
1999-07-18 03:00:45 +08:00
|
|
|
queryHeader(fp, h, queryFormat);
|
1995-12-28 04:08:35 +08:00
|
|
|
|
|
|
|
if (queryFlags & QUERY_FOR_LIST) {
|
1999-12-09 03:04:50 +08:00
|
|
|
if (!headerGetEntry(h, RPMTAG_BASENAMES, &type,
|
1999-11-27 05:58:42 +08:00
|
|
|
(void **) &baseNames, &count)) {
|
1999-07-18 03:00:45 +08:00
|
|
|
fputs(_("(contains no files)"), fp);
|
|
|
|
fputs("\n", fp);
|
1996-01-06 02:12:17 +08:00
|
|
|
} else {
|
1996-11-19 02:02:36 +08:00
|
|
|
if (!headerGetEntry(h, RPMTAG_FILESTATES, &type,
|
1996-03-30 03:24:52 +08:00
|
|
|
(void **) &fileStatesList, &count)) {
|
|
|
|
fileStatesList = NULL;
|
|
|
|
}
|
1999-12-09 03:04:50 +08:00
|
|
|
headerGetEntry(h, RPMTAG_DIRNAMES, NULL,
|
1999-11-27 05:58:42 +08:00
|
|
|
(void **) &dirNames, NULL);
|
1999-12-09 03:04:50 +08:00
|
|
|
headerGetEntry(h, RPMTAG_DIRINDEXES, NULL,
|
1999-11-27 05:58:42 +08:00
|
|
|
(void **) &dirIndexes, NULL);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_FILEFLAGS, &type,
|
1996-01-06 02:12:17 +08:00
|
|
|
(void **) &fileFlagsList, &count);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_FILESIZES, &type,
|
1996-02-19 12:50:33 +08:00
|
|
|
(void **) &fileSizeList, &count);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_FILEMODES, &type,
|
1996-02-19 12:50:33 +08:00
|
|
|
(void **) &fileModeList, &count);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_FILEMTIMES, &type,
|
1996-02-19 12:50:33 +08:00
|
|
|
(void **) &fileMTimeList, &count);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_FILERDEVS, &type,
|
1996-02-19 12:50:33 +08:00
|
|
|
(void **) &fileRdevList, &count);
|
2000-05-17 02:32:49 +08:00
|
|
|
headerGetEntry(h, RPMTAG_FILEINODES, &type,
|
|
|
|
(void **) &fileInodeList, &count);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_FILELINKTOS, &type,
|
1996-02-19 23:17:56 +08:00
|
|
|
(void **) &fileLinktoList, &count);
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_FILEMD5S, &type,
|
1996-06-21 06:28:02 +08:00
|
|
|
(void **) &fileMD5List, &count);
|
1996-01-06 02:12:17 +08:00
|
|
|
|
1997-02-18 04:18:54 +08:00
|
|
|
if (!headerGetEntry(h, RPMTAG_FILEUIDS, &type,
|
|
|
|
(void **) &fileUIDList, &count)) {
|
|
|
|
fileUIDList = NULL;
|
1999-09-18 04:40:41 +08:00
|
|
|
} else if (!headerGetEntry(h, RPMTAG_FILEGIDS, &type,
|
|
|
|
(void **) &fileGIDList, &count)) {
|
|
|
|
fileGIDList = NULL;
|
1997-02-18 04:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!headerGetEntry(h, RPMTAG_FILEUSERNAME, &type,
|
|
|
|
(void **) &fileOwnerList, &count)) {
|
|
|
|
fileOwnerList = NULL;
|
1999-09-18 04:40:41 +08:00
|
|
|
} else if (!headerGetEntry(h, RPMTAG_FILEGROUPNAME, &type,
|
|
|
|
(void **) &fileGroupList, &count)) {
|
|
|
|
fileGroupList = NULL;
|
1997-02-18 04:18:54 +08:00
|
|
|
}
|
|
|
|
|
1996-01-06 02:12:17 +08:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if (!((queryFlags & QUERY_FOR_DOCS) ||
|
|
|
|
(queryFlags & QUERY_FOR_CONFIG))
|
|
|
|
|| ((queryFlags & QUERY_FOR_DOCS) &&
|
|
|
|
(fileFlagsList[i] & RPMFILE_DOC))
|
|
|
|
|| ((queryFlags & QUERY_FOR_CONFIG) &&
|
|
|
|
(fileFlagsList[i] & RPMFILE_CONFIG))) {
|
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
if (!rpmIsVerbose())
|
1999-07-18 03:00:45 +08:00
|
|
|
prefix ? fputs(prefix, fp) : 0;
|
1996-06-21 06:28:02 +08:00
|
|
|
|
|
|
|
if (queryFlags & QUERY_FOR_STATE) {
|
|
|
|
if (fileStatesList) {
|
|
|
|
switch (fileStatesList[i]) {
|
2000-07-10 07:10:25 +08:00
|
|
|
case RPMFILE_STATE_NORMAL:
|
1999-07-18 03:00:45 +08:00
|
|
|
fputs(_("normal "), fp); break;
|
2000-07-10 07:10:25 +08:00
|
|
|
case RPMFILE_STATE_REPLACED:
|
1999-07-18 03:00:45 +08:00
|
|
|
fputs(_("replaced "), fp); break;
|
2000-07-10 07:10:25 +08:00
|
|
|
case RPMFILE_STATE_NOTINSTALLED:
|
1999-07-18 03:00:45 +08:00
|
|
|
fputs(_("not installed "), fp); break;
|
2000-07-10 07:10:25 +08:00
|
|
|
case RPMFILE_STATE_NETSHARED:
|
1999-08-16 03:11:40 +08:00
|
|
|
fputs(_("net shared "), fp); break;
|
2000-07-10 07:10:25 +08:00
|
|
|
default:
|
1999-07-18 03:00:45 +08:00
|
|
|
fprintf(fp, _("(unknown %3d) "),
|
1999-09-18 04:40:41 +08:00
|
|
|
(int)fileStatesList[i]);
|
1996-02-19 12:50:33 +08:00
|
|
|
}
|
1996-06-21 06:28:02 +08:00
|
|
|
} else {
|
1999-07-18 03:00:45 +08:00
|
|
|
fputs( _("(no state) "), fp);
|
1996-01-06 02:12:17 +08:00
|
|
|
}
|
1996-06-21 06:28:02 +08:00
|
|
|
}
|
1999-10-06 23:51:14 +08:00
|
|
|
|
1996-06-21 06:28:02 +08:00
|
|
|
if (queryFlags & QUERY_FOR_DUMPFILES) {
|
1999-10-06 23:51:14 +08:00
|
|
|
fprintf(fp, "%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],
|
|
|
|
fileMD5List[i], fileModeList[i]);
|
|
|
|
|
1999-09-18 04:40:41 +08:00
|
|
|
if (fileOwnerList && fileGroupList)
|
1999-07-18 03:00:45 +08:00
|
|
|
fprintf(fp, "%s %s", fileOwnerList[i],
|
1996-06-21 06:28:02 +08:00
|
|
|
fileGroupList[i]);
|
1999-09-18 04:40:41 +08:00
|
|
|
else if (fileUIDList && fileGIDList)
|
1999-07-18 03:00:45 +08:00
|
|
|
fprintf(fp, "%d %d", fileUIDList[i],
|
1996-06-21 06:28:02 +08:00
|
|
|
fileGIDList[i]);
|
1997-02-18 04:18:54 +08:00
|
|
|
else {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_INTERNAL, _("package has "
|
|
|
|
"neither file owner or id lists"));
|
1997-02-18 04:18:54 +08:00
|
|
|
}
|
1996-06-21 06:28:02 +08:00
|
|
|
|
1999-07-18 03:00:45 +08:00
|
|
|
fprintf(fp, " %s %s %u ",
|
1996-06-21 06:28:02 +08:00
|
|
|
fileFlagsList[i] & RPMFILE_CONFIG ? "1" : "0",
|
|
|
|
fileFlagsList[i] & RPMFILE_DOC ? "1" : "0",
|
1998-11-17 05:40:28 +08:00
|
|
|
(unsigned)fileRdevList[i]);
|
1996-06-21 06:28:02 +08:00
|
|
|
|
|
|
|
if (strlen(fileLinktoList[i]))
|
1999-07-18 03:00:45 +08:00
|
|
|
fprintf(fp, "%s\n", fileLinktoList[i]);
|
1996-06-21 06:28:02 +08:00
|
|
|
else
|
1999-07-18 03:00:45 +08:00
|
|
|
fprintf(fp, "X\n");
|
1996-06-21 06:28:02 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
} else if (!rpmIsVerbose()) {
|
1999-11-27 05:58:42 +08:00
|
|
|
fputs(dirNames[dirIndexes[i]], fp);
|
|
|
|
fputs(baseNames[i], fp);
|
1999-07-18 03:00:45 +08:00
|
|
|
fputs("\n", fp);
|
1997-02-18 04:18:54 +08:00
|
|
|
} else {
|
1999-10-06 23:51:14 +08:00
|
|
|
char * filespec;
|
2000-05-17 02:32:49 +08:00
|
|
|
int nlink;
|
1999-10-06 23:51:14 +08:00
|
|
|
|
1999-11-27 05:58:42 +08:00
|
|
|
filespec = xmalloc(strlen(dirNames[dirIndexes[i]])
|
|
|
|
+ strlen(baseNames[i]) + 1);
|
|
|
|
strcpy(filespec, dirNames[dirIndexes[i]]);
|
|
|
|
strcat(filespec, baseNames[i]);
|
1999-10-06 23:51:14 +08:00
|
|
|
|
2000-05-17 02:32:49 +08:00
|
|
|
nlink = countLinks(fileRdevList, fileInodeList, count, i);
|
1999-10-06 23:51:14 +08:00
|
|
|
if (fileOwnerList && fileGroupList) {
|
|
|
|
printFileInfo(fp, filespec, fileSizeList[i],
|
|
|
|
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]);
|
|
|
|
} else if (fileUIDList && fileGIDList) {
|
|
|
|
printFileInfo(fp, filespec, fileSizeList[i],
|
|
|
|
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]);
|
|
|
|
} else {
|
|
|
|
rpmError(RPMERR_INTERNAL, _("package has "
|
|
|
|
"neither file owner or id lists"));
|
|
|
|
}
|
|
|
|
|
|
|
|
free(filespec);
|
1997-02-18 04:18:54 +08:00
|
|
|
}
|
1995-12-28 04:08:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-27 05:58:42 +08:00
|
|
|
free(dirNames);
|
|
|
|
free(baseNames);
|
1996-02-19 23:17:56 +08:00
|
|
|
free(fileLinktoList);
|
1996-06-21 06:28:02 +08:00
|
|
|
free(fileMD5List);
|
1996-02-19 12:50:33 +08:00
|
|
|
if (fileOwnerList) free(fileOwnerList);
|
|
|
|
if (fileGroupList) free(fileGroupList);
|
1996-01-06 02:12:17 +08:00
|
|
|
}
|
1995-12-28 04:08:35 +08:00
|
|
|
}
|
1996-04-16 06:21:30 +08:00
|
|
|
}
|
1999-05-11 07:41:04 +08:00
|
|
|
return 0; /* XXX FIXME: need real return code */
|
1996-04-16 06:21:30 +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;
|
1999-02-23 01:44:57 +08:00
|
|
|
struct speclines *sl = spec->sl;
|
|
|
|
struct 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++) {
|
2000-02-24 01:34:41 +08:00
|
|
|
struct spectag * t = st->st_t + i;
|
|
|
|
const char * tn = tagName(t->t_tag);
|
|
|
|
const char * errstr;
|
|
|
|
char fmt[128];
|
|
|
|
|
|
|
|
fmt[0] = '\0';
|
|
|
|
(void) stpcpy( stpcpy( stpcpy( fmt, "%{"), tn), "}\n");
|
2000-12-13 04:03:45 +08:00
|
|
|
if (msgstr) free((void *)msgstr);
|
2000-02-24 01:34:41 +08:00
|
|
|
msgstr = headerSprintf(h, fmt, rpmTagTable, rpmHeaderFormats, &errstr);
|
|
|
|
if (msgstr == NULL) {
|
|
|
|
fprintf(stderr, _("can't query %s: %s\n"), tn, errstr);
|
|
|
|
return;
|
1999-02-23 01:44:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(t->t_tag) {
|
|
|
|
case RPMTAG_SUMMARY:
|
|
|
|
case RPMTAG_GROUP:
|
1999-09-18 04:40:41 +08:00
|
|
|
free(sl->sl_lines[t->t_startx]);
|
|
|
|
sl->sl_lines[t->t_startx] = NULL;
|
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++) {
|
|
|
|
free(sl->sl_lines[t->t_startx + j]);
|
|
|
|
sl->sl_lines[t->t_startx + j] = NULL;
|
|
|
|
}
|
1999-02-23 01:44:57 +08:00
|
|
|
if (t->t_lang && strcmp(t->t_lang, RPMBUILD_DEFAULT_LANG)) {
|
1999-09-18 04:40:41 +08:00
|
|
|
free(sl->sl_lines[t->t_startx]);
|
|
|
|
sl->sl_lines[t->t_startx] = NULL;
|
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;
|
|
|
|
}
|
|
|
|
}
|
2000-12-13 04:03:45 +08:00
|
|
|
if (msgstr) free((void *)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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-14 03:23:55 +08:00
|
|
|
void rpmDisplayQueryTags(FILE * f)
|
|
|
|
{
|
1999-05-11 07:41:04 +08:00
|
|
|
const struct headerTagTableEntry * t;
|
|
|
|
int i;
|
|
|
|
const struct headerSprintfExtension * ext = rpmHeaderFormats;
|
|
|
|
|
|
|
|
for (i = 0, t = rpmTagTable; i < rpmTagTableSize; i++, t++) {
|
|
|
|
fprintf(f, "%s\n", t->name + 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (ext->name) {
|
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++) {
|
|
|
|
if (!strcmp(t->name, ext->name))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= rpmTagTableSize && ext->type == HEADER_EXT_TAG)
|
|
|
|
fprintf(f, "%s\n", ext->name + 7);
|
|
|
|
ext++;
|
1999-05-11 07:41:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-27 08:10:28 +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;
|
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;
|
|
|
|
}
|
|
|
|
rpmdbFreeIterator(mi);
|
|
|
|
return ec;
|
|
|
|
}
|
1999-05-11 07:41:04 +08:00
|
|
|
|
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,
|
|
|
|
const char *buildRoot, int inBuildArch, const char *passPhrase,
|
|
|
|
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
|
|
|
*/
|
1999-07-01 05:18:43 +08:00
|
|
|
void (*freeSpecVec) (Spec spec) = NULL;
|
|
|
|
|
2000-08-30 06:04:33 +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;
|
1996-06-21 06:28:02 +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:
|
1999-12-13 01:46:22 +08:00
|
|
|
{ int argc = 0;
|
|
|
|
const char ** argv = NULL;
|
|
|
|
int i;
|
1998-12-01 08:10:18 +08:00
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
rc = rpmGlob(arg, &argc, &argv);
|
|
|
|
if (rc)
|
|
|
|
return 1;
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
FD_t fd;
|
|
|
|
fd = Fopen(argv[i], "r.ufdio");
|
|
|
|
if (Ferror(fd)) {
|
|
|
|
/* XXX Fstrerror */
|
|
|
|
fprintf(stderr, _("open of %s failed: %s\n"), argv[i],
|
1999-11-11 06:09:49 +08:00
|
|
|
#ifndef NOTYET
|
1999-12-12 09:46:13 +08:00
|
|
|
urlStrerror(argv[i]));
|
1999-11-11 06:09:49 +08:00
|
|
|
#else
|
|
|
|
Fstrerror(fd));
|
|
|
|
#endif
|
1999-12-13 01:46:22 +08:00
|
|
|
if (fd) Fclose(fd);
|
|
|
|
retcode = 1;
|
|
|
|
break;
|
|
|
|
}
|
1996-10-15 11:14:50 +08:00
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
retcode = rpmReadPackageHeader(fd, &h, &isSource, NULL, NULL);
|
1996-10-15 11:14:50 +08:00
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
Fclose(fd);
|
1996-10-15 11:14:50 +08:00
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
switch (retcode) {
|
|
|
|
case 0:
|
|
|
|
if (h == NULL) {
|
|
|
|
fprintf(stderr, _("old format source packages cannot "
|
1998-12-01 08:10:18 +08:00
|
|
|
"be queried\n"));
|
1999-12-13 01:46:22 +08:00
|
|
|
retcode = 1;
|
|
|
|
break;
|
|
|
|
}
|
2000-05-07 08:53:11 +08:00
|
|
|
retcode = showPackage(qva, rpmdb, h);
|
1999-12-13 01:46:22 +08:00
|
|
|
headerFree(h);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
fprintf(stderr, _("%s does not appear to be a RPM package\n"),
|
|
|
|
argv[i]);
|
|
|
|
/*@fallthrough@*/
|
|
|
|
case 2:
|
|
|
|
fprintf(stderr, _("query of %s failed\n"), argv[i]);
|
1999-05-11 07:41:04 +08:00
|
|
|
retcode = 1;
|
|
|
|
break;
|
1996-01-06 02:12:17 +08:00
|
|
|
}
|
|
|
|
}
|
1999-12-13 01:46:22 +08:00
|
|
|
if (argv) {
|
|
|
|
for (i = 0; i < argc; i++)
|
2000-12-13 04:03:45 +08:00
|
|
|
free((void *)argv[i]);
|
|
|
|
free((void *)argv);
|
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;
|
|
|
|
int inBuildArch = 0;
|
|
|
|
char * passPhrase = "";
|
|
|
|
char *cookie = NULL;
|
|
|
|
int anyarch = 1;
|
|
|
|
int force = 1;
|
1999-07-01 05:18:43 +08:00
|
|
|
|
1999-11-01 05:38:21 +08:00
|
|
|
rc = parseSpecVec(&spec, arg, "/", buildRoot, inBuildArch, passPhrase,
|
1999-07-01 05:18:43 +08:00
|
|
|
cookie, anyarch, force);
|
1998-11-20 08:29:46 +08:00
|
|
|
if (rc || spec == NULL) {
|
|
|
|
|
|
|
|
fprintf(stderr, _("query of specfile %s failed, can't parse\n"), arg);
|
1999-07-01 05:24:06 +08:00
|
|
|
if (spec != NULL) 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);
|
1999-07-01 05:24:06 +08:00
|
|
|
freeSpecVec(spec);
|
1999-02-23 01:44:57 +08:00
|
|
|
retcode = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-11-20 08:29:46 +08:00
|
|
|
for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
|
1999-05-11 07:41:04 +08:00
|
|
|
showPackage(qva, NULL, pkg->header);
|
1998-11-20 08:29:46 +08:00
|
|
|
}
|
1999-07-01 05:24:06 +08:00
|
|
|
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) {
|
|
|
|
fprintf(stderr, _("no packages\n"));
|
|
|
|
retcode = 1;
|
|
|
|
} else {
|
2000-04-27 08:10:28 +08:00
|
|
|
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) {
|
|
|
|
fprintf(stderr, _("group %s does not contain any packages\n"), arg);
|
|
|
|
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) {
|
|
|
|
fprintf(stderr, _("no package triggers %s\n"), arg);
|
|
|
|
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) {
|
|
|
|
fprintf(stderr, _("no package requires %s\n"), arg);
|
|
|
|
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) {
|
|
|
|
fprintf(stderr, _("no package provides %s\n"), arg);
|
|
|
|
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;
|
|
|
|
|
|
|
|
for (s = arg; *s; s++)
|
|
|
|
if (!(*s == '.' || *s == '/')) break;
|
|
|
|
|
|
|
|
if (*s == '\0') {
|
|
|
|
char fnbuf[PATH_MAX];
|
|
|
|
fn = /*@-unrecog@*/ realpath(arg, fnbuf) /*@=unrecog@*/;
|
|
|
|
fn = xstrdup( (fn ? fn : arg) );
|
|
|
|
} 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-07-10 07:10:25 +08:00
|
|
|
fprintf(stderr, _("file %s: %s\n"), fn, strerror(myerrno));
|
2000-04-12 21:42:57 +08:00
|
|
|
break;
|
|
|
|
case 0:
|
2000-07-10 07:10:25 +08:00
|
|
|
fprintf(stderr, _("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
|
|
|
}
|
2000-12-13 04:03:45 +08:00
|
|
|
free((void *)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;
|
2000-04-24 04:37:57 +08:00
|
|
|
int recOffset;
|
|
|
|
|
|
|
|
/* 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)) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("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-04-24 04:37:57 +08:00
|
|
|
fprintf(stderr, _("record %d 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) {
|
|
|
|
fprintf(stderr, _("package %s is not installed\n"), arg);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-08-30 06:04:33 +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
|
|
|
|
2000-05-07 08:53:11 +08:00
|
|
|
if (rpmdb)
|
|
|
|
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
|
|
|
}
|