From baccbd047d9dbe2183ae77a902a9763f53f2327d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 7 Sep 2010 10:24:59 -0700 Subject: [PATCH] Cleaner upgrade process and backup previous .vagrant file --- lib/vagrant/command/upgrade_to_060.rb | 22 +++++++++++++++++----- templates/locales/en.yml | 12 +++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/vagrant/command/upgrade_to_060.rb b/lib/vagrant/command/upgrade_to_060.rb index 3c34adccf..b77461b72 100644 --- a/lib/vagrant/command/upgrade_to_060.rb +++ b/lib/vagrant/command/upgrade_to_060.rb @@ -1,3 +1,5 @@ +require 'fileutils' + module Vagrant module Command class UpgradeTo060Command < Base @@ -12,19 +14,29 @@ module Vagrant return end - if !@env.local_data.empty? + local_data = @env.local_data + if !local_data.empty? + if local_data[:active] + @env.ui.confirm "vagrant.commands.upgrade_to_060.already_done", :_prefix => false + return + end + + # Backup the previous file + @env.ui.info "vagrant.commands.upgrade_to_060.backing_up", :_prefix => false + FileUtils.cp(local_data.file_path, "#{local_data.file_path}.bak-#{Time.now.to_i}") + # Gather the previously set virtual machines into a single # active hash - active = @env.local_data.inject({}) do |acc, data| + active = local_data.inject({}) do |acc, data| key, uuid = data acc[key.to_sym] = uuid acc end # Set the active hash to the active list and save it - @env.local_data.clear - @env.local_data[:active] = active - @env.local_data.commit + local_data.clear + local_data[:active] = active + local_data.commit end @env.ui.confirm "vagrant.commands.upgrade_to_060.complete", :_prefix => false diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 3dad59a6f..44feb4a96 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -127,15 +127,17 @@ en: up: vm_created: "VM already created. Booting if its not already running..." upgrade_to_060: + already_done: "Environment appears to already be upgraded to 0.6.0. Doing nothing!" + ask: "Are you sure you want to execute this command?" + backing_up: "Backing up previous .vagrant file..." + complete: "Environment upgraded to 0.6.0 successfully." info: |- This command will upgrade the current environment from a pre-0.6.0 environment to a 0.6.x compatible environment. Running this command - on a 0.6.0 environment may cause corrupt virtual machines, however, - so verify now that this is your first time running this command and - that this environment was created pre-0.6.0. - ask: "Are you sure you want to execute this command?" + multiple times should be okay. This command will make a backup file + prior to making any changes. Therefore, if anything goes wrong, then + restore that file to ".vagrant" in the same directory as the Vagrantfile. quit: "Not executing this command by user request. Quitting..." - complete: "Environment upgraded to 0.6.0 successfully." version: output: "Vagrant version %{version}"