aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederic Lepied <flepied@mandriva.com>2000-10-19 12:26:49 +0000
committerFrederic Lepied <flepied@mandriva.com>2000-10-19 12:26:49 +0000
commitac2e4abe983f7de769ecef5e35f9c33f0bc88d7d (patch)
tree0bf54e676118f1acaf3727a15033c9afb81e489f
parent22043e605df0b810c7c688ee96c2a3caffe85f56 (diff)
downloadrpmtools-ac2e4abe983f7de769ecef5e35f9c33f0bc88d7d.tar
rpmtools-ac2e4abe983f7de769ecef5e35f9c33f0bc88d7d.tar.gz
rpmtools-ac2e4abe983f7de769ecef5e35f9c33f0bc88d7d.tar.bz2
rpmtools-ac2e4abe983f7de769ecef5e35f9c33f0bc88d7d.tar.xz
rpmtools-ac2e4abe983f7de769ecef5e35f9c33f0bc88d7d.zip
use iterators.
-rw-r--r--rpm-find-leaves.c5
-rw-r--r--rpmtools.xs27
2 files changed, 16 insertions, 16 deletions
diff --git a/rpm-find-leaves.c b/rpm-find-leaves.c
index c72337a..45e2e29 100644
--- a/rpm-find-leaves.c
+++ b/rpm-find-leaves.c
@@ -28,17 +28,18 @@ int main() {
int numConflicts;
rpmdb db;
int i;
+ rpmdbMatchIterator mi;
rpmReadConfigFiles(NULL, NULL);
db = open_rpmdb();
- for(i = rpmdbFirstRecNum(db); i; i = rpmdbNextRecNum(db, i)) {
+ while(header = rpmdbNextIterator(mi)) {
trans = rpmtransCreateSet(db, NULL);
+ i=rpmdbGetIteratorOffset(mi);
rpmtransRemovePackage(trans, i);
if (rpmdepCheck(trans, &conflicts, &numConflicts)) die("rpmdepCheck");
if (numConflicts == 0) {
- header = rpmdbGetRecord(db, i);
printf("%s-%s-%s\n", get(RPMTAG_NAME), get(RPMTAG_VERSION), get(RPMTAG_RELEASE));
headerFree(header);
}
diff --git a/rpmtools.xs b/rpmtools.xs
index b7621e0..01bbdfd 100644
--- a/rpmtools.xs
+++ b/rpmtools.xs
@@ -146,24 +146,23 @@ get_packages_installed(prefix, packages, lnames)
int num, i, j, rc, len;
char *name;
Header header;
-
+ rpmdbMatchIterator mi;
+
if (rpmReadConfigFiles(NULL, NULL) == 0) {
if (rpmdbOpen(prefix, &db, O_RDONLY, 0644) == 0) {
len = av_len(names);
for (j = 0; j <= len; ++j) {
isv = av_fetch(names, j, 0);
name = SvPV_nolen(*isv);
- rc = rpmdbFindPackage(db, name, &matches);
- if (rc == 0) {
- count += matches.count;
- for (i = 0; i < matches.count; ++i) {
- header = rpmdbGetRecord(db, matches.recs[i].recOffset);
- info = get_info(header);
+ mi = rpmdbInitIterator(db, RPMTAG_NAME, name, 0);
+ count=0;
+ while (header = rpmdbNextIterator(mi)) {
+ count++;
+ info = get_info(header);
- if (info != 0) av_push(pkgs, newRV_noinc((SV*)info));
+ if (info != 0) av_push(pkgs, newRV_noinc((SV*)info));
- headerFree(header);
- }
+ headerFree(header);
}
}
rpmdbClose(db);
@@ -188,18 +187,18 @@ get_all_packages_installed(prefix, packages)
rpmdb db;
int num;
Header header;
+ rpmdbMatchIterator mi;
if (rpmReadConfigFiles(NULL, NULL) == 0) {
if (rpmdbOpen(prefix, &db, O_RDONLY, 0644) == 0) {
- num = rpmdbFirstRecNum(db);
- while (num > 0) {
- header = rpmdbGetRecord(db, num);
+ mi = rpmdbInitIterator(db, RPMDBI_PACKAGES, NULL, 0);
+
+ while (header = rpmdbNextIterator(mi)) {
info = get_info(header);
if (info != 0) av_push(pkgs, newRV_noinc((SV*)info));
headerFree(header);
- num = rpmdbNextRecNum(db, num);
++count;
}
rpmdbClose(db);