summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel E. Giddins <segiddins@segiddins.me>2015-04-12 00:15:03 -0700
committerSamuel Giddins <segiddins@segiddins.me>2016-01-25 10:45:41 -0600
commitda2adf34ecff1a7198413e2df6b0bc0841ab3553 (patch)
tree30cf7304cb6c5ab39f8342978975db80d3aa2512
parenta2222f14ebda0f2e37573c457a9a6c0095c08278 (diff)
downloadbundler-da2adf34ecff1a7198413e2df6b0bc0841ab3553.tar.gz
[Fetcher] Fix availability logic to avoid multiple calls
-rw-r--r--lib/bundler/fetcher.rb4
-rw-r--r--lib/bundler/fetcher/base.rb4
-rw-r--r--lib/bundler/fetcher/compact_index.rb14
-rw-r--r--lib/bundler/fetcher/dependency.rb4
4 files changed, 17 insertions, 9 deletions
diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb
index 63e76c7e81..9501b2486d 100644
--- a/lib/bundler/fetcher.rb
+++ b/lib/bundler/fetcher.rb
@@ -140,8 +140,8 @@ module Bundler
if remote_uri.scheme == "file" || Bundler::Fetcher.disable_endpoint
@use_api = false
else
- fetchers.reject! {|f| f.api_fetcher? && !f.api_available? }
- @use_api = fetchers.any?(&:api_fetcher?)
+ fetchers.select!(&:available?)
+ @use_api = fetchers.first.api_fetcher?
end
end
diff --git a/lib/bundler/fetcher/base.rb b/lib/bundler/fetcher/base.rb
index 5cc405cc8a..1d1adc73db 100644
--- a/lib/bundler/fetcher/base.rb
+++ b/lib/bundler/fetcher/base.rb
@@ -28,8 +28,8 @@ module Bundler
end
end
- def api_available?
- api_fetcher?
+ def available?
+ true
end
def api_fetcher?
diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb
index 028ad10a5a..6f3e8323ab 100644
--- a/lib/bundler/fetcher/compact_index.rb
+++ b/lib/bundler/fetcher/compact_index.rb
@@ -5,12 +5,16 @@ module Bundler
class Fetcher
class CompactIndex < Base
def specs(_gem_names)
- compact_gem_list.versions.values.flatten(1).map! do |args|
+ @specs ||= compact_gem_list.versions.values.flatten(1).map! do |args|
args = args.fill(nil, args.size..2)
RemoteSpecification.new(*args, self)
end
- rescue HTTPError => e
- raise unless e.message =~ /^Net::HTTPNotFound/
+ rescue NetworkDownError => e
+ raise HTTPError, e.message
+ rescue AuthenticationRequiredError
+ # We got a 401 from the server. Just fail.
+ raise
+ rescue HTTPError
end
def fetch_spec(spec)
@@ -18,6 +22,10 @@ module Bundler
compact_gem_list.spec(*spec)
end
+ def available?
+ specs([])
+ end
+
private
def compact_gem_list
diff --git a/lib/bundler/fetcher/dependency.rb b/lib/bundler/fetcher/dependency.rb
index c5a5342a75..6240f7f894 100644
--- a/lib/bundler/fetcher/dependency.rb
+++ b/lib/bundler/fetcher/dependency.rb
@@ -4,7 +4,7 @@ require "cgi"
module Bundler
class Fetcher
class Dependency < Base
- def api_available?
+ def available?
downloader.fetch(dependency_api_uri)
rescue NetworkDownError => e
raise HTTPError, e.message
@@ -24,7 +24,7 @@ module Bundler
log_specs(query_list)
if query_list.empty?
- return last_spec_list.map do |*args|
+ return last_spec_list.map do |args|
EndpointSpecification.new(*args)
end
end