Skip to content

Commit 88f6e3b

Browse files
committed
Record ETag and Last-Modified for each URL
1 parent 7fb20f6 commit 88f6e3b

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

src/VersionsJSONUtil.jl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,38 @@ function get_tags()
143143
JSON.parse(String(read(tags_json_path)))
144144
end
145145

146+
##### --------------------------------------------------------------------------------------
147+
##### Get ETag and Last-Modified, so we know if we need to re-download and re-checksum files
148+
149+
Base.@kwdef struct HeadInfo
150+
etag::Union{String, Nothing}
151+
last_modified::Union{String, Nothing}
152+
end
153+
154+
function get_new_headinfo_for_url(url::URI)
155+
local response = nothing
156+
try
157+
response = HTTP.head(url)
158+
catch
159+
error("Encountered error when making HEAD request to URL: $url")
160+
end
161+
headers = Dict(HTTP.headers(response))
162+
etag = get(headers, "ETag", "")
163+
last_modified = get(headers, "Last-Modified", "")
164+
if isempty(strip(etag))
165+
@warn "Got empty new ETag for URL: $new_etag"
166+
etag = nothing
167+
end
168+
if isempty(strip(last_modified))
169+
@warn "Got empty new ETag for URL: $new_etag"
170+
last_modified = nothing
171+
end
172+
head_info = HeadInfo(; etag, last_modified)
173+
return head_info
174+
end
175+
176+
##### --------------------------------------------------------------------------------------
177+
146178
function main(out_path)
147179
tags = get_tags()
148180
tag_versions = filter(x -> x !== nothing, [vnum_maybe(basename(t["ref"])) for t in tags])
@@ -241,6 +273,24 @@ function main(out_path)
241273
end
242274

243275
# Build up metadata about this file
276+
if endswith(filename, ".dmg")
277+
kind = "archive"
278+
extension = "dmg"
279+
elseif endswith(filename, ".exe")
280+
kind = "installer"
281+
extension = "exe"
282+
elseif endswith(filename, ".tar.gz")
283+
kind = "archive"
284+
extension = "tar.gz"
285+
elseif endswith(filename, ".zip")
286+
kind = "archive"
287+
extension = "zip"
288+
else
289+
error("Unsupported file extension in filename: $(filename)")
290+
end
291+
292+
headinfo = get_new_headinfo_for_url(url)
293+
244294
file_dict = Dict(
245295
"triplet" => triplet(platform),
246296
"os" => meta_os(platform),
@@ -260,6 +310,13 @@ function main(out_path)
260310
file_dict["asc"] = asc_signature
261311
end
262312

313+
if !isnothing(headinfo.etag)
314+
file_dict["etag"] = headinfo.etag
315+
end
316+
if !isnothing(headinfo.last_modified)
317+
file_dict["last-modified"] = headinfo.last_modified
318+
end
319+
263320
# Right now, all we have are archives, but let's be forward-thinking
264321
# and make this an array of dictionaries that is easy to extensibly match
265322
push!(meta[version]["files"], file_dict)

test/more_tests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ end
6767
]
6868
optional_keys = [
6969
"asc",
70+
"etag",
7071
"git-tree-sha1",
7172
"git-tree-sha256",
73+
"last-modified",
7274
]
7375
allowed_keys = union(required_keys, optional_keys)
7476
@test required_keys collect(keys(filedict))

0 commit comments

Comments
 (0)