diff options
-rw-r--r-- | debian/changelog | 7 | ||||
-rwxr-xr-x | pristine-gz | 40 |
2 files changed, 33 insertions, 14 deletions
diff --git a/debian/changelog b/debian/changelog index c180780..789e26e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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. diff --git a/pristine-gz b/pristine-gz index b2ca53a..8079f18 100755 --- a/pristine-gz +++ b/pristine-gz @@ -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); |