]>
Commit | Line | Data |
---|---|---|
090089c4 | 1 | #!/usr/local/bin/perl |
2 | ||
3 | # check_cache.pl - martin hamilton <m.t.hamilton@lut.ac.uk> | |
4 | # | |
5 | # Check the Harvest cache directory for stale objects - i.e. those | |
6 | # which exist on disk but aren't listed in cached's log file. | |
7 | # Version 1 did all this in memory, but the log file can be a | |
8 | # little on the large side... 8-( | |
9 | ||
30a4f2a8 | 10 | # $Id: check_cache.pl,v 1.3 1996/07/09 03:41:16 wessels Exp $ |
090089c4 | 11 | |
12 | require "getopts.pl"; | |
13 | &Getopts("c:dl:rt:v"); | |
14 | ||
15 | $cachedir = $opt_c || "/usr/local/harvest/cache"; | |
16 | # -d -> turn on debugging output | |
17 | $logfile = $opt_l || "$cachedir/log"; | |
18 | # -r -> actually remove stale files | |
19 | $tmpdir = $opt_t || $ENV{TMPDIR} || "/var/tmp"; | |
20 | # -v -> list stale files | |
21 | ||
22 | chdir($tmpdir); | |
23 | ||
24 | # snarf filenames from Harvest log & sort em | |
234967c9 | 25 | system("cut -f1 -d' ' $logfile >pl$$"); |
090089c4 | 26 | system("sort -T $tmpdir pl$$ >spl$$; rm pl$$"); |
27 | ||
28 | # get list of files in cache & sort em | |
29 | system("find $cachedir -print -type f >cd$$"); | |
30 | system("sort -T $tmpdir cd$$ >scd$$; rm cd$$"); | |
31 | ||
32 | # get list of objects in one file but not the other | |
33 | system("comm -13 spl$$ scd$$ >comm$$; rm spl$$ scd$$"); | |
34 | ||
35 | # iterate through it | |
36 | open(IN, "comm$$") || die "Can't open temporary file $tmpdir/comm$$: $!"; | |
37 | while(<IN>) { | |
38 | chop; | |
39 | print STDERR ">> inspecting $_\n" if $opt_d; | |
40 | next if -d "$_"; # don't want directories | |
41 | next if /(log|cached.out)/; # don't want to zap these! | |
42 | ||
43 | print "$_\n" if $opt_v; # print filename if asked | |
44 | ||
45 | # skip if cached file appeared since script started running | |
46 | if (-M $_ < 0) { | |
47 | print STDERR "skipping $_\n" if $opt_d; | |
48 | next; | |
49 | } | |
50 | unlink($_) if $opt_r; # only remove if asked! | |
51 | } | |
52 | close(IN); | |
53 | ||
54 | unlink("comm$$"); | |
55 |