diff --git a/.travis.yml b/.travis.yml index 13f60015e5c17..e8445b240c913 100644 --- a/.travis.yml +++ b/.travis.yml @@ -128,7 +128,7 @@ script: - export JULIA_CPU_CORES=2 && export JULIA_TEST_MAXRSS_MB=600 && cd /tmp/julia/share/julia/test && /tmp/julia/bin/julia --check-bounds=yes runtests.jl $TESTSTORUN && - /tmp/julia/bin/julia --check-bounds=yes runtests.jl libgit2-online pkg + /tmp/julia/bin/julia --check-bounds=yes runtests.jl libgit2-online download pkg - cd `dirname $TRAVIS_BUILD_DIR` && mv julia2 julia && rm -f julia/deps/scratch/libgit2-*/CMakeFiles/CMakeOutput.log # uncomment the following if failures are suspected to be due to the out-of-memory killer diff --git a/appveyor.yml b/appveyor.yml index be29747bf7d14..b7bdb2e3e50fc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -56,4 +56,4 @@ test_script: - usr\bin\julia -e "versioninfo()" - usr\bin\julia --precompiled=no -e "true" - cd test && ..\usr\bin\julia --check-bounds=yes runtests.jl all && - ..\usr\bin\julia --check-bounds=yes runtests.jl libgit2-online pkg + ..\usr\bin\julia --check-bounds=yes runtests.jl libgit2-online download pkg diff --git a/base/interactiveutil.jl b/base/interactiveutil.jl index 12663bb92363a..d4c3a2bbe23f0 100644 --- a/base/interactiveutil.jl +++ b/base/interactiveutil.jl @@ -588,9 +588,14 @@ else end end if downloadcmd == :wget - run(`wget -O $filename $url`) + try + run(`wget -O $filename $url`) + catch + rm(filename) # wget always creates a file + rethrow() + end elseif downloadcmd == :curl - run(`curl -o $filename -L $url`) + run(`curl -L -f -o $filename $url`) elseif downloadcmd == :fetch run(`fetch -f $filename $url`) else diff --git a/test/download.jl b/test/download.jl new file mode 100644 index 0000000000000..317179f172dbd --- /dev/null +++ b/test/download.jl @@ -0,0 +1,26 @@ +# This file is a part of Julia. License is MIT: http://julialang.org/license + +mktempdir() do temp_dir + # Download a file + file = joinpath(temp_dir, "ip") + @test download("http://httpbin.org/ip", file) == file + @test isfile(file) + @test !isempty(read(file)) + + # Download an empty file + empty_file = joinpath(temp_dir, "empty") + @test download("http://httpbin.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("http://httpbin.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