This repository was archived by the owner on Jul 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCacheCleaner.pl
More file actions
executable file
·58 lines (47 loc) · 1.54 KB
/
CacheCleaner.pl
File metadata and controls
executable file
·58 lines (47 loc) · 1.54 KB
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
48
49
50
51
52
53
54
55
56
57
#!/usr/local/bin/perl
# Copyright SRA International
#
# Distributed under the OSI-approved BSD 3-Clause License.
# See http://ncip.github.com/pathway-interaction-database/LICENSE.txt for details.
use strict;
use constant HOURS_TO_LIVE => 5;
use constant HOURS_TO_LIVE_FOR_GENOMICS => 148;
use constant TIME_TO_LIVE => HOURS_TO_LIVE * 60 * 60;
use constant TIME_TO_LIVE_FOR_GENOMICS => HOURS_TO_LIVE_FOR_GENOMICS * 60 * 60;
my (
$CACHE_PATH,
$PREFIXES
) = @ARGV;
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
$atime, $mtime, $ctime, $blksize, $blocks);
my ($filename, %prefixes, $prefix, $suffix);
my $now = time();
for $prefix (split ",", $PREFIXES) {
$prefixes{$prefix} = 1;
}
opendir (CACHE_DIR, $CACHE_PATH) || die "can not open $CACHE_PATH";
while( $filename = readdir(CACHE_DIR) ) {
if( !($filename =~ /^\./) ) {
if( $filename =~ /^[a-zA-Z]+\.\d+$/) {
($prefix, $suffix) = split /\./, $filename;
if (defined $prefixes{$prefix}){
$filename = $CACHE_PATH . "/" . $filename;
($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
$atime, $mtime, $ctime, $blksize, $blocks) = stat ($filename);
if ( $prefix eq "GENOMICS") {
if ($now - $atime > TIME_TO_LIVE_FOR_GENOMICS) {
print "deleting file: $filename\n";
unlink($filename);
}
}
else {
if ($now - $atime > TIME_TO_LIVE) {
print "deleting file: $filename\n";
unlink($filename);
}
}
}
}
}
}
closedir CACHEDIR;