From 0ec639c8e1adbf20e7ba1a1c9305c8969406aef3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 14 Nov 2012 16:12:47 -0800 Subject: [PATCH] BoxCollection#find should only find V1 box when searching for vbox --- lib/vagrant/box_collection.rb | 28 ++++++++++++++---------- test/unit/vagrant/box_collection_test.rb | 8 +++++++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/vagrant/box_collection.rb b/lib/vagrant/box_collection.rb index 8f56f9a90..11fe918a1 100644 --- a/lib/vagrant/box_collection.rb +++ b/lib/vagrant/box_collection.rb @@ -198,18 +198,22 @@ module Vagrant return Box.new(name, provider, box_directory.dirname) end - # 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. - @logger.info("Searching for V1 box: #{name}") - if v1_box?(@directory.join(name)) - @logger.warn("V1 box found: #{name}") - raise Errors::BoxUpgradeRequired, :name => name + # If we're looking for a VirtualBox box, then we check if there is + # a V1 box. + if provider == :virtualbox + # 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. + @logger.info("Searching for V1 box: #{name}") + if v1_box?(@directory.join(name)) + @logger.warn("V1 box found: #{name}") + raise Errors::BoxUpgradeRequired, :name => name + end end # Didn't find it, return nil diff --git a/test/unit/vagrant/box_collection_test.rb b/test/unit/vagrant/box_collection_test.rb index f8dac7555..b996484fd 100644 --- a/test/unit/vagrant/box_collection_test.rb +++ b/test/unit/vagrant/box_collection_test.rb @@ -168,6 +168,14 @@ describe Vagrant::BoxCollection do expect { instance.find("foo", :virtualbox) }. to raise_error(Vagrant::Errors::BoxUpgradeRequired) end + + it "should return nil if there is a V1 box but we're looking for another provider" do + # Create a V1 box + environment.box1("foo") + + # Test + instance.find("foo", :another_provider).should be_nil + end end describe "upgrading" do