aboutsummaryrefslogtreecommitdiff
path: root/scripts/nix-collect-garbage.in
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-08-25 16:54:08 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-08-25 16:54:08 +0000
commiteb233e728f06ec2b5cbcfc85059fa91a1150f291 (patch)
tree81cf94bd444b36f83fe489f2ae0061b0ae32fd1b /scripts/nix-collect-garbage.in
parentfdec72c6cc720be899431c32f99221e8c4b88cd0 (diff)
* `--min-age' flag in nix-store and nix-collect-garbage to only delete
unreachable paths that haven't been used for N hours. For instance, `nix-collect-garbage --min-age 168' only deletes paths that haven't been accessed in the last week. This is useful for instance in the build farm where many derivations can be shared between consecutive builds, and we wouldn't want a garbage collect to throw them all away. We could of course register them as roots, but then we'd to unregister them at some point, which would be a pain to manage. The `--min-age' flag gives us a sort of MRU caching scheme. BUG: this really shouldn't be in gc.cc since that violates mechanism/policy separation.
Diffstat (limited to 'scripts/nix-collect-garbage.in')
-rwxr-xr-xscripts/nix-collect-garbage.in16
1 files changed, 12 insertions, 4 deletions
diff --git a/scripts/nix-collect-garbage.in b/scripts/nix-collect-garbage.in
index 539979cbb..44bcc16bb 100755
--- a/scripts/nix-collect-garbage.in
+++ b/scripts/nix-collect-garbage.in
@@ -9,16 +9,24 @@ my $storeDir = "@storedir@";
my %alive;
my $gcOper = "--delete";
-my $keepSuccessors = 1;
+my $minAge = 0;
my @roots = ();
# Parse the command line.
-foreach my $arg (@ARGV) {
+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;
- } else { die "unknown argument `$arg'" };
+ }
+ elsif ($arg eq "--min-age") {
+ $i++;
+ $minAge = undef;
+ $minAge = $ARGV[$i];
+ die "invalid minimum age" unless defined $minAge && $minAge =~ /^\d*$/;
+ }
+ else { die "unknown argument `$arg'" };
}
@@ -69,7 +77,7 @@ findRoots 1, $rootsDir;
# Run the collector with the roots we found.
-my $pid = open2(">&1", \*WRITE, "@bindir@/nix-store --gc $gcOper")
+my $pid = open2(">&1", \*WRITE, "@bindir@/nix-store --gc $gcOper --min-age $minAge")
or die "cannot run `nix-store --gc'";
foreach my $root (@roots) {