aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPer Øyvind Karlsen <peroyvind@mandriva.org>2010-12-10 17:52:57 +0000
committerPer Øyvind Karlsen <peroyvind@mandriva.org>2010-12-10 17:52:57 +0000
commit60367f5a047b79e4481bbbb4dd7e75d059a3296b (patch)
tree0b4a4333bb3d464a2e3c84459d45033a61fa14e8
parent95bc9bd7128fdd360f39df62a9406726a7fb6177 (diff)
downloadperl-URPM-60367f5a047b79e4481bbbb4dd7e75d059a3296b.tar
perl-URPM-60367f5a047b79e4481bbbb4dd7e75d059a3296b.tar.gz
perl-URPM-60367f5a047b79e4481bbbb4dd7e75d059a3296b.tar.bz2
perl-URPM-60367f5a047b79e4481bbbb4dd7e75d059a3296b.tar.xz
perl-URPM-60367f5a047b79e4481bbbb4dd7e75d059a3296b.zip
replace broken hdlist parsing code with working rpmgi hdlist iterator from rpmlib
-rw-r--r--NEWS2
-rw-r--r--URPM.xs80
2 files changed, 42 insertions, 40 deletions
diff --git a/NEWS b/NEWS
index d3bc3e6..d487e14 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,6 @@
Version 4.3 -
+- fix broken support for parsing hdlists, use rpmgi iterator from rpmlib to
+ simplify code and get packages ordered as an extra benefit in the process.
- URPM::Package::fullname will now always return six items for array in stead
of four to make room for disttag & distepoch, arch will still be returned as
last item (ie. array[5] in stead of array[3]) (#61702)
diff --git a/URPM.xs b/URPM.xs
index da91349..2978fea 100644
--- a/URPM.xs
+++ b/URPM.xs
@@ -27,6 +27,7 @@
#undef Stat
#undef Fstat
+#define _RPMGI_INTERNAL
#define _RPMEVR_INTERNAL
#define _RPMPS_INTERNAL
@@ -38,6 +39,7 @@
#include <rpmte.h>
#include <rpmps.h>
#include <rpmbuild.h>
+#include <rpmgi.h>
#include <rpmlog.h>
#include "xfile.h"
@@ -3462,10 +3464,12 @@ Urpm_parse_hdlist__XS(urpm, filename, ...)
close(d);
if (empty_archive) {
- XPUSHs(sv_2mortal(newSViv(1 + av_len(depslist))));
- XPUSHs(sv_2mortal(newSViv(av_len(depslist))));
+ XPUSHs(sv_2mortal(newSViv(1 + av_len(depslist))));
+ XPUSHs(sv_2mortal(newSViv(av_len(depslist))));
} else if (d >= 0 && fd) {
- Header header;
+ rpmts ts = NULL;
+ rpmgi gi = NULL;
+ rpmRC rc = RPMRC_NOTFOUND;
int start_id = 1 + av_len(depslist);
int packing = 0;
SV *callback = NULL;
@@ -3488,43 +3492,39 @@ Urpm_parse_hdlist__XS(urpm, filename, ...)
}
PUTBACK;
- do {
- const char item[] = "Header";
- const char * msg = NULL;
- rpmRC rc = rpmpkgRead(item, fd, &header, &msg);
-
- switch (rc) {
- default:
- rpmlog(RPMLOG_ERR, "%s: %s: %s\n", "rpmpkgRead", item, msg);
- case RPMRC_NOTFOUND:
- header = NULL;
- case RPMRC_OK:
- break;
- }
- msg = (const char*)_free(msg);
-
- if (header != NULL) {
- struct s_Package pkg, *_pkg;
- SV *sv_pkg;
-
- memset(&pkg, 0, sizeof(struct s_Package));
- pkg.flag = 1 + av_len(depslist);
- pkg.h = header;
- sv_pkg = sv_setref_pv(newSVpv("", 0), "URPM::Package",
- _pkg = memcpy(malloc(sizeof(struct s_Package)), &pkg, sizeof(struct s_Package)));
- if (call_package_callback(urpm, sv_pkg, callback)) {
- if (provides) {
- update_provides(_pkg, provides);
- update_provides_files(_pkg, provides);
- }
- if (obsoletes) update_obsoletes(_pkg, obsoletes);
- if (packing) pack_header(_pkg);
- av_push(depslist, sv_pkg);
+ rc = RPMRC_NOTFOUND;
+ ts = rpmtsCreate();
+ rpmtsSetRootDir(ts, NULL);
+ gi = rpmgiNew(ts, RPMDBI_HDLIST, NULL, 0);
+
+ rpmtsSetVSFlags(ts, _RPMVSF_NOSIGNATURES | RPMVSF_NOHDRCHK | _RPMVSF_NOPAYLOAD | _RPMVSF_NOHEADER);
+ gi->active = 1;
+ gi->fd = fd;
+ while ((rc = rpmgiNext(gi)) == RPMRC_OK) {
+ struct s_Package pkg, *_pkg;
+ SV *sv_pkg;
+
+ memset(&pkg, 0, sizeof(struct s_Package));
+ pkg.flag = 1 + av_len(depslist);
+ pkg.h = rpmgiHeader(gi);
+ /* prevent rpmgiNext() from freeing header */
+ gi->h = NULL;
+ sv_pkg = sv_setref_pv(newSVpv("", 0), "URPM::Package",
+ _pkg = memcpy(malloc(sizeof(struct s_Package)), &pkg, sizeof(struct s_Package)));
+ if (call_package_callback(urpm, sv_pkg, callback)) {
+ if (provides) {
+ update_provides(_pkg, provides);
+ update_provides_files(_pkg, provides);
}
+ if (obsoletes) update_obsoletes(_pkg, obsoletes);
+ if (packing) pack_header(_pkg);
+ av_push(depslist, sv_pkg);
}
- } while (header != NULL);
+ }
+ gi = rpmgiFree(gi);
+ ts = rpmtsFree(ts);
- int ok = Fclose(fd) == 0;
+ int ok;
if (pid) {
kill(pid, SIGTERM);
@@ -3541,9 +3541,9 @@ Urpm_parse_hdlist__XS(urpm, filename, ...)
XPUSHs(sv_2mortal(newSViv(av_len(depslist))));
}
} else {
- SV **nofatal = hv_fetch((HV*)SvRV(urpm), "nofatal", 7, 0);
- if (!nofatal || !SvIV(*nofatal))
- croak("cannot open hdlist file %s", filename);
+ SV **nofatal = hv_fetch((HV*)SvRV(urpm), "nofatal", 7, 0);
+ if (!nofatal || !SvIV(*nofatal))
+ croak("cannot open hdlist file %s", filename);
}
} else croak("first argument should contain a depslist ARRAY reference");
} else croak("first argument should be a reference to a HASH");