Add mount options cap for smb

This commit is contained in:
sophia 2020-07-30 16:14:07 -05:00
parent cde39e26ba
commit de28cec95f
3 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,36 @@
require_relative "../../unix_mount_helpers"
module VagrantPlugins
module SyncedFolderSMB
module Cap
module MountOptions
extend VagrantPlugins::SyncedFolder::UnixMountHelpers
def self.mount_options(machine, name, guest_path, options)
mount_options = options.fetch(:mount_options, [])
detected_ids = detect_owner_group_ids(machine, guest_path, mount_options, options)
mount_uid = detected_ids[:uid]
mount_gid = detected_ids[:gid]
mnt_opts = []
if machine.env.host.capability?(:smb_mount_options)
mnt_opts += machine.env.host.capability(:smb_mount_options)
else
mnt_opts << "sec=ntlmssp"
end
mnt_opts << "credentials=/etc/smb_creds_#{name}"
mnt_opts << "uid=#{mount_uid}"
mnt_opts << "gid=#{mount_gid}"
if !ENV['VAGRANT_DISABLE_SMBMFSYMLINKS']
mnt_opts << "mfsymlinks"
end
mnt_opts = merge_mount_options(mnt_opts, options[:mount_options] || [])
mount_options = mnt_opts.join(",")
return mount_options, mount_uid, mount_gid
end
end
end
end
end

View File

@ -28,6 +28,11 @@ module VagrantPlugins
Cap::DefaultFstabModification
end
synced_folder_capability("smb", "mount_options") do
require_relative "cap/mount_options"
Cap::MountOptions
end
protected
def self.init!

View File

@ -99,6 +99,20 @@ module VagrantPlugins
fi
EOH
end
def merge_mount_options(base, overrides)
base = base.join(",").split(",")
overrides = overrides.join(",").split(",")
b_kv = Hash[base.map{|item| item.split("=", 2) }]
o_kv = Hash[overrides.map{|item| item.split("=", 2) }]
merged = {}.tap do |opts|
(b_kv.keys + o_kv.keys).uniq.each do |key|
opts[key] = o_kv.fetch(key, b_kv[key])
end
end
merged.map do |key, value|
[key, value].compact.join("=")
end
end
end
end