diff --git a/lib/vagrant/box_collection2.rb b/lib/vagrant/box_collection2.rb index d5ef4508d..64ab80ea4 100644 --- a/lib/vagrant/box_collection2.rb +++ b/lib/vagrant/box_collection2.rb @@ -24,6 +24,18 @@ module Vagrant box_directory = @directory.join(name, provider.to_s, "metadata.json") return Box2.new(name, provider, box_directory.dirname) if box_directory.file? + # Check if a V1 version of this box exists, and if so, raise an + # exception notifying the caller that the box exists but needs + # to be upgraded. We don't do the upgrade here because it can be + # a fairly intensive activity and don't want to immediately degrade + # user performance on a find. + # + # To determine if it is a V1 box we just do a simple heuristic + # based approach. + if @directory.join(name, "box.ovf").file? + raise Errors::BoxUpgradeRequired, :name => name + end + # Didn't find it, return nil nil end diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 4b3686310..0aae5c519 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -123,6 +123,10 @@ module Vagrant error_key(:untar_failure, "vagrant.actions.box.unpackage") end + class BoxUpgradeRequired < VagrantError + error_key(:box_upgrade_required) + end + class BoxVerificationFailed < VagrantError status_code(15) error_key(:failed, "vagrant.actions.box.verify") diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 152f4e7cc..4b727f9bc 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -16,6 +16,10 @@ en: errors: base_vm_not_found: The base VM with the name '%{name}' was not found. box_not_found: Box '%{name}' could not be found. + box_upgrade_required: |- + The box '%{name}' is still stored on disk in the Vagrant 1.0.x + format. This box must be upgraded in order to work properly with + this version of Vagrant. cli_invalid_options: |- An invalid option was specified. The help for this command is available below. diff --git a/test/unit/vagrant/box_collection2_test.rb b/test/unit/vagrant/box_collection2_test.rb index 2ee60c8a6..7404525d8 100644 --- a/test/unit/vagrant/box_collection2_test.rb +++ b/test/unit/vagrant/box_collection2_test.rb @@ -24,5 +24,16 @@ describe Vagrant::BoxCollection2 do result.should be_kind_of(box_class) result.name.should == "foo" end + + it "should throw an exception if it is a v1 box" do + # Create a V1 box + box_dir = environment.boxes_dir.join("foo") + box_dir.mkpath + box_dir.join("box.ovf").open("w") { |f| f.write("") } + + # Test! + expect { instance.find("foo", :virtualbox) }. + to raise_error(Vagrant::Errors::BoxUpgradeRequired) + end end end