Add a resolve_host_path capability for bsd and darwin hosts
For bsd the resolve_host_path capability is a no-op. For darwin hosts, if firmlinks are defined on the system, paths will be properly resolved to real path.
This commit is contained in:
parent
2c16c96e57
commit
8f42dbff21
|
@ -0,0 +1,11 @@
|
||||||
|
module VagrantPlugins
|
||||||
|
module HostBSD
|
||||||
|
module Cap
|
||||||
|
class Path
|
||||||
|
def self.resolve_host_path(env, path)
|
||||||
|
path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -36,6 +36,11 @@ module VagrantPlugins
|
||||||
Cap::NFS
|
Cap::NFS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
host_capability("bsd", "resolve_host_path") do
|
||||||
|
require_relative "cap/path"
|
||||||
|
Cap::Path
|
||||||
|
end
|
||||||
|
|
||||||
host_capability("bsd", "set_ssh_key_permissions") do
|
host_capability("bsd", "set_ssh_key_permissions") do
|
||||||
require_relative "cap/ssh"
|
require_relative "cap/ssh"
|
||||||
Cap::SSH
|
Cap::SSH
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
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
|
|
@ -16,6 +16,11 @@ module VagrantPlugins
|
||||||
Cap::ProviderInstallVirtualBox
|
Cap::ProviderInstallVirtualBox
|
||||||
end
|
end
|
||||||
|
|
||||||
|
host_capability("darwin", "resolve_host_path") do
|
||||||
|
require_relative "cap/path"
|
||||||
|
Cap::Path
|
||||||
|
end
|
||||||
|
|
||||||
host_capability("darwin", "rdp_client") do
|
host_capability("darwin", "rdp_client") do
|
||||||
require_relative "cap/rdp"
|
require_relative "cap/rdp"
|
||||||
Cap::RDP
|
Cap::RDP
|
||||||
|
|
Loading…
Reference in New Issue