diff --git a/lib/vagrant-cachier/action/configure_bucket_root.rb b/lib/vagrant-cachier/action/configure_bucket_root.rb index 4bd8e67..624f798 100644 --- a/lib/vagrant-cachier/action/configure_bucket_root.rb +++ b/lib/vagrant-cachier/action/configure_bucket_root.rb @@ -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 diff --git a/lib/vagrant-cachier/config.rb b/lib/vagrant-cachier/config.rb index ad8495c..8a2479f 100644 --- a/lib/vagrant-cachier/config.rb +++ b/lib/vagrant-cachier/config.rb @@ -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