Sha256: bbaf7cb71838647063ff086764b42e5af66e301eeb45a1763218edb52c75dfb3

Contents?: true

Size: 1.97 KB

Versions: 21

Compression:

Stored size: 1.97 KB

Contents

require 'pathname'

require "log4r"

module VagrantPlugins
  module ProviderLibvirt
    module Action
      class ShareFolders
        def initialize(app, env)
          @logger = Log4r::Logger.new("vagrant::action::vm::share_folders")
          @app    = app
        end

        def call(env)
          @env = env

          prepare_folders
          create_metadata

          @app.call(env)
        end

        # This method returns an actual list of shared
        # folders to create and their proper path.
        def shared_folders
          {}.tap do |result|
            @env[:machine].config.vm.synced_folders.each do |id, data|
              # Ignore NFS shared folders
              next if !data[:type] == :nfs

              # 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 create_metadata
          @env[:ui].info I18n.t("vagrant.actions.vm.share_folders.creating")

          folders = []
          shared_folders.each do |id, data|
            folders << {
              :name => id,
              :hostpath => File.expand_path(data[:hostpath], @env[:root_path]),
              :transient => data[:transient]
            }
          end
        end

      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
vagrant-libvirt-0.0.36 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.35 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.33 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.32 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.31 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.30 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.29 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.28 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.27 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.26 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.25 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.24 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.23 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.22 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.21 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.20 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.19 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.18 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.17 lib/vagrant-libvirt/action/share_folders.rb
vagrant-libvirt-0.0.16 lib/vagrant-libvirt/action/share_folders.rb