From 5a4094ca6bf8d5dcb9364397b9b70e77be8695dc Mon Sep 17 00:00:00 2001 From: Will Grant Date: Mon, 13 Aug 2018 18:04:00 +1000 Subject: [PATCH 1/6] Fix download agent search relying on throwing of Sys.which() --- base/download.jl | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/base/download.jl b/base/download.jl index e5ed437a94a7f..b80280a66bb0b 100644 --- a/base/download.jl +++ b/base/download.jl @@ -25,28 +25,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 !isempty(Sys.which("wget")) try run(`wget -O $filename $url`) catch rm(filename) # wget always creates a file rethrow() end - elseif downloadcmd == "curl" + elseif !isempty(Sys.which("curl")) run(`curl -g -L -f -o $filename $url`) - elseif downloadcmd == "fetch" + elseif !isempty(Sys.which("fetch")) run(`fetch -f $filename $url`) else error("no download agent available; install curl, wget, or fetch") From 16898d76f934aa4b312122d067bf9678bad3e8ed Mon Sep 17 00:00:00 2001 From: Will Grant Date: Fri, 17 Aug 2018 10:03:32 +1000 Subject: [PATCH 2/6] change isempty to != nothing --- base/download.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/base/download.jl b/base/download.jl index b80280a66bb0b..9704c3c5aa7fc 100644 --- a/base/download.jl +++ b/base/download.jl @@ -25,16 +25,16 @@ if Sys.iswindows() end else function download(url::AbstractString, filename::AbstractString) - if !isempty(Sys.which("wget")) + if Sys.which("wget") != nothing try run(`wget -O $filename $url`) catch rm(filename) # wget always creates a file rethrow() end - elseif !isempty(Sys.which("curl")) + elseif Sys.which("curl") != nothing run(`curl -g -L -f -o $filename $url`) - elseif !isempty(Sys.which("fetch")) + elseif Sys.which("fetch") != nothing run(`fetch -f $filename $url`) else error("no download agent available; install curl, wget, or fetch") From 058d34887a8c35466dbf0512c8fefe7daad28881 Mon Sep 17 00:00:00 2001 From: Will Grant Date: Fri, 17 Aug 2018 10:47:33 +1000 Subject: [PATCH 3/6] change != to !== --- base/download.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/base/download.jl b/base/download.jl index 9704c3c5aa7fc..161eb2d805e2e 100644 --- a/base/download.jl +++ b/base/download.jl @@ -25,16 +25,16 @@ if Sys.iswindows() end else function download(url::AbstractString, filename::AbstractString) - if Sys.which("wget") != nothing + if Sys.which("wget") !== nothing try run(`wget -O $filename $url`) catch rm(filename) # wget always creates a file rethrow() end - elseif Sys.which("curl") != nothing + elseif Sys.which("curl") !== nothing run(`curl -g -L -f -o $filename $url`) - elseif Sys.which("fetch") != nothing + elseif Sys.which("fetch") !== nothing run(`fetch -f $filename $url`) else error("no download agent available; install curl, wget, or fetch") From 0c531873b62faf82682f2ddb101336c247a1ea50 Mon Sep 17 00:00:00 2001 From: Will Grant Date: Mon, 20 Aug 2018 10:46:10 +1000 Subject: [PATCH 4/6] check file exists before deleting --- base/download.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/download.jl b/base/download.jl index 161eb2d805e2e..9b8098f6a90df 100644 --- a/base/download.jl +++ b/base/download.jl @@ -29,7 +29,7 @@ else try run(`wget -O $filename $url`) catch - rm(filename) # wget always creates a file + isfile(filename) && rm(filename) # wget always creates a file rethrow() end elseif Sys.which("curl") !== nothing From 3940b3405def371b882284066fca03ff65db47d2 Mon Sep 17 00:00:00 2001 From: Will Grant Date: Mon, 20 Aug 2018 11:24:51 +1000 Subject: [PATCH 5/6] try to use curl before wget --- base/download.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/base/download.jl b/base/download.jl index 9b8098f6a90df..edad8a1f156e2 100644 --- a/base/download.jl +++ b/base/download.jl @@ -25,15 +25,15 @@ if Sys.iswindows() end else function download(url::AbstractString, filename::AbstractString) - if Sys.which("wget") !== nothing + 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 isfile(filename) && rm(filename) # wget always creates a file rethrow() end - elseif Sys.which("curl") !== nothing - run(`curl -g -L -f -o $filename $url`) elseif Sys.which("fetch") !== nothing run(`fetch -f $filename $url`) else From 85eec993a619102c5b34595ff58bd582b01f4b1a Mon Sep 17 00:00:00 2001 From: Will Grant Date: Tue, 21 Aug 2018 10:58:35 +1000 Subject: [PATCH 6/6] set rm to force and remove unused variable --- base/download.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/base/download.jl b/base/download.jl index edad8a1f156e2..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" @@ -31,7 +29,7 @@ else try run(`wget -O $filename $url`) catch - isfile(filename) && rm(filename) # wget always creates a file + rm(filename, force=true) # wget always creates a file rethrow() end elseif Sys.which("fetch") !== nothing