From a8b2f78f59643328c2d82ce07f48690e8057459e Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 20 Apr 2017 16:28:39 -0700 Subject: [PATCH] Do not prefix Windows paths if UNC prefix already exists While VirtualBox has commented that they do not support UNC remote paths (but do for long paths) it seems that remote paths can work. If user provides UNC path, allow it to be used as-is. Fixes #7011 --- lib/vagrant/util/platform.rb | 13 +++++++++---- test/unit/vagrant/util/platform_test.rb | 8 ++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index 39803b46c..5ad926395 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -188,11 +188,16 @@ module Vagrant def windows_unc_path(path) path = path.gsub("/", "\\") - # If the path is just a drive letter, then return that as-is - return path + "\\" if path =~ /^[a-zA-Z]:\\?$/ - # Convert to UNC path - "\\\\?\\" + path.gsub("/", "\\") + if path =~ /^[a-zA-Z]:\\?$/ + # If the path is just a drive letter, then return that as-is + path + "\\" + elsif path.start_with?("\\\\") + # If the path already starts with `\\` assume UNC and return as-is + path + else + "\\\\?\\" + path.gsub("/", "\\") + end end # Returns a boolean noting whether the terminal supports color. diff --git a/test/unit/vagrant/util/platform_test.rb b/test/unit/vagrant/util/platform_test.rb index 25f10cd54..a69696eed 100644 --- a/test/unit/vagrant/util/platform_test.rb +++ b/test/unit/vagrant/util/platform_test.rb @@ -55,5 +55,13 @@ describe Vagrant::Util::Platform do it "correctly converts a path" do expect(described_class.windows_unc_path("c:/foo").to_s).to eql("\\\\?\\c:\\foo") end + + context "when given a UNC path" do + let(:unc_path){ "\\\\srvname\\path" } + + it "should not modify the path" do + expect(described_class.windows_unc_path(unc_path).to_s).to eql(unc_path) + end + end end end