summaryrefslogtreecommitdiff
path: root/pristine-gz
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-11-21 20:31:32 -0500
committerJoey Hess <joey@kodama.kitenet.net>2008-11-21 20:31:32 -0500
commit5858d1fa5cd7e5e1f382f0328034a117b503c75a (patch)
tree4c01efba5a7052fbbcd7dcab6dcd9a816527072a /pristine-gz
parent94d16a72764c9a73d4dc2f2e29288cb26c9a65b8 (diff)
downloadpristine-tar-5858d1fa5cd7e5e1f382f0328034a117b503c75a.tar.gz
pristine-tar-5858d1fa5cd7e5e1f382f0328034a117b503c75a.tar.bz2
pristine-tar-5858d1fa5cd7e5e1f382f0328034a117b503c75a.zip
pristine-gz: Avoid uncompressing the original file more than once. Closes: #506490
Diffstat (limited to 'pristine-gz')
-rwxr-xr-xpristine-gz40
1 files changed, 26 insertions, 14 deletions
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);