Make mount options a synced_folder capability
This commit is contained in:
parent
afd2a28f60
commit
cde39e26ba
@ -36,7 +36,11 @@ module Vagrant
|
||||
|
||||
# Find the proper implementation
|
||||
ordered.each do |_, key, impl|
|
||||
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
|
||||
|
||||
return nil
|
||||
|
||||
@ -11,7 +11,7 @@ module Vagrant
|
||||
# API for querying the state and making state changes to the machine, which
|
||||
# is backed by any sort of provider (VirtualBox, VMware, etc.).
|
||||
class Machine
|
||||
include Vagrant::Action::Builtin::MixinSyncedFolders
|
||||
extend Vagrant::Action::Builtin::MixinSyncedFolders
|
||||
|
||||
# The box that is backing this machine.
|
||||
#
|
||||
@ -619,6 +619,29 @@ module Vagrant
|
||||
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
|
||||
|
||||
# Returns the path to the file that stores the UID.
|
||||
|
||||
@ -16,7 +16,7 @@ module VagrantPlugins
|
||||
builtin_mount_type = "-cit #{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}"
|
||||
|
||||
# Create the guest path if it doesn't exist
|
||||
|
||||
@ -22,7 +22,7 @@ module VagrantPlugins
|
||||
end
|
||||
export_folders = fstab_folders.map do |name, data|
|
||||
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"
|
||||
{
|
||||
name: name,
|
||||
|
||||
@ -727,11 +727,9 @@ module VagrantPlugins
|
||||
|
||||
if @allow_fstab_modification == UNSET_VALUE
|
||||
plugins = Vagrant.plugin("2").manager.synced_folders
|
||||
machine.synced_folders.each do |type, _|
|
||||
instance = plugins[type.to_sym][0].new
|
||||
instance._initialize(machine, type)
|
||||
if instance.capability?(:default_fstab_modification)
|
||||
if instance.capability(:default_fstab_modification) == false
|
||||
machine.synced_folder_types.each do |_, inst|
|
||||
if inst.capability?(:default_fstab_modification)
|
||||
if inst.capability(:default_fstab_modification) == false
|
||||
@allow_fstab_modification = false
|
||||
break
|
||||
end
|
||||
|
||||
23
plugins/providers/virtualbox/cap/mount_options.rb
Normal file
23
plugins/providers/virtualbox/cap/mount_options.rb
Normal 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
|
||||
@ -68,6 +68,11 @@ module VagrantPlugins
|
||||
require_relative "cap"
|
||||
Cap
|
||||
end
|
||||
|
||||
synced_folder_capability(:virtualbox, "mount_options") do
|
||||
require_relative "cap/mount_options"
|
||||
Cap::MountOptions
|
||||
end
|
||||
end
|
||||
|
||||
autoload :Action, File.expand_path("../action", __FILE__)
|
||||
|
||||
@ -99,18 +99,6 @@ module VagrantPlugins
|
||||
fi
|
||||
EOH
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user