Do not attempt to configure apt-cacher-ng bucket if it is not installed on the guest machine

This commit is contained in:
Fabio Rehm 2013-10-26 15:47:31 -02:00
parent 8e40d0c060
commit 7bc70b7d6e
2 changed files with 23 additions and 14 deletions

View file

@ -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')

View file

@ -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