fold duplicates into one line
[andk-cpan-tools.git] / bin / ls-build+tmp.pl
blob712ab35199fe86e45a9aa903e5122591deee7564
3 =head1
5 read the build directories and the /tmp and the home directory and
6 merge them in such a way that we can say which distro dropped
7 something.
9 =cut
11 use strict;
12 use warnings;
15 use Getopt::Long;
16 use Time::HiRes qw(sleep);
18 my %ignore = map { ;"/tmp/$_" => 1; } ".X121-lock", ".UUID_NODEID";
19 for my $de (qw(.aptitude backup .bash_history .bash_logout .bash_profile .bashrc bin .ccache .cpan .cpanplus .cpanreporter .crossfire )) {
20 $ignore{"/home/sand/$de"} = 1;
22 my %Config = (
23 cleanup => 30, # only for /tmp
26 GetOptions(\my %config,
27 (map { "$_=s" } keys %Config),
28 "debug!",
29 ) or die;
32 while (my($k,$v) = each %config) {
33 $Config{$k} = $v;
37 my @all;
38 for my $dir (qw(/tmp /home/sand/.cpan/build /home/k/.cpan/build)) {
39 opendir my $dh, $dir or die "Couldn't opendir: $!";
40 push @all, map { "$dir/$_" } readdir $dh;
42 @all = grep { ! exists $ignore{$_} } @all;
43 my @rall = sort { $a->[1] <=> $b->[1] }
44 map { [$_, (stat$_)[9]] } @all;
45 DIRENT: for my $dirent (@rall) {
46 if (my $cleanup_time = $Config{cleanup}) {
47 if ($dirent->[0] =~ m|^/tmp/........|) {
48 my $age = sprintf "%.4f", -M $dirent->[0];
49 if ($age > $cleanup_time) {
50 require File::Path;
51 warn "Going to rmtree '$dirent->[0]' age[$age]\n";
52 sleep 0.05;
53 File::Path::rmtree($dirent->[0]);
54 next DIRENT;
58 if ($Config{debug}) {
59 my @t = localtime($dirent->[1]);
60 $t[5]+=1900;
61 $t[4]++;
62 my $sigil = -d $dirent->[0] ? "/" : "";
63 printf "%04d-%02d-%02dT%02d:%02d:%02d %6d %s%s\n", @t[5,4,3,2,1,0], -s $dirent->[0], $dirent->[0], $sigil;
64 # printf "%s\n", $dirent->[0];