Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid creating files when download fails #21071

Merged
merged 3 commits into from
Mar 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -587,9 +587,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