Make mount options a synced_folder capability

This commit is contained in:
sophia 2020-07-30 16:11:21 -05:00
parent afd2a28f60
commit cde39e26ba
8 changed files with 63 additions and 22 deletions

View File

@ -36,7 +36,11 @@ module Vagrant
# Find the proper implementation # Find the proper implementation
ordered.each do |_, key, impl| ordered.each do |_, key, impl|
return key if impl.new.usable?(machine) begin
return key if impl.new.usable?(machine)
rescue
# Don't do anything. If an error is raised, the impl is not usable
end
end end
return nil return nil

View File

@ -11,7 +11,7 @@ module Vagrant
# API for querying the state and making state changes to the machine, which # API for querying the state and making state changes to the machine, which
# is backed by any sort of provider (VirtualBox, VMware, etc.). # is backed by any sort of provider (VirtualBox, VMware, etc.).
class Machine class Machine
include Vagrant::Action::Builtin::MixinSyncedFolders extend Vagrant::Action::Builtin::MixinSyncedFolders
# The box that is backing this machine. # The box that is backing this machine.
# #
@ -619,6 +619,29 @@ module Vagrant
end end
end end
# This returns the set of shared folders that should be done for
# this machine. It returns the folders in a hash keyed by the
# implementation class for the synced folders.
#
# @return [Hash<Symbol, Hash<String, Hash>>]
def synced_folders
self.class.synced_folders(self)
end
# Returns the SyncedFolder object associated with this machine.
#
# @return [List<Class>]
def synced_folder_types
return @synced_folder_types if defined?(@synced_folder_types)
plugins = Vagrant.plugin("2").manager.synced_folders
@synced_folder_types = synced_folders.map { |type, folders|
impl = plugins[type][0].new()
impl._initialize(self, type)
[type, impl]
}.to_h
@synced_folder_types
end
protected protected
# Returns the path to the file that stores the UID. # Returns the path to the file that stores the UID.

View File

@ -16,7 +16,7 @@ module VagrantPlugins
builtin_mount_type = "-cit #{VB_MOUNT_TYPE}" builtin_mount_type = "-cit #{VB_MOUNT_TYPE}"
addon_mount_type = "-t #{VB_MOUNT_TYPE}" addon_mount_type = "-t #{VB_MOUNT_TYPE}"
mount_options, mount_uid, mount_gid = mount_options(machine, name, guest_path, options) mount_options, mount_uid, mount_gid = machine.synced_folder_types[:virtualbox].capability(:mount_options, name, guestpath, options)
mount_command = "mount #{addon_mount_type} -o #{mount_options} #{name} #{guest_path}" mount_command = "mount #{addon_mount_type} -o #{mount_options} #{name} #{guest_path}"
# Create the guest path if it doesn't exist # Create the guest path if it doesn't exist

View File

@ -22,7 +22,7 @@ module VagrantPlugins
end end
export_folders = fstab_folders.map do |name, data| export_folders = fstab_folders.map do |name, data|
guest_path = Shellwords.escape(data[:guestpath]) guest_path = Shellwords.escape(data[:guestpath])
mount_options, mount_uid, mount_gid = mount_options(machine, name, guest_path, data) mount_options, mount_uid, mount_gid = machine.synced_folder_types[:virtualbox].capability(:mount_options, name, guest_path, data)
mount_options = "#{mount_options},nofail" mount_options = "#{mount_options},nofail"
{ {
name: name, name: name,
@ -45,4 +45,4 @@ module VagrantPlugins
end end
end end
end end
end end

View File

@ -727,11 +727,9 @@ module VagrantPlugins
if @allow_fstab_modification == UNSET_VALUE if @allow_fstab_modification == UNSET_VALUE
plugins = Vagrant.plugin("2").manager.synced_folders plugins = Vagrant.plugin("2").manager.synced_folders
machine.synced_folders.each do |type, _| machine.synced_folder_types.each do |_, inst|
instance = plugins[type.to_sym][0].new if inst.capability?(:default_fstab_modification)
instance._initialize(machine, type) if inst.capability(:default_fstab_modification) == false
if instance.capability?(:default_fstab_modification)
if instance.capability(:default_fstab_modification) == false
@allow_fstab_modification = false @allow_fstab_modification = false
break break
end end

View File

@ -0,0 +1,23 @@
require_relative "../../../synced_folders/unix_mount_helpers"
module VagrantPlugins
module ProviderVirtualBox
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]
mount_options << "uid=#{mount_uid}"
mount_options << "gid=#{mount_gid}"
mount_options = mount_options.join(',')
return mount_options, mount_uid, mount_gid
end
end
end
end
end

View File

@ -68,6 +68,11 @@ module VagrantPlugins
require_relative "cap" require_relative "cap"
Cap Cap
end end
synced_folder_capability(:virtualbox, "mount_options") do
require_relative "cap/mount_options"
Cap::MountOptions
end
end end
autoload :Action, File.expand_path("../action", __FILE__) autoload :Action, File.expand_path("../action", __FILE__)

View File

@ -99,18 +99,6 @@ module VagrantPlugins
fi fi
EOH EOH
end end
def 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]
mount_options << "uid=#{mount_uid}"
mount_options << "gid=#{mount_gid}"
mount_options = mount_options.join(',')
return mount_options, mount_uid, mount_gid
end
end end
end end
end end