2003-07-14 13:45:04 +03:00
|
|
|
#! /usr/bin/perl -w
|
|
|
|
|
2003-08-25 17:36:04 +03:00
|
|
|
use strict;
|
|
|
|
use IPC::Open2;
|
|
|
|
|
2003-07-14 13:45:04 +03:00
|
|
|
my $linkdir = "@localstatedir@/nix/links";
|
|
|
|
my $storedir = "@prefix@/store";
|
|
|
|
|
|
|
|
my %alive;
|
|
|
|
|
2003-10-09 18:38:31 +03:00
|
|
|
my $keepsuccessors = 1;
|
2003-07-29 17:28:17 +03:00
|
|
|
my $invert = 0;
|
|
|
|
|
|
|
|
foreach my $arg (@ARGV) {
|
2003-10-09 18:38:31 +03:00
|
|
|
if ($arg eq "--no-successors") { $keepsuccessors = 0; }
|
2003-07-29 17:42:14 +03:00
|
|
|
elsif ($arg eq "--invert") { $invert = 1; }
|
2003-07-29 17:28:17 +03:00
|
|
|
else { die "unknown argument `$arg'" };
|
|
|
|
}
|
|
|
|
|
|
|
|
my $extraarg = "";
|
|
|
|
if ($keepsuccessors) { $extraarg = "--include-successors"; };
|
2003-08-25 17:36:04 +03: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 13:45:04 +03:00
|
|
|
chomp;
|
|
|
|
$alive{$_} = 1;
|
2003-07-29 17:28:17 +03:00
|
|
|
if ($invert) { print "$_\n"; };
|
2003-07-14 13:45:04 +03:00
|
|
|
}
|
2003-08-25 17:36:04 +03:00
|
|
|
close READ;
|
|
|
|
|
|
|
|
waitpid $pid, 0;
|
|
|
|
$? == 0 or die "determining live paths";
|
2003-07-14 13:45:04 +03:00
|
|
|
|
2003-07-29 17:28:17 +03:00
|
|
|
exit 0 if ($invert);
|
|
|
|
|
2003-07-14 13:45:04 +03: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";
|
|
|
|
}
|
|
|
|
}
|