That file has to exist

This commit is contained in:
Seth Vargo 2016-05-29 00:18:33 -04:00
parent 982af05178
commit 1b414d3d9e
No known key found for this signature in database
GPG Key ID: 905A90C2949E8787
1 changed files with 5 additions and 4 deletions

View File

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