From e82109bd5b7fb1492008994f2343af84df0ddc44 Mon Sep 17 00:00:00 2001 From: wfrgra Date: Wed, 5 Sep 2018 04:15:02 +1000 Subject: [PATCH] Fix download agent search relying on throwing of Sys.which(). Update t #28157 (#28682) * Fix download agent search relying on throwing of Sys.which() (cherry picked from commit 14fb104b5f73e1ff91394f0615c01c2e0a00fc02) --- base/download.jl | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/base/download.jl b/base/download.jl index e5ed437a94a7f..798a9930b7d42 100644 --- a/base/download.jl +++ b/base/download.jl @@ -2,9 +2,7 @@ # file downloading -downloadcmd = nothing if Sys.iswindows() - downloadcmd = "powershell" function download(url::AbstractString, filename::AbstractString) ps = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" tls12 = "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12" @@ -25,28 +23,16 @@ if Sys.iswindows() end else function download(url::AbstractString, filename::AbstractString) - global downloadcmd - if downloadcmd === nothing - for checkcmd in ("curl", "wget", "fetch") - try - # Sys.which() will throw() if it can't find `checkcmd` - Sys.which(checkcmd) - downloadcmd = checkcmd - break - catch - end - end - end - if downloadcmd == "wget" + if 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) # wget always creates a file + rm(filename, force=true) # wget always creates a file rethrow() end - elseif downloadcmd == "curl" - run(`curl -g -L -f -o $filename $url`) - elseif downloadcmd == "fetch" + elseif Sys.which("fetch") !== nothing run(`fetch -f $filename $url`) else error("no download agent available; install curl, wget, or fetch")