module VagrantPlugins
  module VMwareFreeBSD
    module Cap
      class MountVmwareSharedFolder
        def self.mount_vmware_shared_folder(machine, name, guestpath, options)
          machine.communicate.tap do |comm|
            comm.sudo("rm \"#{guestpath}\"")     if comm.test("test -L \"#{guestpath}\"", :sudo => true)
            comm.sudo("rm -Rf \"#{guestpath}\"") if comm.test("test -d \"#{guestpath}\"", :sudo => true)
            comm.sudo("mkdir -p \"#{guestpath}\"") # mkdir -p doesn't care if it exists already

            comm.sudo("mount -t vmhgfs \".host:/#{name}\" \"#{guestpath}\"")
          end
        end
      end
    end
  end
end

module VagrantPlugins
  module VMwareFreeBSD
    module Cap
      class MountVmwareSharedFolder
        def self.mount_vmware_shared_folder(machine, name, guestpath, options)
          machine.communicate.tap do |comm|
            comm.sudo("rm \"#{guestpath}\"")     if comm.test("test -L \"#{guestpath}\"", :sudo => true)
            comm.sudo("rm -Rf \"#{guestpath}\"") if comm.test("test -d \"#{guestpath}\"", :sudo => true)

            intermediate_dir = File.dirname(guestpath)
            comm.sudo("mkdir -p \"#{intermediate_dir}\"") # mkdir -p doesn't care if it exists already

            unless comm.test("test -d \"/mnt/hgfs/#{name}\"")
              comm.sudo("mkdir -p /mnt/hgfs")
              comm.sudo("mount -t vmhgfs \".host:/\" \"/mnt/hgfs\"")
            end

            comm.sudo("ln -s \"/mnt/hgfs/#{name}\" \"#{guestpath}\"")
          end
        end
      end
    end
  end
end

Change MountVmwareSharedFolder to use symlinks.
Change MountVmwareSharedFolder to use symlinks.

The vmhgfs mount only ever seems to mount the virtual directory and
never any of its subdirectories. So instead of trying to mount them in
the desired path we instead mount on /mnt/hgfs and then symlink the
named directories to the guest paths.
