From 97b39b07dc2ef6ffed0bd952afe5597dd05b2534 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 6 Oct 2015 23:13:49 +0200 Subject: [PATCH] Check for errors when compressing NARs Otherwise, an error (like disk full) will cause a truncated NAR file to be uploaded to the binary cache. --- mirror-channel.pl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mirror-channel.pl b/mirror-channel.pl index 365d066..5a9a780 100644 --- a/mirror-channel.pl +++ b/mirror-channel.pl @@ -59,7 +59,9 @@ my $bucket = $s3->bucket($bucketName) or die; # Fetch the manifest. -system("$curl '$srcChannelURL/MANIFEST' > $dstChannelPath/MANIFEST") == 0 or die; +unless (-e "$dstChannelPath/MANIFEST") { + system("$curl '$srcChannelURL/MANIFEST' > $dstChannelPath/MANIFEST") == 0 or die; +} if (defined $nixexprsURL) { @@ -144,6 +146,7 @@ sub mirrorStorePath { # Verify that $storePath hasn't been corrupted and compress it at the same time. $ext = "xz"; my $narHash = `bash -c 'exec 4>&1; nix-store --dump $storePath | tee >(nix-hash --type sha256 --base32 --flat /dev/stdin >&4) | xz -7 > $dstFileTmp'`; + die "unable to compress $storePath to $dstFileTmp\n" if $? != 0; chomp $narHash; die "hash mismatch in `$storePath'" if "sha256:$narHash" ne $nar->{narHash}; } else {