diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index c452eb295..fc6c4d5e0 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -144,6 +144,13 @@ module Vagrant path end + # Converts a given path to UNC format by adding a prefix and converting slashes. + # @param [String] path Path to convert to UNC for Windows + # @return [String] + def windows_unc_path(path) + "//?/" + path.gsub("/", "\\") + end + # Returns a boolean noting whether the terminal supports color. # output. def terminal_supports_colors? diff --git a/plugins/providers/virtualbox/driver/version_4_3.rb b/plugins/providers/virtualbox/driver/version_4_3.rb index 81f2252b6..07c17cef8 100644 --- a/plugins/providers/virtualbox/driver/version_4_3.rb +++ b/plugins/providers/virtualbox/driver/version_4_3.rb @@ -496,10 +496,14 @@ module VagrantPlugins def share_folders(folders) folders.each do |folder| + hostpath = folder[:hostpath] + if Vagrant::Util::Platform.windows? + hostpath = Vagrant::Util::Platform.windows_unc_path(hostpath) + end args = ["--name", folder[:name], "--hostpath", - Vagrant::Util::Platform.windows? ? ("//?/" + File.expand_path(folder[:hostpath])).gsub("/","\\") : folder[:hostpath]] + hostpath] args << "--transient" if folder.key?(:transient) && folder[:transient] # Enable symlinks on the shared folder diff --git a/test/unit/vagrant/util/platform_test.rb b/test/unit/vagrant/util/platform_test.rb index 3e980937f..ac0960afc 100644 --- a/test/unit/vagrant/util/platform_test.rb +++ b/test/unit/vagrant/util/platform_test.rb @@ -10,4 +10,10 @@ describe Vagrant::Util::Platform do expect(described_class.fs_real_path("c:/foo").to_s).to eql("C:/foo") end end + + describe "#windows_unc_path" do + it "correctly converts a path" do + expect(described_class.windows_unc_path("c:/foo").to_s).to eql("//?/c:\\foo") + end + end end