Skip to content

Commit 14fb104

Browse files
wfrgraKristofferC
authored andcommitted
Fix download agent search relying on throwing of Sys.which(). Update t #28157 (#28682)
* Fix download agent search relying on throwing of Sys.which()
1 parent e7d7259 commit 14fb104

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

base/download.jl

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
# file downloading
44

5-
downloadcmd = nothing
65
if Sys.iswindows()
7-
downloadcmd = "powershell"
86
function download(url::AbstractString, filename::AbstractString)
97
ps = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
108
tls12 = "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
@@ -25,28 +23,16 @@ if Sys.iswindows()
2523
end
2624
else
2725
function download(url::AbstractString, filename::AbstractString)
28-
global downloadcmd
29-
if downloadcmd === nothing
30-
for checkcmd in ("curl", "wget", "fetch")
31-
try
32-
# Sys.which() will throw() if it can't find `checkcmd`
33-
Sys.which(checkcmd)
34-
downloadcmd = checkcmd
35-
break
36-
catch
37-
end
38-
end
39-
end
40-
if downloadcmd == "wget"
26+
if Sys.which("curl") !== nothing
27+
run(`curl -g -L -f -o $filename $url`)
28+
elseif Sys.which("wget") !== nothing
4129
try
4230
run(`wget -O $filename $url`)
4331
catch
44-
rm(filename) # wget always creates a file
32+
rm(filename, force=true) # wget always creates a file
4533
rethrow()
4634
end
47-
elseif downloadcmd == "curl"
48-
run(`curl -g -L -f -o $filename $url`)
49-
elseif downloadcmd == "fetch"
35+
elseif Sys.which("fetch") !== nothing
5036
run(`fetch -f $filename $url`)
5137
else
5238
error("no download agent available; install curl, wget, or fetch")

0 commit comments

Comments
 (0)