Add config.cache.root option to specify a custom cache root.

Only available for single box environments.
Requires that the custom cache root already exists - because it is
custom, it is your responsbility instead of vagrant-cachier's.
Fixes #87.
This commit is contained in:
Aneesh Agrawal 2015-05-11 05:51:53 -04:00
parent 3b18f4a5ec
commit 0733ad5afe
2 changed files with 18 additions and 2 deletions

View file

@ -21,7 +21,19 @@ module VagrantPlugins
end
def setup_buckets_folder
FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist?
custom_root = @env[:machine].config.cache.root
if custom_root != nil
case @env[:machine].config.cache.scope.to_sym
when :box
unless File.directory? custom_root
raise "Custom cache root must already exist and be a directory"
end
else
raise "Custom cache root only supported in single box environments"
end
else
FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist?
end
synced_folder_opts = {id: "vagrant-cache"}
synced_folder_opts.merge!(@env[:machine].config.cache.synced_folder_opts || {})
@ -33,6 +45,8 @@ module VagrantPlugins
def cache_root
@cache_root ||= case @env[:machine].config.cache.scope.to_sym
when :box
custom_root = @env[:machine].config.cache.root
return custom_root unless custom_root == nil
@box_name = box_name
# Box is optional with docker provider
if @box_name.nil? && @env[:machine].provider_name.to_sym == :docker

View file

@ -1,7 +1,7 @@
module VagrantPlugins
module Cachier
class Config < Vagrant.plugin(2, :config)
attr_accessor :scope, :auto_detect, :synced_folder_opts
attr_accessor :scope, :auto_detect, :synced_folder_opts, :root
attr_reader :buckets
ALLOWED_SCOPES = %w( box machine )
@ -11,6 +11,7 @@ module VagrantPlugins
@auto_detect = UNSET_VALUE
@synced_folder_opts = UNSET_VALUE
@ui = Vagrant::UI::Colored.new
@root = UNSET_VALUE
end
def enable(bucket, opts = {})
@ -51,6 +52,7 @@ module VagrantPlugins
@auto_detect = true if @auto_detect == UNSET_VALUE
@synced_folder_opts = nil if @synced_folder_opts == UNSET_VALUE
@buckets = @buckets ? @buckets.dup : {}
@root = nil if @root == UNSET_VALUE
end
private