From 798ffc93bd2283d78a72ba3ff2411aae45330510 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 9 Jul 2012 21:34:32 -0700 Subject: [PATCH] BoxCollection#add throws an UpgradeRequired exception if a V1 box already exists --- lib/vagrant/box_collection.rb | 4 ++++ test/unit/vagrant/box_collection_test.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/box_collection.rb b/lib/vagrant/box_collection.rb index 68fbe3bd2..d06147ae6 100644 --- a/lib/vagrant/box_collection.rb +++ b/lib/vagrant/box_collection.rb @@ -60,6 +60,10 @@ module Vagrant # to unpack any files. check_box_exists.call(provider) if provider + # Verify that a V1 box doesn't exist. If it does, then we signal + # to the user that we need an upgrade. + raise Errors::BoxUpgradeRequired, :name => name if v1_box?(@directory.join(name)) + # Create a temporary directory since we're not sure at this point if # the box we're unpackaging already exists (if no provider was given) Dir.mktmpdir("vagrant-") do |temp_dir| diff --git a/test/unit/vagrant/box_collection_test.rb b/test/unit/vagrant/box_collection_test.rb index d1e44f42e..34acc4702 100644 --- a/test/unit/vagrant/box_collection_test.rb +++ b/test/unit/vagrant/box_collection_test.rb @@ -83,7 +83,7 @@ describe Vagrant::BoxCollection do # Attempt to add some V2 box with the same name box_path = environment.box2_file(:vmware) - expect { instance.add(box_path, prev_box_name, :vmware) }. + expect { instance.add(box_path, prev_box_name) }. to raise_error(Vagrant::Errors::BoxUpgradeRequired) end