aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2013-10-11 18:56:38 -0500
committerJack Nagel2013-10-11 19:14:52 -0500
commit284a3716eab362be520f30e77c49abc5e0ec9b6f (patch)
tree9164ed7558f3477433692e4987389eb80a1fba95 /Library
parent28a20b70fc6874e6b3329e729bd199816281ed4a (diff)
downloadbrew-284a3716eab362be520f30e77c49abc5e0ec9b6f.tar.bz2
CurlDownloadStrategy: dup mirror list before mutating it
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/download_strategy.rb11
-rw-r--r--Library/Homebrew/test/test_resource.rb3
2 files changed, 6 insertions, 8 deletions
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb
index 5cc70678a..d42e0b090 100644
--- a/Library/Homebrew/download_strategy.rb
+++ b/Library/Homebrew/download_strategy.rb
@@ -67,9 +67,8 @@ class VCSDownloadStrategy < AbstractDownloadStrategy
end
class CurlDownloadStrategy < AbstractDownloadStrategy
- def initialize name, resource
- super
- @mirrors = resource.mirrors
+ def mirrors
+ @mirrors ||= resource.mirrors.dup
end
def tarball_path
@@ -120,9 +119,9 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
puts "Already downloaded: #{tarball_path}"
end
rescue CurlDownloadStrategyError
- raise if @mirrors.empty?
+ raise if mirrors.empty?
puts "Trying a mirror..."
- @url = @mirrors.shift
+ @url = mirrors.shift
retry
else
tarball_path
@@ -170,7 +169,7 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
private
def curl(*args)
- args << '--connect-timeout' << '5' unless @mirrors.empty?
+ args << '--connect-timeout' << '5' unless mirrors.empty?
super
end
diff --git a/Library/Homebrew/test/test_resource.rb b/Library/Homebrew/test/test_resource.rb
index 7916c3e0d..a649ad142 100644
--- a/Library/Homebrew/test/test_resource.rb
+++ b/Library/Homebrew/test/test_resource.rb
@@ -75,8 +75,7 @@ class ResourceTests < Test::Unit::TestCase
assert_empty @resource.mirrors
@resource.mirror('foo')
@resource.mirror('bar')
- assert_equal 'foo', @resource.mirrors.shift
- assert_equal 'bar', @resource.mirrors.shift
+ assert_equal %w{foo bar}, @resource.mirrors
end
def test_checksum_setters