From adbcc9f34e931cc5a61220831bb45e67c854da06 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 23 Jan 2014 13:13:26 -0800 Subject: [PATCH] core: delete the temporary file if adding succeeds --- lib/vagrant/action/builtin/box_add.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/action/builtin/box_add.rb b/lib/vagrant/action/builtin/box_add.rb index 4403ed863..062dcb943 100644 --- a/lib/vagrant/action/builtin/box_add.rb +++ b/lib/vagrant/action/builtin/box_add.rb @@ -73,11 +73,22 @@ module Vagrant provider: metadata_provider.name)) # Now we have a URL, we have to download this URL. - box_url = download(metadata_provider.url, env) + box = nil + begin + box_url = download(metadata_provider.url, env) - # Add the box! - box = env[:box_collection].add( - box_url, metadata.name, metadata_version.version) + # Add the box! + box = env[:box_collection].add( + box_url, metadata.name, metadata_version.version) + ensure + # Make sure we delete the temporary file after we add it, + # unless we were interrupted, in which case we keep it around + # so we can resume the download later. + if !@download_interrupted + @logger.debug("Deleting temporary box: #{box_url}") + box_url.delete + end + end env[:ui].success(I18n.t( "vagrant.box_added",