diff --git a/plugins/guests/linux/cap/mount_smb_shared_folder.rb b/plugins/guests/linux/cap/mount_smb_shared_folder.rb index c0d1bf3f3..5389437d2 100644 --- a/plugins/guests/linux/cap/mount_smb_shared_folder.rb +++ b/plugins/guests/linux/cap/mount_smb_shared_folder.rb @@ -46,22 +46,27 @@ SCRIPT # Attempt to mount the folder. We retry here a few times because # it can fail early on. - - retryable(on: Vagrant::Errors::LinuxMountFailed, tries: 10, sleep: 2) do - no_such_device = false - stderr = "" - status = machine.communicate.sudo(mount_command, error_check: false) do |type, data| - if type == :stderr - no_such_device = true if data =~ /No such device/i - stderr += data.to_s + begin + retryable(on: Vagrant::Errors::LinuxMountFailed, tries: 10, sleep: 2) do + no_such_device = false + stderr = "" + status = machine.communicate.sudo(mount_command, error_check: false) do |type, data| + if type == :stderr + no_such_device = true if data =~ /No such device/i + stderr += data.to_s + end + end + if status != 0 || no_such_device + clean_command = mount_command.gsub(smb_password, "PASSWORDHIDDEN") + raise Vagrant::Errors::LinuxMountFailed, + command: clean_command, + output: stderr end end - if status != 0 || no_such_device - clean_command = mount_command.gsub(smb_password, "PASSWORDHIDDEN") - raise Vagrant::Errors::LinuxMountFailed, - command: clean_command, - output: stderr - end + ensure + # Always remove credentials file after mounting attempts + # have been completed + machine.communicate.sudo("rm /etc/smb_creds_#{name}") end emit_upstart_notification(machine, expanded_guest_path) diff --git a/test/unit/plugins/guests/linux/cap/mount_smb_shared_folder.rb b/test/unit/plugins/guests/linux/cap/mount_smb_shared_folder.rb index cde67e6a6..62d4745f2 100644 --- a/test/unit/plugins/guests/linux/cap/mount_smb_shared_folder.rb +++ b/test/unit/plugins/guests/linux/cap/mount_smb_shared_folder.rb @@ -63,6 +63,11 @@ describe "VagrantPlugins::GuestLinux::Cap::MountSMBSharedFolder" do cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options) end + it "removes the credentials file before completion" do + expect(comm).to receive(:sudo).with(/rm.+smb_creds_.+/) + cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options) + end + it "sends upstart notification after mount" do expect(comm).to receive(:sudo).with(/emit/) cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options)