Skip to content

Commit

Permalink
Merge branch 'filter_synced_folders' of https://github.com/maxlinc/va…
Browse files Browse the repository at this point in the history
…grant into maxlinc-filter_synced_folders
  • Loading branch information
mitchellh committed Jul 9, 2015
2 parents d51c5fb + a317a4d commit cea4484
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
9 changes: 9 additions & 0 deletions lib/vagrant/action/builtin/mixin_synced_folders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ def default_synced_folder_type(machine, plugins)
# 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 = allowed_types.map do |type|
ordered.find do |_, key, impl|
key == type
end
end.compact
end

# Find the proper implementation
ordered.each do |_, key, impl|
return key if impl.new.usable?(machine)
Expand Down
7 changes: 7 additions & 0 deletions plugins/kernel_v2/config/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Kernel_V2
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
Expand All @@ -39,6 +40,7 @@ class VMConfig < Vagrant.plugin("2", :config)
def initialize
@logger = Log4r::Logger.new("vagrant::config::vm")

@allowed_synced_folder_types = UNSET_VALUE
@base_mac = UNSET_VALUE
@boot_timeout = UNSET_VALUE
@box = UNSET_VALUE
Expand Down Expand Up @@ -351,6 +353,7 @@ def define(name, options=nil, &block)

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
Expand All @@ -375,6 +378,10 @@ def finalize!
@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
Expand Down
34 changes: 31 additions & 3 deletions test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,47 @@
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)
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
Expand Down

0 comments on commit cea4484

Please sign in to comment.