From fdec72c6cc720be899431c32f99221e8c4b88cd0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 25 Aug 2004 15:39:13 +0000 Subject: * `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). --- scripts/nix-collect-garbage.in | 44 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) (limited to 'scripts/nix-collect-garbage.in') diff --git a/scripts/nix-collect-garbage.in b/scripts/nix-collect-garbage.in index 8b571536d87f..539979cbb6c0 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 () { - 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"; -- cgit 1.4.1