From b50374162a9677fc90d2d027dfc6b849f2bd3ca8 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 3 Aug 2013 14:30:39 -0300 Subject: [PATCH] ProvisionExt is not an action! --- lib/vagrant-cachier/action/provision_ext.rb | 70 --------------------- lib/vagrant-cachier/plugin.rb | 4 +- lib/vagrant-cachier/provision_ext.rb | 68 ++++++++++++++++++++ 3 files changed, 70 insertions(+), 72 deletions(-) delete mode 100644 lib/vagrant-cachier/action/provision_ext.rb create mode 100644 lib/vagrant-cachier/provision_ext.rb diff --git a/lib/vagrant-cachier/action/provision_ext.rb b/lib/vagrant-cachier/action/provision_ext.rb deleted file mode 100644 index d03a307..0000000 --- a/lib/vagrant-cachier/action/provision_ext.rb +++ /dev/null @@ -1,70 +0,0 @@ -require_relative '../bucket' - -module VagrantPlugins - module Cachier - module Action - module ProvisionExt - def self.included(base) - base.class_eval do - def cachier_debug(msg) - @logger.debug "[CACHIER] #{msg}" - end - - alias :old_call :call - def call(env) - return old_call(env) unless env[:machine].config.cache.enabled? - - @env = env - - FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist? - - nfs_flag = env[:machine].config.cache.enable_nfs - env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', id: "vagrant-cache", nfs: nfs_flag - - env[:cache_dirs] = [] - - old_call(env) - - configure_cache_buckets - end - - alias :old_run_provisioner :run_provisioner - def run_provisioner(*args) - configure_cache_buckets - old_run_provisioner(*args) - end - - def configure_cache_buckets - if @env[:machine].config.cache.auto_detect - Bucket.auto_detect(@env) - end - - return unless @env[:machine].config.cache.buckets.any? - - @env[:ui].info 'Configuring cache buckets...' - cache_config = @env[:machine].config.cache - cache_config.buckets.each do |bucket_name, configs| - cachier_debug "Installing #{bucket_name} with configs #{configs.inspect}" - Bucket.install(bucket_name, @env, configs) - end - - data_file = @env[:machine].data_dir.join('cache_dirs') - data_file.open('w') { |f| f.print @env[:cache_dirs].uniq.join("\n") } - end - - def cache_root - @cache_root ||= case @env[:machine].config.cache.scope - when :box - @env[:home_path].join('cache', @env[:machine].box.name) - when :machine - @env[:machine].data_dir.join('cache') - else - raise "Unknown cache scope: '#{@env[:machine].config.cache.scope}'" - end - end - end - end - end - end - end -end diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index 597f338..8f8db3e 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -1,6 +1,6 @@ -require_relative 'action/provision_ext' +require_relative 'provision_ext' Vagrant::Action::Builtin::Provision.class_eval do - include VagrantPlugins::Cachier::Action::ProvisionExt + include VagrantPlugins::Cachier::ProvisionExt end # Add our custom translations to the load path diff --git a/lib/vagrant-cachier/provision_ext.rb b/lib/vagrant-cachier/provision_ext.rb new file mode 100644 index 0000000..e8cc8b3 --- /dev/null +++ b/lib/vagrant-cachier/provision_ext.rb @@ -0,0 +1,68 @@ +require_relative 'bucket' + +module VagrantPlugins + module Cachier + module ProvisionExt + def self.included(base) + base.class_eval do + def cachier_debug(msg) + @logger.debug "[CACHIER] #{msg}" + end + + alias :old_call :call + def call(env) + return old_call(env) unless env[:machine].config.cache.enabled? + + @env = env + + FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist? + + nfs_flag = env[:machine].config.cache.enable_nfs + env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', id: "vagrant-cache", nfs: nfs_flag + + env[:cache_dirs] = [] + + old_call(env) + + configure_cache_buckets + end + + alias :old_run_provisioner :run_provisioner + def run_provisioner(*args) + configure_cache_buckets + old_run_provisioner(*args) + end + + def configure_cache_buckets + if @env[:machine].config.cache.auto_detect + Bucket.auto_detect(@env) + end + + return unless @env[:machine].config.cache.buckets.any? + + @env[:ui].info 'Configuring cache buckets...' + cache_config = @env[:machine].config.cache + cache_config.buckets.each do |bucket_name, configs| + cachier_debug "Installing #{bucket_name} with configs #{configs.inspect}" + Bucket.install(bucket_name, @env, configs) + end + + data_file = @env[:machine].data_dir.join('cache_dirs') + data_file.open('w') { |f| f.print @env[:cache_dirs].uniq.join("\n") } + end + + def cache_root + @cache_root ||= case @env[:machine].config.cache.scope + when :box + @env[:home_path].join('cache', @env[:machine].box.name) + when :machine + @env[:machine].data_dir.join('cache') + else + raise "Unknown cache scope: '#{@env[:machine].config.cache.scope}'" + end + end + end + end + end + end +end