From 300d151608c188972fde9d832f97d368fbd174f9 Mon Sep 17 00:00:00 2001 From: Timothy Sutton Date: Tue, 6 Aug 2013 10:17:12 -0400 Subject: [PATCH] Darwin guest: mount_vmware_shared_folder cap for use with vmware_fusion provider - It's not clear whether it's possible to mount individual shares using 'mount -t vmhgfs', as the vagrant-vmware-fusion provider now does for Linux guests. Any mount from '.host', even if not a valid share name, succeeds and mounts _all_ shares in their respective directories at the root of the mountpoint. Instead, we symlink each directory from its place in '/Volumes/VMware Shared Folders' --- .../darwin/cap/mount_vmware_shared_folder.rb | 36 +++++++++++++++++++ plugins/guests/darwin/plugin.rb | 5 +++ 2 files changed, 41 insertions(+) create mode 100644 plugins/guests/darwin/cap/mount_vmware_shared_folder.rb diff --git a/plugins/guests/darwin/cap/mount_vmware_shared_folder.rb b/plugins/guests/darwin/cap/mount_vmware_shared_folder.rb new file mode 100644 index 000000000..7b932cd43 --- /dev/null +++ b/plugins/guests/darwin/cap/mount_vmware_shared_folder.rb @@ -0,0 +1,36 @@ +module VagrantPlugins + module GuestDarwin + module Cap + class MountVmwareSharedFolder + + # we seem to be unable to ask 'mount -t vmhgfs' to mount the roots + # of specific shares, so instead we symlink from what is already + # mounted by the guest tools + # (ie. the behaviour of the VMware_fusion provider prior to 0.8.x) + + def self.mount_vmware_shared_folder(machine, name, guestpath, options) + machine.communicate.tap do |comm| + # clear prior symlink + if comm.test("sudo test -L \"#{guestpath}\"") + comm.sudo("rm \"#{guestpath}\"") + end + + # clear prior directory if exists + if comm.test("sudo test -d \"#{guestpath}\"") + comm.sudo("rm -Rf \"#{guestpath}\"") + end + + # create intermediate directories if needed + intermediate_dir = File.dirname(guestpath) + if !comm.test("sudo test -d \"#{intermediate_dir}\"") + comm.sudo("mkdir -p \"#{intermediate_dir}\"") + end + + # finally make the symlink + comm.sudo("ln -s \"/Volumes/VMware Shared Folders/#{name}\" \"#{guestpath}\"") + end + end + end + end + end +end diff --git a/plugins/guests/darwin/plugin.rb b/plugins/guests/darwin/plugin.rb index ff437f866..a8884f6f0 100644 --- a/plugins/guests/darwin/plugin.rb +++ b/plugins/guests/darwin/plugin.rb @@ -31,6 +31,11 @@ module VagrantPlugins Cap::MountNFSFolder end + guest_capability("darwin", "mount_vmware_shared_folder") do + require_relative "cap/mount_vmware_shared_folder" + Cap::MountVmwareSharedFolder + end + guest_capability("darwin", "shell_expand_guest_path") do require_relative "cap/shell_expand_guest_path" Cap::ShellExpandGuestPath