]>
gitweb.michael.orlitzky.com - dead/janitor.git/blob - src/janitor.rb
1 require('src/apache_conf_file')
5 attr_accessor
:apache_vhosts_directory
7 SECONDS_PER_MINUTE
= 60
10 SECONDS_PER_DAY
= SECONDS_PER_MINUTE
* MINUTES_PER_HOUR
* HOURS_PER_DAY
14 @apache_vhosts_directory = nil
20 def seconds_to_whole_days(seconds
)
21 # Given some number of seconds, computer how many
22 # entire days are contained in that number of seconds.
23 # Fractions of days don't count!
26 raise(ArgumentException
.new('Negative seconds?'))
29 return (seconds
/ SECONDS_PER_DAY
).floor
34 # Get a list of all the temporary directories that
35 # we'd like to clean out.
36 def get_temporary_directories(remove_duplicates
= true)
39 # Get the PHP temp dirs if we've been given a vhosts path
40 if !
@apache_vhosts_directory.nil? && File
.directory
?(@apache_vhosts_directory)
41 Dir
.glob(@apache_vhosts_directory +
'/*.conf').each
do |conf_file
|
42 acf
= ApacheConfFile
.new(conf_file
)
44 # Don't remove the duplicates here since we have
45 # to do it afterwards anyway.
46 temp_dirs +
= acf
.get_php_temporary_directory_list(false)
50 # We expect these to have been strip()ed already
59 def clean_directory(directory
, max_age
, file_pattern
= '*')
60 glob_pattern
= File
.join(directory
, file_pattern
)
62 Dir
.glob(glob_pattern
).each
do |f
|
63 # Obviously, we should bail if it's not a file.
64 next if not File
.file
?(f
)
66 # Calculate how old it is
67 days_old
= seconds_to_whole_days(Time
.now
- File
.mtime(f
))
69 # And then delete the file (with a notice) if it's too old.
71 puts
"Deleting file: #{f} (#{days_old} days old)"