Merge pull request #8707 from briancain/disable-double-config-loading

Disable loading identical Vagrantfile twice from same dir
This commit is contained in:
Brian Cain 2017-06-22 13:55:19 -07:00 committed by GitHub
commit c4eb18eb1a
2 changed files with 32 additions and 1 deletions

View File

@ -101,6 +101,18 @@ module Vagrant
warnings = []
errors = []
if !@sources[:root].nil? && @sources[:root].eql?(@sources[:home])
# Vagrants home dir is set to the same dir as its project directory
# so we don't want to load and merge the same Vagrantfile config
# and execute its settings/procs twice
#
# Note: This protection won't work if there are two separate but
# identical Vagrantfiles in the home and project dir
@logger.info("Duplicate Vagrantfile config objects detected in :root and :home.")
@sources.delete(:home)
@logger.info("Removed :home config from being loaded")
end
order.each do |key|
next if !@sources.key?(key)

View File

@ -23,7 +23,7 @@ describe Vagrant::Config::Loader do
end
def self.merge(old, new)
old.merge(new)
old.merge(new) {|key, oldval, newval| oldval.concat(newval)}
end
end
end
@ -177,6 +177,25 @@ describe Vagrant::Config::Loader do
end
end
it "should discard duplicate configs if :home and :root are the same" do
proc = Proc.new do |config|
config[:foo] = ["yep"]
end
order = [:root, :home]
instance.set(:root, [[current_version, proc]])
instance.set(:home, [[current_version, proc]])
result, warnings, errors = instance.load(order)
# Verify the config result
expect(result[:foo]).to eq(["yep"])
expect(result[:foo].size).to eq(1)
expect(warnings).to eq([])
expect(errors).to eq([])
end
it "should only load configuration files once" do
$_config_data = 0