From d37831219df2c4976eddeba3076cfba6f3486d1d Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 29 Oct 2019 19:06:57 +0100 Subject: [PATCH] Use temp file for calculating hash. --- Library/Homebrew/utils/curl.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 33c2e68433..5c2f4dbaaf 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -184,9 +184,12 @@ def curl_check_http_content(url, user_agents: [:default], check_content: false, end def curl_http_content_headers_and_checksum(url, hash_needed: false, user_agent: :default) + file = Tempfile.new.tap(&:close) + max_time = hash_needed ? "600" : "25" output, = curl_output( - "--connect-timeout", "15", "--include", "--max-time", max_time, "--location", url, + "--dump-header", "-", "--output", file.path, "--include", "--location", + "--connect-timeout", "15", "--max-time", max_time, url, user_agent: user_agent ) @@ -197,7 +200,7 @@ def curl_http_content_headers_and_checksum(url, hash_needed: false, user_agent: final_url = headers[/^Location:\s*(.*)$/i, 1]&.chomp end - output_hash = Digest::SHA256.digest(output) if hash_needed + output_hash = Digest::SHA256.file(file.path) if hash_needed final_url ||= url @@ -210,6 +213,8 @@ def curl_http_content_headers_and_checksum(url, hash_needed: false, user_agent: file_hash: output_hash, file: output, } +ensure + file.unlink end def http_status_ok?(status)