From 36eedad57021caae4b14892339c28d03e9aba42b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kusalananda=20K=C3=A4h=C3=A4ri?= <ak4@sanger.ac.uk> Date: Mon, 18 Aug 2003 10:14:14 +0000 Subject: [PATCH] More logic. Now uses gzip directly to figure out the uncompressed size of a gzipped file (this shouldn't be >= 2Gb either...). Compress::Zlib doesn't do this. --- misc-scripts/binary_delta/build.README | 2 ++ misc-scripts/binary_delta/build.pl | 24 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/misc-scripts/binary_delta/build.README b/misc-scripts/binary_delta/build.README index 244beb9b79..ae1045c592 100644 --- a/misc-scripts/binary_delta/build.README +++ b/misc-scripts/binary_delta/build.README @@ -42,6 +42,8 @@ Requirements / Configuration * File::Basename * Getopt::Std + 3. The GNU zip (gzip) program. + Check your distribution CDs before downloading and installing these prerequisits from the web. diff --git a/misc-scripts/binary_delta/build.pl b/misc-scripts/binary_delta/build.pl index d01b1ff533..23ba3a8a30 100755 --- a/misc-scripts/binary_delta/build.pl +++ b/misc-scripts/binary_delta/build.pl @@ -85,7 +85,6 @@ The options may be any of these: EOT } - # Compress a file. sub do_compress { @@ -110,6 +109,21 @@ sub do_compress close IN; } +# Gets the size of the uncompressed file (uses gzip since +# Compress::Zlib doesn't do this). +sub compress_size +{ + my $zfile_path = shift; + + open(IN, "gzip --list $zfile_path|") or die $!; + + my $dummy = <IN>; + my $zsize = ( split(/\s+/, <IN>) )[1]; + + close IN; + return $zsize; +} + my %opts; my $xdelta_cmd = $opts{'c'} = 'xdelta'; my $src_prefix = $opts{'s'} = '.'; @@ -178,10 +192,16 @@ foreach my $v2_file (glob($v2_dir . '/*')) { if ($v1_sum eq $v2_sum && $v1_size == $v2_size) { $patch_command = 'COPY'; print "\tThe files are identical\n"; - } elsif ($v1_size >= $too_big || $v2_size >= $too_big) { + } elsif ($v2_file !~ /\.gz$/ && + ($v1_size >= $too_big || $v2_size >= $too_big)) { $patch_command = 'ZIP'; print "\tFiles are huge, compressing new file\n"; do_compress($v2_file, $delta_file); + } elsif (($v2_file =~ /\.gz$/ && compress_size($v2_file) >= $too_big) || + ($v1_file =~ /\.gz$/ && compress_size($v1_file) >= $too_big)) { + $patch_command = 'ADD'; + print "\tFiles are huge, adding compressed new file\n"; + copy($v2_file, $delta_file); } else { print "\tCreating delta file\n"; system($xdelta_cmd, 'delta', '-9', $v1_file, $v2_file, $delta_file); -- GitLab