-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Downloads stdlib; replace Base.download
- Base.download is deprecated in favor of Downloads.download - the former is now implemented by calling the latter
- Loading branch information
1 parent
b5a53c2
commit a561a39
Showing
12 changed files
with
95 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
deps/checksums/Downloads-1a1d2e0a10209512f5b29e585bfd78e7a47f8f61.tar.gz/md5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
24a8b8fc2398d20c24a13ce73482a3d7 |
1 change: 1 addition & 0 deletions
1
deps/checksums/Downloads-1a1d2e0a10209512f5b29e585bfd78e7a47f8f61.tar.gz/sha512
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
4b652be535dce6a5cf36e546a31d3221f4c2534d1a3ac710f31f9ed2dfbeabd21b36c0186e4abe12cfee992ff557317aefe2bdeb9cb8b1c44da085b030719329 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ | |
/Statistics | ||
/LibCURL-* | ||
/LibCURL | ||
/Downloads-* | ||
/Downloads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DOWNLOADS_BRANCH = master | ||
DOWNLOADS_SHA1 = 1a1d2e0a10209512f5b29e585bfd78e7a47f8f61 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,6 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
# Test that `Base.download_url()` is altered by `Base.DOWNLOAD_HOOKS`. | ||
let urls = ["http://httpbin.julialang.org/ip", "https://httpbin.julialang.org/ip"] | ||
for url in urls | ||
@test Base.download_url(url) == url | ||
end | ||
push!(Base.DOWNLOAD_HOOKS, url->replace(url, r"^http://" => "https://")) | ||
for url in urls | ||
@test Base.download_url(url) == urls[end] | ||
end | ||
pop!(Base.DOWNLOAD_HOOKS) | ||
for url in urls | ||
@test Base.download_url(url) == url | ||
end | ||
end | ||
|
||
mktempdir() do temp_dir | ||
# Download a file | ||
file = joinpath(temp_dir, "ip") | ||
@test download("https://httpbin.julialang.org/ip", file) == file | ||
@test isfile(file) | ||
@test !isempty(read(file)) | ||
ip = read(file, String) | ||
|
||
# Test download rewrite hook | ||
push!(Base.DOWNLOAD_HOOKS, url->replace(url, r"/status/404$" => "/ip")) | ||
@test download("https://httpbin.julialang.org/status/404", file) == file | ||
@test isfile(file) | ||
@test !isempty(read(file)) | ||
@test ip == read(file, String) | ||
pop!(Base.DOWNLOAD_HOOKS) | ||
|
||
# Download an empty file | ||
empty_file = joinpath(temp_dir, "empty") | ||
@test download("https://httpbin.julialang.org/status/200", empty_file) == empty_file | ||
|
||
# Windows and older versions of curl do not create the empty file (https://github.com/curl/curl/issues/183) | ||
@test !isfile(empty_file) || isempty(read(empty_file)) | ||
|
||
# Make sure that failed downloads do not leave files around | ||
missing_file = joinpath(temp_dir, "missing") | ||
@test_throws ProcessFailedException download("https://httpbin.julialang.org/status/404", missing_file) | ||
@test !isfile(missing_file) | ||
|
||
# Make sure we properly handle metachar ' on windows with ^ escaping | ||
if Sys.iswindows() | ||
metachar_file = joinpath(temp_dir, "metachar") | ||
Base.download_powershell("https://httpbin.julialang.org/get?test='^'", metachar_file) | ||
metachar_string = read(metachar_file, String) | ||
m = match(r"\"test\"\s*:\s*\"(.*)\"", metachar_string) | ||
@test m.captures[1] == "'^'" | ||
end | ||
|
||
# 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 ProcessFailedException download("http://192.0.2.1", invalid_host_file) | ||
@test !isfile(invalid_host_file) | ||
cmd = `$(Base.julia_cmd()) --depwarn=no --startup-file=no download_exec.jl` | ||
if !success(pipeline(cmd; stdout=stdout, stderr=stderr)) | ||
error("download test failed, cmd : $cmd") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
module TestDownload | ||
|
||
using Test | ||
|
||
# Test that `Base.download_url()` is altered by `Base.DOWNLOAD_HOOKS`. | ||
let urls = ["http://httpbin.julialang.org/ip", "https://httpbin.julialang.org/ip"] | ||
for url in urls | ||
@test Base.download_url(url) == url | ||
end | ||
push!(Base.DOWNLOAD_HOOKS, url->replace(url, r"^http://" => "https://")) | ||
for url in urls | ||
@test Base.download_url(url) == urls[end] | ||
end | ||
pop!(Base.DOWNLOAD_HOOKS) | ||
for url in urls | ||
@test Base.download_url(url) == url | ||
end | ||
end | ||
|
||
mktempdir() do temp_dir | ||
# Download a file | ||
file = joinpath(temp_dir, "ip") | ||
@test download("https://httpbin.julialang.org/ip", file) == file | ||
@test isfile(file) | ||
@test !isempty(read(file)) | ||
ip = read(file, String) | ||
|
||
# Test download rewrite hook | ||
push!(Base.DOWNLOAD_HOOKS, url->replace(url, r"/status/404$" => "/ip")) | ||
@test download("https://httpbin.julialang.org/status/404", file) == file | ||
@test isfile(file) | ||
@test !isempty(read(file)) | ||
@test ip == read(file, String) | ||
pop!(Base.DOWNLOAD_HOOKS) | ||
|
||
# Download an empty file | ||
empty_file = joinpath(temp_dir, "empty") | ||
@test download("https://httpbin.julialang.org/status/200", empty_file) == empty_file | ||
|
||
# Windows and older versions of curl do not create the empty file (https://github.com/curl/curl/issues/183) | ||
@test !isfile(empty_file) || isempty(read(empty_file)) | ||
|
||
# Make sure that failed downloads do not leave files around | ||
missing_file = joinpath(temp_dir, "missing") | ||
@test_throws ErrorException download("https://httpbin.julialang.org/status/404", missing_file) | ||
@test !isfile(missing_file) | ||
|
||
# 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) | ||
@test !isfile(invalid_host_file) | ||
end | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters