about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-09-13T22·09-0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-09-13T22·09-0400
commit983220bcd46e89ee4d2ce0417eb514cd6c062f2d (patch)
tree282997c51e41e52783a2aa43f08f893a397f3e4a /scripts
parent9fd9dedf12bb64e02b35e9231173f9ebae5e1492 (diff)
nix-collect-garbage: Support --dry-run
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/nix-collect-garbage.in9
1 files changed, 6 insertions, 3 deletions
diff --git a/scripts/nix-collect-garbage.in b/scripts/nix-collect-garbage.in
index 835213226f23..bd186022095c 100755
--- a/scripts/nix-collect-garbage.in
+++ b/scripts/nix-collect-garbage.in
@@ -9,10 +9,13 @@ my $profilesDir = "@localstatedir@/nix/profiles";
 # Process the command line arguments.
 my @args = ();
 my $removeOld = 0;
+my $dryRun = 0;
 
 for my $arg (@ARGV) {
     if ($arg eq "--delete-old" || $arg eq "-d") {
         $removeOld = 1;
+    } elsif ($arg eq "--dry-run") {
+        $dryRun = 1;
     } else {
         push @args, $arg;
     }
@@ -35,13 +38,13 @@ sub removeOldGenerations {
         $name = $dir . "/" . $name;
         if (-l $name && (readlink($name) =~ /link/)) {
             print STDERR "removing old generations of profile $name\n";
-            system("$Nix::Config::binDir/nix-env", "-p", $name, "--delete-generations", "old");
+            system("$Nix::Config::binDir/nix-env", "-p", $name, "--delete-generations", "old", $dryRun ? "--dry-run" : ());
         }
         elsif (! -l $name && -d $name) {
             removeOldGenerations $name;
         }
     }
-    
+
     closedir $dh or die;
 }
 
@@ -49,4 +52,4 @@ removeOldGenerations $profilesDir if $removeOld;
 
 
 # Run the actual garbage collector.
-exec "$Nix::Config::binDir/nix-store", "--gc", @args;
+exec "$Nix::Config::binDir/nix-store", "--gc", @args unless $dryRun;