2003-07-14 12:45:04 +02:00
|
|
|
#! /usr/bin/perl -w
|
|
|
|
|
2003-08-25 16:36:04 +02:00
|
|
|
use strict;
|
|
|
|
use IPC::Open2;
|
|
|
|
|
2003-07-14 12:45:04 +02:00
|
|
|
my $linkdir = "@localstatedir@/nix/links";
|
|
|
|
my $storedir = "@prefix@/store";
|
|
|
|
|
|
|
|
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'" };
|
|
|
|
}
|
|
|
|
|
|
|
|
my $extraarg = "";
|
|
|
|
if ($keepsuccessors) { $extraarg = "--include-successors"; };
|
2003-08-25 16:36:04 +02:00
|
|
|
my $pid = open2(\*READ, \*WRITE, "nix --query --requisites $extraarg \$(cat $linkdir/*.id)")
|
|
|
|
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-07-14 12:45:04 +02:00
|
|
|
opendir(DIR, $storedir) or die "cannot opendir $storedir: $!";
|
|
|
|
my @names = readdir(DIR);
|
|
|
|
closedir DIR;
|
|
|
|
|
|
|
|
foreach my $name (@names) {
|
|
|
|
next if ($name eq "." || $name eq "..");
|
|
|
|
$name = "$storedir/$name";
|
|
|
|
if (!$alive{$name}) {
|
|
|
|
print "$name\n";
|
|
|
|
}
|
|
|
|
}
|