From a909b647cfa48d8b4eb441816efa65d66617afbc Mon Sep 17 00:00:00 2001 From: Mus M Date: Fri, 19 May 2017 13:17:26 -0400 Subject: [PATCH 1/6] Use powershell for download function for Windows --- base/interactiveutil.jl | 11 ++++++----- test/download.jl | 7 +++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/base/interactiveutil.jl b/base/interactiveutil.jl index 34f7724736493..60a53d6d712f1 100644 --- a/base/interactiveutil.jl +++ b/base/interactiveutil.jl @@ -571,11 +571,12 @@ end downloadcmd = nothing if is_windows() function download(url::AbstractString, filename::AbstractString) - res = ccall((:URLDownloadToFileW,:urlmon),stdcall,Cuint, - (Ptr{Void},Cwstring,Cwstring,Cuint,Ptr{Void}),C_NULL,url,filename,0,C_NULL) - if res != 0 - error("automatic download failed (error: $res): $url") - end + ps = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" + tls12 = "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12" + client = "New-Object System.Net.Webclient" + # in the following we escape ' with '' (see https://ss64.com/ps/syntax-esc.html) + downloadfile = "($client).DownloadFile('$(replace(url, "'", "''"))', '$(replace(filename, "'", "''"))')" + run(`$ps -NoProfile -Command "$tls12; $downloadfile"`) filename end else diff --git a/test/download.jl b/test/download.jl index e982dbfbcc53f..699d3004d683b 100644 --- a/test/download.jl +++ b/test/download.jl @@ -19,6 +19,13 @@ mktempdir() do temp_dir @test_throws ErrorException download("http://httpbin.org/status/404", missing_file) @test !isfile(missing_file) + # Make sure we properly handle metachar ' + metachar_file = joinpath(temp_dir, "metachar") + download("https://httpbin.org/get?test='^'", metachar_file) + metachar_string = readstring(metachar_file) + m = match(r"\"url\"\s*:\s*\"(.*)\"", metachar_string) + @test m.captures[1] == "https://httpbin.org/get?test='^'" + # Use a TEST-NET (192.0.2.0/24) address which shouldn't be bound invalid_host_file = joinpath(temp_dir, "invalid_host") @test_throws ErrorException download("http://192.0.2.1", invalid_host_file) From 64cb9ae2d43c862985ad5afb9212fb28cfcd3640 Mon Sep 17 00:00:00 2001 From: Mus M Date: Fri, 2 Jun 2017 11:54:02 -0400 Subject: [PATCH 2/6] Move global downloadcmd to non windows branch --- base/interactiveutil.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/interactiveutil.jl b/base/interactiveutil.jl index 60a53d6d712f1..96a493e03868e 100644 --- a/base/interactiveutil.jl +++ b/base/interactiveutil.jl @@ -568,7 +568,6 @@ end # file downloading -downloadcmd = nothing if is_windows() function download(url::AbstractString, filename::AbstractString) ps = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" @@ -580,6 +579,7 @@ if is_windows() filename end else + downloadcmd = nothing function download(url::AbstractString, filename::AbstractString) global downloadcmd if downloadcmd === nothing From 6f215f79fc9c9f3634612a194b832060ecccbd58 Mon Sep 17 00:00:00 2001 From: Mus M Date: Sun, 25 Jun 2017 23:38:36 -0400 Subject: [PATCH 3/6] set downloadcmd to powershell --- base/interactiveutil.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/interactiveutil.jl b/base/interactiveutil.jl index 96a493e03868e..abd23db4624e4 100644 --- a/base/interactiveutil.jl +++ b/base/interactiveutil.jl @@ -567,8 +567,9 @@ function methodswith(t::Type, showparents::Bool=false) end # file downloading - +downloadcmd = nothing if is_windows() + 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" @@ -579,7 +580,6 @@ if is_windows() filename end else - downloadcmd = nothing function download(url::AbstractString, filename::AbstractString) global downloadcmd if downloadcmd === nothing From d5616eb998ed050c71212b5748a6a642a0ce0e34 Mon Sep 17 00:00:00 2001 From: Mus M Date: Sun, 25 Jun 2017 23:40:18 -0400 Subject: [PATCH 4/6] whites fix --- base/interactiveutil.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/base/interactiveutil.jl b/base/interactiveutil.jl index abd23db4624e4..698c4b8dd3178 100644 --- a/base/interactiveutil.jl +++ b/base/interactiveutil.jl @@ -567,6 +567,7 @@ function methodswith(t::Type, showparents::Bool=false) end # file downloading + downloadcmd = nothing if is_windows() downloadcmd = :powershell From 33b582b485635b1115f4eb7d3d6988ab469436ca Mon Sep 17 00:00:00 2001 From: Mus M Date: Sat, 15 Jul 2017 14:12:40 -0400 Subject: [PATCH 5/6] Update interactiveutil.jl --- base/interactiveutil.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/base/interactiveutil.jl b/base/interactiveutil.jl index 2a49bfc0f1771..dbca8667ed047 100644 --- a/base/interactiveutil.jl +++ b/base/interactiveutil.jl @@ -590,7 +590,7 @@ function methodswith(t::Type, showparents::Bool=false) end # file downloading - +downloadcmd = nothing if Sys.iswindows() downloadcmd = :powershell function download(url::AbstractString, filename::AbstractString) @@ -603,7 +603,6 @@ if Sys.iswindows() filename end else - downloadcmd = nothing function download(url::AbstractString, filename::AbstractString) global downloadcmd if downloadcmd === nothing From 569d69ab57cd95d8266112cdbb3753bbac626b2e Mon Sep 17 00:00:00 2001 From: Mus M Date: Fri, 21 Jul 2017 15:28:54 -0400 Subject: [PATCH 6/6] Update download.jl --- test/download.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/download.jl b/test/download.jl index 699d3004d683b..5fa3eef9597b3 100644 --- a/test/download.jl +++ b/test/download.jl @@ -22,7 +22,7 @@ mktempdir() do temp_dir # Make sure we properly handle metachar ' metachar_file = joinpath(temp_dir, "metachar") download("https://httpbin.org/get?test='^'", metachar_file) - metachar_string = readstring(metachar_file) + metachar_string = read(metachar_file, String) m = match(r"\"url\"\s*:\s*\"(.*)\"", metachar_string) @test m.captures[1] == "https://httpbin.org/get?test='^'"