From 98c211590c9eb0e4aed40af652982b8673100c07 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Thu, 2 Jan 2014 01:13:09 -0200 Subject: [PATCH] After 5 months I believe it is safe to get rid of this code --- CHANGELOG.md | 4 ++ .../action/ensure_single_cache_root.rb | 64 ------------------- lib/vagrant-cachier/plugin.rb | 15 ----- 3 files changed, 4 insertions(+), 79 deletions(-) delete mode 100644 lib/vagrant-cachier/action/ensure_single_cache_root.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 02df9fd..a5e8b89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [0.6.0](https://github.com/fgrehm/vagrant-cachier/compare/v0.5.1...master) (unreleased) +BACKWARDS INCOMPATIBILITY: + + - Automatic handling of multiple machine scoped cache dirs from versions + prior to 0.3.0 of this plugin was removed. ## [0.5.1](https://github.com/fgrehm/vagrant-cachier/compare/v0.5.0...v0.5.1) (Dec 20, 2013) diff --git a/lib/vagrant-cachier/action/ensure_single_cache_root.rb b/lib/vagrant-cachier/action/ensure_single_cache_root.rb deleted file mode 100644 index def6375..0000000 --- a/lib/vagrant-cachier/action/ensure_single_cache_root.rb +++ /dev/null @@ -1,64 +0,0 @@ -require_relative '../errors' - -module VagrantPlugins - module Cachier - class Action - class EnsureSingleCacheRoot - def initialize(app, env) - @app = app - end - - def call(env) - @env = env - - # If the cache is scoped to boxes or the existing cache dirs are not - # provider specific, there's nothing we need to do - if cache_scoped_to_machine? && provider_specific_cache_dirs.any? - ensure_single_cache_root_exists! - end - - @app.call(env) - end - - def cache_scoped_to_machine? - @env[:machine].config.cache.enabled? && - @env[:machine].config.cache.scope.to_sym == :machine - end - - def ensure_single_cache_root_exists! - if provider_specific_cache_dirs.size > 1 - cache_dirs = provider_specific_cache_dirs.map do |dir| - " - #{dir.to_s.gsub(/^#{@env[:root_path]}\//, '')}" - end - machine_path = @env[:machine].data_dir.parent.to_s.gsub(/^#{@env[:root_path]}\//, '') - raise Cachier::Errors::MultipleProviderSpecificCacheDirsFound, - machine: @env[:machine].name, - machine_path: machine_path, - dirs: cache_dirs.join("\n") - else - current_path = provider_specific_cache_dirs.first.to_s.gsub(/^#{@env[:root_path]}\//, '') - new_path = @env[:machine].data_dir.parent.join('cache') - FileUtils.rm_rf new_path.to_s if new_path.directory? - - new_path = new_path.to_s.gsub(/^#{@env[:root_path]}\//, '') - # If we got here there is a single provider specific cacher dir, so - # let's be nice with users and just fix it ;) - @env[:ui].warn I18n.t('vagrant_cachier.will_fix_machine_cache_dir', - current_path: current_path, - new_path: new_path) - FileUtils.mv current_path, new_path - end - end - - def provider_specific_cache_dirs - return @provider_specific_cache_dirs if @provider_specific_cache_dirs - - # By default data_dir points to ./.vagrant/machines//, - # so we go one directory up - machine_dir = @env[:machine].data_dir.parent - @provider_specific_cache_dirs = Pathname.glob(machine_dir.join('*/cache')) - end - end - end - end -end diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index c6c638f..6d0ffcd 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -70,21 +70,6 @@ module VagrantPlugins Cap::SuSE::ZypperCacheDir 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.before 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.before 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, Action::Clean