From 1c04934d89e3e67399274409633e7be7a9571159 Mon Sep 17 00:00:00 2001 From: alh84001 Date: Mon, 25 May 2015 15:35:06 +0200 Subject: [PATCH] Mounting to paths where user has no write permissions (e.g. /) --- .../guests/darwin/cap/mount_smb_shared_folder.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/guests/darwin/cap/mount_smb_shared_folder.rb b/plugins/guests/darwin/cap/mount_smb_shared_folder.rb index acd2b33a9..5f1cdaec4 100644 --- a/plugins/guests/darwin/cap/mount_smb_shared_folder.rb +++ b/plugins/guests/darwin/cap/mount_smb_shared_folder.rb @@ -8,16 +8,24 @@ module VagrantPlugins extend Vagrant::Util::Retryable def self.mount_smb_shared_folder(machine, name, guestpath, options) expanded_guest_path = machine.guest.capability(:shell_expand_guest_path, guestpath) - machine.communicate.execute("mkdir -p #{expanded_guest_path}") + + 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_options = options[:mount_options]; - mount_command = "mount -t smbfs " + (mount_options ? "-o '#{mount_options.join(",")}' " : "") + "'//#{options[:smb_username]}:#{smb_password}@#{options[:smb_host]}/#{name}' " + "#{expanded_guest_path}" - retryable(on: Vagrant::Errors::DarwinMountFailed, tries: 10, sleep: 5) do + retryable(on: Vagrant::Errors::DarwinMountFailed, tries: 10, sleep: 2) do machine.communicate.execute( mount_command, error_class: Vagrant::Errors::DarwinMountFailed)