diff --git a/plugins/hosts/windows/cap/smb.rb b/plugins/hosts/windows/cap/smb.rb index d224e06a3..457807f9c 100644 --- a/plugins/hosts/windows/cap/smb.rb +++ b/plugins/hosts/windows/cap/smb.rb @@ -63,7 +63,9 @@ module VagrantPlugins # Check if this name is already in use if share_info = current_shares[data[:smb_id]] - if !hostpath.empty? && share_info["Path"].downcase != hostpath.downcase + exist_path = File.expand_path(share_info["Path"]).downcase + request_path = File.expand_path(hostpath).downcase + if !hostpath.empty? && exist_path != request_path raise SyncedFolderSMB::Errors::SMBNameError, path: hostpath, existing_path: share_info["Path"], diff --git a/test/unit/plugins/hosts/windows/cap/smb_test.rb b/test/unit/plugins/hosts/windows/cap/smb_test.rb index 216be6397..c904bc205 100644 --- a/test/unit/plugins/hosts/windows/cap/smb_test.rb +++ b/test/unit/plugins/hosts/windows/cap/smb_test.rb @@ -110,6 +110,29 @@ Description : Not Vagrant Owned subject.smb_prepare(env, machine, folders, options) end + context "when share already exists" do + let(:shares){ {"ID1" => {"Path" => "/host/2"}} } + before do + allow(File).to receive(:expand_path).and_call_original + expect(subject).to receive(:existing_shares).and_return(shares) + end + + it "should expand paths when comparing existing to requested" do + expect(File).to receive(:expand_path).at_least(2).with("/host/2").and_return("expanded_path") + subject.smb_prepare(env, machine, folders, options) + end + + context "with different path" do + let(:shares){ {"ID1" => {"Path" => "/host/3"}} } + + it "should raise an error" do + expect{ + subject.smb_prepare(env, machine, folders, options) + }.to raise_error(VagrantPlugins::SyncedFolderSMB::Errors::SMBNameError) + end + end + end + context "when no shared are defined" do after{ subject.smb_prepare(env, machine, {}, options) }