From 542fc6906297fcb72cbcb01d688c2f27819e0cf7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 13 Dec 2010 08:39:10 +0000 Subject: [PATCH] * When doing a query (e.g. `nix-store -r --dry-run'), don't make a lot of expensive calls to `nix-store --check-validity'. --- scripts/download-using-manifests.pl.in | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/download-using-manifests.pl.in b/scripts/download-using-manifests.pl.in index 47ff09e60..29321bff9 100644 --- a/scripts/download-using-manifests.pl.in +++ b/scripts/download-using-manifests.pl.in @@ -12,6 +12,10 @@ STDOUT->autoflush(1); my $manifestDir = ($ENV{"NIX_MANIFESTS_DIR"} or "@localstatedir@/nix/manifests"); my $logFile = "@localstatedir@/log/nix/downloads"; +# For queries, skip expensive calls to nix-hash etc. We're just +# estimating the expected download size. +my $fast = 1; + # Load all manifests. my %narFiles; @@ -33,7 +37,11 @@ for my $manifest (glob "$manifestDir/*.nixmanifest") { sub isValidPath { my $p = shift; - return system("$binDir/nix-store --check-validity '$p' 2> /dev/null") == 0; + if ($fast) { + return -e $p; + } else { + return system("$binDir/nix-store --check-validity '$p' 2> /dev/null") == 0; + } } @@ -51,7 +59,6 @@ sub parseHash { # given path. sub computeSmallestDownload { my $targetPath = shift; - my $fast = shift; # Build a graph of all store paths that might contribute to the # construction of $targetPath, and the special node "start". The @@ -207,7 +214,7 @@ if ($ARGV[0] eq "--query") { print scalar @references, "\n"; print "$_\n" foreach @references; - my @path = computeSmallestDownload $storePath, 1; + my @path = computeSmallestDownload $storePath; my $downloadSize = 0; while (scalar @path > 0) { @@ -241,6 +248,7 @@ elsif ($ARGV[0] ne "--substitute") { die unless scalar @ARGV == 2; my $targetPath = $ARGV[1]; +$fast = 0; # Create a temporary directory. @@ -273,7 +281,7 @@ foreach my $localPath (@{$localPathList}) { # Compute the shortest path. -my @path = computeSmallestDownload $targetPath, 0; +my @path = computeSmallestDownload $targetPath; die "don't know how to produce $targetPath\n" if scalar @path == 0;