2004-03-15 16:23:53 +01:00
|
|
|
#! @perl@ -w
|
2003-07-14 12:45:04 +02:00
|
|
|
|
2003-08-25 16:36:04 +02:00
|
|
|
use strict;
|
|
|
|
use IPC::Open2;
|
|
|
|
|
2004-02-06 11:30:20 +01:00
|
|
|
my $linkdir = "@localstatedir@/nix/profiles";
|
2004-02-20 12:32:30 +01:00
|
|
|
my $storedir = "@storedir@";
|
2003-07-14 12:45:04 +02:00
|
|
|
|
|
|
|
my %alive;
|
|
|
|
|
2003-10-09 17:38:31 +02:00
|
|
|
my $keepsuccessors = 1;
|
2003-07-29 16:28:17 +02:00
|
|
|
my $invert = 0;
|
|
|
|
|
|
|
|
foreach my $arg (@ARGV) {
|
2003-10-09 17:38:31 +02:00
|
|
|
if ($arg eq "--no-successors") { $keepsuccessors = 0; }
|
2003-07-29 16:42:14 +02:00
|
|
|
elsif ($arg eq "--invert") { $invert = 1; }
|
2003-07-29 16:28:17 +02:00
|
|
|
else { die "unknown argument `$arg'" };
|
|
|
|
}
|
|
|
|
|
2003-11-22 16:58:34 +01:00
|
|
|
opendir(DIR, $linkdir) or die "cannot open directory $linkdir: $!";
|
|
|
|
my @links = readdir DIR or die "cannot read directory $linkdir: $!";
|
|
|
|
closedir DIR;
|
|
|
|
|
|
|
|
my @roots;
|
|
|
|
foreach my $link (@links) {
|
|
|
|
$link = $linkdir . "/" . $link;
|
2004-02-06 11:30:20 +01:00
|
|
|
next if (!($link =~ /.gcroot$/));
|
2003-11-22 16:58:34 +01:00
|
|
|
open ROOT, "<$link" or die "cannot open $link: $!";
|
|
|
|
my $root = <ROOT>;
|
|
|
|
chomp $root;
|
|
|
|
close ROOT;
|
|
|
|
push @roots, $root;
|
|
|
|
}
|
|
|
|
|
2003-07-29 16:28:17 +02:00
|
|
|
my $extraarg = "";
|
|
|
|
if ($keepsuccessors) { $extraarg = "--include-successors"; };
|
2003-11-22 16:58:34 +01:00
|
|
|
my $pid = open2(\*READ, \*WRITE, "nix-store --query --requisites $extraarg @roots")
|
2003-08-25 16:36:04 +02:00
|
|
|
or die "determining live paths";
|
|
|
|
close WRITE;
|
|
|
|
while (<READ>) {
|
2003-07-14 12:45:04 +02:00
|
|
|
chomp;
|
|
|
|
$alive{$_} = 1;
|
2003-07-29 16:28:17 +02:00
|
|
|
if ($invert) { print "$_\n"; };
|
2003-07-14 12:45:04 +02:00
|
|
|
}
|
2003-08-25 16:36:04 +02:00
|
|
|
close READ;
|
|
|
|
|
|
|
|
waitpid $pid, 0;
|
|
|
|
$? == 0 or die "determining live paths";
|
2003-07-14 12:45:04 +02:00
|
|
|
|
2003-07-29 16:28:17 +02:00
|
|
|
exit 0 if ($invert);
|
|
|
|
|
2003-11-22 16:58:34 +01:00
|
|
|
opendir(DIR, $storedir) or die "cannot open directory $storedir: $!";
|
|
|
|
my @names = readdir DIR;
|
2003-07-14 12:45:04 +02:00
|
|
|
closedir DIR;
|
|
|
|
|
|
|
|
foreach my $name (@names) {
|
|
|
|
next if ($name eq "." || $name eq "..");
|
|
|
|
$name = "$storedir/$name";
|
|
|
|
if (!$alive{$name}) {
|
|
|
|
print "$name\n";
|
|
|
|
}
|
|
|
|
}
|