[rubygems/rubygems] Avoid unnecessary network requests for local gem

https://github.com/rubygems/rubygems/commit/ec5f04f7b1
This commit is contained in:
David Rodríguez 2023-07-10 17:01:17 +02:00 коммит произвёл Hiroshi SHIBATA
Родитель 0b0df03b0d
Коммит 34f541ae36
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: F9CF13417264FAC2
2 изменённых файлов: 37 добавлений и 1 удалений

Просмотреть файл

@ -148,6 +148,8 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set
res << Gem::Resolver::InstalledSpecification.new(self, gemspec)
end unless @ignore_installed
matching_local = []
if consider_local?
matching_local = @local.values.select do |spec, _|
req.match? spec
@ -169,7 +171,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set
end
end
res.concat @remote_set.find_all req if consider_remote?
res.concat @remote_set.find_all req if consider_remote? && matching_local.empty?
res
end

Просмотреть файл

@ -476,6 +476,40 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[b-1], inst.installed_gems.map(&:full_name)
end
def test_install_local_dependency_no_network_for_target_gem
a1, a1_gem = util_gem "a", "1"
_, b1_gem = util_gem "b", "1" do |s|
s.add_dependency "a"
end
util_setup_spec_fetcher(a1)
a1_data = Gem.read_binary(a1_gem)
@fetcher.data["http://gems.example.com/gems/a-1.gem"] = a1_data
# compact index is available
compact_index_response = Net::HTTPResponse.new "1.1", 200, "OK"
compact_index_response.uri = URI("http://gems.example.com")
@fetcher.data["http://gems.example.com/"] = compact_index_response
# but private local gem not present there
@fetcher.data["http://gems.example.com/info/b"] =
proc do
raise "should not happen"
end
FileUtils.mv b1_gem, @tempdir
inst = nil
Dir.chdir @tempdir do
inst = Gem::DependencyInstaller.new
inst.install "b-1.gem"
end
assert_equal %w[a-1 b-1], inst.installed_gems.map(&:full_name)
end
def test_install_local_subdir
util_setup_gems