Sha256: 3e55b9050140721b068f33176ae8a9c4728ed9ade98d88da6082888c6fbc62a2

Contents?: true

Size: 1.99 KB

Versions: 10

Compression:

Stored size: 1.99 KB

Contents

module Vagrant
  module LXC
    module Action
      class ShareFolders
        def initialize(app, env)
          @app = app
        end

        def call(env)
          @env = env
          prepare_folders
          add_override_configs
          @app.call env
        end

        # This method returns an actual list of VirtualBox shared
        # folders to create and their proper path.
        def shared_folders
          {}.tap do |result|
            @env[:machine].config.vm.synced_folders.each do |id, data|
              # This to prevent overwriting the actual shared folders data
              result[id] = data.dup
            end
          end
        end

        # Prepares the shared folders by verifying they exist and creating them
        # if they don't.
        def prepare_folders
          shared_folders.each do |id, options|
            hostpath = Pathname.new(options[:hostpath]).expand_path(@env[:root_path])

            if !hostpath.directory? && options[:create]
              # Host path doesn't exist, so let's create it.
              @logger.debug("Host path doesn't exist, creating: #{hostpath}")

              begin
                hostpath.mkpath
              rescue Errno::EACCES
                raise Vagrant::Errors::SharedFolderCreateFailed,
                  :path => hostpath.to_s
              end
            end
          end
        end

        def add_override_configs
          @env[:ui].info I18n.t("vagrant.actions.lxc.share_folders.preparing")

          folders = []
          shared_folders.each do |id, data|
            folders << {
              :name      => id,
              :hostpath  => File.expand_path(data[:hostpath], @env[:root_path]),
              :guestpath => data[:guestpath]
            }
            @env[:ui].info(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
                                  :guest_path => data[:guestpath]))
          end
          @env[:machine].provider.driver.share_folders(folders)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
vagrant-lxc-0.6.2 lib/vagrant-lxc/action/share_folders.rb
vagrant-lxc-0.6.1 lib/vagrant-lxc/action/share_folders.rb
vagrant-lxc-0.6.0 lib/vagrant-lxc/action/share_folders.rb
vagrant-lxc-0.5.0 lib/vagrant-lxc/action/share_folders.rb
vagrant-lxc-0.4.0 lib/vagrant-lxc/action/share_folders.rb
vagrant-lxc-0.3.4 lib/vagrant-lxc/action/share_folders.rb
vagrant-lxc-0.3.3 lib/vagrant-lxc/action/share_folders.rb
vagrant-lxc-0.3.2 lib/vagrant-lxc/action/share_folders.rb
vagrant-lxc-0.3.1 lib/vagrant-lxc/action/share_folders.rb
vagrant-lxc-0.3.0 lib/vagrant-lxc/action/share_folders.rb