From d781dce8f87b14749be6e215c9ecf2622163f7f0 Mon Sep 17 00:00:00 2001 From: Max Lincoln Date: Tue, 16 Dec 2014 23:35:01 -0500 Subject: [PATCH 1/3] Filter synced folders by allowed_synced_folder_types --- .../action/builtin/mixin_synced_folders.rb | 7 +++++++ plugins/kernel_v2/config/vm.rb | 3 +++ .../builtin/mixin_synced_folders_test.rb | 18 +++++++++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) 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) From 853042f2facb1e4449a0085f77e5669d367f4860 Mon Sep 17 00:00:00 2001 From: Max Lincoln Date: Tue, 16 Dec 2014 23:47:17 -0500 Subject: [PATCH 2/3] Make sure allowed_synced_folder_types order overrides priority --- .../action/builtin/mixin_synced_folders.rb | 8 +++++--- .../action/builtin/mixin_synced_folders_test.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/action/builtin/mixin_synced_folders.rb b/lib/vagrant/action/builtin/mixin_synced_folders.rb index 3b5634687..fb0abcce2 100644 --- a/lib/vagrant/action/builtin/mixin_synced_folders.rb +++ b/lib/vagrant/action/builtin/mixin_synced_folders.rb @@ -27,9 +27,11 @@ module Vagrant allowed_types = machine.config.vm.allowed_synced_folder_types if allowed_types - ordered = ordered.select do |_, key, impl| - allowed_types.include? key - end + ordered = allowed_types.map do |type| + ordered.find do |_, key, impl| + key == type + end + end.compact end # Find the proper implementation 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 abfc6f3bd..264e158d2 100644 --- a/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb +++ b/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb @@ -53,6 +53,22 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do result = subject.default_synced_folder_type(machine, plugins) expect(result).to eq("good") end + + it "reprioritizes based on allowed_synced_folder_types" do + plugins = { + "bad" => [impl(false, "bad"), 0], + "good" => [impl(true, "good"), 1], + "same" => [impl(true, "same"), 1], + } + + expect(vm_config).to receive(:allowed_synced_folder_types).and_return(["good", "same"]) + result = subject.default_synced_folder_type(machine, plugins) + expect(result).to eq("good") + + expect(vm_config).to receive(:allowed_synced_folder_types).and_return(["same", "good"]) + result = subject.default_synced_folder_type(machine, plugins) + expect(result).to eq("same") + end end describe "impl_opts" do From a317a4d50dc070bf7ced1d6aff92cc12033e9900 Mon Sep 17 00:00:00 2001 From: Max Lincoln Date: Wed, 17 Dec 2014 14:49:04 -0500 Subject: [PATCH 3/3] Ensure allowed_synced_folder_types is a list of symbols --- plugins/kernel_v2/config/vm.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 9d216a4d6..017eee59b 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -373,6 +373,10 @@ module VagrantPlugins @usable_port_range = (2200..2250) end + if @allowed_synced_folder_types + @allowed_synced_folder_types = Array(@allowed_synced_folder_types).map(&:to_sym) + end + # Make sure that the download checksum is a string and that # the type is a symbol @box_download_checksum = "" if !@box_download_checksum