#!/usr/bin/env ruby
$KCODE='e'
# $Id: goRua_cache_clean.rb,v 1.2 2002/05/19 08:31:56 haruyama Exp $
# ファイルがアクセスされたのが time 以前ならファイルを消す

if ARGV[0] == nil
  time=60*60*24*30
elsif /[^\d]/ =~ ARGV[0] 
  STDERR.print "杪を整数で入れてください\n"
  exit 1
else
  time = ARGV[0].to_i
end


def delete_files(dir,time,time_now)
#Dir.chdir(BASE_DIR+ '/subject/')
  Dir.chdir(dir)
  Dir.glob ("*"){ |filename|
    file = open ( filename)
    if file.lstat.ftype == "file"
      #      if time_now - file.mtime()  > 60*60*24*30
      if time_now - file.atime()  > time
	p file.path
	file.close
	File.unlink(filename)
      end
    end
  }
end

time_now = Time.now

BASE_DIR = ENV["HOME"]+ '/.goRua_2ch/'
delete_files(BASE_DIR+ '/thread/',time,time_now)
delete_files(BASE_DIR+ '/subject/',time,time_now)
