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: $!";
|
2004-04-14 10:09:27 +02:00
|
|
|
while (<ROOT>) {
|
|
|
|
chomp;
|
|
|
|
foreach my $root (split ' ') {
|
|
|
|
die "bad root `$root' in file `$link'" unless $root =~ /^\S+$/;
|
|
|
|
push @roots, $root;
|
|
|
|
}
|
|
|
|
}
|
2003-11-22 16:58:34 +01:00
|
|
|
close ROOT;
|
|
|
|
}
|
|
|
|
|
2003-07-29 16:28:17 +02:00
|
|
|
my $extraarg = "";
|
|
|
|
if ($keepsuccessors) { $extraarg = "--include-successors"; };
|
2004-04-06 10:18:51 +02:00
|
|
|
my $pid = open2(\*READ, \*WRITE, "@bindir@/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";
|
|
|
|
}
|
|
|
|
}
|