about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2007-03-13T11·30+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2007-03-13T11·30+0000
commiteb2dd4815c05fcc592d049bddcd2f42d13216eab (patch)
tree90bbb6974976999ed4d7ebb6d789fe0156ff3792 /scripts
parent917e06bf6398ed77a23e5e1fc894321a7fc7f86e (diff)
* Remove old generations in all directories under
  /nix/var/nix/profiles, not just in that directory itself.  (NixOS
  puts profiles in /nix/var/nix/profiles/per-user.)

Diffstat (limited to 'scripts')
-rw-r--r--scripts/nix-collect-garbage.in21
1 files changed, 15 insertions, 6 deletions
diff --git a/scripts/nix-collect-garbage.in b/scripts/nix-collect-garbage.in
index f1ea09b8ee93..b92deefc2436 100644
--- a/scripts/nix-collect-garbage.in
+++ b/scripts/nix-collect-garbage.in
@@ -21,22 +21,31 @@ for my $arg (@ARGV) {
 # If `-d' was specified, remove all old generations of all profiles.
 # Of course, this makes rollbacks to before this point in time
 # impossible.
-if ($removeOld) {
 
-    opendir DIR, $profilesDir or die;
+sub removeOldGenerations;
+sub removeOldGenerations {
+    my $dir = shift;
 
-    foreach my $name (sort (readdir DIR)) {
-        $name = $profilesDir . "/" . $name;
+    my $dh;
+    opendir $dh, $dir or die;
+
+    foreach my $name (sort (readdir $dh)) {
+        next if $name eq "." || $name eq "..";
+        $name = $dir . "/" . $name;
         if (-l $name && (readlink($name) =~ /link/)) {
             print STDERR "removing old generations of profile $name\n";
             system("@bindir@/nix-env", "-p", $name, "--delete-generations", "old");
         }
+        elsif (! -l $name && -d $name) {
+            removeOldGenerations $name;
+        }
     }
     
-    closedir DIR or die;
-    
+    closedir $dh or die;
 }
 
+removeOldGenerations $profilesDir if $removeOld;
+
 
 # Run the actual garbage collector.
 exec "@bindir@/nix-store", "--gc", @args;