diff --git a/lib/vagrant/action/builtin/mixin_synced_folders.rb b/lib/vagrant/action/builtin/mixin_synced_folders.rb index 5a44c5ac8..3b5634687 100644 --- a/lib/vagrant/action/builtin/mixin_synced_folders.rb +++ b/lib/vagrant/action/builtin/mixin_synced_folders.rb @@ -25,6 +25,13 @@ module Vagrant # Order the plugins by priority. Higher is tried before lower. ordered = ordered.sort { |a, b| b[0] <=> a[0] } + allowed_types = machine.config.vm.allowed_synced_folder_types + if allowed_types + ordered = ordered.select do |_, key, impl| + allowed_types.include? key + end + end + # Find the proper implementation ordered.each do |_, key, impl| return key if impl.new.usable?(machine) diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 87bc8d71b..9d216a4d6 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -14,6 +14,7 @@ module VagrantPlugins class VMConfig < Vagrant.plugin("2", :config) DEFAULT_VM_NAME = :default + attr_accessor :allowed_synced_folder_types attr_accessor :base_mac attr_accessor :boot_timeout attr_accessor :box @@ -36,6 +37,7 @@ module VagrantPlugins attr_reader :provisioners def initialize + @allowed_synced_folder_types = UNSET_VALUE @base_mac = UNSET_VALUE @boot_timeout = UNSET_VALUE @box = UNSET_VALUE @@ -347,6 +349,7 @@ module VagrantPlugins def finalize! # Defaults + @allowed_synced_folder_types = nil if @allowed_synced_folder_types == UNSET_VALUE @base_mac = nil if @base_mac == UNSET_VALUE @boot_timeout = 300 if @boot_timeout == UNSET_VALUE @box = nil if @box == UNSET_VALUE diff --git a/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb b/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb index 9ab2bf637..abfc6f3bd 100644 --- a/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb +++ b/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb @@ -28,14 +28,26 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do end end - let(:vm_config) { double("machine_vm_config") } + let(:vm_config) { double("machine_vm_config", :allowed_synced_folder_types => nil) } describe "default_synced_folder_type" do it "returns the usable implementation" do plugins = { "bad" => [impl(false, "bad"), 0], - "nope" => [impl(true, "nope"), 1], - "good" => [impl(true, "good"), 5], + "good" => [impl(true, "good"), 1], + "best" => [impl(true, "best"), 5], + } + + result = subject.default_synced_folder_type(machine, plugins) + expect(result).to eq("best") + end + + it "filters based on allowed_synced_folder_types" do + expect(vm_config).to receive(:allowed_synced_folder_types).and_return(["bad", "good"]) + plugins = { + "bad" => [impl(false, "bad"), 0], + "good" => [impl(true, "good"), 1], + "best" => [impl(true, "best"), 5], } result = subject.default_synced_folder_type(machine, plugins)