pristine-tar: handle properly Perl gzips
authorFaidon Liambotis <paravoid@debian.org>
Mon, 14 Mar 2011 23:45:23 +0000 (01:45 +0200)
committerJoey Hess <joey@kitenet.net>
Tue, 15 Mar 2011 03:45:44 +0000 (23:45 -0400)
Perl's Compress::Raw::Zlib interfaces directly with zlib and
apparently is the only implementation out there which tunes a very
specific parameter of zlib, memLevel, to 9, instead of 8 which is
the default.

The module is used, among others, by Compress::Gzip which in turn is
used by IO::Zlib.

It was found on the real world on tarballs generated by Perl 5.10's
Module::Build (cf. #618284)

debian/changelog
pristine-gz
zgz/zgz.c

index b97062a..aa6003f 100644 (file)
@@ -1,3 +1,10 @@
+pristine-tar (1.13) unstable; urgency=low
+
+  * Add a Perl quirks mode for tarballs generated by Perl's IO::Zlib, which
+    is used among other things by Module::Build. Closes: #618284
+
+ -- Faidon Liambotis <paravoid@debian.org>  Tue, 15 Mar 2011 01:43:28 +0200
+
 pristine-tar (1.12) unstable; urgency=low
 
   * Fix gzg building with --as-needed. Closes: #604030
index 81afec8..bdd5da1 100755 (executable)
@@ -210,6 +210,14 @@ sub reproducegz {
        # -m and -M
        push @try, [@args];
 
+       # Perl's Compress::Raw::Zlib interfaces directly with zlib and
+       # apparently is the only implementation out there which tunes a very
+       # specific parameter of zlib, memLevel, to 9, instead of 8 which is
+       # the default. The module is used, among others, by Compress::Gzip
+       # which in turn is used by IO::Zlib. It was found on the real world on
+       # tarballs generated by Perl 5.10's Module::Build (cf. #618284)
+       push @try, [@args, '--quirk', 'perl'];
+
        # apparently, there is an old version of bsd-gzip (or a similar tool
        # based on zlib) that creates gz using maximum compression (-9) but
        # does not indicate so in the headers. surprisingly, there are many
index 0ddda6e..5593fc3 100644 (file)
--- a/zgz/zgz.c
+++ b/zgz/zgz.c
@@ -128,7 +128,7 @@ static      void    maybe_err(const char *fmt, ...)
     __attribute__((__format__(__printf__, 1, 2),noreturn));
 static void    maybe_errx(const char *fmt, ...)
     __attribute__((__format__(__printf__, 1, 2),noreturn));
-static void    gz_compress(int, int, const char *, uint32_t, int, int, int, int);
+static void    gz_compress(int, int, const char *, uint32_t, int, int, int, int, int);
 static void    usage(void);
 static void    display_version(void);
 static void    display_license(void);
@@ -173,8 +173,10 @@ main(int argc, char **argv)
        const char *progname = argv[0];
        int gnu = 0;
        int bzold = 0;
+       int quirks = 0;
        char *origname = NULL;
        uint32_t timestamp = 0;
+       int memlevel = 8; /* zlib's default */
        int nflag = 0;
        int mflag = 0;
        int fflag = 0;
@@ -238,6 +240,7 @@ main(int argc, char **argv)
                        origname = optarg;
                        break;
                case 'k':
+                       quirks = 1;
                        if (strcmp(optarg, "buggy-bsd") == 0) {
                                /* certain archives made with older versions of
                                 * BSD variants of gzip */
@@ -255,6 +258,9 @@ main(int argc, char **argv)
                                mflag = 1;
                                /* osflag is NTFS */
                                osflag = GZIP_OS_NTFS;
+                       } else if (strcmp(optarg, "perl") == 0) {
+                               /* Perl's Compress::Raw::Zlib */
+                               memlevel = 9;
                        } else {
                                fprintf(stderr, "%s: unknown quirk!\n", progname);
                                usage();
@@ -305,13 +311,13 @@ main(int argc, char **argv)
                timestamp = 0;
 
        if (gnu) {
-               if (ntfs_quirk || xflag >= 0) {
+               if (quirks) {
                        fprintf(stderr, "%s: quirks not supported with --gnu\n", progname);
                        return 1;
                }
                gnuzip(STDIN_FILENO, STDOUT_FILENO, origname, timestamp, level, osflag, rsync);
        } else if (bzold) {
-               if (ntfs_quirk || xflag >= 0) {
+               if (quirks) {
                        fprintf(stderr, "%s: quirks not supported with --old-bzip\n", progname);
                        return 1;
                }
@@ -322,7 +328,7 @@ main(int argc, char **argv)
                        return 1;
                }
 
-               gz_compress(STDIN_FILENO, STDOUT_FILENO, origname, timestamp, level, osflag, xflag, ntfs_quirk);
+               gz_compress(STDIN_FILENO, STDOUT_FILENO, origname, timestamp, level, memlevel, osflag, xflag, ntfs_quirk);
        }
        return 0;
 }
@@ -357,7 +363,7 @@ maybe_errx(const char *fmt, ...)
 
 /* compress input to output. */
 static void
-gz_compress(int in, int out, const char *origname, uint32_t mtime, int level, int osflag, int xflag, int ntfs_quirk)
+gz_compress(int in, int out, const char *origname, uint32_t mtime, int level, int memlevel, int osflag, int xflag, int ntfs_quirk)
 {
        z_stream z;
        char *outbufp, *inbufp;
@@ -396,7 +402,7 @@ gz_compress(int in, int out, const char *origname, uint32_t mtime, int level, in
        z.avail_out = BUFLEN - i;
 
        error = deflateInit2(&z, level, Z_DEFLATED,
-                            (-MAX_WBITS), 8, Z_DEFAULT_STRATEGY);
+                            (-MAX_WBITS), memlevel, Z_DEFAULT_STRATEGY);
        if (error != Z_OK)
                maybe_err("deflateInit2 failed");
 
@@ -516,7 +522,7 @@ usage(void)
     " \ngnu-specific options:\n"
     " -R --rsyncable           make rsync-friendly archive\n"
     " \nzlib-specific options:\n"
-    " -k --quirk QUIRK         enable a format quirk (buggy-bsd, ntfs)\n");
+    " -k --quirk QUIRK         enable a format quirk (buggy-bsd, ntfs, perl)\n");
        exit(0);
 }