forked from the-distro/channel-scripts
* Update the /data/releases cleanup scripts.
git-svn-id: https://nixos.org/repos/nix/release/trunk/channels@34040 70bd8c7a-acb8-0310-9f0d-9cc1c95dcdbb
This commit is contained in:
parent
a00b5af18d
commit
d6bbc1d9f5
21
ReadCache.pm
Normal file
21
ReadCache.pm
Normal file
|
@ -0,0 +1,21 @@
|
|||
package readcache;
|
||||
use strict;
|
||||
|
||||
# Read the archive directories.
|
||||
our %archives;
|
||||
|
||||
sub readDir {
|
||||
my $dir = shift;
|
||||
opendir(DIR, "$dir") or die "cannot open `$dir': $!";
|
||||
my @as = readdir DIR;
|
||||
foreach my $archive (@as) {
|
||||
next unless $archive =~ /^sha256_/ || $archive =~ /\.nar-bsdiff$/ || $archive =~ /\.nar\.bz2$/;
|
||||
$archives{$archive} = "$dir/$archive";
|
||||
}
|
||||
closedir DIR;
|
||||
}
|
||||
|
||||
readDir "/data/releases/nars";
|
||||
readDir "/data/releases/patches";
|
||||
|
||||
print STDERR scalar (keys %archives), "\n";
|
58
print-dead-files.pl
Executable file
58
print-dead-files.pl
Executable file
|
@ -0,0 +1,58 @@
|
|||
#! /var/run/current-system/sw/bin/perl -w -I .
|
||||
|
||||
use strict;
|
||||
use Nix::Manifest;
|
||||
use ReadCache;
|
||||
use File::Basename;
|
||||
|
||||
|
||||
# Read the manifests.
|
||||
my %narFiles;
|
||||
my %patches;
|
||||
|
||||
foreach my $manifest (@ARGV) {
|
||||
print STDERR "loading $manifest\n";
|
||||
if (readManifest($manifest, \%narFiles, \%patches, 1) < 3) {
|
||||
# die "manifest `$manifest' is too old (i.e., for Nix <= 0.7)\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Find the live archives.
|
||||
my %usedFiles;
|
||||
|
||||
foreach my $narFile (keys %narFiles) {
|
||||
foreach my $file (@{$narFiles{$narFile}}) {
|
||||
$file->{url} =~ /\/([^\/]+)$/;
|
||||
my $basename = $1;
|
||||
die unless defined $basename;
|
||||
#print STDERR "GOT $basename\n";
|
||||
$usedFiles{$basename} = 1;
|
||||
print STDERR "missing archive `$basename'\n"
|
||||
unless defined $readcache::archives{$basename};
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
die "missing archive `$basename'"
|
||||
unless defined $readcache::archives{$basename};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Print out the dead archives.
|
||||
foreach my $archive (keys %readcache::archives) {
|
||||
next if $archive eq "." || $archive eq "..";
|
||||
if (!defined $usedFiles{$archive}) {
|
||||
my $file = $readcache::archives{$archive};
|
||||
print "$file\n";
|
||||
my $hashFile = dirname($file) . "/.hash." . basename($file);
|
||||
print "$hashFile\n" if -e $hashFile;
|
||||
}
|
||||
}
|
4
remove-dead-files.sh
Normal file
4
remove-dead-files.sh
Normal file
|
@ -0,0 +1,4 @@
|
|||
#! /bin/sh
|
||||
./print-dead-files.pl /data/releases/patches/all-patches $(find /data/releases -name MANIFEST | grep -v '\.trash' | grep -v '\.tmp') | sort > /tmp/dead
|
||||
mkdir -p /data/releases/.trash/
|
||||
xargs -d '\n' sh -c 'find "$@" -mtime +100 -print' < /tmp/dead | xargs -d '\n' mv -v --target-directory=/data/releases/.trash/
|
Loading…
Reference in a new issue