From 0bfd57916d1bd03d7d271e367c5ccd41d2127acf Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Tue, 6 Mar 2007 18:34:09 +0000 Subject: [PATCH] Refactor compression filtering code. --- ChangeLog | 8 ++++++ debian/changelog | 1 + lib/compression.c | 68 +++++++++++++++-------------------------------- 3 files changed, 31 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6877dbe8..5a7c251c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-03-06 Guillem Jover + + * lib/compression.c (fd_fd_filter): New function, refactored. As + a side effect the 'failed to exec' string gets unified, and all + commands use oshite now. + (decompress_cat): Use fd_fd_filter instead of the duped code. + (compress_cat): Likewise. + 2007-03-06 Guillem Jover * scripts/dpkg-scanpackages.pl (usage): Documemt that the override diff --git a/debian/changelog b/debian/changelog index 6d36e64c..c497110d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -43,6 +43,7 @@ dpkg (1.14.0) UNRELEASED; urgency=low and dpkg-shlibdeps. Closes: #162348 * Cleaning and format unification of manual pages. * Make the override-file argument to dpkg-scanpackages optional. + * Refactor compression filtering code. [ Updated dpkg translations ] * Romanian (Eddy Petrișor). diff --git a/lib/compression.c b/lib/compression.c index cdafa362..5d096cf1 100644 --- a/lib/compression.c +++ b/lib/compression.c @@ -17,6 +17,23 @@ #include "dpkg.h" #include "dpkg-db.h" +static void +fd_fd_filter(int fd_in, int fd_out, + const char *file, const char *cmd, const char *args, + const char *desc) +{ + if (fd_in != 0) { + m_dup2(fd_in, 0); + close(fd_in); + } + if (fd_out != 1) { + m_dup2(fd_out, 1); + close(fd_out); + } + execlp(file, cmd, args, NULL); + ohshite(_("%s: failed to exec '%s %s'"), desc, cmd, args); +} + void decompress_cat(enum compression_type type, int fd_in, int fd_out, char *desc, ...) { va_list al; struct varbuf v; @@ -49,15 +66,7 @@ void decompress_cat(enum compression_type type, int fd_in, int fd_out, char *des } exit(0); #else - if (fd_in != 0) { - m_dup2(fd_in, 0); - close(fd_in); - } - if (fd_out != 1) { - m_dup2(fd_out, 1); - close(fd_out); - } - execlp(GZIP,"gzip","-dc",(char*)0); ohshite(_("%s: failed to exec gzip -dc"), v.buf); + fd_fd_filter(fd_in, fd_out, GZIP, "gzip", "-dc", v.buf); #endif case BZ2: #ifdef WITH_BZ2 @@ -80,27 +89,10 @@ void decompress_cat(enum compression_type type, int fd_in, int fd_out, char *des } exit(0); #else - if (fd_in != 0) { - m_dup2(fd_in, 0); - close(fd_in); - } - if (fd_out != 1) { - m_dup2(fd_out, 1); - close(fd_out); - } - execlp(BZIP2,"bzip2","-dc",(char*)0); ohshite(_("%s: failed to exec bzip2 -dc"), v.buf); + fd_fd_filter(fd_in, fd_out, BZIP2, "bzip2", "-dc", v.buf); #endif case compress_type_lzma: - if (fd_in != 0) { - m_dup2(fd_in, 0); - close(fd_in); - } - if (fd_out != 1) { - m_dup2(fd_out, 1); - close(fd_out); - } - execlp(LZMA, "lzma", "-dc", (char *)0); - ohshite(_("%s: failed to exec %s"), v.buf, "lzma -dc"); + fd_fd_filter(fd_in, fd_out, LZMA, "lzma", "-dc", v.buf); case CAT: fd_fd_copy(fd_in, fd_out, -1, _("%s: decompression"), v.buf); exit(0); @@ -155,17 +147,9 @@ void compress_cat(enum compression_type type, int fd_in, int fd_out, const char exit(0); } #else - if (fd_in != 0) { - m_dup2(fd_in, 0); - close(fd_in); - } - if (fd_out != 1) { - m_dup2(fd_out, 1); - close(fd_out); - } strncpy(combuf, "-9c", sizeof(combuf)); combuf[1]= *compression; - execlp(GZIP,"gzip",combuf,(char*)0); ohshit(_("%s: failed to exec gzip %s"), v.buf, combuf); + fd_fd_filter(fd_in, fd_out, GZIP, "gzip", combuf, v.buf); #endif case BZ2: #ifdef WITH_BZ2 @@ -198,17 +182,9 @@ void compress_cat(enum compression_type type, int fd_in, int fd_out, const char exit(0); } #else - if (fd_in != 0) { - m_dup2(fd_in, 0); - close(fd_in); - } - if (fd_out != 1) { - m_dup2(fd_out, 1); - close(fd_out); - } strncpy(combuf, "-9c", sizeof(combuf)); combuf[1]= *compression; - execlp(BZIP2,"bzip2",combuf,(char*)0); ohshit(_("%s: failed to exec bzip2 %s"), v.buf, combuf); + fd_fd_filter(fd_in, fd_out, BZIP2, "bzip2", combuf, v.buf); #endif case CAT: fd_fd_copy(fd_in, fd_out, -1, _("%s: compression"), v.buf); -- 2.39.5