Always remove credentials file after mount attempts
This commit is contained in:
parent
eae5230b5d
commit
e85ef1655b
|
@ -46,22 +46,27 @@ SCRIPT
|
||||||
|
|
||||||
# Attempt to mount the folder. We retry here a few times because
|
# Attempt to mount the folder. We retry here a few times because
|
||||||
# it can fail early on.
|
# it can fail early on.
|
||||||
|
begin
|
||||||
retryable(on: Vagrant::Errors::LinuxMountFailed, tries: 10, sleep: 2) do
|
retryable(on: Vagrant::Errors::LinuxMountFailed, tries: 10, sleep: 2) do
|
||||||
no_such_device = false
|
no_such_device = false
|
||||||
stderr = ""
|
stderr = ""
|
||||||
status = machine.communicate.sudo(mount_command, error_check: false) do |type, data|
|
status = machine.communicate.sudo(mount_command, error_check: false) do |type, data|
|
||||||
if type == :stderr
|
if type == :stderr
|
||||||
no_such_device = true if data =~ /No such device/i
|
no_such_device = true if data =~ /No such device/i
|
||||||
stderr += data.to_s
|
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
|
||||||
end
|
end
|
||||||
if status != 0 || no_such_device
|
ensure
|
||||||
clean_command = mount_command.gsub(smb_password, "PASSWORDHIDDEN")
|
# Always remove credentials file after mounting attempts
|
||||||
raise Vagrant::Errors::LinuxMountFailed,
|
# have been completed
|
||||||
command: clean_command,
|
machine.communicate.sudo("rm /etc/smb_creds_#{name}")
|
||||||
output: stderr
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
emit_upstart_notification(machine, expanded_guest_path)
|
emit_upstart_notification(machine, expanded_guest_path)
|
||||||
|
|
|
@ -63,6 +63,11 @@ describe "VagrantPlugins::GuestLinux::Cap::MountSMBSharedFolder" do
|
||||||
cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options)
|
cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options)
|
||||||
end
|
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
|
it "sends upstart notification after mount" do
|
||||||
expect(comm).to receive(:sudo).with(/emit/)
|
expect(comm).to receive(:sudo).with(/emit/)
|
||||||
cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options)
|
cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options)
|
||||||
|
|
Loading…
Reference in New Issue