Skip to content

Commit 27d2923

Browse files
hsbtclaude
andcommitted
Make Gem::CompactIndexClient loadable from a Bundler-shipped copy
The client's subfiles reached sibling RubyGems files with cross-tree require_relative, which breaks when the copy shipped inside the Bundler gem is loaded on an older RubyGems: the relative targets are not part of that copy. Require them by feature name instead so they resolve against the host RubyGems. vendored_net_http is newer than the oldest supported host, so require it defensively; in the Bundler context Gem::Net is always defined by Bundler's own shim before this file loads. Also guard the entry point against double loading when the host copy and the shipped copy are required from different paths. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent d37e5fa commit 27d2923

5 files changed

Lines changed: 16 additions & 4 deletions

File tree

lib/rubygems/compact_index_client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# frozen_string_literal: true
22

3+
# Skip reloading when an identical copy (e.g. the one shipped inside the Bundler
4+
# gem) was already required from a different path, to avoid redefinition warnings.
5+
return if defined?(Gem::CompactIndexClient::INFO_REQS)
6+
37
##
48
# The CompactIndexClient fetches and parses the compact index files
59
# (names, versions and info/[gem]) served by a gem server, keeping a

lib/rubygems/compact_index_client/cache_file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "digest"
44
require "fileutils"
5-
require_relative "../package"
5+
require "rubygems/package"
66

77
class Gem::CompactIndexClient
88
# write cache files in a way that is robust to concurrent modifications

lib/rubygems/compact_index_client/http_fetcher.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require_relative "../remote_fetcher"
3+
require "rubygems/remote_fetcher"
44

55
class Gem::CompactIndexClient
66
# Fetches compact index files relative to +base_uri+ using

lib/rubygems/compact_index_client/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require_relative "../resolver/api_set/gem_parser"
3+
require "rubygems/resolver/api_set/gem_parser"
44

55
class Gem::CompactIndexClient
66
class Parser

lib/rubygems/compact_index_client/updater.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
# frozen_string_literal: true
22

33
require "zlib"
4-
require_relative "../vendored_net_http"
4+
5+
# On RubyGems versions too old to vendor Gem::Net (when this file is loaded
6+
# from the copy shipped inside the Bundler gem), Bundler's own
7+
# vendored_net_http shim has already defined it before this file is loaded.
8+
begin
9+
require "rubygems/vendored_net_http" unless defined?(Gem::Net::HTTP)
10+
rescue LoadError
11+
require "net/http"
12+
end
513

614
class Gem::CompactIndexClient
715
# Updates the cached files on disk, keeping them in sync with the server

0 commit comments

Comments
 (0)