@@ -154,44 +154,50 @@ function get_tags()
154154 end
155155end
156156
157- Base. @kwdef struct OutputDestination
157+ Base. @kwdef struct Config
158158 versions_json_filename:: AbstractString
159159 internal_json_filename:: AbstractString
160160end
161161
162- function OutputDestination (output_directory:: AbstractString )
162+ function Config (output_directory:: AbstractString )
163163 versions_json_filename = joinpath (output_directory, " versions.json" )
164164 internal_json_filename = joinpath (output_directory, " internal.json" )
165- dest = OutputDestination (; versions_json_filename, internal_json_filename)
166- return dest
165+
166+ settings_file = joinpath (dirname (@__DIR__ ), " Settings.toml" )
167+ settings_toml = TOML. parsefile (settings_file)
168+
169+ cfg = Config (;
170+ versions_json_filename,
171+ internal_json_filename,
172+ )
173+ return cfg
167174end
168175
169176struct OutputJsonContent
170177 versions_json:: OrderedDict # this variable was previously named `meta`
171178 internal_json:: OrderedDict
172179end
173180
174- function OutputJsonContent (dest :: OutputDestination )
175- if isfile (dest . versions_json_filename)
176- versions_json = OrderedDict (JSON. parsefile (dest . versions_json_filename))
181+ function OutputJsonContent (cfg :: Config )
182+ if isfile (cfg . versions_json_filename)
183+ versions_json = OrderedDict (JSON. parsefile (cfg . versions_json_filename))
177184 else
178185 versions_json = OrderedDict ()
179186 end
180- if isfile (dest . internal_json_filename)
181- internal_json = OrderedDict (JSON. parsefile (dest . internal_json_filename))
187+ if isfile (cfg . internal_json_filename)
188+ internal_json = OrderedDict (JSON. parsefile (cfg . internal_json_filename))
182189 else
183190 internal_json = OrderedDict ()
184191 end
185192 return OutputJsonContent (versions_json, internal_json)
186193end
187194
188- function checkpoint (content:: OutputJsonContent , dest:: OutputDestination )
189- indent = 2
190- open (dest. versions_json_filename, " w" ) do io
191- JSON. print (io, content. versions_json, indent)
195+ function checkpoint (content:: OutputJsonContent , cfg:: Config )
196+ open (cfg. versions_json_filename, " w" ) do io
197+ JSON. json (io, content. versions_json; pretty= true , sort_keys= false )
192198 end
193- open (dest . internal_json_filename, " w" ) do io
194- JSON. print (io, content. internal_json, indent )
199+ open (cfg . internal_json_filename, " w" ) do io
200+ JSON. json (io, content. internal_json; pretty = true , sort_keys = false )
195201 end
196202 return nothing
197203end
@@ -341,7 +347,12 @@ function filedict_is_complete_and_good(filedict::AbstractDict)
341347end
342348
343349function get_new_etag_for_url (url:: AbstractString ):: String
344- response = HTTP. head (url)
350+ local response = nothing
351+ try
352+ response = HTTP. head (url)
353+ catch
354+ error (" Encountered error when making HEAD request to URL: $url " )
355+ end
345356 new_etag = get (Dict (HTTP. headers (response)), " ETag" , " " )
346357 if isempty (strip (new_etag))
347358 @warn " Got empty new ETag for URL: $new_etag "
@@ -350,16 +361,6 @@ function get_new_etag_for_url(url::AbstractString)::String
350361 return new_etag
351362end
352363
353- function main (output_directory:: AbstractString )
354- dest = OutputDestination (output_directory)
355- return main (dest)
356- end
357-
358- function main (dest:: OutputDestination )
359- content = OutputJsonContent (dest)
360- return main! (content, dest)
361- end
362-
363364function assert_sanity_check_tag_number (tag_versions:: Vector{VersionNumber} )
364365 # IIRC, we have never deleted a tag from JuliaLang/julia
365366 # So this number should be monotonically non-decreasing over time
@@ -374,7 +375,17 @@ function assert_sanity_check_tag_number(tag_versions::Vector{VersionNumber})
374375 end
375376end
376377
377- function main! (content:: OutputJsonContent , dest:: OutputDestination )
378+ function main (output_directory:: AbstractString )
379+ cfg = Config (output_directory)
380+ return main (cfg)
381+ end
382+
383+ function main (cfg:: Config )
384+ content = OutputJsonContent (cfg)
385+ return main! (content, cfg)
386+ end
387+
388+ function main! (content:: OutputJsonContent , cfg:: Config )
378389 tags = get_tags ()
379390 tag_versions = filter (x -> ! isnothing (x), [VersionNumber (basename (t[" ref" ])) for t in tags])
380391 unique! (tag_versions)
@@ -394,6 +405,7 @@ function main!(content::OutputJsonContent, dest::OutputDestination)
394405 number_urls_success = 0
395406 num_urls_already_complete = 0
396407 number_urls_already_known_nonexistent = 0
408+ checkpoint (content, cfg)
397409 for version in tag_versions
398410 for platform in julia_platforms
399411 url = download_url (version, platform)
@@ -421,14 +433,19 @@ function main!(content::OutputJsonContent, dest::OutputDestination)
421433 if (ex isa HTTP. Exceptions. StatusError) && (ex. status == 404 )
422434 println (stdout , " ✗" )
423435 mark_url_as_nonexistent! (content, version, url)
424- checkpoint (content, dest )
436+ checkpoint (content, cfg )
425437 continue # skip the rest of this for-loop iteration
426438 else
427439 rethrow ()
428440 end
429441 end
430442 filepath:: AbstractString
431443
444+ if filesize (filepath) == 0
445+ # The file is empty
446+ continue # skip the rest of this for-loop iteration
447+ end
448+
432449 number_urls_success += 1
433450 println (stdout , " ✓" )
434451
@@ -488,7 +505,7 @@ function main!(content::OutputJsonContent, dest::OutputDestination)
488505 push! (meta[string (version)][" files" ], file_dict)
489506
490507 # Write out new versions of our versions.json as we go
491- checkpoint (content, dest )
508+ checkpoint (content, cfg )
492509
493510 # Delete downloaded file
494511 rm (filepath)
@@ -517,7 +534,7 @@ function main!(content::OutputJsonContent, dest::OutputDestination)
517534 if (ex isa HTTP. Exceptions. StatusError) && (ex. status == 404 )
518535 println (stdout , " ✗" )
519536 mark_url_as_nonexistent! (content, version, url)
520- checkpoint (content, dest )
537+ checkpoint (content, cfg )
521538 continue # skip the rest of this for-loop iteration
522539 else
523540 rethrow ()
@@ -529,13 +546,17 @@ function main!(content::OutputJsonContent, dest::OutputDestination)
529546 # Add in `.asc` signature content, if applicable
530547 if ! isnothing (asc_signature)
531548 file_dict[" asc" ] = asc_signature
532- checkpoint (content, dest )
549+ checkpoint (content, cfg )
533550 end
534551 end
535552 end
536553 end
537554 @info " Tried $(number_urls_tried) versions, successfully downloaded $(number_urls_success) . Skipped $num_urls_already_complete already good. Skipped $(number_urls_already_known_nonexistent) known bad."
538- return dest
555+
556+ return_value = (;
557+ cfg. versions_json_filename,
558+ )
559+ return cfg
539560end
540561
541562end # module
0 commit comments