Skip to content

Commit

Permalink
Allow curl on windows if available and silence curl downloads (JuliaL…
Browse files Browse the repository at this point in the history
  • Loading branch information
musm authored and StefanKarpinski committed Mar 6, 2019
1 parent a1e41b9 commit c034b2f
Showing 1 changed file with 39 additions and 20 deletions.
59 changes: 39 additions & 20 deletions base/download.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# file downloading

if Sys.iswindows()
function download(url::AbstractString, filename::AbstractString)
function download_powershell(url::AbstractString, filename::AbstractString)
ps = joinpath(get(ENV, "SYSTEMROOT", "C:\\Windows"), "System32\\WindowsPowerShell\\v1.0\\powershell.exe")
tls12 = "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
client = "New-Object System.Net.Webclient"
Expand All @@ -19,29 +19,48 @@ if Sys.iswindows()
end
pipeline_error(proc)
end
filename
return filename
end
else
function download(url::AbstractString, filename::AbstractString)
if Sys.isapple() && Sys.isexecutable("/usr/bin/curl")
run(`/usr/bin/curl -g -L -f -o $filename $url`) # issue #30956
elseif Sys.which("curl") !== nothing
run(`curl -g -L -f -o $filename $url`)
elseif Sys.which("wget") !== nothing
try
run(`wget -O $filename $url`)
catch
rm(filename, force=true) # wget always creates a file
rethrow()
end
elseif Sys.which("fetch") !== nothing
run(`fetch -f $filename $url`)
else
error("no download agent available; install curl, wget, or fetch")
end

function find_curl()
if Sys.isapple() && Sys.isexecutable("/usr/bin/curl")
"/usr/bin/curl"
elseif Sys.iswindows() && Sys.isexecutable(joinpath(get(ENV, "SYSTEMROOT", "C:\\Windows"), "System32\\curl.exe"))
joinpath(get(ENV, "SYSTEMROOT", "C:\\Windows"), "System32\\curl.exe")
elseif Sys.which("curl") !== nothing
"curl"
else
nothing
end
end

function download_curl(curl_exe, url, filename)
run(`$curl_exe -s -S -g -L -f -o $filename $url`)
return filename
end

function download(url::AbstractString, filename::AbstractString)
curl_exe = find_curl()
if curl_exe !== nothing
return download_curl(curl_exe, url, filename)
elseif Sys.iswindows()
return download_powershell(url, filename)
elseif Sys.which("wget") !== nothing
try
run(`wget -O $filename $url`)
catch
rm(filename, force=true) # wget always creates a file
rethrow()
end
filename
elseif Sys.which("fetch") !== nothing
run(`fetch -f $filename $url`)
else
error("No download agent available; install curl, wget, or fetch.")
end
return filename
end

function download(url::AbstractString)
filename = tempname()
download(url, filename)
Expand Down

0 comments on commit c034b2f

Please sign in to comment.