2014-02-01 19:21:46 +00:00
|
|
|
require 'timeout'
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module Cachier
|
|
|
|
class Action
|
|
|
|
class ConfigureBucketRoot
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
@logger = Log4r::Logger.new("vagrant::cachier::action::clean")
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
@env = env
|
|
|
|
|
|
|
|
if !env[:cache_buckets_folder_configured] && env[:machine].config.cache.enabled?
|
|
|
|
setup_buckets_folder
|
|
|
|
env[:cache_buckets_folder_configured] = true
|
|
|
|
end
|
|
|
|
|
|
|
|
@app.call env
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_buckets_folder
|
|
|
|
FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist?
|
|
|
|
|
|
|
|
synced_folder_opts = {id: "vagrant-cache"}
|
2014-02-12 02:48:20 +00:00
|
|
|
synced_folder_opts.merge!(@env[:machine].config.cache.synced_folder_opts || {})
|
2014-02-01 19:21:46 +00:00
|
|
|
|
|
|
|
@env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', synced_folder_opts
|
|
|
|
@env[:cache_dirs] = []
|
|
|
|
end
|
|
|
|
|
|
|
|
def cache_root
|
|
|
|
@cache_root ||= case @env[:machine].config.cache.scope.to_sym
|
|
|
|
when :box
|
2014-07-23 05:53:29 +00:00
|
|
|
@box_name = box_name
|
|
|
|
# Box is optional with docker provider, so use image name if unset
|
|
|
|
if @box_name.nil? && @env[:machine].provider_name.to_sym == :docker
|
|
|
|
bucket_name = image_name.gsub(':', '-')
|
|
|
|
else
|
|
|
|
bucket_name = @box_name
|
|
|
|
end
|
|
|
|
@env[:home_path].join('cache', bucket_name)
|
2014-02-01 19:21:46 +00:00
|
|
|
when :machine
|
|
|
|
@env[:machine].data_dir.parent.join('cache')
|
|
|
|
else
|
|
|
|
raise "Unknown cache scope: '#{@env[:machine].config.cache.scope}'"
|
|
|
|
end
|
|
|
|
end
|
2014-07-20 23:34:14 +00:00
|
|
|
|
|
|
|
def box_name
|
|
|
|
@env[:machine].config.vm.box
|
|
|
|
end
|
2014-07-23 05:53:29 +00:00
|
|
|
|
|
|
|
def image_name
|
|
|
|
@env[:machine].provider_config.image
|
|
|
|
end
|
2014-02-01 19:21:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|