diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2005-03-14 14:03:41 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2005-03-14 14:03:41 +0000 |
commit | 1562dfe9bad119e58296f35c1982fc539a97ac30 (patch) | |
tree | ceaa93943f2a2a613f45a92ef302b8003bae65d4 | |
parent | 012b812698e9b2d8cdb43ffd41e46cc160256d77 (diff) |
* Script to garbage collect nix-push directories. It prints out all
file names in the directory not included in any of the manifests
specified on the command line.
-rwxr-xr-x | scripts/gc-releases.pl | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/scripts/gc-releases.pl b/scripts/gc-releases.pl new file mode 100755 index 000000000..2423d8c0e --- /dev/null +++ b/scripts/gc-releases.pl @@ -0,0 +1,75 @@ +#! /usr/bin/perl -w + +use strict; +use readmanifest; + + +# Read the archive directories. +my @archives = (); +my %archives; + +sub readDir { + my $dir = shift; + opendir(DIR, "$dir") or die "cannot open `$dir': $!"; + my @as = readdir DIR; + foreach my $archive (@as) { + push @archives, $archive; + $archives{$archive} = "$dir/$archive"; + } + closedir DIR; +} + +readDir "/mnt/scratchy/eelco/public_html/nix-cache"; +readDir "/mnt/scratchy/eelco/public_html/patches"; + +print STDERR scalar @archives, "\n"; + + +# Read the manifests. +my %narFiles; +my %patches; +my %successors; + +foreach my $manifest (@ARGV) { + print STDERR "loading $manifest\n"; + if (readManifest($manifest, \%narFiles, \%patches, \%successors) < 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 $basename, "\n"; + $usedFiles{$basename} = 1; + die "missing archive `$basename'" + unless defined $archives{$basename}; + } +} + +foreach my $patch (keys %patches) { + foreach my $file (@{$patches{$patch}}) { + $file->{url} =~ /\/([^\/]+)$/; + my $basename = $1; + die unless defined $basename; +# print $basename, "\n"; + $usedFiles{$basename} = 1; + die "missing archive `$basename'" + unless defined $archives{$basename}; + } +} + + +# Print out the dead archives. +foreach my $archive (@archives) { + next if $archive eq "." || $archive eq ".."; + if (!defined $usedFiles{$archive}) { + print $archives{$archive}, "\n"; + } +} |