BoxCollection#find should only find V1 box when searching for vbox

This commit is contained in:
Mitchell Hashimoto 2012-11-14 16:12:47 -08:00
parent e2dd0b0cf2
commit 0ec639c8e1
2 changed files with 24 additions and 12 deletions

View File

@ -198,18 +198,22 @@ module Vagrant
return Box.new(name, provider, box_directory.dirname) return Box.new(name, provider, box_directory.dirname)
end end
# Check if a V1 version of this box exists, and if so, raise an # If we're looking for a VirtualBox box, then we check if there is
# exception notifying the caller that the box exists but needs # a V1 box.
# to be upgraded. We don't do the upgrade here because it can be if provider == :virtualbox
# a fairly intensive activity and don't want to immediately degrade # Check if a V1 version of this box exists, and if so, raise an
# user performance on a find. # exception notifying the caller that the box exists but needs
# # to be upgraded. We don't do the upgrade here because it can be
# To determine if it is a V1 box we just do a simple heuristic # a fairly intensive activity and don't want to immediately degrade
# based approach. # user performance on a find.
@logger.info("Searching for V1 box: #{name}") #
if v1_box?(@directory.join(name)) # To determine if it is a V1 box we just do a simple heuristic
@logger.warn("V1 box found: #{name}") # based approach.
raise Errors::BoxUpgradeRequired, :name => name @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 end
# Didn't find it, return nil # Didn't find it, return nil

View File

@ -168,6 +168,14 @@ describe Vagrant::BoxCollection do
expect { instance.find("foo", :virtualbox) }. expect { instance.find("foo", :virtualbox) }.
to raise_error(Vagrant::Errors::BoxUpgradeRequired) to raise_error(Vagrant::Errors::BoxUpgradeRequired)
end 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 end
describe "upgrading" do describe "upgrading" do