Skip to content

Commit 92e586b

Browse files
hsbtclaude
andcommitted
Use Gem::CompactIndexClient in Bundler
Switch Bundler's compact index fetcher and the outdated-version check from Bundler::CompactIndexClient to the RubyGems client, wiring Bundler's filesystem access helper into the new hook. Bundler keeps its orchestration layer (parallel workers, FIPS detection, mirrors) and only swaps the client underneath. The RubyGems updater raises Gem::CompactIndexClient::Error for an invalid gzip response where Bundler's raised HTTPError, so rescue it in compact_index_request to preserve the fallback to the dependency API. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 188c765 commit 92e586b

4 files changed

Lines changed: 23 additions & 11 deletions

File tree

lib/bundler.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ module Bundler
4141
autoload :Checksum, File.expand_path("bundler/checksum", __dir__)
4242
autoload :CLI, File.expand_path("bundler/cli", __dir__)
4343
autoload :CIDetector, File.expand_path("bundler/ci_detector", __dir__)
44-
autoload :CompactIndexClient, File.expand_path("bundler/compact_index_client", __dir__)
4544
autoload :Definition, File.expand_path("bundler/definition", __dir__)
4645
autoload :Dependency, File.expand_path("bundler/dependency", __dir__)
4746
autoload :Deprecate, File.expand_path("bundler/deprecate", __dir__)

lib/bundler/cli.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,13 @@ def warn_on_outdated_bundler
785785
return unless SharedHelpers.md5_available?
786786

787787
require_relative "vendored_uri"
788+
require "rubygems/compact_index_client"
789+
if Gem::CompactIndexClient.respond_to?(:filesystem_access=)
790+
Gem::CompactIndexClient.filesystem_access = SharedHelpers.method(:filesystem_access)
791+
end
788792
remote = Source::Rubygems::Remote.new(Gem::URI("https://rubygems.org"))
789793
cache_path = Bundler.user_cache.join("compact_index", remote.cache_slug)
790-
latest = Bundler::CompactIndexClient.new(cache_path).latest_version("bundler")
794+
latest = Gem::CompactIndexClient.new(cache_path).latest_version("bundler")
791795
return unless latest
792796

793797
current = Gem::Version.new(VERSION)

lib/bundler/fetcher/compact_index.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
require_relative "base"
44
require_relative "../worker"
5+
require "rubygems/compact_index_client"
6+
7+
# Route the client's filesystem access through Bundler's helper so
8+
# permission problems raise friendly Bundler errors. The respond_to?
9+
# check covers a host RubyGems that already loaded its own copy of the
10+
# client from before the hook existed.
11+
if Gem::CompactIndexClient.respond_to?(:filesystem_access=)
12+
Gem::CompactIndexClient.filesystem_access = Bundler::SharedHelpers.method(:filesystem_access)
13+
end
514

615
module Bundler
716
class Fetcher
@@ -11,12 +20,12 @@ def self.compact_index_request(method_name)
1120
undef_method(method_name)
1221
define_method(method_name) do |*args, &blk|
1322
method.bind_call(self, *args, &blk)
14-
rescue NetworkDownError, CompactIndexClient::Updater::MismatchedChecksumError => e
23+
rescue NetworkDownError, Gem::CompactIndexClient::Updater::MismatchedChecksumError => e
1524
raise HTTPError, e.message
1625
rescue AuthenticationRequiredError, BadAuthenticationError
1726
# Fail since we got a 401 from the server.
1827
raise
19-
rescue HTTPError => e
28+
rescue HTTPError, Gem::CompactIndexClient::Error => e
2029
Bundler.ui.trace(e)
2130
nil
2231
end
@@ -35,7 +44,7 @@ def specs_for_names(gem_names)
3544
until remaining_gems.empty?
3645
log_specs { "Looking up gems #{remaining_gems.inspect}" }
3746
deps = fetch_gem_infos(remaining_gems).flatten(1)
38-
next_gems = deps.flat_map {|d| d[CompactIndexClient::INFO_DEPS].flat_map(&:first) }.uniq
47+
next_gems = deps.flat_map {|d| d[Gem::CompactIndexClient::INFO_DEPS].flat_map(&:first) }.uniq
3948
deps.each {|dep| gem_info << dep }
4049
complete_gems.concat(deps.map(&:first)).uniq!
4150
remaining_gems = next_gems - complete_gems
@@ -53,7 +62,7 @@ def available?
5362
end
5463
# Read info file checksums out of /versions, so we can know if gems are up to date
5564
compact_index_client.available?
56-
rescue CompactIndexClient::Updater::MismatchedChecksumError => e
65+
rescue Gem::CompactIndexClient::Updater::MismatchedChecksumError => e
5766
Bundler.ui.debug(e.message)
5867
nil
5968
end
@@ -75,7 +84,7 @@ def release_resolution_memory!
7584
def compact_index_client
7685
@compact_index_client ||=
7786
SharedHelpers.filesystem_access(cache_path) do
78-
CompactIndexClient.new(cache_path, client_fetcher)
87+
Gem::CompactIndexClient.new(cache_path, client_fetcher)
7988
end
8089
end
8190

spec/install/gems/compact_index_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323

2424
bundle :install, artifice: "compact_index", env: { "DEBUG_COMPACT_INDEX" => "true" }
2525
expect(out).to include("Fetching gem metadata from #{source_uri}")
26-
expect(err).to include("[Bundler::CompactIndexClient] available?")
27-
expect(err).to include("[Bundler::CompactIndexClient] fetching versions")
28-
expect(err).to include("[Bundler::CompactIndexClient] info(myrack)")
29-
expect(err).to include("[Bundler::CompactIndexClient] fetching info/myrack")
26+
expect(err).to include("[Gem::CompactIndexClient] available?")
27+
expect(err).to include("[Gem::CompactIndexClient] fetching versions")
28+
expect(err).to include("[Gem::CompactIndexClient] info(myrack)")
29+
expect(err).to include("[Gem::CompactIndexClient] fetching info/myrack")
3030
expect(the_bundle).to include_gems "myrack 1.0.0"
3131
end
3232

0 commit comments

Comments
 (0)