pristine-gz: Avoid uncompressing the original file more than once. Closes: #506490
authorJoey Hess <joey@kodama.kitenet.net>
Sat, 22 Nov 2008 01:31:32 +0000 (20:31 -0500)
committerJoey Hess <joey@kodama.kitenet.net>
Sat, 22 Nov 2008 01:31:32 +0000 (20:31 -0500)
debian/changelog
pristine-gz

index c1807806d6b46c3dd8b11ba5fcb8ce4727e7f9ae..789e26eda1148b17bf036143869ca1704b00ff46 100644 (file)
@@ -1,3 +1,10 @@
+pristine-tar (0.18) UNRELEASED; urgency=low
+
+  * pristine-gz: Avoid uncompressing the original file more than once.
+    Closes: #506490 
+
+ -- Joey Hess <joeyh@debian.org>  Fri, 21 Nov 2008 20:23:52 -0500
+
 pristine-tar (0.17) unstable; urgency=low
 
   * Correct -f order to come after --gnu.
index b2ca53a216536bf0b4a9845e4dd1b854ea542f15..8079f18702d4bff6f90f3bd30301ab2640ee32a1 100755 (executable)
@@ -209,28 +209,40 @@ sub comparefiles {
 sub testvariant {
        my ($old, $new, $origname, @args) = @_;
 
-       # Unzip attempt of the previous run (or the original on the first run)
-       doit('gunzip', '-N', $new);
-       if (-e $new) {
-               die "gunzip failed, aborting";
+       # We need an uncompressed file to test the compressor with.
+       # See if one already exists.
+       my $uncompressed = $new;
+       $uncompressed =~ s/\.gz$//;
+       if ($origname && -e $origname) {
+               $uncompressed = $origname;
        }
-       elsif ($origname && -e $origname) {
-               # original new because we passed -N to gunzip
-               $new = $origname;
-       }
-       else {
-               $new =~ s/\.gz$//;
-               unless (-e $new) {
-                       die("gunzip succeded but I can't find the new file");
+       elsif (! -e $uncompressed) {
+               # Generate the uncompressed file.
+               doit('gunzip', '-N', $new);
+               if (-e $new) {
+                       die "gunzip failed, aborting";
+               }
+               elsif ($origname && -e $origname) {
+                       $uncompressed = $origname;
+               }
+               elsif (! -e $uncompressed) {
+                       die("gunzip succeded but I can't find the uncompressed file");
                }
        }
+               
+       # Cache a copy of the uncompressed file to avoid needing to
+       # uncompress it again. (By hard linking, we avoid an
+       # expensive copy, but need to pass -f when gzipping.)
+       doit("ln", "-f", $uncompressed, "$uncompressed.cached");
 
        # try gzipping with the arguments passed
-       doit('zgz', @args, "-f", $new);
-       $new .= '.gz';
+       doit('zgz', @args, "-f", $uncompressed);
+       $new = "$uncompressed.gz";
        unless (-e $new) {
                die("zgz failed, aborting");
        }
+       # move cached uncompressed file into place for later use
+       doit("mv", "-f", "$uncompressed.cached", $uncompressed);
 
        # and compare the generated with the original
        return !comparefiles($old, $new);