Author: eelco
Date: Mon Nov 29 09:15:45 2010
New Revision: 24909
URL: https://svn.nixos.org/websvn/nix/?rev=24909&sc=1
Log:
* Impose a configurable time limit on patch generation. This is
necessary because bsdiff has some pathological worst-case behaviour,
e.g. O(n^2) on files consisting only of 0s.
Modified:
nix/branches/sqlite/scripts/generate-patches.pl.in
Modified: nix/branches/sqlite/scripts/generate-patches.pl.in
==============================================================================
--- nix/branches/sqlite/scripts/generate-patches.pl.in Mon Nov 29 09:10:10
2010 (r24908)
+++ nix/branches/sqlite/scripts/generate-patches.pl.in Mon Nov 29 09:15:45
2010 (r24909)
@@ -15,6 +15,9 @@
my $maxPatchFraction = $ENV{"NIX_PATCH_FRACTION"};
$maxPatchFraction = 0.60 if !defined $maxPatchFraction;
+my $timeLimit = $ENV{"NIX_BSDIFF_TIME_LIMIT"};
+$timeLimit = 180 if !defined $timeLimit;
+
die unless scalar @ARGV == 5;
@@ -29,8 +32,6 @@
my $tmpDir = tempdir("nix-generate-patches.XXXXXX", CLEANUP => 1, TMPDIR => 1)
or die "cannot create a temporary directory";
-print "TEMP = $tmpDir\n";
-
#END { rmdir $tmpDir; }
my %srcNarFiles;
@@ -223,7 +224,7 @@
foreach my $q (keys %srcOutPaths) {
(my $name2, my $version2) = getNameVersion $q;
- next unless defined $name2 && defined $version2;
+ next unless defined $name2 && defined $version2;
if ($name eq $name2) {
@@ -312,8 +313,13 @@
next;
}
- system("@libexecdir@/bsdiff $tmpDir/A $tmpDir/B $tmpDir/DIFF") == 0
- or die "cannot compute binary diff";
+ my $time1 = time();
+ my $res = system("ulimit -t $timeLimit; @libexecdir@/bsdiff $tmpDir/A
$tmpDir/B $tmpDir/DIFF");
+ my $time2 = time();
+ if ($res) {
+ warn "binary diff computation aborted after ", $time2 - $time1, "
seconds\n";
+ next;
+ }
my $baseHash = `...@bindir@/nix-hash --flat --type $hashAlgo --base32
$tmpDir/A` or die;
chomp $baseHash;
@@ -327,7 +333,7 @@
my $narDiffSize = (stat "$tmpDir/DIFF")[7];
my $dstNarBz2Size = (stat $dstNarBz2)[7];
- print " size $narDiffSize; full size $dstNarBz2Size\n";
+ print " size $narDiffSize; full size $dstNarBz2Size; ", $time2 -
$time1, " seconds\n";
if ($narDiffSize >= $dstNarBz2Size) {
print " rejecting; patch bigger than full archive\n";
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits