From a6f348599c94d8a5f7b41c7d8e43658dc6407be7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 17 Jul 2012 16:19:40 -0400 Subject: [PATCH] Print some debug output --- scripts/download-from-binary-cache.pl.in | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/scripts/download-from-binary-cache.pl.in b/scripts/download-from-binary-cache.pl.in index ca3ff807b..6f4b55766 100644 --- a/scripts/download-from-binary-cache.pl.in +++ b/scripts/download-from-binary-cache.pl.in @@ -18,6 +18,8 @@ my @binaryCacheUrls = map { s/\/+$//; $_ } split(/ /, my $maxParallelRequests = int($Nix::Config::config{"binary-caches-parallel-connections"} // 150); $maxParallelRequests = 1 if $maxParallelRequests < 1; +my $debug = ($ENV{"NIX_DEBUG_SUBST"} // "") eq 1; + my ($dbh, $insertNAR, $queryNAR, $insertNARExistence, $queryNARExistence); my %cacheIds; @@ -34,7 +36,7 @@ sub addRequest { my $curl = WWW::Curl::Easy->new; my $curlId = $curlIdCount++; - $requests{$curlId} = { storePath => $storePath, url => $url, handle => $curl, content => "" }; + $requests{$curlId} = { storePath => $storePath, url => $url, handle => $curl, content => "", type => $head ? "HEAD" : "GET" }; $curl->setopt(CURLOPT_PRIVATE, $curlId); $curl->setopt(CURLOPT_URL, $url); @@ -68,12 +70,15 @@ sub processRequests { if ($curlm->perform() != $activeRequests) { while (my ($id, $result) = $curlm->info_read) { if ($id) { - my $handle = $requests{$id}->{handle}; - $requests{$id}->{result} = $result; - $requests{$id}->{httpStatus} = $handle->getinfo(CURLINFO_HTTP_CODE); - #print STDERR "\nRequest completed ($id, $result, $requests{$id}->{httpStatus})\n"; + my $request = $requests{$id} or die; + my $handle = $request->{handle}; + $request->{result} = $result; + $request->{httpStatus} = $handle->getinfo(CURLINFO_HTTP_CODE); + + print STDERR "$request->{type} on $request->{url} [$request->{result}, $request->{httpStatus}]\n" if $debug; + $activeRequests--; - delete $requests{$id}->{handle}; + delete $request->{handle}; if (scalar(keys %scheduled) > 0) { my $id2 = (keys %scheduled)[0]; @@ -81,7 +86,6 @@ sub processRequests { $activeRequests++; delete $scheduled{$id2}; } - } } } @@ -189,7 +193,10 @@ sub processNARInfo { my $compression = "bzip2"; my @refs; foreach my $line (split "\n", $request->{content}) { - $line =~ /^(.*): (.*)$/ or return undef; + unless ($line =~ /^(.*): (.*)$/) { + print STDERR "bad NAR info file ‘$request->{url}’\n"; + return undef; + } if ($1 eq "StorePath") { $storePath2 = $2; } elsif ($1 eq "URL") { $url = $2; } elsif ($1 eq "Compression") { $compression = $2; }