aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2015-01-04 15:33:25 -0500
committerJack Nagel2015-01-04 15:33:25 -0500
commit799d2571e383149210e2d1d8ac333390b1481386 (patch)
treee0fd4b7a27cba468ba537319a4dec72f758cd40a /Library
parent683e209b10e897199595696f9c86a9568fd7bc6c (diff)
downloadbrew-799d2571e383149210e2d1d8ac333390b1481386.tar.bz2
Extract non-curl parts of CurlDownloadStrategy into a base class
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/download_strategy.rb130
1 files changed, 67 insertions, 63 deletions
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb
index dddc2cb65..553e99129 100644
--- a/Library/Homebrew/download_strategy.rb
+++ b/Library/Homebrew/download_strategy.rb
@@ -159,45 +159,7 @@ class VCSDownloadStrategy < AbstractDownloadStrategy
end
end
-class CurlDownloadStrategy < AbstractDownloadStrategy
- attr_reader :mirrors, :tarball_path, :temporary_path
-
- def initialize(name, resource)
- super
- @mirrors = resource.mirrors.dup
- @tarball_path = HOMEBREW_CACHE.join("#{name}-#{version}#{ext}")
- @temporary_path = Pathname.new("#{cached_location}.incomplete")
- end
-
- def fetch
- ohai "Downloading #{@url}"
- unless cached_location.exist?
- had_incomplete_download = temporary_path.exist?
- begin
- _fetch
- rescue ErrorDuringExecution
- # 33 == range not supported
- # try wiping the incomplete download and retrying once
- if $?.exitstatus == 33 && had_incomplete_download
- ohai "Trying a full download"
- temporary_path.unlink
- had_incomplete_download = false
- retry
- else
- raise CurlDownloadStrategyError.new(@url)
- end
- end
- ignore_interrupts { temporary_path.rename(cached_location) }
- else
- puts "Already downloaded: #{cached_location}"
- end
- rescue CurlDownloadStrategyError
- raise if mirrors.empty?
- puts "Trying a mirror..."
- @url = mirrors.shift
- retry
- end
-
+class AbstractFileDownloadStrategy < AbstractDownloadStrategy
def stage
case cached_location.compression_type
when :zip
@@ -228,32 +190,8 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
end
end
- def cached_location
- tarball_path
- end
-
- def clear_cache
- super
- rm_rf(temporary_path)
- end
-
private
- # Private method, can be overridden if needed.
- def _fetch
- curl @url, "-C", downloaded_size, "-o", temporary_path
- end
-
- def downloaded_size
- temporary_path.size? || 0
- end
-
- def curl(*args)
- args << '--connect-timeout' << '5' unless mirrors.empty?
- args << "--user" << meta.fetch(:user) if meta.key?(:user)
- super
- end
-
def chdir
entries = Dir['*']
case entries.length
@@ -291,6 +229,72 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
end
end
+class CurlDownloadStrategy < AbstractFileDownloadStrategy
+ attr_reader :mirrors, :tarball_path, :temporary_path
+
+ def initialize(name, resource)
+ super
+ @mirrors = resource.mirrors.dup
+ @tarball_path = HOMEBREW_CACHE.join("#{name}-#{version}#{ext}")
+ @temporary_path = Pathname.new("#{cached_location}.incomplete")
+ end
+
+ def fetch
+ ohai "Downloading #{@url}"
+ unless cached_location.exist?
+ had_incomplete_download = temporary_path.exist?
+ begin
+ _fetch
+ rescue ErrorDuringExecution
+ # 33 == range not supported
+ # try wiping the incomplete download and retrying once
+ if $?.exitstatus == 33 && had_incomplete_download
+ ohai "Trying a full download"
+ temporary_path.unlink
+ had_incomplete_download = false
+ retry
+ else
+ raise CurlDownloadStrategyError.new(@url)
+ end
+ end
+ ignore_interrupts { temporary_path.rename(cached_location) }
+ else
+ puts "Already downloaded: #{cached_location}"
+ end
+ rescue CurlDownloadStrategyError
+ raise if mirrors.empty?
+ puts "Trying a mirror..."
+ @url = mirrors.shift
+ retry
+ end
+
+ def cached_location
+ tarball_path
+ end
+
+ def clear_cache
+ super
+ rm_rf(temporary_path)
+ end
+
+ private
+
+ # Private method, can be overridden if needed.
+ def _fetch
+ curl @url, "-C", downloaded_size, "-o", temporary_path
+ end
+
+ def downloaded_size
+ temporary_path.size? || 0
+ end
+
+ def curl(*args)
+ args << '--connect-timeout' << '5' unless mirrors.empty?
+ args << "--user" << meta.fetch(:user) if meta.key?(:user)
+ super
+ end
+end
+
# Detect and download from Apache Mirror
class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy
def apache_mirrors