diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index 981e9175a..f8e6bd6cb 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -1,4 +1,5 @@ require_relative "util/ssh" +require_relative "action/builtin/mixin_synced_folders" require "digest/md5" require "thread" @@ -10,6 +11,8 @@ 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 + # The box that is backing this machine. # # @return [Box] diff --git a/lib/vagrant/plugin/v2/components.rb b/lib/vagrant/plugin/v2/components.rb index d7c64d370..973c6cee2 100644 --- a/lib/vagrant/plugin/v2/components.rb +++ b/lib/vagrant/plugin/v2/components.rb @@ -64,6 +64,11 @@ module Vagrant # @return [Registry>] attr_reader :synced_folders + # This contains all the registered synced folder capabilities. + # + # @return [Hash] + attr_reader :synced_folder_capabilities + def initialize # The action hooks hash defaults to [] @action_hooks = Hash.new { |h, k| h[k] = [] } @@ -78,6 +83,7 @@ module Vagrant @provider_capabilities = Hash.new { |h, k| h[k] = Registry.new } @pushes = Registry.new @synced_folders = Registry.new + @synced_folder_capabilities = Hash.new { |h, k| h[k] = Registry.new } end end end diff --git a/lib/vagrant/plugin/v2/manager.rb b/lib/vagrant/plugin/v2/manager.rb index bba37ae04..0927958ad 100644 --- a/lib/vagrant/plugin/v2/manager.rb +++ b/lib/vagrant/plugin/v2/manager.rb @@ -257,7 +257,21 @@ module Vagrant end end end + + # This returns all the registered synced folder capabilities. + # + # @return [Hash] + def synced_folder_capabilities + results = Hash.new { |h, k| h[k] = Registry.new } + @registered.each do |plugin| + plugin.components.synced_folder_capabilities.each do |synced_folder, caps| + results[synced_folder].merge!(caps) + end + end + + results + end # This registers a plugin. This should _NEVER_ be called by the public # and should only be called from within Vagrant. Vagrant will # automatically register V2 plugins when a name is set on the diff --git a/lib/vagrant/plugin/v2/plugin.rb b/lib/vagrant/plugin/v2/plugin.rb index 9bc166268..7ec9f6644 100644 --- a/lib/vagrant/plugin/v2/plugin.rb +++ b/lib/vagrant/plugin/v2/plugin.rb @@ -247,6 +247,18 @@ module Vagrant nil end + # Defines a capability for the given synced folder. The block should return + # a class/module that has a method with the capability name, ready + # to be executed. This means that if it is an instance method, + # the block should return an instance of the class. + # + # @param [String] host The name of the synced folder + # @param [String] cap The name of the capability + def self.synced_folder_capability(synced_folder, cap, &block) + components.synced_folder_capabilities[synced_folder.to_sym].register(cap.to_sym, &block) + nil + end + # Returns the internal data associated with this plugin. This # should NOT be called by the general public. # diff --git a/lib/vagrant/plugin/v2/synced_folder.rb b/lib/vagrant/plugin/v2/synced_folder.rb index 9747b9cc3..06b4ec623 100644 --- a/lib/vagrant/plugin/v2/synced_folder.rb +++ b/lib/vagrant/plugin/v2/synced_folder.rb @@ -3,6 +3,8 @@ module Vagrant module V2 # This is the base class for a synced folder implementation. class SyncedFolder + include CapabilityHost + # This is called early when the synced folder is set to determine # if this implementation can be used for this machine. This should # return true or false. @@ -54,6 +56,12 @@ module Vagrant # @param [Hash] opts def cleanup(machine, opts) end + + def _initialize(machine, synced_folder_type) + plugins = Vagrant.plugin("2").manager.synced_folders + capabilities = Vagrant.plugin("2").manager.synced_folder_capabilities + initialize_capabilities!(synced_folder_type, plugins, capabilities, machine) + end end end end diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 14dc2de80..4bf64f355 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -508,7 +508,6 @@ module VagrantPlugins def finalize! # Defaults - @allow_fstab_modification = true if @allow_fstab_modification == UNSET_VALUE @allowed_synced_folder_types = nil if @allowed_synced_folder_types == UNSET_VALUE @base_mac = nil if @base_mac == UNSET_VALUE @base_address = nil if @base_address == UNSET_VALUE @@ -726,6 +725,21 @@ module VagrantPlugins def validate(machine, ignore_provider=nil) errors = _detected_errors + 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 + @allow_fstab_modification = false + break + end + end + end + @allow_fstab_modification = true if @allow_fstab_modification == UNSET_VALUE + end + if !box && !clone && !machine.provider_options[:box_optional] errors << I18n.t("vagrant.config.vm.box_missing") end diff --git a/plugins/synced_folders/smb/cap/default_fstab_modification.rb b/plugins/synced_folders/smb/cap/default_fstab_modification.rb new file mode 100644 index 000000000..12f54ef02 --- /dev/null +++ b/plugins/synced_folders/smb/cap/default_fstab_modification.rb @@ -0,0 +1,11 @@ +module VagrantPlugins + module SyncedFolderSMB + module Cap + module DefaultFstabModification + def self.default_fstab_modification(machine) + return false + end + end + end + end +end diff --git a/plugins/synced_folders/smb/plugin.rb b/plugins/synced_folders/smb/plugin.rb index bfb58a5b2..8115c377e 100644 --- a/plugins/synced_folders/smb/plugin.rb +++ b/plugins/synced_folders/smb/plugin.rb @@ -23,6 +23,11 @@ module VagrantPlugins SyncedFolder end + synced_folder_capability("smb", "default_fstab_modification") do + require_relative "cap/default_fstab_modification" + Cap::DefaultFstabModification + end + protected def self.init!