Sha256: 0a22691ff7a0285d5105e3de630030519b3a3b95b25fd72349d6b3434cbd3f35

Contents?: true

Size: 1.9 KB

Versions: 11

Compression:

Stored size: 1.9 KB

Contents

module VagrantPlugins
  module HostDarwin
    module Cap
      class Path
        @@logger = Log4r::Logger.new("vagrant::host::darwin::path")

        FIRMLINK_DEFS = "/usr/share/firmlinks".freeze
        FIRMLINK_DATA_PATH = "/System/Volumes/Data".freeze

        # Resolve the given host path to the actual
        # usable system path by detecting firmlinks
        # if available on the current system
        #
        # @param [String] path Host system path
        # @return [String] resolved path
        def self.resolve_host_path(env, path)
          path = File.expand_path(path)
          firmlink = firmlink_map.detect do |mount_path, data_path|
            path.start_with?(mount_path)
          end
          return path if firmlink.nil?
          current_prefix, new_suffix = firmlink
          new_prefix = File.join(FIRMLINK_DATA_PATH, new_suffix)
          new_path = path.sub(current_prefix, new_prefix)
          @@logger.debug("Resolved given path `#{path}` to `#{new_path}`")
          new_path
        end

        # Generate mapping of firmlinks if available on the host
        #
        # @return [Hash<String,String>]
        def self.firmlink_map
          if !@firmlink_map
            return @firmlink_map = {} if !File.exist?(FIRMLINK_DEFS)
            begin
              @firmlink_map = Hash[
                File.readlines(FIRMLINK_DEFS).map { |d|
                  d.strip.split(/\s+/, 2)
                }
              ]
            rescue => err
              @@logger.warn("Failed to parse firmlink definitions: #{err}")
              @firmlink_map = {}
            end
          end
          @firmlink_map
        end

        # @private
        # Reset the cached values for capability. This is not considered a public
        # API and should only be used for testing.
        def self.reset!
          instance_variables.each(&method(:remove_instance_variable))
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
vagrant-unbundled-2.2.18.0 plugins/hosts/darwin/cap/path.rb
vagrant-unbundled-2.2.16.0 plugins/hosts/darwin/cap/path.rb
vagrant-unbundled-2.2.14.0 plugins/hosts/darwin/cap/path.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/plugins/hosts/darwin/cap/path.rb
vagrant-unbundled-2.2.10.0 plugins/hosts/darwin/cap/path.rb
vagrant-unbundled-2.2.9.0 plugins/hosts/darwin/cap/path.rb
vagrant-unbundled-2.2.8.0 plugins/hosts/darwin/cap/path.rb
vagrant-unbundled-2.2.7.0 plugins/hosts/darwin/cap/path.rb
vagrant-unbundled-2.2.6.2 plugins/hosts/darwin/cap/path.rb
vagrant-unbundled-2.2.6.1 plugins/hosts/darwin/cap/path.rb
vagrant-unbundled-2.2.6.0 plugins/hosts/darwin/cap/path.rb