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.
This commit is contained in:
parent
fb60d34236
commit
fb7c4033a9
|
@ -118,8 +118,7 @@ module Vagrant
|
||||||
# @param [Hash] download_options Options to pass to the downloader.
|
# @param [Hash] download_options Options to pass to the downloader.
|
||||||
# @return [BoxMetadata]
|
# @return [BoxMetadata]
|
||||||
def load_metadata(**download_options)
|
def load_metadata(**download_options)
|
||||||
tf = Tempfile.new("vagrant")
|
path = Dir::Tmpname.create("vagrant-load-metadata") {}
|
||||||
tf.close
|
|
||||||
|
|
||||||
url = @metadata_url
|
url = @metadata_url
|
||||||
if File.file?(url) || url !~ /^[a-z0-9]+:.*$/i
|
if File.file?(url) || url !~ /^[a-z0-9]+:.*$/i
|
||||||
|
@ -129,13 +128,13 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
opts = { headers: ["Accept: application/json"] }.merge(download_options)
|
opts = { headers: ["Accept: application/json"] }.merge(download_options)
|
||||||
Util::Downloader.new(url, tf.path, **opts).download!
|
Util::Downloader.new(url, path, **opts).download!
|
||||||
BoxMetadata.new(File.open(tf.path, "r"))
|
BoxMetadata.new(File.open(path, "r"))
|
||||||
rescue Errors::DownloaderError => e
|
rescue Errors::DownloaderError => e
|
||||||
raise Errors::BoxMetadataDownloadError,
|
raise Errors::BoxMetadataDownloadError,
|
||||||
message: e.extra_data[:message]
|
message: e.extra_data[:message]
|
||||||
ensure
|
ensure
|
||||||
tf.unlink if tf
|
File.unlink(path) if File.file?(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks if the box has an update and returns the metadata, version,
|
# Checks if the box has an update and returns the metadata, version,
|
||||||
|
|
Loading…
Reference in New Issue