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:
parent
3b18f4a5ec
commit
0733ad5afe
2 changed files with 18 additions and 2 deletions
lib/vagrant-cachier
|
@ -21,7 +21,19 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_buckets_folder
|
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 = {id: "vagrant-cache"}
|
||||||
synced_folder_opts.merge!(@env[:machine].config.cache.synced_folder_opts || {})
|
synced_folder_opts.merge!(@env[:machine].config.cache.synced_folder_opts || {})
|
||||||
|
@ -33,6 +45,8 @@ module VagrantPlugins
|
||||||
def cache_root
|
def cache_root
|
||||||
@cache_root ||= case @env[:machine].config.cache.scope.to_sym
|
@cache_root ||= case @env[:machine].config.cache.scope.to_sym
|
||||||
when :box
|
when :box
|
||||||
|
custom_root = @env[:machine].config.cache.root
|
||||||
|
return custom_root unless custom_root == nil
|
||||||
@box_name = box_name
|
@box_name = box_name
|
||||||
# Box is optional with docker provider
|
# Box is optional with docker provider
|
||||||
if @box_name.nil? && @env[:machine].provider_name.to_sym == :docker
|
if @box_name.nil? && @env[:machine].provider_name.to_sym == :docker
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module Cachier
|
module Cachier
|
||||||
class Config < Vagrant.plugin(2, :config)
|
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
|
attr_reader :buckets
|
||||||
|
|
||||||
ALLOWED_SCOPES = %w( box machine )
|
ALLOWED_SCOPES = %w( box machine )
|
||||||
|
@ -11,6 +11,7 @@ module VagrantPlugins
|
||||||
@auto_detect = UNSET_VALUE
|
@auto_detect = UNSET_VALUE
|
||||||
@synced_folder_opts = UNSET_VALUE
|
@synced_folder_opts = UNSET_VALUE
|
||||||
@ui = Vagrant::UI::Colored.new
|
@ui = Vagrant::UI::Colored.new
|
||||||
|
@root = UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
def enable(bucket, opts = {})
|
def enable(bucket, opts = {})
|
||||||
|
@ -51,6 +52,7 @@ module VagrantPlugins
|
||||||
@auto_detect = true if @auto_detect == UNSET_VALUE
|
@auto_detect = true if @auto_detect == UNSET_VALUE
|
||||||
@synced_folder_opts = nil if @synced_folder_opts == UNSET_VALUE
|
@synced_folder_opts = nil if @synced_folder_opts == UNSET_VALUE
|
||||||
@buckets = @buckets ? @buckets.dup : {}
|
@buckets = @buckets ? @buckets.dup : {}
|
||||||
|
@root = nil if @root == UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Loading…
Reference in a new issue