diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2005-02-01 15:05:32 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2005-02-01 15:05:32 +0000 |
commit | 65b6c8ab4c7832abdad46a29ce2ef18d289b2471 (patch) | |
tree | 3038d7ed1f60efdf2e2dad43cfec93023d7c699f /scripts | |
parent | 630ae0c9d7f65a2d6bef85a5194b4d704e54eded (diff) | |
download | guix-65b6c8ab4c7832abdad46a29ce2ef18d289b2471.tar.gz |
* Move root finding from `nix-collect-garbage' to `nix-store --gc'.
This was necessary becase root finding must be done after acquisition of the global GC lock. This makes `nix-collect-garbage' obsolete; it is now just a wrapper around `nix-store --gc'. * Automatically remove stale GC roots (i.e., indirect GC roots that point to non-existent paths).
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/nix-collect-garbage.in | 85 |
1 files changed, 2 insertions, 83 deletions
diff --git a/scripts/nix-collect-garbage.in b/scripts/nix-collect-garbage.in index c92737f25c..7ec9f349b1 100644 --- a/scripts/nix-collect-garbage.in +++ b/scripts/nix-collect-garbage.in @@ -1,83 +1,2 @@ -#! @perl@ -w - -use strict; -use IPC::Open2; - -my $rootsDir = "@localstatedir@/nix/gcroots"; -my $storeDir = "@storedir@"; - -my %alive; - -my $gcOper = "--delete"; -my $extraArgs = ""; - -my @roots = (); - - -# Parse the command line. -for (my $i = 0; $i < scalar @ARGV; $i++) { - my $arg = $ARGV[$i]; - if ($arg eq "--delete" || $arg eq "--print-live" || $arg eq "--print-dead") { - $gcOper = $arg; - } - elsif ($arg =~ /^-v+$/) { - $extraArgs = "$extraArgs $arg"; - } - else { die "unknown argument `$arg'" }; -} - - -# Recursively finds all symlinks to the store in the given directory. -sub findRoots; -sub findRoots { - my $followSymlinks = shift; - my $dir = shift; - - opendir(DIR, $dir) or die "cannot open directory `$dir': $!"; - my @names = readdir DIR or die "cannot read directory `$dir': $!"; - closedir DIR; - - foreach my $name (@names) { - next if $name eq "." || $name eq ".."; - my $path = $dir . "/" . $name; - - if (-l $path) { - my $target = readlink $path - or die "cannot read symlink `$path': $!"; - - if (substr($target, 0, length $storeDir) eq $storeDir) { - # We're only interested in the store-level part. - $target = substr($target, length $storeDir); - $target = "$storeDir/$target"; - push @roots, $target; - } - - elsif ($followSymlinks && -d $path) { - findRoots 0, $path; - } - } - - elsif (-d $path) { - findRoots $followSymlinks, $path; - } - } - -} - - -# Find GC roots, starting at $rootsDir. -findRoots 1, $rootsDir; - - -# Run the collector with the roots we found. -my $pid = open2(">&1", \*WRITE, "@bindir@/nix-store --gc $gcOper $extraArgs") - or die "cannot run `nix-store --gc'"; - -foreach my $root (@roots) { - print WRITE "$root\n"; -} - -close WRITE; - -waitpid $pid, 0; -$? == 0 or die "`nix-store --gc' failed"; +#! @shell@ -e +exec @bindir@/nix-store --gc "$@" |