Automatically upgrade the boxes all over.

This commit is contained in:
Mitchell Hashimoto 2012-07-10 23:06:26 -07:00
parent bcd1304ef4
commit f20666e230
3 changed files with 28 additions and 4 deletions

View File

@ -12,7 +12,17 @@ module Vagrant
def call(env) def call(env)
@env[:ui].info I18n.t("vagrant.actions.box.add.adding", :name => env[:box_name]) @env[:ui].info I18n.t("vagrant.actions.box.add.adding", :name => env[:box_name])
env[:box_collection].add(env[:box_download_temp_path], env[:box_name])
begin
env[:box_collection].add(env[:box_download_temp_path], env[:box_name])
rescue Vagrant::Errors::BoxUpgradeRequired
# Upgrade the box
env[:box_collection].upgrade(env[:box_name])
# Try adding it again
retry
end
@app.call(env) @app.call(env)
end end
end end

View File

@ -16,7 +16,14 @@ module VagrantPlugins
return if !argv return if !argv
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 2 raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 2
b = @env.boxes.find(argv[0], argv[1].to_sym) b = nil
begin
b = @env.boxes.find(argv[0], argv[1].to_sym)
rescue Vagrant::Errors::BoxUpgradeRequired
@env.boxes.upgrade(argv[0])
retry
end
raise Vagrant::Errors::BoxNotFound, :name => argv[0] if !b raise Vagrant::Errors::BoxNotFound, :name => argv[0] if !b
b.destroy! b.destroy!

View File

@ -21,8 +21,15 @@ module VagrantPlugins
box_provider = argv[1].to_sym box_provider = argv[1].to_sym
# Verify the box exists that we want to repackage # Verify the box exists that we want to repackage
box = @env.boxes.find(box_name, box_provider) box = nil
raise Vagrant::Errors::BoxNotFound, :name => box_name if !b begin
box = @env.boxes.find(box_name, box_provider)
rescue Vagrant::Errors::BoxUpgradeRequired
@env.boxes.upgrade(box_name)
retry
end
raise Vagrant::Errors::BoxNotFound, :name => box_name if !box
# Repackage the box # Repackage the box
output_path = File.expand_path(@env.config.global.package.name, FileUtils.pwd) output_path = File.expand_path(@env.config.global.package.name, FileUtils.pwd)