summaryrefslogtreecommitdiffstats
path: root/util/cleandir.pl
blob: 63b484e446f6b044ab4ae60252171cff2f521c65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
# $Id$
use strict;
use BBSFileHeader;

my($nDels, $prefix) = ();

foreach( @ARGV ){
    print "cleaning: $_\n";
    cleandir($_);
    print "\n";
}

sub toclean
{
    unlink("$prefix/$_[0]");
    print "$_[0]\t";
    ++$nDels;
}

sub cleandir($)
{
    my($dir) = @_;
    my(%files, %dotDIR, $now, $counter) = ();
    $now = time();
    $prefix = $dir;

    opendir DIR, $dir;
    foreach( readdir(DIR) ){
    if( /^M\.\d+\.A/ ){
        $files{$_} = 1;
    } elsif( (/^SR\./) && (stat($_))[2] < ($now - 86400) ){
        toclean($_);
    }
    }
    close DIR;

    tie %dotDIR, 'BBSFileHeader', $dir;
    foreach( 0..($dotDIR{num} - 1) ){
    my $fn = $dotDIR{"$_.filename"};
    delete $files{$fn};
    }
    untie %dotDIR;

    toclean($_)
    foreach( keys %files );
}