diff options
author | Thierry Vignaud <tv@mageia.org> | 2012-06-26 18:23:05 +0000 |
---|---|---|
committer | Thierry Vignaud <tv@mageia.org> | 2012-06-26 18:23:05 +0000 |
commit | c5cc5f1aca642525e7e53241f742e93ebbeaa2b6 (patch) | |
tree | 6132fb9fdda5a3511b0d968a145f0ef64913c2aa | |
parent | d7810ba7ecf037fcb276e226bcd0e16ccad3a325 (diff) | |
download | perl-URPM-c5cc5f1aca642525e7e53241f742e93ebbeaa2b6.tar perl-URPM-c5cc5f1aca642525e7e53241f742e93ebbeaa2b6.tar.gz perl-URPM-c5cc5f1aca642525e7e53241f742e93ebbeaa2b6.tar.bz2 perl-URPM-c5cc5f1aca642525e7e53241f742e93ebbeaa2b6.tar.xz perl-URPM-c5cc5f1aca642525e7e53241f742e93ebbeaa2b6.zip |
(parse_synthesis__XS) enable to read xz & bzip2 compressed synthesis
(backported from trunk)
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | URPM.xs | 33 | ||||
-rw-r--r-- | t/synthesis.t | 18 |
3 files changed, 38 insertions, 15 deletions
@@ -1,3 +1,5 @@ +- enable to read xz & bzip2 compressed synthesis + Version 3.40 - 16 March 2012 - add URPM::traverse_tag_find() for urpme --env @@ -20,7 +20,6 @@ #include <sys/wait.h> #include <fcntl.h> #include <unistd.h> -#include <zlib.h> #include <libintl.h> #undef Fflush @@ -3294,12 +3293,13 @@ Urpm_parse_synthesis__XS(urpm, filename, ...) if (depslist != NULL) { char buff[65536]; - char *p, *eol; + char *p, *eol, *t; int buff_len; struct s_Package pkg; - gzFile f; + FD_t f = NULL; int start_id = 1 + av_len(depslist); SV *callback = NULL; + rpmCompressedMagic compressed = COMPRESSED_OTHER; if (items > 2) { int i; @@ -3313,12 +3313,25 @@ Urpm_parse_synthesis__XS(urpm, filename, ...) } PUTBACK; - if ((f = gzopen(filename, "rb")) != NULL) { + int rc = rpmFileIsCompressed(filename, &compressed); + + switch (compressed) { + case COMPRESSED_BZIP2: t = "r.bzip2"; break; + case COMPRESSED_LZMA: + case COMPRESSED_XZ: + t = "r.xz"; break; + case COMPRESSED_OTHER: + default: + t = "r.gzip"; break; + } + f = Fopen(filename, "r.fdio"); + + if (!rc && (f = Fdopen(f, t)) != NULL && !Ferror(f)) { memset(&pkg, 0, sizeof(struct s_Package)); buff[sizeof(buff)-1] = 0; p = buff; int ok = 1; - while ((buff_len = gzread(f, p, sizeof(buff)-1-(p-buff))) >= 0 && + while ((buff_len = Fread(p, sizeof(buff)-1-(p-buff), 1, f)) >= 0 && (buff_len += p-buff)) { buff[buff_len] = 0; p = buff; @@ -3334,17 +3347,15 @@ Urpm_parse_synthesis__XS(urpm, filename, ...) ok = 0; break; } - if (gzeof(f)) { - if (!parse_line(depslist, provides, obsoletes, &pkg, p, urpm, callback)) ok = 0; - break; - } else { /* move the remaining non-complete-line at beginning */ memmove(buff, p, buff_len-(p-buff)); /* point to the end of the non-complete-line */ p = &buff[buff_len-(p-buff)]; - } } - if (gzclose(f) != 0) ok = 0; + // EOF: + if (!parse_line(depslist, provides, obsoletes, &pkg, p, urpm, callback)) + ok = 0; + if (Fclose(f) != 0) ok = 0; SPAGAIN; if (ok) { mXPUSHs(newSViv(start_id)); diff --git a/t/synthesis.t b/t/synthesis.t index 6729b3b..8961e2a 100644 --- a/t/synthesis.t +++ b/t/synthesis.t @@ -2,29 +2,39 @@ use strict ; use warnings ; -use Test::More tests => 94; +use Test::More tests => 95; use URPM; chdir 't' if -d 't'; my $file1 = 'synthesis.sample.cz'; +my $file2 = 'synthesis.sample-xz.cz'; -open my $f, "| gzip -9 >$file1"; -print $f <<'EOF'; +my $s = <<'EOF'; @provides@glibc-devel == 6:2.2.4-25mdk @requires@/sbin/install-info@glibc == 2.2.4@kernel-headers@kernel-headers >= 2.2.1@/bin/sh@/bin/sh@/bin/sh@rpmlib(PayloadFilesHavePrefix) <= 4.0-1@rpmlib(CompressedFileNames) <= 3.0.4-1 @conflicts@texinfo < 3.11@gcc < 2.96-0.50mdk @obsoletes@libc-debug@libc-headers@libc-devel@linuxthreads-devel@glibc-debug @info@glibc-devel-2.2.4-25mdk.i586@6@45692097@Development/C EOF +open my $f, "| gzip -9 >$file1"; +print $f $s; +close $f; +open my $f, "| xz -9 >$file2"; +print $f $s; +$s =~ s/-devel//g; +print $f $s; close $f; -END { unlink $file1 } +END { unlink $file1, $file2 } my $a = new URPM; ok($a); my ($first, $end); +($first, $end) = URPM->new->parse_synthesis($file2); +ok($first == 0 && $end == 1, 'parse XZ synthesis'); + ($first, $end) = URPM->new->parse_synthesis('empty_synthesis.cz'); is("$first $end", "0 -1", 'parse empty synthesis'); |