about summary refs log tree commit diff
path: root/scripts/nix-collect-garbage.in
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-08-25T15·39+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-08-25T15·39+0000
commitfdec72c6cc720be899431c32f99221e8c4b88cd0 (patch)
tree668c1c754e7a47f67e5fd41aec0b882ea01186c6 /scripts/nix-collect-garbage.in
parent818047881e4906c670104851f69c3179ecc7fb1f (diff)
* `nix-collect-garbage' now actually performs a garbage collection, it
  doesn't just print the set of paths that should be deleted.  So
  there is no more need to pipe the result into `nix-store --delete'
  (which doesn't even exist anymore).

Diffstat (limited to 'scripts/nix-collect-garbage.in')
-rwxr-xr-xscripts/nix-collect-garbage.in44
1 files changed, 13 insertions, 31 deletions
diff --git a/scripts/nix-collect-garbage.in b/scripts/nix-collect-garbage.in
index 8b571536d8..539979cbb6 100755
--- a/scripts/nix-collect-garbage.in
+++ b/scripts/nix-collect-garbage.in
@@ -8,17 +8,17 @@ my $storeDir = "@storedir@";
 
 my %alive;
 
+my $gcOper = "--delete";
 my $keepSuccessors = 1;
-my $invert = 0;
 
 my @roots = ();
 
 
 # Parse the command line.
 foreach my $arg (@ARGV) {
-    if ($arg eq "--no-successors") { $keepSuccessors = 0; }
-    elsif ($arg eq "--invert") { $invert = 1; }
-    else { die "unknown argument `$arg'" };
+    if ($arg eq "--delete" || $arg eq "--print-live" || $arg eq "--print-dead") {
+        $gcOper = $arg;
+    } else { die "unknown argument `$arg'" };
 }
 
 
@@ -68,33 +68,15 @@ sub findRoots {
 findRoots 1, $rootsDir;
 
 
-# Determine all store paths reachable from the roots.
-my $extraarg = "";
-if ($keepSuccessors) { $extraarg = "--include-successors"; };
-my $pid = open2(\*READ, \*WRITE, "@bindir@/nix-store --query --requisites $extraarg @roots") 
-    or die "determining live paths";
-close WRITE;
-while (<READ>) {
-	chomp;
-	$alive{$_} = 1;
-	if ($invert) { print "$_\n"; };
-}
-close READ;
+# Run the collector with the roots we found.
+my $pid = open2(">&1", \*WRITE, "@bindir@/nix-store --gc $gcOper")
+    or die "cannot run `nix-store --gc'";
 
-waitpid $pid, 0;
-$? == 0 or die "determining live paths";
-
-exit 0 if ($invert);
+foreach my $root (@roots) {
+    print WRITE "$root\n";
+}
 
+close WRITE;
 
-# Using that information, find all store paths *not* reachable from
-# the roots.
-opendir(DIR, $storeDir) or die "cannot open directory $storeDir: $!";
-foreach my $name (readdir DIR) {
-    next if ($name eq "." || $name eq "..");
-    $name = "$storeDir/$name";
-    if (!$alive{$name}) {
-        print "$name\n";
-    }
-}
-closedir DIR;
+waitpid $pid, 0;
+$? == 0 or die "`nix-store --gc' failed";