From 7bc70b7d6eaebd983eafc79cbefd1533874e12c8 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 26 Oct 2013 15:47:31 -0200 Subject: [PATCH] Do not attempt to configure apt-cacher-ng bucket if it is not installed on the guest machine --- lib/vagrant-cachier/bucket/apt_cacher.rb | 24 +++++++++---------- .../cap/debian/apt_cacher_dir.rb | 13 ++++++++-- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/vagrant-cachier/bucket/apt_cacher.rb b/lib/vagrant-cachier/bucket/apt_cacher.rb index 3f4a194..57c6f8d 100644 --- a/lib/vagrant-cachier/bucket/apt_cacher.rb +++ b/lib/vagrant-cachier/bucket/apt_cacher.rb @@ -13,21 +13,21 @@ module VagrantPlugins guest = machine.guest if guest.capability?(:apt_cacher_dir) - if machine.config.cache.enable_nfs - guest_path = guest.capability(:apt_cacher_dir) + if guest_path = guest.capability(:apt_cacher_dir) + if machine.config.cache.enable_nfs + @env[:cache_dirs] << guest_path - @env[:cache_dirs] << guest_path - - machine.communicate.tap do |comm| - comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}") - unless comm.test("test -L #{guest_path}") - comm.sudo("rm -rf #{guest_path}") - comm.sudo("mkdir -p `dirname #{guest_path}`") - comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}") + machine.communicate.tap do |comm| + comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}") + unless comm.test("test -L #{guest_path}") + comm.sudo("rm -rf #{guest_path}") + comm.sudo("mkdir -p `dirname #{guest_path}`") + comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}") + end end + else + @env[:ui].info I18n.t('vagrant_cachier.nfs_required', bucket: 'apt-cacher') end - else - @env[:ui].info I18n.t('vagrant_cachier.nfs_required', bucket: 'apt-cacher') end else @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'apt-cacher') diff --git a/lib/vagrant-cachier/cap/debian/apt_cacher_dir.rb b/lib/vagrant-cachier/cap/debian/apt_cacher_dir.rb index 766eff1..3880b1e 100644 --- a/lib/vagrant-cachier/cap/debian/apt_cacher_dir.rb +++ b/lib/vagrant-cachier/cap/debian/apt_cacher_dir.rb @@ -3,9 +3,18 @@ module VagrantPlugins module Cap module Debian module AptCacherDir + CACHER_CONF = '/etc/apt-cacher-ng/acng.conf' + CACHER_CACHE_DIR = "$(cat #{CACHER_CONF} | grep CacheDir | cut -d' ' -f 2)" + def self.apt_cacher_dir(machine) - # cat /etc/apt-cacher-ng/acng.conf |grep CacheDir - '/var/cache/apt-cacher-ng' + cache_dir = nil + machine.communicate.tap do |comm| + return unless comm.test("test -f #{CACHER_CONF}") + comm.execute "echo #{CACHER_CACHE_DIR}" do |buffer, output| + cache_dir = output.chomp if buffer == :stdout + end + end + return cache_dir end end end