module VagrantPlugins
  module Parallels
    module GuestLinuxCap
      class MountParallelsSharedFolder

        def self.mount_parallels_shared_folder(machine, name, guestpath, options)
          machine.communicate.tap do |comm|
            # clear prior symlink
            if comm.test("test -L \"#{guestpath}\"", :sudo => true)
              comm.sudo("rm \"#{guestpath}\"")
            end

            # clear prior directory if exists
            if comm.test("test -d \"#{guestpath}\"", :sudo => true)
              comm.sudo("rm -Rf \"#{guestpath}\"")
            end

            # create intermediate directories if needed
            intermediate_dir = File.dirname(guestpath)
            if !comm.test("test -d \"#{intermediate_dir}\"", :sudo => true)
              comm.sudo("mkdir -p \"#{intermediate_dir}\"")
            end

            # finally make the symlink
            comm.sudo("ln -s \"/media/psf/#{name}\" \"#{guestpath}\"")
          end
        end
      end
    end
  end
end

module VagrantPlugins
  module Parallels
    module GuestLinuxCap
      class MountParallelsSharedFolder

        def self.mount_parallels_shared_folder(machine, name, guestpath, options)
          # Expand the guest path so we can handle things like "~/vagrant"
          expanded_guest_path = machine.guest.capability(
            :shell_expand_guest_path, guestpath)

          machine.communicate.tap do |comm|
            # clear prior symlink
            if comm.test("test -L \"#{expanded_guest_path}\"", :sudo => true)
              comm.sudo("rm \"#{expanded_guest_path}\"")
            end

            # clear prior directory if exists
            if comm.test("test -d \"#{expanded_guest_path}\"", :sudo => true)
              comm.sudo("rm -Rf \"#{expanded_guest_path}\"")
            end

            # create intermediate directories if needed
            intermediate_dir = File.dirname(expanded_guest_path)
            if !comm.test("test -d \"#{intermediate_dir}\"", :sudo => true)
              comm.sudo("mkdir -p \"#{intermediate_dir}\"")
            end

            # finally make the symlink
            comm.sudo("ln -s \"/media/psf/#{name}\" \"#{expanded_guest_path}\"")
          end
        end
      end
    end
  end
end

Use 'shell_expand_guest_path' guest capability to expand "~/" in shared folder mounts
Use 'shell_expand_guest_path' guest capability to expand "~/" in shared folder mounts

This was copied from the official NFS mount capability
