Convert to rpm-3.1 API.
CVS patchset: 3672 CVS date: 2000/04/12 18:21:40
This commit is contained in:
parent
a4a828e3a5
commit
bb472e02e1
|
@ -802,6 +802,7 @@ static PyObject * rpmdbNext(rpmdbObject * s, PyObject * args) {
|
|||
return Py_BuildValue("i", where);
|
||||
}
|
||||
|
||||
#ifdef DYING
|
||||
static PyObject * handleDbResult(int rc, dbiIndexSet matches) {
|
||||
PyObject * list;
|
||||
int i;
|
||||
|
@ -822,44 +823,81 @@ static PyObject * handleDbResult(int rc, dbiIndexSet matches) {
|
|||
|
||||
return list;
|
||||
}
|
||||
#else /* DYING */
|
||||
static PyObject * handleDbResult(rpmdbMatchIterator mi) {
|
||||
PyObject * list;
|
||||
|
||||
if (mi == NULL) {
|
||||
PyErr_SetString(pyrpmError, "error reading from database");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list = PyList_New(0);
|
||||
|
||||
/* XXX FIXME: unnecessary header mallocs are side effect here */
|
||||
while (rpmdbNextIterator(mi)) {
|
||||
PyList_Append(list, PyInt_FromLong(rpmdbGetIteratorOffset(mi)));
|
||||
}
|
||||
rpmdbFreeIterator(mi);
|
||||
|
||||
return list;
|
||||
}
|
||||
#endif
|
||||
|
||||
static PyObject * rpmdbByName(rpmdbObject * s, PyObject * args) {
|
||||
char * str;
|
||||
dbiIndexSet matches;
|
||||
int rc;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &str)) return NULL;
|
||||
|
||||
rc = rpmdbFindPackage(s->db, str, &matches);
|
||||
return handleDbResult(rc, matches);
|
||||
#ifdef DYING
|
||||
{ dbiIndexSet matches;
|
||||
int rc;
|
||||
rc = rpmdbFindPackage(s->db, str, &matches);
|
||||
return handleDbResult(rc, matches);
|
||||
}
|
||||
#else
|
||||
return handleDbResult(rpmdbInitIterator(s->db, RPMDBI_NAME, str, 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
static PyObject * rpmdbByFile(rpmdbObject * s, PyObject * args) {
|
||||
char * str;
|
||||
dbiIndexSet matches;
|
||||
int rc;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &str)) return NULL;
|
||||
|
||||
rc = rpmdbFindByFile(s->db, str, &matches);
|
||||
return handleDbResult(rc, matches);
|
||||
#ifdef DYING
|
||||
{ dbiIndexSet matches;
|
||||
int rc;
|
||||
rc = rpmdbFindByFile(s->db, str, &matches);
|
||||
return handleDbResult(rc, matches);
|
||||
}
|
||||
#else
|
||||
return handleDbResult(rpmdbInitIterator(s->db, RPMDBI_FILE, str, 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
static PyObject * rpmdbByProvides(rpmdbObject * s, PyObject * args) {
|
||||
char * str;
|
||||
dbiIndexSet matches;
|
||||
int rc;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &str)) return NULL;
|
||||
|
||||
rc = rpmdbFindByProvides(s->db, str, &matches);
|
||||
return handleDbResult(rc, matches);
|
||||
#ifdef DYING
|
||||
{ dbiIndexSet matches;
|
||||
int rc;
|
||||
rc = rpmdbFindByProvides(s->db, str, &matches);
|
||||
return handleDbResult(rc, matches);
|
||||
}
|
||||
#else
|
||||
return handleDbResult(rpmdbInitIterator(s->db, RPMDBI_PROVIDES, str, 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
static int rpmdbLength(rpmdbObject * s) {
|
||||
int first;
|
||||
int count = 0;
|
||||
|
||||
#ifdef DYING
|
||||
int first;
|
||||
|
||||
first = rpmdbFirstRecNum(s->db);
|
||||
if (!first) return 0;
|
||||
|
||||
|
@ -867,6 +905,16 @@ static int rpmdbLength(rpmdbObject * s) {
|
|||
while ((first = rpmdbNextRecNum(s->db, first))) {
|
||||
count++;
|
||||
}
|
||||
#else
|
||||
{ rpmdbMatchIterator mi;
|
||||
|
||||
mi = rpmdbInitIterator(s->db, RPMDBI_PACKAGES, NULL, 0);
|
||||
/* XXX FIXME: unnecessary header mallocs are side effect here */
|
||||
while (rpmdbNextIterator(mi) != NULL)
|
||||
count++;
|
||||
rpmdbFreeIterator(mi);
|
||||
}
|
||||
#endif
|
||||
|
||||
return count;
|
||||
}
|
||||
|
|
134
python/upgrade.c
134
python/upgrade.c
|
@ -96,8 +96,6 @@ static void compareFileList(int availFileCount, char **availBaseNames,
|
|||
|
||||
static void addLostFiles(rpmdb db, struct pkgSet *psp, struct hash_table *ht)
|
||||
{
|
||||
int num;
|
||||
Header h;
|
||||
char *name;
|
||||
struct packageInfo **pack;
|
||||
struct packageInfo key;
|
||||
|
@ -107,15 +105,31 @@ static void addLostFiles(rpmdb db, struct pkgSet *psp, struct hash_table *ht)
|
|||
int_32 * installedDirIndexes;
|
||||
int installedFileCount;
|
||||
|
||||
num = rpmdbFirstRecNum(db);
|
||||
while (num) {
|
||||
{ Header h = NULL;
|
||||
|
||||
#ifdef DYING
|
||||
int num;
|
||||
|
||||
for (num = rpmdbFirstRecNum(db);
|
||||
num > 0;
|
||||
num = rpmdbNextRecNum(db, num))
|
||||
{
|
||||
if (h) {
|
||||
headerFree(h);
|
||||
h = NULL;
|
||||
}
|
||||
h = rpmdbGetRecord(db, num);
|
||||
#else
|
||||
rpmdbMatchIterator mi;
|
||||
|
||||
mi = rpmdbInitIterator(db, RPMDBI_PACKAGES, NULL, 0);
|
||||
while ((h = rpmdbNextIterator(mi)) != NULL) {
|
||||
#endif
|
||||
|
||||
headerGetEntry(h, RPMTAG_NAME, NULL, (void **) &name, NULL);
|
||||
if (name && !strcmp(name, "metroess")) {
|
||||
/* metro was removed from 5.1, but leave it if it's already
|
||||
installed */
|
||||
headerFree(h);
|
||||
num = rpmdbNextRecNum(db, num);
|
||||
continue;
|
||||
}
|
||||
key.name = name;
|
||||
|
@ -138,16 +152,23 @@ static void addLostFiles(rpmdb db, struct pkgSet *psp, struct hash_table *ht)
|
|||
free(installedDirs);
|
||||
}
|
||||
}
|
||||
|
||||
headerFree(h);
|
||||
num = rpmdbNextRecNum(db, num);
|
||||
#ifndef DYING
|
||||
}
|
||||
|
||||
rpmdbFreeIterator(mi);
|
||||
#else
|
||||
}
|
||||
if (h) {
|
||||
headerFree(h);
|
||||
h = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static int findPackagesWithObsoletes(rpmdb db, struct pkgSet *psp)
|
||||
{
|
||||
dbiIndexSet matches;
|
||||
int rc, count, obsoletesCount;
|
||||
int count, obsoletesCount;
|
||||
struct packageInfo **pip;
|
||||
char **obsoletes;
|
||||
|
||||
|
@ -162,6 +183,10 @@ static int findPackagesWithObsoletes(rpmdb db, struct pkgSet *psp)
|
|||
if (headerGetEntryMinMemory((*pip)->h, RPMTAG_OBSOLETES, NULL,
|
||||
(void **) &obsoletes, &obsoletesCount)) {
|
||||
while (obsoletesCount--) {
|
||||
#ifdef DYING
|
||||
dbiIndexSet matches;
|
||||
int rc;
|
||||
|
||||
rc = rpmdbFindPackage(db, obsoletes[obsoletesCount], &matches);
|
||||
if (!rc) {
|
||||
if (dbiIndexSetCount(matches)) {
|
||||
|
@ -172,6 +197,12 @@ static int findPackagesWithObsoletes(rpmdb db, struct pkgSet *psp)
|
|||
|
||||
dbiFreeIndexSet(matches);
|
||||
}
|
||||
#else
|
||||
if (rpmdbCountPackages(db, obsoletes[obsoletesCount]) > 0) {
|
||||
(*pip)->selected = 1;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
free(obsoletes);
|
||||
|
@ -193,8 +224,11 @@ static int findUpgradePackages(rpmdb db, struct pkgSet *psp,
|
|||
int skipThis;
|
||||
Header h, installedHeader;
|
||||
char *name;
|
||||
#ifdef DYING
|
||||
dbiIndexSet matches;
|
||||
int rc, i, count;
|
||||
int rc, i;
|
||||
#endif
|
||||
int count;
|
||||
char **installedFiles, **availFiles;
|
||||
char **installedDirs, ** availDirs;
|
||||
int_32 * installedDirIndexes, * availDirIndexes;
|
||||
|
@ -214,6 +248,7 @@ static int findUpgradePackages(rpmdb db, struct pkgSet *psp,
|
|||
}
|
||||
|
||||
DEBUG (("Avail: %s\n", name));
|
||||
#ifdef DYING
|
||||
rc = rpmdbFindPackage(db, name, &matches);
|
||||
|
||||
if (rc == 0) {
|
||||
|
@ -239,6 +274,27 @@ static int findUpgradePackages(rpmdb db, struct pkgSet *psp,
|
|||
skipThis = 1;
|
||||
DEBUG (("Not installed\n"))
|
||||
}
|
||||
#else
|
||||
{ rpmdbMatchIterator mi;
|
||||
|
||||
mi = rpmdbInitIterator(db, RPMDBI_NAME, name, 0);
|
||||
skipThis = (mi ? 0 : 1);
|
||||
rpmErrorSetCallback(errorFunction);
|
||||
while((installedHeader = rpmdbNextIterator(mi)) != NULL) {
|
||||
if (rpmVersionCompare(installedHeader, h) >= 0) {
|
||||
/* already have a newer version installed */
|
||||
DEBUG (("Already have newer version\n"))
|
||||
skipThis = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
rpmdbFreeIterator(mi);
|
||||
rpmErrorSetCallback(NULL);
|
||||
if (! skipThis) {
|
||||
DEBUG (("No newer version installed\n"))
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (skipThis) {
|
||||
DEBUG (("DO NOT INSTALL\n"))
|
||||
|
@ -257,6 +313,7 @@ static int findUpgradePackages(rpmdb db, struct pkgSet *psp,
|
|||
(void **) &availDirIndexes, NULL);
|
||||
}
|
||||
|
||||
#ifdef DYING
|
||||
for (i = 0; i < dbiIndexSetCount(matches); i++) {
|
||||
/* Compare the file lists */
|
||||
installedHeader =
|
||||
|
@ -280,6 +337,31 @@ static int findUpgradePackages(rpmdb db, struct pkgSet *psp,
|
|||
}
|
||||
headerFree(installedHeader);
|
||||
}
|
||||
#else
|
||||
{ rpmdbMatchIterator mi;
|
||||
mi = rpmdbInitIterator(db, RPMDBI_NAME, name, 0);
|
||||
while((installedHeader = rpmdbNextIterator(mi)) != NULL) {
|
||||
if (headerGetEntryMinMemory(installedHeader, RPMTAG_BASENAMES,
|
||||
NULL, (void **) &installedFiles,
|
||||
&installedFileCount)) {
|
||||
headerGetEntryMinMemory(installedHeader, RPMTAG_DIRNAMES,
|
||||
NULL, (void **) &installedDirs, NULL);
|
||||
headerGetEntryMinMemory(installedHeader, RPMTAG_DIRINDEXES,
|
||||
NULL, (void **) &installedDirIndexes, NULL);
|
||||
|
||||
compareFileList(availFileCount, availFiles,
|
||||
availDirs, availDirIndexes,
|
||||
installedFileCount, installedFiles,
|
||||
installedDirs, installedDirIndexes,
|
||||
ht);
|
||||
|
||||
free(installedFiles);
|
||||
free(installedDirs);
|
||||
}
|
||||
}
|
||||
rpmdbFreeIterator(mi);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (availFiles) {
|
||||
free(availFiles);
|
||||
|
@ -287,9 +369,11 @@ static int findUpgradePackages(rpmdb db, struct pkgSet *psp,
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef DYING
|
||||
if (rc == 0) {
|
||||
dbiFreeIndexSet(matches);
|
||||
}
|
||||
#endif
|
||||
|
||||
DEBUG (("\n\n"))
|
||||
|
||||
|
@ -422,11 +506,10 @@ static void printCount(struct pkgSet *psp)
|
|||
|
||||
static int unmarkPackagesAlreadyInstalled(rpmdb db, struct pkgSet *psp)
|
||||
{
|
||||
dbiIndexSet matches;
|
||||
Header h, installedHeader;
|
||||
char *name;
|
||||
struct packageInfo **pip;
|
||||
int count, rc, i;
|
||||
int count;
|
||||
|
||||
count = psp->numPackages;
|
||||
pip = psp->packages;
|
||||
|
@ -441,6 +524,11 @@ static int unmarkPackagesAlreadyInstalled(rpmdb db, struct pkgSet *psp)
|
|||
/*logMessage("Failed with bad header");*/
|
||||
return(-1);
|
||||
}
|
||||
#ifdef DYING
|
||||
{ dbiIndexSet matches;
|
||||
int rc;
|
||||
int i;
|
||||
|
||||
rc = rpmdbFindPackage(db, name, &matches);
|
||||
if (rc == 0) {
|
||||
rpmErrorSetCallback(errorFunction);
|
||||
|
@ -460,6 +548,24 @@ static int unmarkPackagesAlreadyInstalled(rpmdb db, struct pkgSet *psp)
|
|||
dbiFreeIndexSet(matches);
|
||||
}
|
||||
}
|
||||
#else
|
||||
{ rpmdbMatchIterator mi;
|
||||
|
||||
mi = rpmdbInitIterator(db, RPMDBI_NAME, name, 0);
|
||||
rpmErrorSetCallback(errorFunction);
|
||||
while((installedHeader = rpmdbNextIterator(mi)) != NULL) {
|
||||
if (rpmVersionCompare(installedHeader, h) >= 0) {
|
||||
/* already have a newer version installed */
|
||||
DEBUG (("Already have newer version\n"))
|
||||
(*pip)->selected = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
rpmdbFreeIterator(mi);
|
||||
rpmErrorSetCallback(NULL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
pip++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue