From 4d2afe48b08b4c0245a522baa338ccc577340d97 Mon Sep 17 00:00:00 2001 From: Andreas Koenig Date: Sat, 30 Dec 2017 12:51:48 +0100 Subject: [PATCH] WIP --- bin/analysis-oldsolutions-extinction-program.pl | 36 ++++++++++++++++++++----- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/bin/analysis-oldsolutions-extinction-program.pl b/bin/analysis-oldsolutions-extinction-program.pl index f9203014..1851c052 100644 --- a/bin/analysis-oldsolutions-extinction-program.pl +++ b/bin/analysis-oldsolutions-extinction-program.pl @@ -28,6 +28,11 @@ This help Stop after how many +=item B<--minage=f> + +Minimum age in days of the target directory +(measured with C<-M>). + =back =head1 DESCRIPTION @@ -38,10 +43,7 @@ Stop after how many use FindBin; -use lib "$FindBin::Bin/../lib"; -BEGIN { - push @INC, qw( ); -} +use lib "$FindBin::Bin/../CPAN-Blame/lib"; use Dumpvalue; use File::Basename qw(dirname); @@ -61,19 +63,39 @@ GetOptions(\%Opt, if ($Opt{help}) { pod2usage(0); } +$Opt{minage} //= 1440; my $root = $CPAN::Blame::Config::Cnntp::Config->{ctgetreports_dir} || die; my $workdir = $CPAN::Blame::Config::Cnntp::Config->{solver_vardir} || die; -my $workdir =~ s"$"/workdir/solved"; +$workdir =~ s"$"/workdir/solved"; opendir my $dh, $workdir or die; my(%seen, $i); -for my $dirent (readdir $dh) { +DIRENT: for my $dirent (readdir $dh) { # CPAN-Mini-Indexed-0.01_01.1.slv.LCK, CPAN-Mini-Indexed-0.03_01.2.slv, CPAN-Mini-Indexed-0.03_01.2.slvdv.gz, CPAN-Mini-Indexed-0.03_01.2.yml my($stem) = $dirent =~ /(.+)(?:\.slv\.LCK|\.slv|\.slvdv.gz|\.yml)$/ or next; next if $seen{$stem}++; warn "$stem\n"; my $troot = sprintf "%s/%s/%s", $root, substr($stem,0,1), $stem; - system "ls -l $stem* $troot*"; + my @trcand = grep { -e $_ } glob("$troot\{,.tar}"); + # if (-e "$troot.tar") { + if (@trcand) { + my $trcand = scalar @trcand; + warn " has $trcand tarballs or something: @trcand\n"; + next DIRENT; + } + my @cand = grep { -e $_ } glob("$workdir/$stem\{.slv.LCK,.slv,.slvdv.gz,.yml}"); + if (map { /[\*\?]/ } @cand) { + die "Illegal filename with glob character discovered: @cand"; + } + system "ls -l @cand"; + my @ages = sort { $a <=> $b } map { -M $_ } @cand; + if ($ages[0] < $Opt{minage}) { + warn " is younger than $Opt{minage} days ($ages[0])\n"; + next DIRENT; + } + warn " about to unlink @cand\n"; + unlink @cand or die "Could not unlink: $!"; + system df => $root; last if $Opt{max} && ++$i >= $Opt{max}; } -- 2.11.4.GIT