2014-02-01 19:50:12 +00:00
|
|
|
require_relative '../bucket'
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module Cachier
|
|
|
|
class Action
|
|
|
|
class InstallBuckets
|
2014-02-12 01:53:07 +00:00
|
|
|
def initialize(app, env, opts = {})
|
2014-02-01 20:13:42 +00:00
|
|
|
@app = app
|
|
|
|
@logger = Log4r::Logger.new("vagrant::cachier::action::clean")
|
2014-02-12 01:53:07 +00:00
|
|
|
@opts = opts
|
2014-02-01 19:50:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
@app.call(env)
|
|
|
|
|
2014-02-12 02:49:00 +00:00
|
|
|
return unless env[:machine].config.cache.enabled?
|
|
|
|
|
2014-02-12 01:53:07 +00:00
|
|
|
chmod_bucket_root(env[:machine]) if @opts[:chmod]
|
2014-02-01 20:12:38 +00:00
|
|
|
configure_cache_buckets(env)
|
2014-02-01 19:50:12 +00:00
|
|
|
end
|
|
|
|
|
2014-02-12 01:53:07 +00:00
|
|
|
def chmod_bucket_root(machine)
|
2014-07-21 01:13:37 +00:00
|
|
|
machine.communicate.sudo 'mkdir -p /tmp/vagrant-cache'
|
|
|
|
|
|
|
|
# https://github.com/fgrehm/vagrant-cachier/issues/107
|
|
|
|
if ! smb_synced_folder_enabled?(machine)
|
|
|
|
@logger.info "'chmod'ing bucket root dir to 777..."
|
|
|
|
machine.communicate.sudo 'chmod 777 /tmp/vagrant-cache'
|
|
|
|
end
|
2014-02-12 01:53:07 +00:00
|
|
|
end
|
|
|
|
|
2014-02-01 22:17:01 +00:00
|
|
|
def configure_cache_buckets(env)
|
2014-02-01 20:12:38 +00:00
|
|
|
if env[:machine].config.cache.auto_detect
|
|
|
|
Bucket.auto_detect(env)
|
2014-02-01 19:50:12 +00:00
|
|
|
end
|
|
|
|
|
2014-02-01 20:12:38 +00:00
|
|
|
return unless env[:machine].config.cache.buckets.any?
|
2014-02-01 19:50:12 +00:00
|
|
|
|
2014-02-01 20:12:38 +00:00
|
|
|
env[:ui].info 'Configuring cache buckets...'
|
|
|
|
cache_config = env[:machine].config.cache
|
2014-02-01 19:50:12 +00:00
|
|
|
cache_config.buckets.each do |bucket_name, configs|
|
2014-02-01 20:13:42 +00:00
|
|
|
@logger.info "Installing #{bucket_name} with configs #{configs.inspect}"
|
2014-02-01 20:12:38 +00:00
|
|
|
Bucket.install(bucket_name, env, configs)
|
2014-02-01 19:50:12 +00:00
|
|
|
end
|
|
|
|
|
2014-02-01 20:12:38 +00:00
|
|
|
data_file = env[:machine].data_dir.join('cache_dirs')
|
|
|
|
data_file.open('w') { |f| f.print env[:cache_dirs].uniq.join("\n") }
|
2014-02-01 19:50:12 +00:00
|
|
|
end
|
2014-07-21 01:13:37 +00:00
|
|
|
|
|
|
|
def smb_synced_folder_enabled?(machine)
|
|
|
|
synced_folder_opts = machine.config.cache.synced_folder_opts
|
|
|
|
synced_folder_opts ||= {}
|
|
|
|
|
|
|
|
# If smb was explicitly enabled
|
|
|
|
if synced_folder_opts[:type] && synced_folder_opts[:type].to_s == 'smb'
|
|
|
|
return true
|
|
|
|
elsif machine.provider_name.to_sym == :hyperv
|
|
|
|
# If the provider in use is hyperv, the default synced folder is 'smb'
|
|
|
|
# unless specified
|
|
|
|
return synced_folder_opts[:type] == nil
|
|
|
|
end
|
|
|
|
end
|
2014-02-01 19:50:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|