cleancache.pl.in
上传用户:s81996212
上传日期:2007-01-04
资源大小:722k
文件大小:2k
- #! @PERL@
- #
- # $Id: cleancache.pl.in,v 1.2 1999/12/08 06:00:38 mrsam Exp $
- #
- # Copyright 1998 - 1999 Double Precision, Inc. See COPYING for
- # distribution information.
- #
- # This script is only used when sqwebmail is compiled with the option to
- # use a cache to store login information (saving a getpw lookup for each
- # HTTP request, which can be very expensive on large sites).
- #
- # If the login cache option is used, this script must be regularly executed
- # by cron to remove stale cache entries.
- $cachedir="@cachedir@";
- $timeout=@TIMEOUTHARD@; # DO NOT CHANGE UNDER PENALTY OF LAW!!!
- chdir($cachedir) || exit 0;
- #
- # timeout is hardcoded at configure time. Cached entries are created in
- # subdirs named after int( time / $timeout). Therefore, the oldest possibly
- # valid login would be in ( (time-$timeout) / $timeout ), or:
- #
- $oldestdir=int(time / $timeout)-1;
- #
- # So, our task is simply to remove all directories older than that.
- #
- opendir(TOPDIR, ".") || exit 0;
- while (defined ($name=readdir(TOPDIR)))
- {
- next unless $name =~ /^[0-9]+$/;
- next unless $name < $oldestdir;
- push @DIRS, $name;
- }
- closedir(TOPDIR);
- while ( defined ($name=shift @DIRS) )
- {
- chdir($name) && &rmrf && chdir("..") && rmdir($name) && next;
- chomp(($pwd=`pwd`)); die "$pwd/$name: $!n";
- }
- sub rmrf {
- my(@dir);
- my($name);
- opendir(DIR, ".") || return 0;
- while (defined ($name=readdir(DIR)))
- {
- next if $name eq "." || $name eq "..";
- push @dir, $name;
- }
- closedir(DIR);
- while ( defined ($name=shift @dir))
- {
- next if unlink($name);
- chdir($name) && &rmrf && chdir("..") && rmdir($name) && next;
- chomp(($pwd=`pwd`)); die "$pwd/$name: $!n";
- }
- return 1;
- }