Mageia Bugzilla – Attachment 1183 Details for
Bug 1962
genhdlist2 doesn't reuse most of the existing hdlist
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
[patch]
old patch of mine trying to use librpm, now working fine with previous rpm patch
URPM4.diff (text/plain), 3.62 KB, created by
Thierry Vignaud
on 2011-12-06 16:18:31 CET
(
hide
)
Description:
old patch of mine trying to use librpm, now working fine with previous rpm patch
Filename:
MIME Type:
Creator:
Thierry Vignaud
Created:
2011-12-06 16:18:31 CET
Size:
3.62 KB
patch
obsolete
>(open_archive) switch from forking unpacker to using librpm >--- URPM.xs 2011-12-06 14:57:46.606581011 +0000 >+++ /URPM.xs 2011-10-11 14:59:42.972840095 +0000 >@@ -1000,9 +1000,10 @@ update_provides_files(URPM__Package pkg, > } > } > >-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, > 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 >@@ -1420,6 +1382,8 @@ int rpmtag_from_string(char *tag) > return RPMTAG_TRIGGERNAME; > else if (!strcmp(tag, "path")) > return RPMTAG_BASENAMES; >+ else if (!strcmp(tag, "nvra")) >+ return RPMTAG_NVRA; > else croak("unknown tag [%s]", tag); > } > >@@ -3439,18 +3403,17 @@ 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)) { >+ fprintf(stderr, "Failed to open hdlist: %s\n", Fstrerror(fd)); >+ } else if (fd) { > Header header; > int start_id = 1 + av_len(depslist); > int packing = 0;
(open_archive) switch from forking unpacker to using librpm --- URPM.xs 2011-12-06 14:57:46.606581011 +0000 +++ /URPM.xs 2011-10-11 14:59:42.972840095 +0000 @@ -1000,9 +1000,10 @@ update_provides_files(URPM__Package pkg, } } -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, 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 @@ -1420,6 +1382,8 @@ int rpmtag_from_string(char *tag) return RPMTAG_TRIGGERNAME; else if (!strcmp(tag, "path")) return RPMTAG_BASENAMES; + else if (!strcmp(tag, "nvra")) + return RPMTAG_NVRA; else croak("unknown tag [%s]", tag); } @@ -3439,18 +3403,17 @@ 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)) { + fprintf(stderr, "Failed to open hdlist: %s\n", Fstrerror(fd)); + } else if (fd) { Header header; int start_id = 1 + av_len(depslist); int packing = 0;
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1962
:
1181
|
1182
| 1183 |
1184