From 6d149f92538380ebc3659649a55b44231c47c93f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 23 Jun 2010 14:07:47 +0000 Subject: [PATCH] * Store the NARs in a different directory. git-svn-id: https://nixos.org/repos/nix/release/trunk/channels@22396 70bd8c7a-acb8-0310-9f0d-9cc1c95dcdbb --- mirror-channel.pl | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/mirror-channel.pl b/mirror-channel.pl index 56105d2..cc4b41a 100644 --- a/mirror-channel.pl +++ b/mirror-channel.pl @@ -5,19 +5,24 @@ use File::stat; use File::Temp qw/tempfile/; use Fcntl ':flock'; -if (scalar @ARGV != 3 && scalar @ARGV != 4) { - print STDERR "Syntax: perl mirror-channel.pl []\n"; +if (scalar @ARGV != 6 && scalar @ARGV != 7) { + print STDERR "Syntax: perl mirror-channel.pl []\n"; exit 1; } my $curl = "curl --location --silent --show-error --fail"; my $srcChannelURL = $ARGV[0]; -my $dstChannelURL = $ARGV[1]; -my $dstChannelPath = $ARGV[2]; -my $nixexprsURL = $ARGV[3] || "$srcChannelURL/nixexprs.tar.bz2"; +my $dstChannelPath = $ARGV[1]; +my $narPath = $ARGV[2]; +my $narURL = $ARGV[3]; +my $patchesPath = $ARGV[4]; +my $patchesURL = $ARGV[5]; +my $nixexprsURL = $ARGV[6] || "$srcChannelURL/nixexprs.tar.bz2"; die "$dstChannelPath doesn't exist\n" unless -d $dstChannelPath; +die "$narPath doesn't exist\n" unless -d $narPath; +die "$patchesPath doesn't exist\n" unless -d $patchesPath; open LOCK, ">$dstChannelPath/.lock" or die; flock LOCK, LOCK_EX; @@ -51,20 +56,20 @@ while (my ($storePath, $files) = each %narFiles) { my $srcURL = $file->{url}; my $dstName = $narHash; $dstName =~ s/:/_/; # `:' in filenames might cause problems - my $dstFile = "$dstChannelPath/$dstName"; - my $dstURL = "$dstChannelURL/$dstName"; + my $dstFile = "$narPath/$dstName"; + my $dstURL = "$narURL/$dstName"; $file->{url} = $dstURL; if (! -e $dstFile) { print "downloading $srcURL\n"; - my $dstFileTmp = "$dstChannelPath/.tmp.$$.nar.$dstName"; - system("$curl '$srcURL' > $dstFileTmp") == 0 or die; + my $dstFileTmp = "$narPath/.tmp.$$.nar.$dstName"; + system("$curl '$srcURL' > $dstFileTmp") == 0 or next; rename($dstFileTmp, $dstFile) or die "cannot rename $dstFileTmp"; } $file->{size} = stat($dstFile)->size or die; - my $hashFile = "$dstChannelPath/.hash.$dstName"; + my $hashFile = "$narPath/.hash.$dstName"; my $hash; if (-e $hashFile) { open HASH, "<$hashFile" or die; @@ -86,5 +91,15 @@ writeManifest("$dstChannelPath/MANIFEST", \%narFiles, \%patches); # Mirror nixexprs.tar.bz2. my $tmpFile = "$dstChannelPath/.tmp.$$.nixexprs.tar.bz2"; -system("$curl '$nixexprsURL' > $tmpFile") == 0 or die; +system("$curl '$nixexprsURL' > $tmpFile") == 0 or die "cannot download `$nixexprsURL'"; rename($tmpFile, "$dstChannelPath/nixexprs.tar.bz2") or die "cannot rename $tmpFile"; + +# Remove ".hash.*" files corresponding to NARs that have been removed. +foreach my $fn (glob "$narPath/.hash.*") { + my $fn2 = $fn; + $fn2 =~ s/\.hash\.//; + if (! -e "$fn2") { + print STDERR "removing hash $fn\n"; + unlink "$fn"; + } +}