Sha256: 44ccd25608ec3036460cb875cf48a049fc29a14789995f11c46cf1819ee84d2b

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 KB

Contents

module VagrantPlugins
  module GuestLinux
    module Cap
      class MountVirtualBoxSharedFolder
        def self.mount_virtualbox_shared_folder(machine, name, guestpath, options)
          expanded_guest_path = machine.guest.capability(
            :shell_expand_guest_path, guestpath)

          # Determine the permission string to attach to the mount command
          mount_options = "-o uid=`id -u #{options[:owner]}`,gid=`id -g #{options[:group]}`"
          mount_options += ",#{options[:extra]}" if options[:extra]
          mount_command = "mount -t vboxsf #{mount_options} #{name} #{expanded_guest_path}"

          # Create the guest path if it doesn't exist
          machine.communicate.sudo("mkdir -p #{expanded_guest_path}")

          # Attempt to mount the folder. We retry here a few times because
          # it can fail early on.
          attempts = 0
          while true
            success = true
            machine.communicate.sudo(mount_command) do |type, data|
              success = false if type == :stderr && data =~ /No such device/i
            end

            break if success

            attempts += 1
            raise Vagrant::Errors::LinuxMountFailed, :command => mount_command
            sleep 2
          end

          # Chown the directory to the proper user
          machine.communicate.sudo(
            "chown `id -u #{options[:owner]}`:`id -g #{options[:group]}` #{expanded_guest_path}")
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb
tnargav-1.2.3 plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb
vagrant-shell-0.2.6 vendor/bundle/gems/tnargav-1.2.2/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb
vagrant-shell-0.2.5 vendor/bundle/gems/tnargav-1.2.2/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb
tnargav-1.2.2 plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb