aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <thierry.vignaud@gmail.com>2020-05-03 02:52:48 +0200
committerThierry Vignaud <thierry.vignaud@gmail.com>2020-05-04 18:04:40 +0200
commitb69c5a49cd00d1748509599fcee6967ea0ec0987 (patch)
treee957aad9ed3cb44ce12a2761293b355610b6e8d9
parent6a48db05e192f766e7b5f6312c3c3ae518d0a1e6 (diff)
downloadperl-URPM-b69c5a49cd00d1748509599fcee6967ea0ec0987.tar
perl-URPM-b69c5a49cd00d1748509599fcee6967ea0ec0987.tar.gz
perl-URPM-b69c5a49cd00d1748509599fcee6967ea0ec0987.tar.bz2
perl-URPM-b69c5a49cd00d1748509599fcee6967ea0ec0987.tar.xz
perl-URPM-b69c5a49cd00d1748509599fcee6967ea0ec0987.zip
split open_compressed_file()
-rw-r--r--URPM.xs45
1 files changed, 26 insertions, 19 deletions
diff --git a/URPM.xs b/URPM.xs
index 11dbf15..4b7658c 100644
--- a/URPM.xs
+++ b/URPM.xs
@@ -981,6 +981,29 @@ update_provides_files(const URPM__Package pkg, HV *provides) {
}
}
+static FD_t open_compressed_file(char *filename) {
+ char *t;
+ rpmCompressedMagic compressed = COMPRESSED_OTHER;
+ int rc = rpmFileIsCompressed(filename, &compressed);
+ switch (compressed) {
+ case COMPRESSED_BZIP2: t = "r.bzip2"; break;
+ case COMPRESSED_LZMA:
+ case COMPRESSED_XZ:
+ t = "r.xz"; break;
+#ifdef RPM4_14_0
+ case COMPRESSED_ZSTD:
+ t = "r.zstd"; break;
+#endif
+ case COMPRESSED_OTHER:
+ default:
+ t = "r.gzip"; break;
+ }
+ if (rc)
+ return NULL;
+ FD_t f = Fopen(filename, "r.fdio");
+ return Fdopen(f, t);
+}
+
static FD_t
open_archive(char *filename, int *empty_archive) {
int fd;
@@ -2911,13 +2934,12 @@ Urpm_parse_synthesis__XS(urpm, filename, ...)
if (depslist != NULL) {
char buff[65536*2];
- char *p, *eol, *t;
+ char *p, *eol;
int buff_len;
struct s_Package pkg;
FD_t f = NULL;
int start_id = 1 + av_len(depslist);
SV *callback = NULL;
- rpmCompressedMagic compressed = COMPRESSED_OTHER;
if (items > 2) {
int i;
@@ -2931,24 +2953,9 @@ Urpm_parse_synthesis__XS(urpm, filename, ...)
}
PUTBACK;
- int rc = rpmFileIsCompressed(filename, &compressed);
-
- switch (compressed) {
- case COMPRESSED_BZIP2: t = "r.bzip2"; break;
- case COMPRESSED_LZMA:
- case COMPRESSED_XZ:
- t = "r.xz"; break;
-#ifdef RPM4_14_0
- case COMPRESSED_ZSTD:
- t = "r.zstd"; break;
-#endif
- case COMPRESSED_OTHER:
- default:
- t = "r.gzip"; break;
- }
- f = Fopen(filename, "r.fdio");
+ f = open_compressed_file(filename);
- if (!rc && (f = Fdopen(f, t)) != NULL && !Ferror(f)) {
+ if (f != NULL && !Ferror(f)) {
// initialize first package
memset(&pkg, 0, sizeof(struct s_Package));
buff[sizeof(buff)-1] = 0;