From c519f14626b2457b48fbf1e176e356b563104ca1 Mon Sep 17 00:00:00 2001 From: John Bender Date: Fri, 30 Jul 2010 18:55:01 -0700 Subject: [PATCH] moved rescue to recover --- lib/vagrant/action/box/download.rb | 6 ++++-- lib/vagrant/action/general/package.rb | 2 +- lib/vagrant/action/vm/import.rb | 2 +- lib/vagrant/action/warden.rb | 2 +- test/vagrant/action/box/download_test.rb | 5 +++-- test/vagrant/action/general/package_test.rb | 4 ++-- test/vagrant/action/vm/import_test.rb | 4 ++-- test/vagrant/action/warden_test.rb | 18 +++++++++--------- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/lib/vagrant/action/box/download.rb b/lib/vagrant/action/box/download.rb index 2657a7e75..0545583c6 100644 --- a/lib/vagrant/action/box/download.rb +++ b/lib/vagrant/action/box/download.rb @@ -22,8 +22,10 @@ module Vagrant return if env.error? @app.call(@env) + + recover(env) # called in both cases to cleanup workspace end - + def instantiate_downloader @env["download.classes"].each do |klass| if klass.match?(@env["box"].uri) @@ -48,7 +50,7 @@ module Vagrant end end - def rescue(env) + def recover(env) if temp_path && File.exist?(temp_path) env.logger.info "Cleaning up downloaded box..." File.unlink(temp_path) diff --git a/lib/vagrant/action/general/package.rb b/lib/vagrant/action/general/package.rb index 01691463c..0e9ab770f 100644 --- a/lib/vagrant/action/general/package.rb +++ b/lib/vagrant/action/general/package.rb @@ -32,7 +32,7 @@ module Vagrant @app.call(env) end - def rescue(env) + def recover(env) # Cleanup any packaged files if the packaging failed at some point. File.delete(tar_path) if File.exist?(tar_path) end diff --git a/lib/vagrant/action/vm/import.rb b/lib/vagrant/action/vm/import.rb index 3bd633a2b..6154db5a8 100644 --- a/lib/vagrant/action/vm/import.rb +++ b/lib/vagrant/action/vm/import.rb @@ -25,7 +25,7 @@ module Vagrant @app.call(env) end - def rescue(env) + def recover(env) # Interrupted, destroy the VM env["actions"].run(:destroy) end diff --git a/lib/vagrant/action/warden.rb b/lib/vagrant/action/warden.rb index 5303e2a56..7027e8f28 100644 --- a/lib/vagrant/action/warden.rb +++ b/lib/vagrant/action/warden.rb @@ -21,7 +21,7 @@ module Vagrant def begin_rescue(env) @stack.reverse.each do |act| - act.rescue(env) if act.respond_to?(:rescue) + act.recover(env) if act.respond_to?(:recover) end exit if env.interrupted? diff --git a/test/vagrant/action/box/download_test.rb b/test/vagrant/action/box/download_test.rb index 913ac17a2..1b596a70b 100644 --- a/test/vagrant/action/box/download_test.rb +++ b/test/vagrant/action/box/download_test.rb @@ -32,6 +32,7 @@ class DownloadBoxActionTest < Test::Unit::TestCase @instance.expects(:instantiate_downloader).in_sequence(seq).returns(true) @instance.expects(:download).in_sequence(seq) @app.expects(:call).with(@env).in_sequence(seq) + @instance.expects(:recover).with(@env).in_sequence(seq) @instance.call(@env) end @@ -113,13 +114,13 @@ class DownloadBoxActionTest < Test::Unit::TestCase should "delete the temporary file if it exists" do File.expects(:unlink).with(@temp_path).once - @instance.rescue(@env) + @instance.recover(@env) end should "not delete anything if it doesn't exist" do File.stubs(:exist?).returns(false) File.expects(:unlink).never - @instance.rescue(@env) + @instance.recover(@env) end end diff --git a/test/vagrant/action/general/package_test.rb b/test/vagrant/action/general/package_test.rb index 6e2b1bb63..71ab6b620 100644 --- a/test/vagrant/action/general/package_test.rb +++ b/test/vagrant/action/general/package_test.rb @@ -110,14 +110,14 @@ class PackageGeneralActionTest < Test::Unit::TestCase File.expects(:exist?).with(@instance.tar_path).returns(false) File.expects(:delete).never - @instance.rescue(@env) + @instance.recover(@env) end should "delete the packaged box if it exists" do File.expects(:exist?).returns(true) File.expects(:delete).with(@instance.tar_path).once - @instance.rescue(@env) + @instance.recover(@env) end end diff --git a/test/vagrant/action/vm/import_test.rb b/test/vagrant/action/vm/import_test.rb index cfc903647..02f326755 100644 --- a/test/vagrant/action/vm/import_test.rb +++ b/test/vagrant/action/vm/import_test.rb @@ -37,11 +37,11 @@ class ImportVMActionTest < Test::Unit::TestCase assert @env.error? end - should "run the destroy action on rescue" do + should "run the destroy action on recover" do env = mock("env") destroy = mock("destory") env.expects(:[]).with("actions").returns(destroy) destroy.expects(:run).with(:destroy) - @instance.rescue(env) + @instance.recover(env) end end diff --git a/test/vagrant/action/warden_test.rb b/test/vagrant/action/warden_test.rb index c71cd2283..914a2eb7a 100644 --- a/test/vagrant/action/warden_test.rb +++ b/test/vagrant/action/warden_test.rb @@ -55,7 +55,7 @@ class ActionWardenTest < Test::Unit::TestCase @instance.call(new_env) end - should "begin rescue on environment error" do + should "begin recover on environment error" do @instance.expects(:begin_rescue) @instance.actions << lambda {} @instance.actions.first.expects(:call).never @@ -70,7 +70,7 @@ class ActionWardenTest < Test::Unit::TestCase @instance.call(new_env_with_error) end - should "call begin rescue when the called action returns with an env error" do + should "call begin recover when the called action returns with an env error" do class Foo def initialize(*args); end def call(env) @@ -90,23 +90,23 @@ class ActionWardenTest < Test::Unit::TestCase end end - context "rescue" do - should "call rescue on all items in the stack" do + context "recover" do + should "call recover on all items in the stack" do mock_action = rescueable_mock("action") - mock_action.expects(:rescue).times(2) + mock_action.expects(:recover).times(2) @instance.stack = [mock_action, mock_action] @instance.begin_rescue(new_env) end - should "call rescue on stack in reversed order" do + should "call recover on stack in reversed order" do seq = sequence("reverse") first_mock_action = rescueable_mock("first") second_mock_action = rescueable_mock("second") @instance.stack = [first_mock_action, second_mock_action] - second_mock_action.expects(:rescue).in_sequence(seq) - first_mock_action.expects(:rescue).in_sequence(seq) + second_mock_action.expects(:recover).in_sequence(seq) + first_mock_action.expects(:recover).in_sequence(seq) @instance.begin_rescue(new_env) end @@ -138,7 +138,7 @@ class ActionWardenTest < Test::Unit::TestCase def rescueable_mock(name) mock_action = mock(name) - mock_action.stubs(:respond_to?).with(:rescue).returns(true) + mock_action.stubs(:respond_to?).with(:recover).returns(true) mock_action end end