2006-09-06 14:23:04 +00:00
|
|
|
#! @perl@ -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
my $profilesDir = "@localstatedir@/nix/profiles";
|
|
|
|
|
|
|
|
|
|
|
|
# Process the command line arguments.
|
|
|
|
my @args = ();
|
|
|
|
my $removeOld = 0;
|
|
|
|
|
|
|
|
for my $arg (@ARGV) {
|
|
|
|
if ($arg eq "--delete-old" || $arg eq "-d") {
|
|
|
|
$removeOld = 1;
|
|
|
|
} else {
|
|
|
|
push @args, $arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# If `-d' was specified, remove all old generations of all profiles.
|
|
|
|
# Of course, this makes rollbacks to before this point in time
|
|
|
|
# impossible.
|
|
|
|
|
2007-03-13 11:30:57 +00:00
|
|
|
sub removeOldGenerations;
|
|
|
|
sub removeOldGenerations {
|
|
|
|
my $dir = shift;
|
2006-09-06 14:23:04 +00:00
|
|
|
|
2007-03-13 11:30:57 +00:00
|
|
|
my $dh;
|
|
|
|
opendir $dh, $dir or die;
|
|
|
|
|
|
|
|
foreach my $name (sort (readdir $dh)) {
|
|
|
|
next if $name eq "." || $name eq "..";
|
|
|
|
$name = $dir . "/" . $name;
|
2006-09-06 14:23:04 +00:00
|
|
|
if (-l $name && (readlink($name) =~ /link/)) {
|
|
|
|
print STDERR "removing old generations of profile $name\n";
|
2006-09-25 10:44:27 +00:00
|
|
|
system("@bindir@/nix-env", "-p", $name, "--delete-generations", "old");
|
2006-09-06 14:23:04 +00:00
|
|
|
}
|
2007-03-13 11:30:57 +00:00
|
|
|
elsif (! -l $name && -d $name) {
|
|
|
|
removeOldGenerations $name;
|
|
|
|
}
|
2006-09-06 14:23:04 +00:00
|
|
|
}
|
|
|
|
|
2007-03-13 11:30:57 +00:00
|
|
|
closedir $dh or die;
|
2006-09-06 14:23:04 +00:00
|
|
|
}
|
|
|
|
|
2007-03-13 11:30:57 +00:00
|
|
|
removeOldGenerations $profilesDir if $removeOld;
|
|
|
|
|
2006-09-06 14:23:04 +00:00
|
|
|
|
|
|
|
# Run the actual garbage collector.
|
|
|
|
exec "@bindir@/nix-store", "--gc", @args;
|