rsync for shared folders added
This commit is contained in:
parent
6397ac579c
commit
7ac7af15d3
|
@ -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
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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 <<self
|
||||
class << self
|
||||
def configures_list
|
||||
@@configures ||= []
|
||||
end
|
||||
|
|
|
@ -37,6 +37,7 @@ class Test::Unit::TestCase
|
|||
config.vm.box_ovf = "box.ovf"
|
||||
config.vm.base_mac = "42"
|
||||
config.vm.project_directory = "/vagrant"
|
||||
config.vm.rsync_project_directory = false
|
||||
config.vm.disk_image_format = 'VMDK'
|
||||
config.vm.forward_port("ssh", 22, 2222)
|
||||
config.vm.shared_folder_uid = nil
|
||||
|
|
|
@ -8,7 +8,10 @@ class BootActionTest < Test::Unit::TestCase
|
|||
|
||||
context "preparing" do
|
||||
should "add the root shared folder" do
|
||||
@runner.env.config.vm.expects(:share_folder).with("v-root", @runner.env.config.vm.project_directory, @runner.env.root_path).once
|
||||
@runner.env.config.vm.expects(:share_folder).with("v-root",
|
||||
@runner.env.config.vm.project_directory,
|
||||
@runner.env.root_path,
|
||||
:rsync => @runner.env.config.vm.rsync_project_directory).once
|
||||
@action.prepare
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue