2006-09-06 17:23:04 +03: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.
|
|
|
|
if ($removeOld) {
|
|
|
|
|
|
|
|
opendir DIR, $profilesDir or die;
|
|
|
|
|
|
|
|
foreach my $name (sort (readdir DIR)) {
|
|
|
|
$name = $profilesDir . "/" . $name;
|
|
|
|
if (-l $name && (readlink($name) =~ /link/)) {
|
|
|
|
print STDERR "removing old generations of profile $name\n";
|
2006-09-25 13:44:27 +03:00
|
|
|
system("@bindir@/nix-env", "-p", $name, "--delete-generations", "old");
|
2006-09-06 17:23:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir DIR or die;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Run the actual garbage collector.
|
|
|
|
exec "@bindir@/nix-store", "--gc", @args;
|