Skip to content

Commit 0b6f4b3

Browse files
committed
Improved handling of incomplete downloads
1 parent 4f9ea39 commit 0b6f4b3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/informers/utils/hub.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,14 @@ def put(request, response)
8585
output_path = resolve_path(request)
8686

8787
begin
88+
tmp_path = "#{output_path}.incomplete"
8889
FileUtils.mkdir_p(File.dirname(output_path))
89-
File.open(output_path, "wb") do |f|
90+
File.open(tmp_path, "wb") do |f|
9091
while !response.eof?
9192
f.write(response.read(1024 * 1024))
9293
end
9394
end
95+
FileUtils.move(tmp_path, output_path)
9496
rescue => e
9597
warn "An error occurred while writing the file to cache: #{e}"
9698
end

0 commit comments

Comments
 (0)