diff --git a/config/default.rb b/config/default.rb index cd5b74ccf..f9cd934e9 100644 --- a/config/default.rb +++ b/config/default.rb @@ -15,6 +15,7 @@ Vagrant::Config.run do |config| config.vm.box_ovf = "box.ovf" config.vm.base_mac = "0800279C2E42" config.vm.project_directory = "/vagrant" + config.vm.rsync_project_directory = false config.vm.forward_port("ssh", 22, 2222) config.vm.disk_image_format = 'VMDK' config.vm.provisioner = nil diff --git a/lib/vagrant/actions/vm/boot.rb b/lib/vagrant/actions/vm/boot.rb index d7f035bb3..9d840c079 100644 --- a/lib/vagrant/actions/vm/boot.rb +++ b/lib/vagrant/actions/vm/boot.rb @@ -3,7 +3,10 @@ module Vagrant module VM class Boot < Base def prepare - @runner.env.config.vm.share_folder("v-root", @runner.env.config.vm.project_directory, @runner.env.root_path) + @runner.env.config.vm.share_folder("v-root", + @runner.env.config.vm.project_directory, + @runner.env.root_path, + :rsync => @runner.env.config.vm.rsync_project_directory) end def execute! diff --git a/lib/vagrant/config.rb b/lib/vagrant/config.rb index 9cd8c32a2..da8829a34 100644 --- a/lib/vagrant/config.rb +++ b/lib/vagrant/config.rb @@ -81,6 +81,7 @@ module Vagrant attr_accessor :base_mac attr_accessor :boot_mode attr_accessor :project_directory + attr_accessor :rsync_project_directory attr_reader :forwarded_ports attr_reader :shared_folders attr_accessor :hd_location @@ -104,8 +105,16 @@ module Vagrant } end - def share_folder(name, guestpath, hostpath) + def share_folder(name, guestpath, hostpath = nil, opts = {}) + guestpath, opts[:rsync] = shift(guestpath, opts[:rsync]) + + # TODO if both are nil the exception information will be unusable + if opts[:rsync] == guestpath + raise Exception.new("The rsync directory #{opts[:rsync]} is identical to the shifted shared folder mount point #{guestpath}") + end + @shared_folders[name] = { + :rsyncpath => opts[:rsync], :guestpath => guestpath, :hostpath => hostpath } @@ -139,6 +148,14 @@ module Vagrant def define(name, &block) defined_vms[name.to_sym] = block end + + def shift(orig, rsync) + if rsync + [orig + '-rsync', rsync == true ? orig : rsync] + else + [orig, rsync] + end + end end class PackageConfig < Base @@ -159,7 +176,7 @@ module Vagrant class Top < Base @@configures = [] - class < @runner.env.config.vm.rsync_project_directory).once @action.prepare end end diff --git a/test/vagrant/config_test.rb b/test/vagrant/config_test.rb index d9d338212..3fa56aabe 100644 --- a/test/vagrant/config_test.rb +++ b/test/vagrant/config_test.rb @@ -257,6 +257,34 @@ class ConfigTest < Test::Unit::TestCase end end + context "shared folders" do + should "set the rsyncpath to nil by default" do + share_with_opts + assert !@config.shared_folders['foo'][:rsyncpath] + end + + should "append rsync to directory name when boolean" do + share_with_opts(:rsync => true) + assert_equal @config.shared_folders['foo'][:rsyncpath], 'foo-dir' + assert_equal @config.shared_folders['foo'][:guestpath], 'foo-dir-rsync' + end + + should "use the specified rsync directory" do + share_with_opts(:rsync => 'bar-baz') + assert_equal @config.shared_folders['foo'][:rsyncpath], 'bar-baz' + end + + should "raise an exception an exception if the guestpath and rsyncpath are the same" do + assert_raise Exception do + share_with_opts(:rsync => 'foo-dir-rsync') + end + end + + def share_with_opts(opts={}) + @config.share_folder('foo', 'foo-dir', '', opts) + end + end + context "uid/gid" do should "return the shared folder UID if set" do @config.shared_folder_uid = "foo"