Skip to content

Commit a9e1141

Browse files
DilumAluthge-LLMcodex
authored andcommitted
Add git-tree-{sha1,sha256} for tar.gz downloads
Co-authored-by: OpenAI Codex GPT-5 <codex@openai.com>
1 parent cfb5c3c commit a9e1141

3 files changed

Lines changed: 62 additions & 15 deletions

File tree

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1010
Lazy = "50d2b5c4-7a5e-59d5-8109-a42b560f39c0"
1111
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1212
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
13+
Tar = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
1314
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
1415
WebCacheUtilities = "0c1c26de-fc5f-47ff-87a8-a157289a9bac"
1516

schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
"sha256": {
4242
"type": "string"
4343
},
44+
"git-tree-sha1": {
45+
"type": "string"
46+
},
47+
"git-tree-sha256": {
48+
"type": "string"
49+
},
4450
"size": {
4551
"type": "integer"
4652
},

src/VersionsJSONUtil.jl

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
module VersionsJSONUtil
22

33
using HTTP, JSON, Pkg.BinaryPlatforms, WebCacheUtilities, SHA, Lazy
4+
using Tar: Tar
45
import Pkg.BinaryPlatforms: triplet, arch
6+
import Pkg.PlatformEngines: exe7z
57

68
"Wrapper types to define three jlext methods for portable, tarball and installer Windows"
79
struct WindowsPortable
@@ -109,6 +111,11 @@ julia_platforms = [
109111
FreeBSD(:x86_64),
110112
]
111113

114+
const tarball_git_tree_hash_skiplist = [
115+
# Corrupt gzip stream: `7z` reports a CRC failure for the embedded tarball.
116+
"https://julialang-s3.julialang.org/bin/linux/x86/0.7/julia-0.7.0-alpha-linux-i686.tar.gz",
117+
]
118+
112119
function vnum_maybe(x::AbstractString)
113120
try
114121
return VersionNumber(x)
@@ -122,6 +129,18 @@ function is_stable(v::VersionNumber)
122129
return v.prerelease == () && v.build == ()
123130
end
124131

132+
function tarball_git_tree_hash(tarball_path::AbstractString; algorithm::AbstractString)
133+
return open(io -> Tar.tree_hash(io; algorithm = algorithm), `$(exe7z()) x $tarball_path -so`)
134+
end
135+
136+
function tarball_git_tree_sha1(tarball_path::AbstractString)
137+
return tarball_git_tree_hash(tarball_path; algorithm = "git-sha1")
138+
end
139+
140+
function tarball_git_tree_sha256(tarball_path::AbstractString)
141+
return tarball_git_tree_hash(tarball_path; algorithm = "git-sha256")
142+
end
143+
125144
# Get list of tags from the Julia repo
126145
function get_tags()
127146
@info("Probing for tag list...")
@@ -160,6 +179,22 @@ function main(out_path)
160179
number_urls_success += 1
161180
println(stdout, "")
162181

182+
if endswith(filename, ".dmg")
183+
kind = "archive"
184+
extension = "dmg"
185+
elseif endswith(filename, ".exe")
186+
kind = "installer"
187+
extension = "exe"
188+
elseif endswith(filename, ".tar.gz")
189+
kind = "archive"
190+
extension = "tar.gz"
191+
elseif endswith(filename, ".zip")
192+
kind = "archive"
193+
extension = "zip"
194+
else
195+
error("Unsupported file extension in filename: $(filename)")
196+
end
197+
163198
tarball_hash_path = hit_file_cache("$(filename).sha256") do tarball_hash_path
164199
open(filepath, "r") do io
165200
open(tarball_hash_path, "w") do hash_io
@@ -169,6 +204,23 @@ function main(out_path)
169204
end
170205
tarball_hash = String(read(tarball_hash_path))
171206

207+
tarball_git_tree_hashes = if extension == "tar.gz" && !(url in tarball_git_tree_hash_skiplist)
208+
Dict(
209+
"git-tree-sha1" => String(read(hit_file_cache("$(filename).git-tree-sha1") do tree_hash_path
210+
open(tree_hash_path, "w") do hash_io
211+
write(hash_io, tarball_git_tree_sha1(filepath))
212+
end
213+
end)),
214+
"git-tree-sha256" => String(read(hit_file_cache("$(filename).git-tree-sha256") do tree_hash_path
215+
open(tree_hash_path, "w") do hash_io
216+
write(hash_io, tarball_git_tree_sha256(filepath))
217+
end
218+
end)),
219+
)
220+
else
221+
nothing
222+
end
223+
172224
# Initialize overall version key, if needed
173225
if !haskey(meta, version)
174226
meta[version] = Dict(
@@ -196,21 +248,6 @@ function main(out_path)
196248
end
197249

198250
# Build up metadata about this file
199-
if endswith(filename, ".dmg")
200-
kind = "archive"
201-
extension = "dmg"
202-
elseif endswith(filename, ".exe")
203-
kind = "installer"
204-
extension = "exe"
205-
elseif endswith(filename, ".tar.gz")
206-
kind = "archive"
207-
extension = "tar.gz"
208-
elseif endswith(filename, ".zip")
209-
kind = "archive"
210-
extension = "zip"
211-
else
212-
error("Unsupported file extension in filename: $(filename)")
213-
end
214251
file_dict = Dict(
215252
"triplet" => triplet(platform),
216253
"os" => meta_os(platform),
@@ -222,6 +259,9 @@ function main(out_path)
222259
"extension" => extension,
223260
"url" => url,
224261
)
262+
if tarball_git_tree_hashes !== nothing
263+
merge!(file_dict, tarball_git_tree_hashes)
264+
end
225265
# Add in `.asc` signature content, if applicable
226266
if asc_signature !== nothing
227267
file_dict["asc"] = asc_signature

0 commit comments

Comments
 (0)