Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added rescue/cleanup methods to box downloading to cleanup temporary …

…files
  • Loading branch information...
commit 35af1fa02b5acfa1deddcd421071cbc8f225d7b7 1 parent a7dbb26
@mitchellh mitchellh authored
View
12 lib/vagrant/actions/box/download.rb
@@ -31,9 +31,15 @@ def execute!
end
end
- def after_unpackage
- logger.info "Cleaning up tempfile..."
- File.unlink(@runner.temp_path) if @runner.temp_path && File.exist?(@runner.temp_path)
+ def cleanup
+ if @runner.temp_path && File.exist?(@runner.temp_path)
+ logger.info "Cleaning up downloaded box..."
+ File.unlink(@runner.temp_path)
+ end
+ end
+
+ def rescue(exception)
+ cleanup
end
def with_tempfile
View
13 test/vagrant/actions/box/download_test.rb
@@ -61,6 +61,13 @@ class DownloadBoxActionTest < Test::Unit::TestCase
end
end
+ context "rescue" do
+ should "call cleanup method" do
+ @action.expects(:cleanup).once
+ @action.rescue(nil)
+ end
+ end
+
context "tempfile" do
should "create a tempfile in the vagrant tmp directory" do
Tempfile.expects(:open).with(Vagrant::Actions::Box::Download::BASENAME, Vagrant::Env.tmp_path).once
@@ -77,7 +84,7 @@ class DownloadBoxActionTest < Test::Unit::TestCase
end
end
- context "after unpackaging" do
+ context "cleaning up" do
setup do
@temp_path = "foo"
@runner.stubs(:temp_path).returns(@temp_path)
@@ -86,13 +93,13 @@ class DownloadBoxActionTest < Test::Unit::TestCase
should "delete the temporary file if it exists" do
File.expects(:unlink).with(@temp_path).once
- @action.after_unpackage
+ @action.cleanup
end
should "not delete anything if it doesn't exist" do
File.stubs(:exist?).returns(false)
File.expects(:unlink).never
- @action.after_unpackage
+ @action.cleanup
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.