From e89bd1ca2e3fe0d98ab23b21b9b4718393597a1d Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Mon, 17 Jun 2013 17:17:31 -0400 Subject: [PATCH] first whack at rvm support in vagrant-cachier --- lib/vagrant-cachier/bucket/rvm.rb | 39 +++++++++++++++++++++++++ lib/vagrant-cachier/cap/linux/rvmdir.rb | 21 +++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 lib/vagrant-cachier/bucket/rvm.rb create mode 100644 lib/vagrant-cachier/cap/linux/rvmdir.rb diff --git a/lib/vagrant-cachier/bucket/rvm.rb b/lib/vagrant-cachier/bucket/rvm.rb new file mode 100644 index 0000000..f06abc4 --- /dev/null +++ b/lib/vagrant-cachier/bucket/rvm.rb @@ -0,0 +1,39 @@ +module VagrantPlugins + module Cachier + class Bucket + class Rvm < Bucket + def self.capability + :rvmdir + end + + def install + machine = @env[:machine] + guest = machine.guest + + if guest.capability?(:rvmdir) + if rvmdir_path = guest.capability(:rvmdir) + prefix = rvmdir_path.split('/').last + bucket_path = "/tmp/vagrant-cache/#{@name}/#{prefix}" + machine.communicate.tap do |comm| + comm.execute("mkdir -p #{bucket_path}") + + rvm_cache_path = "#{rvmdir_path}/archives" + + @env[:cache_dirs] << rvm_cache_path + + unless comm.test("test -L #{rvm_cache_path}") + comm.sudo("rm -rf #{rvm_cache_path}") + comm.sudo("mkdir -p `dirname #{rvm_cache_path}`") + comm.sudo("ln -s #{bucket_path} #{rvm_cache_path}") + end + end + end + else + # TODO: Raise a better error + raise "You've configured a RVM cache for a guest machine that does not support it!" + end + end + end + end + end +end diff --git a/lib/vagrant-cachier/cap/linux/rvmdir.rb b/lib/vagrant-cachier/cap/linux/rvmdir.rb new file mode 100644 index 0000000..ff896d4 --- /dev/null +++ b/lib/vagrant-cachier/cap/linux/rvmdir.rb @@ -0,0 +1,21 @@ +module VagrantPlugins + module Cachier + module Cap + module Linux + module Rvmdir + def self.rvmdir(machine) + rvmdir = nil + machine.communicate.tap do |comm| + return unless comm.test('rvm info') + comm.execute 'echo $rvm_path' do |buffer, output| + rvmdir = output.chomp if buffer == :stdout + end + end + return rvmdir + end + end + end + end + end +end +