Error if a box override changes the box setting...

This commit is contained in:
Mitchell Hashimoto 2013-04-19 23:09:42 -06:00
parent 661b982502
commit e8d8188474
3 changed files with 17 additions and 1 deletions

View File

@ -336,6 +336,7 @@ module Vagrant
# Set this variable in order to keep track of if the box changes
# too many times.
original_box = config.vm.box
box_changed = false
load_box_and_overrides = lambda do
# If a box was found, then we attempt to load the Vagrantfile for
@ -366,11 +367,17 @@ module Vagrant
end
if config.vm.box && original_box != config.vm.box
if box_changed
# We already changed boxes once, so report an error that a
# box is attempting to change boxes again.
raise Errors::BoxConfigChangingBox
end
# The box changed, probably due to the provider override. Let's
# run the configuration one more time with the new box.
# TODO: previous original box
@logger.info("Box changed to: #{config.vm.box}. Reloading configurations.")
original_box = config.vm.box
box_changed = true
box = find_box(config.vm.box, box_formats)
# Recurse so that we reload all the configurations

View File

@ -103,6 +103,10 @@ module Vagrant
error_key(:already_exists, "vagrant.actions.box.unpackage")
end
class BoxConfigChangingBox < VagrantError
error_key(:box_config_changing_box)
end
class BoxMetadataFileNotFound < VagrantError
error_key(:box_metadata_file_not_found)
end

View File

@ -120,6 +120,11 @@ en:
Any errors that occurred are shown below.
%{message}
box_config_changing_box: |-
While loading the Vagrantfile, the provider override specified
a new box. This box, in turn, specified a different box. This isn't
allowed, as it could lead to infinite recursion of Vagrant configuration
loading. Please fix this.
box_metadata_file_not_found: |-
The "metadata.json" file for the box '%{name}' was not found.
Boxes require this file in order for Vagrant to determine the