aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Sigurdhsson2012-08-04 18:50:17 +0200
committerMike McQuaid2013-02-02 14:05:40 -0800
commitaf3bfab9db74951783aa3d90ee36d5aa9547b15a (patch)
tree59b0333a75e3da70ff096e3f9c4a34966024bf03
parentc0822f84001081071845a43371ef9be866b9cc26 (diff)
downloadbrew-af3bfab9db74951783aa3d90ee36d5aa9547b15a.tar.bz2
Make `CurlDownloadStrategy` resume aborted downloads
* `CurlDownloadStrategy#_fetch` (and the same methods in its subclasses) now fetches the file to a temporary path, and `CurlDownloadStrategy#fetch` moves it to the correct location. * `Homebrew#cleanup` cleans the temporary files `CurlDownloadStrategy` creates if they're left in the cache. Closes Homebrew/homebrew#13953. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
-rw-r--r--Library/Homebrew/cmd/cleanup.rb4
-rw-r--r--Library/Homebrew/download_strategy.rb17
2 files changed, 15 insertions, 6 deletions
diff --git a/Library/Homebrew/cmd/cleanup.rb b/Library/Homebrew/cmd/cleanup.rb
index 6b4e6b400..490065606 100644
--- a/Library/Homebrew/cmd/cleanup.rb
+++ b/Library/Homebrew/cmd/cleanup.rb
@@ -77,6 +77,10 @@ module Homebrew extend self
end
end
end
+ if pn.basename.to_s.split('.').last == 'incomplete'
+ puts "Removing #{pn}..."
+ rm pn unless ARGV.dry_run?
+ end
end
end
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb
index 62e210ded..d09cf9038 100644
--- a/Library/Homebrew/download_strategy.rb
+++ b/Library/Homebrew/download_strategy.rb
@@ -44,15 +44,20 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
else
@tarball_path=HOMEBREW_CACHE+File.basename(@url)
end
+ @temporary_path=Pathname.new(@tarball_path.to_s + ".incomplete")
end
def cached_location
@tarball_path
end
+ def downloaded_size
+ @temporary_path.size? or 0
+ end
+
# Private method, can be overridden if needed.
def _fetch
- curl @url, '-o', @tarball_path
+ curl @url, '-C', downloaded_size, '-o', @temporary_path
end
def fetch
@@ -66,13 +71,13 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
begin
_fetch
rescue Exception => e
- ignore_interrupts { @tarball_path.unlink if @tarball_path.exist? }
if e.kind_of? ErrorDuringExecution
raise CurlDownloadStrategyError, "Download failed: #{@url}"
else
raise
end
end
+ ignore_interrupts { @temporary_path.rename(@tarball_path) }
else
puts "Already downloaded: #{@tarball_path}"
end
@@ -154,8 +159,8 @@ class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy
mirrors = MultiJson.decode(open("#{@url}&asjson=1").read)
url = mirrors.fetch('preferred') + mirrors.fetch('path_info')
- ohai "Best Mirror #{url}"
- curl url, '-o', @tarball_path
+ ohai "Best Mirror #{mirror_url}"
+ curl url, '-C', downloaded_size, '-o', @temporary_path
rescue IndexError
raise "Couldn't determine mirror. Try again later."
end
@@ -166,7 +171,7 @@ end
class CurlPostDownloadStrategy < CurlDownloadStrategy
def _fetch
base_url,data = @url.split('?')
- curl base_url, '-d', data, '-o', @tarball_path
+ curl base_url, '-d', data, '-C', downloaded_size, '-o', @temporary_path
end
end
@@ -191,7 +196,7 @@ end
# Try not to need this, as we probably won't accept the formula.
class CurlUnsafeDownloadStrategy < CurlDownloadStrategy
def _fetch
- curl @url, '--insecure', '-o', @tarball_path
+ curl @url, '--insecure', '-C', downloaded_size, '-o', @temporary_path
end
end