2012-05-09 23:13:05 +00:00
|
|
|
#! /var/run/current-system/sw/bin/perl -w -I .
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Nix::Manifest;
|
|
|
|
use File::Basename;
|
|
|
|
|
2012-12-10 18:22:46 +00:00
|
|
|
my $cacheDir = "/data/releases/binary-cache";
|
|
|
|
|
2012-05-09 23:13:05 +00:00
|
|
|
|
|
|
|
# Read the manifests.
|
|
|
|
my %narFiles;
|
|
|
|
my %patches;
|
|
|
|
|
|
|
|
foreach my $manifest (@ARGV) {
|
|
|
|
print STDERR "loading $manifest\n";
|
|
|
|
if (readManifest($manifest, \%narFiles, \%patches, 1) < 3) {
|
2012-12-10 18:22:46 +00:00
|
|
|
warn "manifest `$manifest' is too old (i.e., for Nix <= 0.7)\n";
|
2012-05-09 23:13:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Find the live archives.
|
|
|
|
my %usedFiles;
|
2012-12-10 18:22:46 +00:00
|
|
|
my %hashParts;
|
2012-05-09 23:13:05 +00:00
|
|
|
|
2012-12-10 18:22:46 +00:00
|
|
|
foreach my $storePath (keys %narFiles) {
|
|
|
|
$storePath =~ /\/nix\/store\/([a-z0-9]+)/ or die "WRONG: $storePath";
|
|
|
|
$hashParts{$1} = 1;
|
|
|
|
foreach my $file (@{$narFiles{$storePath}}) {
|
2012-05-09 23:13:05 +00:00
|
|
|
$file->{url} =~ /\/([^\/]+)$/;
|
|
|
|
my $basename = $1;
|
|
|
|
die unless defined $basename;
|
|
|
|
#print STDERR "GOT $basename\n";
|
|
|
|
$usedFiles{$basename} = 1;
|
2013-06-17 02:15:49 +00:00
|
|
|
die "$storePath does not have a file hash" unless defined $file->{hash};
|
|
|
|
if ($file->{hash} =~ /sha256:(.+)/) {
|
|
|
|
die unless length($1) == 52;
|
|
|
|
$usedFiles{"$1.nar.bz2"} = 1;
|
|
|
|
$usedFiles{"$1.nar.xz"} = 1;
|
|
|
|
}
|
2012-12-10 18:22:46 +00:00
|
|
|
#print STDERR "missing archive `$basename'\n"
|
|
|
|
# unless defined $readcache::archives{$basename};
|
2012-05-09 23:13:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $patch (keys %patches) {
|
|
|
|
foreach my $file (@{$patches{$patch}}) {
|
|
|
|
$file->{url} =~ /\/([^\/]+)$/;
|
|
|
|
my $basename = $1;
|
|
|
|
die unless defined $basename;
|
|
|
|
#print STDERR "GOT2 $basename\n";
|
|
|
|
$usedFiles{$basename} = 1;
|
2012-12-10 18:22:46 +00:00
|
|
|
#die "missing archive `$basename'"
|
|
|
|
# unless defined $readcache::archives{$basename};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub checkDir {
|
|
|
|
my ($dir) = @_;
|
|
|
|
opendir(DIR, "$dir") or die "cannot open `$dir': $!";
|
|
|
|
while (readdir DIR) {
|
2013-06-17 02:15:49 +00:00
|
|
|
next unless $_ =~ /^sha256_/ || $_ =~ /\.nar-bsdiff$/ || $_ =~ /\.nar\.bz2$/ || $_ =~ /\.nar\.xz$/;
|
|
|
|
if (!defined $usedFiles{$_}) {
|
|
|
|
print "$dir/$_\n";
|
|
|
|
} else {
|
|
|
|
#print STDERR "keeping $dir/$_\n";
|
|
|
|
}
|
2012-12-10 18:22:46 +00:00
|
|
|
|
2012-05-09 23:13:05 +00:00
|
|
|
}
|
2012-12-10 18:22:46 +00:00
|
|
|
closedir DIR;
|
2012-05-09 23:13:05 +00:00
|
|
|
}
|
|
|
|
|
2012-12-10 18:22:46 +00:00
|
|
|
checkDir("/data/releases/nars");
|
|
|
|
checkDir("/data/releases/patches");
|
|
|
|
checkDir("$cacheDir/nar");
|
2012-05-09 23:13:05 +00:00
|
|
|
|
2012-12-10 18:22:46 +00:00
|
|
|
# Look for obsolete narinfo files.
|
|
|
|
opendir(DIR, $cacheDir) or die;
|
|
|
|
while (readdir DIR) {
|
|
|
|
next unless /^(.*)\.narinfo$/;
|
|
|
|
my $hashPart = $1;
|
|
|
|
if (!defined $hashParts{$hashPart}) {
|
2013-06-17 02:15:49 +00:00
|
|
|
print "$cacheDir/$_\n";
|
2012-12-10 18:22:46 +00:00
|
|
|
} else {
|
2013-06-17 02:15:49 +00:00
|
|
|
#print STDERR "keeping $cacheDir/$_\n";
|
2012-05-09 23:13:05 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-10 18:22:46 +00:00
|
|
|
closedir DIR;
|