about summary refs log tree commit diff
path: root/scripts/nix-pull.in
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2009-12-09T19·36+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2009-12-09T19·36+0000
commit7ca997263680025a7cf5386a44efcb0a9949315e (patch)
tree78875522ac069f4dc0c0c1ef539216a5b0db3487 /scripts/nix-pull.in
parentc4c84d1edb4e0dd4ed77a9b2d1386834cdfaaa34 (diff)
* When doing a nix-pull, remove old manifests downloaded from the same
  URL.  This prevents lots of old cruft accumulating in
  /nix/var/nix/manifests.

Diffstat (limited to 'scripts/nix-pull.in')
-rw-r--r--scripts/nix-pull.in26
1 files changed, 23 insertions, 3 deletions
diff --git a/scripts/nix-pull.in b/scripts/nix-pull.in
index bb041f0a6841..e2a0cc1fafdf 100644
--- a/scripts/nix-pull.in
+++ b/scripts/nix-pull.in
@@ -51,7 +51,7 @@ sub processURL {
 
     # First see if a bzipped manifest is available.
     if (system("@curl@ --fail --silent --head '$url'.bz2 > /dev/null") == 0) {
-        print "obtaining list of Nix archives at `$url.bz2'...\n";
+        print "fetching list of Nix archives at `$url.bz2'...\n";
         my $bzipped = downloadFile "$url.bz2";
 
         $manifest = "$tmpDir/MANIFEST";
@@ -92,11 +92,31 @@ sub processURL {
     my $hash = `$binDir/nix-hash --flat '$manifest'`
         or die "cannot hash `$manifest'";
     chomp $hash;
+
+    my $urlFile = "$manifestDir/$baseName-$hash.url";
+    open URL, ">$urlFile" or die "cannot create `$urlFile'";
+    print URL "$url";
+    close URL;
     
     my $finalPath = "$manifestDir/$baseName-$hash.nixmanifest";
-    
-    system("@coreutils@/ln", "-sfn", "$manifest", "$finalPath") == 0
+
+    unlink $finalPath if -e $finalPath;
+        
+    symlink("$manifest", "$finalPath")
         or die "cannot link `$finalPath to `$manifest'";
+
+    # Delete all old manifests downloaded from this URL.
+    for my $urlFile2 (glob "$manifestDir/*.url") {
+        next if $urlFile eq $urlFile2;
+        open URL, "<$urlFile2" or die;
+        my $url2 = <URL>;
+        chomp $url2;
+        close URL;
+        next unless $url eq $url2;
+        my $base = $urlFile2; $base =~ s/.url$//;
+        unlink "${base}.url";
+        unlink "${base}.nixmanifest";
+    }
 }
 
 while (@ARGV) {