From 678183829a16629f4cc4f8b9419aa46b60a3e304 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Sun, 2 Oct 2022 21:52:58 -0400 Subject: [PATCH] If `cache.julialang.org` is down, try to download Busybox from the upstream URL Co-authored-by: LilithHafner --- test/spawn.jl | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/spawn.jl b/test/spawn.jl index a8a2af40643ff0..7cc094fa7b5332 100644 --- a/test/spawn.jl +++ b/test/spawn.jl @@ -5,7 +5,7 @@ ################################### using Random, Sockets -using Downloads: download +using Downloads: Downloads, download valgrind_off = ccall(:jl_running_on_valgrind, Cint, ()) == 0 @@ -20,8 +20,25 @@ shcmd = `sh` sleepcmd = `sleep` lscmd = `ls` havebb = false + +function _tryonce_download_from_cache(desired_url::AbstractString) + cache_url = "https://cache.julialang.org/$(desired_url)" + cache_head_response = Downloads.request(cache_url; method = "HEAD") + if cache_head_response.status < 400 + return Downloads.download(cache_url) + end + return Downloads.download(desired_url) +end + +function download_from_cache(desired_url::AbstractString) + f = () -> _tryonce_download_from_cache(desired_url) + delays = Float64[30, 30, 60, 60, 60] + g = retry(f; delays) + return g() +end + if Sys.iswindows() - busybox = download("https://cache.julialang.org/https://frippery.org/files/busybox/busybox.exe", joinpath(tempdir(), "busybox.exe")) + busybox = download_from_cache("https://frippery.org/files/busybox/busybox.exe") havebb = try # use busybox-w32 on windows, if available success(`$busybox`) true