Skip to content

Commit

Permalink
Merge pull request #21071 from JuliaLang/cv/download-cleanup
Browse files Browse the repository at this point in the history
Avoid creating files when download fails
  • Loading branch information
tkelman committed Mar 30, 2017
2 parents 6659b59 + decead1 commit 980119a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 7 additions & 2 deletions base/interactiveutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions test/download.jl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 980119a

Please sign in to comment.