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;
|
|
|
|
|
2004-02-06 12:30:20 +02:00
|
|
|
my $linkdir = "@localstatedir@/nix/profiles";
|
2003-07-14 13:45:04 +03:00
|
|
|
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'" };
|
|
|
|
}
|
|
|
|
|
2003-11-22 17:58:34 +02: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 12:30:20 +02:00
|
|
|
next if (!($link =~ /.gcroot$/));
|
2003-11-22 17:58:34 +02:00
|
|
|
open ROOT, "<$link" or die "cannot open $link: $!";
|
|
|
|
my $root = <ROOT>;
|
|
|
|
chomp $root;
|
|
|
|
close ROOT;
|
|
|
|
push @roots, $root;
|
|
|
|
}
|
|
|
|
|
2003-07-29 17:28:17 +03:00
|
|
|
my $extraarg = "";
|
|
|
|
if ($keepsuccessors) { $extraarg = "--include-successors"; };
|
2003-11-22 17:58:34 +02:00
|
|
|
my $pid = open2(\*READ, \*WRITE, "nix-store --query --requisites $extraarg @roots")
|
2003-08-25 17:36:04 +03:00
|
|
|
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-11-22 17:58:34 +02:00
|
|
|
opendir(DIR, $storedir) or die "cannot open directory $storedir: $!";
|
|
|
|
my @names = readdir DIR;
|
2003-07-14 13:45:04 +03:00
|
|
|
closedir DIR;
|
|
|
|
|
|
|
|
foreach my $name (@names) {
|
|
|
|
next if ($name eq "." || $name eq "..");
|
|
|
|
$name = "$storedir/$name";
|
|
|
|
if (!$alive{$name}) {
|
|
|
|
print "$name\n";
|
|
|
|
}
|
|
|
|
}
|