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
commit6f8c02ebe27af056902e707744b4350e27d42e78 (patch)
tree2d925dbfe1cfbf149eb6253bff845e93873d0e38 /Library
parenta56c3296cca539d2d90f0d0ac7509f4a67872662 (diff)
downloadhomebrew-6f8c02ebe27af056902e707744b4350e27d42e78.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