aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--rpmtools.pm38
-rw-r--r--rpmtools.spec9
-rw-r--r--rpmtools.xs150
4 files changed, 126 insertions, 73 deletions
diff --git a/Makefile b/Makefile
index 4d8bbad..a9b903f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION = 2.1
+VERSION = 2.2
NAME = rpmtools
FROMC = parsehdlist rpm2header #rpm-find-leaves
FROMCC = #gendepslist2 hdlist2names hdlist2files hdlist2prereq hdlist2groups
diff --git a/rpmtools.pm b/rpmtools.pm
index 7843604..418e81a 100644
--- a/rpmtools.pm
+++ b/rpmtools.pm
@@ -6,7 +6,7 @@ use vars qw($VERSION @ISA);
require DynaLoader;
@ISA = qw(DynaLoader);
-$VERSION = '0.03';
+$VERSION = '0.04';
bootstrap rpmtools $VERSION;
@@ -25,8 +25,21 @@ rpmtools - Mandrake perl tools to handle rpm files and hdlist files
$params->read_rpms("/RPMS/rpmtools-2.1-5mdk.i586.rpm");
$params->compute_depslist();
- $params->get_packages_installed("", \@packages, \@names);
- $params->get_all_packages_installed("", \@packages);
+ my $db = $params->db_open("");
+ $params->db_traverse_names($db,
+ [ qw(name version release) ],
+ \@names,
+ sub {
+ my ($p) = @_;
+ print "$p->{name}-$p->{version}-$p->{release}\n";
+ });
+ $params->db_traverse($db,
+ [ qw(name version release) ],
+ sub {
+ my ($p) = @_;
+ print "$p->{name}-$p->{version}-$p->{release}\n";
+ });
+ $params->db_close($db);
$params->read_depslist(\*STDIN);
$params->write_depslist(\*STDOUT);
@@ -194,7 +207,7 @@ sub compute_depslist {
#- the package has been read from an ordered depslist file, and need
#- to rebuild its requires tags, so it can safely be used here.
my @rebuild_requires;
- foreach (split /\s+/, $info->{deps}) {
+ foreach (split ' ', $info->{deps}) {
if (/\|/) {
push @rebuild_requires, [ map { $params->{depslist}[$_]{name} || $_ } split /\|/, $_ ];
} else {
@@ -343,7 +356,7 @@ sub read_depslist {
#- safely be removed from requires of others packages.
if ($params->{info}{basesystem} && ! exists $params->{info}{basesystem}{base}) {
my @requires_id;
- foreach (split /\s+/, $params->{info}{basesystem}{deps}) {
+ foreach (split ' ', $params->{info}{basesystem}{deps}) {
/\|/ or push @requires_id, $_;
}
foreach (@requires_id) {
@@ -530,4 +543,19 @@ sub version_compare {
}
}
+#- compability function which should be removed soon, do not use anymore and replace code.
+sub get_packages_installed {
+ my ($prefix, $packages, $names, $flags) = @_; $flags ||= [ qw(name version release)];
+ my $db = db_open($prefix);
+ my $count = db_traverse_names($db, $flags, $names, sub { my ($p) = @_; push @$packages, $p; });
+ db_close($db);
+ $count;
+}
+sub get_all_packages_installed {
+ my ($prefix, $packages, $flags) = @_; $flags ||= [ qw(name version release)];
+ my $db = db_open($prefix);
+ my $count = db_traverse($db, $flags, sub { my ($p) = @_; push @$packages, $p; });
+ db_close($db);
+ $count;
+}
1;
diff --git a/rpmtools.spec b/rpmtools.spec
index bb1c436..3be4046 100644
--- a/rpmtools.spec
+++ b/rpmtools.spec
@@ -1,8 +1,8 @@
%define name rpmtools
-%define release 10mdk
+%define release 1mdk
# do not modify here, see Makefile in the CVS
-%define version 2.1
+%define version 2.2
Summary: Contains various rpm command-line tools
Name: %{name}
@@ -51,6 +51,11 @@ rm -rf $RPM_BUILD_ROOT
%{_libdir}/perl5/man/*/*
%changelog
+* Sat Feb 10 2001 François Pons <fpons@mandrakesoft.com> 2.2-1mdk
+- added faster method to access rpm db to rpmtools.xs
+ as in DrakX.
+- rpmtools.pm to 0.04.
+
* Tue Jan 30 2001 François Pons <fpons@mandrakesoft.com> 2.1-10mdk
- fixed bug of NOTFOUND_6 in depslist computation.
- fixed depslist relocation bug.
diff --git a/rpmtools.xs b/rpmtools.xs
index 07b35b4..1b80442 100644
--- a/rpmtools.xs
+++ b/rpmtools.xs
@@ -282,103 +282,123 @@ HV* get_info(Header header, int bflag, HV* provides) {
return header_info;
}
+void callback_empty(void) {}
MODULE = rpmtools PACKAGE = rpmtools
+void*
+db_open(prefix)
+ char *prefix
+ CODE:
+ rpmdb db;
+ rpmErrorCallBackType old_cb;
+ old_cb = rpmErrorSetCallback(callback_empty);
+ rpmSetVerbosity(RPMMESS_FATALERROR);
+ RETVAL = rpmReadConfigFiles(NULL, NULL) == 0 && rpmdbOpen(prefix, &db, O_RDONLY, 0644) == 0 ? db : NULL;
+ rpmErrorSetCallback(old_cb);
+ rpmSetVerbosity(RPMMESS_NORMAL);
+ OUTPUT:
+ RETVAL
+
+void
+db_close(db)
+ void *db
+ CODE:
+ rpmdbClose((rpmdb)db);
+
+void
+_exit(code)
+ int code
+
int
-get_packages_installed(prefix, packages, lnames, ...)
- char* prefix
- SV* packages
- SV* lnames
+db_traverse_names(db, flags, names, callback)
+ void *db
+ SV *flags
+ SV *names
+ SV *callback
PREINIT:
- SV* flags = &PL_sv_undef;
int count = 0;
CODE:
- if (items > 3)
- flags = ST(3);
- if (SvROK(packages) && SvTYPE(SvRV(packages)) == SVt_PVAV &&
- SvROK(lnames) && SvTYPE(SvRV(lnames)) == SVt_PVAV) {
- AV* pkgs = (AV*)SvRV(packages);
- AV* names = (AV*)SvRV(lnames);
+ if (SvROK(flags) && SvTYPE(SvRV(flags)) == SVt_PVAV &&
+ SvROK(names) && SvTYPE(SvRV(names)) == SVt_PVAV) {
+ AV* flags_av = (AV*)SvRV(flags);
+ AV* names_av = (AV*)SvRV(names);
+ int bflag = get_bflag(flags_av);
+ int len = av_len(names_av);
HV* info;
SV** isv;
- rpmdb db;
- dbiIndexSet matches;
- int bflag, num, i, j, rc, len;
+ int i;
+ STRLEN str_len;
char *name;
Header header;
rpmdbMatchIterator mi;
- if (rpmReadConfigFiles(NULL, NULL) == 0) {
- if (rpmdbOpen(prefix, &db, O_RDONLY, 0644) == 0) {
- bflag = SvROK(flags) && SvTYPE(SvRV(flags)) ?
- get_bflag((AV*)SvRV(flags)) : (HDFLAGS_NAME | HDFLAGS_VERSION | HDFLAGS_RELEASE);
- len = av_len(names);
- for (j = 0; j <= len; ++j) {
- isv = av_fetch(names, j, 0);
- name = SvPV_nolen(*isv);
- mi = rpmdbInitIterator(db, RPMTAG_NAME, name, 0);
- count=0;
- while (header = rpmdbNextIterator(mi)) {
- count++;
- info = get_info(header, bflag, NULL);
-
- if (info != 0) av_push(pkgs, newRV_noinc((SV*)info));
-
- headerFree(header);
- }
+ for (i = 0; i <= len; ++i) {
+ isv = av_fetch(names_av, i, 0);
+ name = SvPV(*isv, str_len);
+ mi = rpmdbInitIterator((rpmdb)db, RPMTAG_NAME, name, str_len);
+ while (header = rpmdbNextIterator(mi)) {
+ count++;
+ info = get_info(header, bflag, NULL);
+
+ if (info != 0 && callback != &PL_sv_undef && SvROK(callback)) {
+ dSP;
+ ENTER;
+ SAVETMPS;
+ PUSHMARK(SP);
+ XPUSHs(sv_2mortal(newRV_noinc((SV*)info)));
+ PUTBACK;
+ call_sv(callback, G_DISCARD | G_SCALAR);
+ FREETMPS;
+ LEAVE;
}
- rpmdbClose(db);
- } else croak("unable to open database");
- } else croak("cannot read rpm config files");
+ }
+ rpmdbFreeIterator(mi);
+ }
} else croak("bad arguments list");
RETVAL = count;
OUTPUT:
RETVAL
-
int
-get_all_packages_installed(prefix, packages, ...)
- char* prefix
- SV* packages
+db_traverse(db, flags, callback)
+ void *db
+ SV *flags
+ SV *callback
PREINIT:
- SV* flags = &PL_sv_undef;
int count = 0;
CODE:
- if (items > 2)
- flags = ST(2);
- if (SvROK(packages) && SvTYPE(SvRV(packages)) == SVt_PVAV) {
- AV* pkgs = (AV*)SvRV(packages);
+ if (SvROK(flags) && SvTYPE(SvRV(flags)) == SVt_PVAV) {
+ AV* flags_av = (AV*)SvRV(flags);
+ int bflag = get_bflag(flags_av);
HV* info;
- rpmdb db;
- int bflag, num;
Header header;
rpmdbMatchIterator mi;
-
- if (rpmReadConfigFiles(NULL, NULL) == 0) {
- if (rpmdbOpen(prefix, &db, O_RDONLY, 0644) == 0) {
- bflag = SvROK(flags) && SvTYPE(SvRV(flags)) ?
- get_bflag((AV*)SvRV(flags)) : (HDFLAGS_NAME | HDFLAGS_VERSION | HDFLAGS_RELEASE);
- mi = rpmdbInitIterator(db, RPMDBI_PACKAGES, NULL, 0);
-
- while (header = rpmdbNextIterator(mi)) {
- info = get_info(header, bflag, NULL);
-
- if (info != 0) av_push(pkgs, newRV_noinc((SV*)info));
-
- headerFree(header);
- ++count;
- }
- rpmdbClose(db);
- } else croak("unable to open database");
- } else croak("cannot read rpm config files");
+
+ mi = rpmdbInitIterator(db, RPMDBI_PACKAGES, NULL, 0);
+ while (header = rpmdbNextIterator(mi)) {
+ info = get_info(header, bflag, NULL);
+
+ if (info != 0 && callback != &PL_sv_undef && SvROK(callback)) {
+ dSP;
+ ENTER;
+ SAVETMPS;
+ PUSHMARK(SP);
+ XPUSHs(sv_2mortal(newRV_noinc((SV*)info)));
+ PUTBACK;
+ call_sv(callback, G_DISCARD | G_SCALAR);
+ FREETMPS;
+ LEAVE;
+ }
+ ++count;
+ }
+ rpmdbFreeIterator(mi);
} else croak("bad arguments list");
RETVAL = count;
OUTPUT:
RETVAL
-
void
_parse_(fileno_or_rpmfile, flag, info, ...)
SV* fileno_or_rpmfile