* Randomly permute the order in which we download NARs so that

mirror-nixos and mirror-nixpkgs don't download the same files at the
  same time.


git-svn-id: https://nixos.org/repos/nix/release/trunk/channels@34682 70bd8c7a-acb8-0310-9f0d-9cc1c95dcdbb
This commit is contained in:
Eelco Dolstra 2013-01-18 11:48:37 +00:00
parent 163a3e591f
commit 3aad07cee3

View file

@ -59,11 +59,22 @@ print STDERR "$size store paths in manifest\n";
die "cowardly refusing to mirror an empty channel" if $size == 0;
sub permute {
my @list = @_;
for (my $n = scalar @list - 1; $n > 0; $n--) {
my $k = int(rand($n + 1)); # 0 <= $k <= $n
@list[$n, $k] = @list[$k, $n];
}
return @list;
}
# Download every file that we don't already have, and update every URL
# to point to the mirror. Also fill in the size and hash fields in
# the manifest in order to be compatible with Nix < 0.13.
while (my ($storePath, $nars) = each %narFiles) {
foreach my $storePath (permute(keys %narFiles)) {
my $nars = $narFiles{$storePath};
my $pathHash = substr(basename($storePath), 0, 32);
my $narInfoFile = "$cacheDir/$pathHash.narinfo";