Always remove credentials file after mount attempts

This commit is contained in:
Chris Roberts 2017-12-14 12:31:43 -08:00
parent eae5230b5d
commit e85ef1655b
2 changed files with 24 additions and 14 deletions

View File

@ -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)

View File

@ -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)