lib/bolt_server/file_cache.rb in bolt-3.23.0 vs lib/bolt_server/file_cache.rb in bolt-3.23.1
- old
+ new
@@ -6,10 +6,11 @@
require 'concurrent/timer_task'
require 'digest'
require 'fileutils'
require 'net/http'
require 'logging'
+require 'timeout'
require 'bolt/error'
module BoltServer
class FileCache
@@ -36,12 +37,11 @@
@logger = Bolt::Logger.logger(self)
@cache_dir_mutex = cache_dir_mutex
if do_purge
@purge = Concurrent::TimerTask.new(execution_interval: purge_interval,
- timeout_interval: purge_timeout,
- run_now: true) { expire(purge_ttl) }
+ run_now: true) { expire(purge_ttl, purge_timeout) }
@purge.execute
end
end
def tmppath
@@ -169,16 +169,18 @@
@logger.debug("Queueing download for: #{file_path}")
serial_execute { download_file(file_path, sha, file_data['uri']) }
end
- def expire(purge_ttl)
+ def expire(purge_ttl, purge_timeout)
expired_time = Time.now - purge_ttl
- @cache_dir_mutex.with_write_lock do
- Dir.glob(File.join(@cache_dir, '*')).select { |f| File.directory?(f) }.each do |dir|
- if (mtime = File.mtime(dir)) < expired_time && dir != tmppath
- @logger.debug("Removing #{dir}, last used at #{mtime}")
- FileUtils.remove_dir(dir)
+ Timeout.timeout(purge_timeout) do
+ @cache_dir_mutex.with_write_lock do
+ Dir.glob(File.join(@cache_dir, '*')).select { |f| File.directory?(f) }.each do |dir|
+ if (mtime = File.mtime(dir)) < expired_time && dir != tmppath
+ @logger.debug("Removing #{dir}, last used at #{mtime}")
+ FileUtils.remove_dir(dir)
+ end
end
end
end
end