create: check that downloaded URL is actually archive

My common mistake is to specify release URL, like

    brew crate https://github.com/hugelgupf/p9/releases/tag/v0.3.0

which gives unpacking errors later. It should be archive instead

    brew create https://github.com/hugelgupf/p9/archive/refs/tags/v0.3.0.tar.gz

Ideally we can try to autodetect the archive from release page,
but erroring out if downloaded file is HTML page should be handy
for early spotting other URL mistakes too.
This commit is contained in:
Anatoli Babenia 2025-03-27 06:09:58 +03:00
parent ad75e9b337
commit 62753a5ec6

View File

@ -82,7 +82,10 @@ module Homebrew
r = Resource.new
r.url(@url)
r.owner = self
@sha256 = r.fetch.sha256 if r.download_strategy == CurlDownloadStrategy
filepath = r.fetch
raise "Downloaded URL is not archive" if File.read(filepath, 100).strip.start_with?("<!DOCTYPE html>")
@sha256 = filepath.sha256
end
if @github