moved findPackageByLabel() to rpmdbFindByLabel() and added rpmdbFindByHeader()

CVS patchset: 1671
CVS date: 1997/05/30 21:14:34
This commit is contained in:
ewt 1997-05-30 21:14:34 +00:00
parent 381df90021
commit eee6452dc0
6 changed files with 9 additions and 98 deletions

View File

@ -1,6 +1,7 @@
2.4.1 -> 2.4.2:
- completely rewrote queryformat code
- added fsnames, fssizes virtual query tags
- added rpmdbFindByHeader() and rpmdbFindByTag() public functions
2.4 -> 2.4.1:
- take advantage of lchown() if it's available

View File

@ -317,7 +317,7 @@ int doUninstall(char * rootdir, char ** argv, int uninstallFlags,
j = 0;
numPackages = 0;
for (arg = argv; *arg; arg++) {
rc = findPackageByLabel(db, *arg, &matches);
rc = rpmdbFindByLabel(db, *arg, &matches);
if (rc == 1) {
fprintf(stderr, _("package %s is not installed\n"), *arg);
numFailed++;

View File

@ -9,7 +9,7 @@ LIBOBJECTS = header.o misc.o messages.o \
uninstall.o oldheader.o install.o \
signature.o verify.o rebuilddb.o \
tread.o cpio.o formats.o \
fs.o
fs.o lookup.o
SOURCES = $(addprefix $(srcdir)/,$(subst .o,.c,$(LIBOBJECTS)))
TAGTABLE = tagtable.o

View File

@ -232,6 +232,10 @@ int rpmdbFindByProvides(rpmdb db, char * provides, dbiIndexSet * matches);
int rpmdbFindByRequiredBy(rpmdb db, char * requires, dbiIndexSet * matches);
int rpmdbFindByConflicts(rpmdb db, char * conflicts, dbiIndexSet * matches);
/* these are just convience functions */
int rpmdbFindByLabel(rpmdb db, char * label, dbiIndexSet * matches);
int rpmdbFindByHeader(rpmdb db, Header h, dbiIndexSet * matches);
int rpmInstallSourcePackage(char * root, int fd, char ** specFile,
rpmNotifyFunction notify, char * labelFormat);
int rpmInstallPackage(char * rootdir, rpmdb db, int fd, char * prefix,

96
query.c
View File

@ -26,8 +26,6 @@ static char * permsString(int mode);
static void printHeader(Header h, int queryFlags, char * queryFormat);
static void showMatches(rpmdb db, dbiIndexSet matches, int queryFlags,
char * queryFormat);
static int findMatches(rpmdb db, char * name, char * version, char * release,
dbiIndexSet * matches);
static void printFileInfo(char * name, unsigned int size, unsigned short mode,
unsigned int mtime, unsigned short rdev,
char * owner, char * group, int uid, int gid,
@ -487,7 +485,7 @@ int doQuery(char * prefix, enum querysources source, int queryFlags,
break;
case QUERY_PACKAGE:
rc = findPackageByLabel(db, arg, &matches);
rc = rpmdbFindByLabel(db, arg, &matches);
if (rc == 1) {
retcode = 1;
fprintf(stderr, _("package %s is not installed\n"), arg);
@ -508,98 +506,6 @@ int doQuery(char * prefix, enum querysources source, int queryFlags,
return retcode;
}
/* 0 found matches */
/* 1 no matches */
/* 2 error */
int findPackageByLabel(rpmdb db, char * arg, dbiIndexSet * matches) {
char * localarg, * chptr;
char * release;
int rc;
if (!strlen(arg)) return 1;
/* did they give us just a name? */
rc = findMatches(db, arg, NULL, NULL, matches);
if (rc != 1) return rc;
/* maybe a name and a release */
localarg = alloca(strlen(arg) + 1);
strcpy(localarg, arg);
chptr = (localarg + strlen(localarg)) - 1;
while (chptr > localarg && *chptr != '-') chptr--;
if (chptr == localarg) return 1;
*chptr = '\0';
rc = findMatches(db, localarg, chptr + 1, NULL, matches);
if (rc != 1) return rc;
/* how about name-version-release? */
release = chptr + 1;
while (chptr > localarg && *chptr != '-') chptr--;
if (chptr == localarg) return 1;
*chptr = '\0';
return findMatches(db, localarg, chptr + 1, release, matches);
}
/* 0 found matches */
/* 1 no matches */
/* 2 error */
int findMatches(rpmdb db, char * name, char * version, char * release,
dbiIndexSet * matches) {
int gotMatches;
int rc;
int i;
char * pkgRelease, * pkgVersion;
int count, type;
int goodRelease, goodVersion;
Header h;
if ((rc = rpmdbFindPackage(db, name, matches))) {
if (rc == -1) return 2; else return 1;
}
if (!version && !release) return 0;
gotMatches = 0;
/* make sure the version and releases match */
for (i = 0; i < matches->count; i++) {
if (matches->recs[i].recOffset) {
h = rpmdbGetRecord(db, matches->recs[i].recOffset);
if (!h) {
fprintf(stderr, _("error: could not read database record\n"));
dbiFreeIndexRecord(*matches);
return 2;
}
headerGetEntry(h, RPMTAG_VERSION, &type, (void **) &pkgVersion,
&count);
headerGetEntry(h, RPMTAG_RELEASE, &type, (void **) &pkgRelease,
&count);
goodRelease = goodVersion = 1;
if (release && strcmp(release, pkgRelease)) goodRelease = 0;
if (version && strcmp(version, pkgVersion)) goodVersion = 0;
if (goodRelease && goodVersion)
gotMatches = 1;
else
matches->recs[i].recOffset = 0;
}
}
if (!gotMatches) {
dbiFreeIndexRecord(*matches);
return 1;
}
return 0;
}
void queryPrintTags(void) {
const struct headerTagTableEntry * t;
int i;

View File

@ -229,7 +229,7 @@ void doVerify(char * prefix, enum verifysources source, char ** argv,
break;
case VERIFY_PACKAGE:
rc = findPackageByLabel(db, arg, &matches);
rc = rpmdbFindByLabel(db, arg, &matches);
if (rc == 1)
fprintf(stderr, _("package %s is not installed\n"), arg);
else if (rc == 2) {