From d528902edc43d41cda037222d2b717e70ea4621c Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 8 Nov 2016 15:33:30 -0800 Subject: [PATCH] Make guestpath an optional parameter for synced_folders --- plugins/kernel_v2/config/vm.rb | 15 +++++++++++++-- test/unit/plugins/kernel_v2/config/vm_test.rb | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index c09e15288..84a57f798 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -201,14 +201,25 @@ module VagrantPlugins # folder. # @param [Hash] options Additional options. def synced_folder(hostpath, guestpath, options=nil) - name = (options && options.delete(:name)) || guestpath if Vagrant::Util::Platform.windows? # On Windows, Ruby just uses normal '/' for path seps, so # just replace normal Windows style seps with Unix ones. hostpath = hostpath.to_s.gsub("\\", "/") end + if guestpath.is_a?(Hash) + options = guestpath + guestpath = nil + end + options ||= {} + + if options.has_key?(:name) + synced_folder_name = options.delete(:name) + else + synced_folder_name = guestpath + end + options[:guestpath] = guestpath.to_s.gsub(/\/$/, '') options[:hostpath] = hostpath options[:disabled] = false if !options.key?(:disabled) @@ -218,7 +229,7 @@ module VagrantPlugins # Make sure the type is a symbol options[:type] = options[:type].to_sym if options[:type] - @__synced_folders[name] = options + @__synced_folders[synced_folder_name] = options end # Define a way to access the machine via a network. This exposes a diff --git a/test/unit/plugins/kernel_v2/config/vm_test.rb b/test/unit/plugins/kernel_v2/config/vm_test.rb index b8320cfc7..17d121ed7 100644 --- a/test/unit/plugins/kernel_v2/config/vm_test.rb +++ b/test/unit/plugins/kernel_v2/config/vm_test.rb @@ -534,6 +534,21 @@ describe VagrantPlugins::Kernel_V2::VMConfig do subject.finalize! assert_valid end + + it "allows providing custom name via options" do + subject.synced_folder(".", "/vagrant", name: "my-vagrant-folder") + sf = subject.synced_folders + expect(sf).to have_key("my-vagrant-folder") + expect(sf["my-vagrant-folder"][:guestpath]).to eq("/vagrant") + expect(sf["my-vagrant-folder"][:hostpath]).to eq(".") + end + + it "allows providing custom name without guest path" do + subject.synced_folder(".", name: "my-vagrant-folder") + sf = subject.synced_folders + expect(sf).to have_key("my-vagrant-folder") + expect(sf["my-vagrant-folder"][:hostpath]).to eq(".") + end end describe "#usable_port_range" do