Class: VagrantDarwinSMB::Cap::MountSMBSharedFolder

Inherits:
Object
  • Object
show all
Extended by:
Vagrant::Util::Retryable
Defined in:
lib/vagrant-darwin-smb/cap/mount_smb_shared_folder.rb

Class Method Summary collapse

Class Method Details

.mount_smb_shared_folder(machine, name, guestpath, options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/vagrant-darwin-smb/cap/mount_smb_shared_folder.rb', line 13

def self.mount_smb_shared_folder(machine, name, guestpath, options)
  expanded_guest_path = machine.guest.capability(:shell_expand_guest_path, guestpath)
  
  mount_point_owner = options[:owner];
  if mount_point_owner
    machine.communicate.sudo("mkdir -p #{expanded_guest_path}")
    machine.communicate.sudo("chown #{mount_point_owner} #{expanded_guest_path}")
  else
    # fallback to assumption that user has permission
    # to create the specified mountpoint
    machine.communicate.execute("mkdir -p #{expanded_guest_path}")
  end

  smb_password = Shellwords.shellescape(options[:smb_password])
  mount_opts = options[:mount_options];
  mount_command = "mount -t smbfs " +
    (mount_opts ? "-o '#{mount_opts.join(",")}' " : "") +
    "'//#{options[:smb_username]}:#{smb_password}@#{options[:smb_host]}/#{name}' " +
    "#{expanded_guest_path}"
  retryable(on: Errors::DarwinMountFailed, tries: 10, sleep: 2) do
    machine.communicate.execute(
      mount_command,
      error_class: Errors::DarwinMountFailed)
  end
end