From f20666e230e1450d95846ff6c937f07f142d5cf2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 10 Jul 2012 23:06:26 -0700 Subject: [PATCH] Automatically upgrade the boxes all over. --- lib/vagrant/action/box/add.rb | 12 +++++++++++- plugins/commands/box/command/remove.rb | 9 ++++++++- plugins/commands/box/command/repackage.rb | 11 +++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/action/box/add.rb b/lib/vagrant/action/box/add.rb index bc9835ad7..e80d52970 100644 --- a/lib/vagrant/action/box/add.rb +++ b/lib/vagrant/action/box/add.rb @@ -12,7 +12,17 @@ module Vagrant def call(env) @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) end end diff --git a/plugins/commands/box/command/remove.rb b/plugins/commands/box/command/remove.rb index 74d28e0d1..c4751e14c 100644 --- a/plugins/commands/box/command/remove.rb +++ b/plugins/commands/box/command/remove.rb @@ -16,7 +16,14 @@ module VagrantPlugins return if !argv 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 b.destroy! diff --git a/plugins/commands/box/command/repackage.rb b/plugins/commands/box/command/repackage.rb index edcaa1571..39ebd3b20 100644 --- a/plugins/commands/box/command/repackage.rb +++ b/plugins/commands/box/command/repackage.rb @@ -21,8 +21,15 @@ module VagrantPlugins box_provider = argv[1].to_sym # Verify the box exists that we want to repackage - box = @env.boxes.find(box_name, box_provider) - raise Vagrant::Errors::BoxNotFound, :name => box_name if !b + box = nil + 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 output_path = File.expand_path(@env.config.global.package.name, FileUtils.pwd)