diff --git a/lib/vagrant-cachier/action/ensure_single_cache_root.rb b/lib/vagrant-cachier/action/ensure_single_cache_root.rb new file mode 100644 index 0000000..e4aa8c6 --- /dev/null +++ b/lib/vagrant-cachier/action/ensure_single_cache_root.rb @@ -0,0 +1,16 @@ +module VagrantPlugins + module Cachier + class Action + class EnsureSingleCacheRoot + def initialize(app, env) + @app = app + end + + def call(env) + raise 'Do our work' + @app.call(env) + end + end + end + end +end diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index 8f8db3e..c6f2a10 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -46,6 +46,21 @@ module VagrantPlugins Cap::Arch::PacmanCacheDir end + # TODO: This should be generic, we don't want to hard code every single + # possible provider action class that Vagrant might have + ensure_single_cache_root = lambda do |hook| + require_relative 'action/ensure_single_cache_root' + hook.after VagrantPlugins::ProviderVirtualBox::Action::Boot, Action::EnsureSingleCacheRoot + + if defined?(Vagrant::LXC) + # TODO: Require just the boot action file once its "require dependencies" are sorted out + require 'vagrant-lxc/action' + hook.after Vagrant::LXC::Action::Boot, Action::EnsureSingleCacheRoot + end + end + action_hook 'ensure-single-cache-root-exists-on-up', :machine_action_up, &ensure_single_cache_root + action_hook 'ensure-single-cache-root-exists-on-reload', :machine_action_reload, &ensure_single_cache_root + clean_action_hook = lambda do |hook| require_relative 'action/clean' hook.before Vagrant::Action::Builtin::GracefulHalt, VagrantPlugins::Cachier::Action::Clean