diff options
author | Thierry Vignaud <tv@mageia.org> | 2012-02-22 19:24:35 +0000 |
---|---|---|
committer | Thierry Vignaud <tv@mageia.org> | 2012-02-22 19:24:35 +0000 |
commit | 29d45cc6bec0ca0e7ad35be7c9d47e5e525e1261 (patch) | |
tree | 22bb38e43927204711850da8dc74b5df4c1f779b | |
parent | 17abf77cb6267459c5a2994bac333691b84462af (diff) | |
download | perl-URPM-29d45cc6bec0ca0e7ad35be7c9d47e5e525e1261.tar perl-URPM-29d45cc6bec0ca0e7ad35be7c9d47e5e525e1261.tar.gz perl-URPM-29d45cc6bec0ca0e7ad35be7c9d47e5e525e1261.tar.bz2 perl-URPM-29d45cc6bec0ca0e7ad35be7c9d47e5e525e1261.tar.xz perl-URPM-29d45cc6bec0ca0e7ad35be7c9d47e5e525e1261.zip |
(open_archive) switch from forking unpacker to using librpm
(backported from trunk)
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | URPM.xs | 75 |
2 files changed, 18 insertions, 58 deletions
@@ -5,6 +5,7 @@ - really prefer packages from first media, thus fixing downloading noarch packages from 32 bit repository (mga#1603) - support kernel 3.x in kmod resolution +- switch from forking unpacker to using librpm Version 3.38.1 - 16 November 2010 @@ -1000,9 +1000,10 @@ update_provides_files(URPM__Package pkg, HV *provides) { } } -int +FD_t open_archive(char *filename, pid_t *pid, int *empty_archive) { int fd; + FD_t rfd = NULL; struct { char header[4]; char toc_d_count[4]; @@ -1019,65 +1020,26 @@ open_archive(char *filename, pid_t *pid, int *empty_archive) { if (read(fd, &buf, sizeof(buf)) != sizeof(buf) || strncmp(buf.header, "cz[0", 4) || strncmp(buf.trailer, "0]cz", 4)) { /* this is not an archive, open it without magic, but first rewind at begin of file */ lseek(fd, 0, SEEK_SET); + return fdDup(fd); } else if (pos == 0) { *empty_archive = 1; - fd = -1; } else { - /* this is an archive, create a pipe and fork for reading with uncompress defined inside */ - int fdno[2]; - - if (!pipe(fdno)) { - if ((*pid = fork()) != 0) { - fd_set readfds; - struct timeval timeout; - - FD_ZERO(&readfds); - FD_SET(fdno[0], &readfds); - timeout.tv_sec = 1; - timeout.tv_usec = 0; - select(fdno[0]+1, &readfds, NULL, NULL, &timeout); - - close(fd); - fd = fdno[0]; - close(fdno[1]); - } else { - char *unpacker[22]; /* enough for 40 bytes in uncompress to never overbuf */ - char *p = buf.uncompress; - int ip = 0; - char *ld_loader = getenv("LD_LOADER"); - - if (ld_loader && *ld_loader) { - unpacker[ip++] = ld_loader; - } - - buf.trailer[0] = 0; /* make sure end-of-string is right */ - while (*p) { - if (*p == ' ' || *p == '\t') *p++ = 0; - else { - unpacker[ip++] = p; - while (*p && *p != ' ' && *p != '\t') ++p; - } - } - unpacker[ip] = NULL; /* needed for execlp */ - - lseek(fd, 0, SEEK_SET); - dup2(fd, STDIN_FILENO); close(fd); - dup2(fdno[1], STDOUT_FILENO); close(fdno[1]); - - /* get rid of "decompression OK, trailing garbage ignored" */ - fd = open("/dev/null", O_WRONLY); - dup2(fd, STDERR_FILENO); close(fd); - - execvp(unpacker[0], unpacker); - exit(1); - } + /* this is an archive, prepare for reading with uncompress defined inside */ + rfd = Fopen(filename, "r.fdio"); + if (strcmp(buf.uncompress, "gzip")) { + rfd = Fdopen(rfd, "r.gzip"); + } else if (strcmp(buf.uncompress, "bzip")) { + rfd = Fdopen(rfd, "r.bzip2"); + } else if (strcmp(buf.uncompress, "xz") || strcmp(buf.uncompress, "lzma")) { + rfd = Fdopen(rfd, "r.xz"); } else { - close(fd); - fd = -1; + free(rfd); + rfd = NULL; } } } - return fd; + close(fd); + return rfd; } static int @@ -3439,18 +3401,15 @@ Urpm_parse_hdlist__XS(urpm, filename, ...) if (depslist != NULL) { pid_t pid = 0; - int d; int empty_archive = 0; FD_t fd; - d = open_archive(filename, &pid, &empty_archive); - fd = fdDup(d); - close(d); + fd = open_archive(filename, &pid, &empty_archive); if (empty_archive) { XPUSHs(sv_2mortal(newSViv(1 + av_len(depslist)))); XPUSHs(sv_2mortal(newSViv(av_len(depslist)))); - } else if (d >= 0 && fd) { + } else if (fd != NULL && !Ferror(fd)) { Header header; int start_id = 1 + av_len(depslist); int packing = 0; |