summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2000-04-12 18:21:40 +0000
committerjbj <devnull@localhost>2000-04-12 18:21:40 +0000
commitbb472e02e1bde04b02702cf72473f9a5dbcb983d (patch)
tree64027c6a563adb11c34b30a606262c8eaed1a89e /python
parenta4a828e3a5ff469d0695028d8b11ca67210da100 (diff)
downloadrpm-bb472e02e1bde04b02702cf72473f9a5dbcb983d.tar.gz
rpm-bb472e02e1bde04b02702cf72473f9a5dbcb983d.tar.bz2
rpm-bb472e02e1bde04b02702cf72473f9a5dbcb983d.zip
Convert to rpm-3.1 API.
CVS patchset: 3672 CVS date: 2000/04/12 18:21:40
Diffstat (limited to 'python')
-rw-r--r--python/rpmmodule.c74
-rw-r--r--python/upgrade.c132
2 files changed, 180 insertions, 26 deletions
diff --git a/python/rpmmodule.c b/python/rpmmodule.c
index 5f3ae7445..84b71ca48 100644
--- a/python/rpmmodule.c
+++ b/python/rpmmodule.c
@@ -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;
}
diff --git a/python/upgrade.c b/python/upgrade.c
index 4f7a5e365..413480ffa 100644
--- a/python/upgrade.c
+++ b/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);
}
}
-
+#ifndef DYING
+ }
+
+ rpmdbFreeIterator(mi);
+#else
+ }
+ if (h) {
headerFree(h);
- num = rpmdbNextRecNum(db, num);
+ 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++;
}