From fb7c4033a917d87be8a432ab972a29d65a19d410 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sat, 28 May 2016 23:05:37 -0400 Subject: [PATCH] Do not create a tempfile when downloading box metadata The only reason we were using Tempfile was to generate the path. This commit switches to using `Dir::Tmpname.create`, which accomplishes the same thing without the overhead of creating and removing a tempfile. --- lib/vagrant/box.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/vagrant/box.rb b/lib/vagrant/box.rb index 7b0c7da3a..a6d6aa737 100644 --- a/lib/vagrant/box.rb +++ b/lib/vagrant/box.rb @@ -118,8 +118,7 @@ module Vagrant # @param [Hash] download_options Options to pass to the downloader. # @return [BoxMetadata] def load_metadata(**download_options) - tf = Tempfile.new("vagrant") - tf.close + path = Dir::Tmpname.create("vagrant-load-metadata") {} url = @metadata_url if File.file?(url) || url !~ /^[a-z0-9]+:.*$/i @@ -129,13 +128,13 @@ module Vagrant end opts = { headers: ["Accept: application/json"] }.merge(download_options) - Util::Downloader.new(url, tf.path, **opts).download! - BoxMetadata.new(File.open(tf.path, "r")) + Util::Downloader.new(url, path, **opts).download! + BoxMetadata.new(File.open(path, "r")) rescue Errors::DownloaderError => e raise Errors::BoxMetadataDownloadError, message: e.extra_data[:message] ensure - tf.unlink if tf + File.unlink(path) if File.file?(path) end # Checks if the box has an update and returns the metadata, version,