aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2022-08-03 19:03:50 +0200
committergit <svn-admin@ruby-lang.org>2022-08-06 15:41:46 +0900
commit466a760e1807e629d0ec9f9ebf160d3c3f649d04 (patch)
treedaffaf58f632ccbc5e25dd178c841a3da2d0e975 /lib
parent8dd63b89d97a0ab149288f2e46d814fb60cb3ba5 (diff)
downloadruby-466a760e1807e629d0ec9f9ebf160d3c3f649d04.tar.gz
[rubygems/rubygems] Fix yanked gems being unintentionally update when other gems are unlocked
This is a regression from a change intended to raise errors when user puts a gem under an incorrect source in the Gemfile by mistake. To fix the issue, we revert the change that caused it and implement it in a different way that restores the resolver independency from real specifications. Now it deals only with names and versions and does not try to materialize anything into real specifications before resolving. https://github.com/rubygems/rubygems/commit/d2bf1b86eb
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler/definition.rb22
-rw-r--r--lib/bundler/lazy_specification.rb8
-rw-r--r--lib/bundler/resolver.rb3
-rw-r--r--lib/bundler/spec_set.rb9
4 files changed, 23 insertions, 19 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 536099a20a..38bd01f08f 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -739,11 +739,22 @@ module Bundler
specs[dep].any? {|s| s.satisfies?(dep) && (!dep.source || s.source.include?(dep.source)) }
end
+ @specs_that_changed_sources = []
+
specs.each do |s|
dep = @dependencies.find {|d| s.satisfies?(d) }
# Replace the locked dependency's source with the equivalent source from the Gemfile
- s.source = (dep && dep.source) || sources.get_with_fallback(s.source)
+ s.source = if dep && dep.source
+ gemfile_source = dep.source
+ lockfile_source = s.source
+
+ @specs_that_changed_sources << s if gemfile_source != lockfile_source
+
+ gemfile_source
+ else
+ sources.get_with_fallback(s.source)
+ end
next if @unlock[:sources].include?(s.source.name)
@@ -821,9 +832,18 @@ module Bundler
end
source_requirements[:default_bundler] = source_requirements["bundler"] || sources.default_source
source_requirements["bundler"] = sources.metadata_source # needs to come last to override
+ verify_changed_sources!
source_requirements
end
+ def verify_changed_sources!
+ @specs_that_changed_sources.each do |s|
+ if s.source.specs.search(s.name).empty?
+ raise GemNotFound, "Could not find gem '#{s.name}' in #{s.source}"
+ end
+ end
+ end
+
def requested_groups
values = groups - Bundler.settings[:without] - @optional_groups + Bundler.settings[:with]
values &= Bundler.settings[:only] unless Bundler.settings[:only].empty?
diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb
index 9f75c7bab2..5b40bec5a8 100644
--- a/lib/bundler/lazy_specification.rb
+++ b/lib/bundler/lazy_specification.rb
@@ -93,14 +93,6 @@ module Bundler
__materialize__(candidates)
end
- def materialize_for_resolution
- return self unless Gem::Platform.match_spec?(self)
-
- candidates = source.specs.search(self)
-
- __materialize__(candidates)
- end
-
def __materialize__(candidates)
@specification = begin
search = candidates.reverse.find do |spec|
diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb
index 40bc247b32..ca1bdbda7b 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -28,10 +28,11 @@ module Bundler
def initialize(source_requirements, base, gem_version_promoter, additional_base_requirements, platforms, metadata_requirements)
@source_requirements = source_requirements
@metadata_requirements = metadata_requirements
+ @base = base
@resolver = Molinillo::Resolver.new(self, self)
@search_for = {}
@base_dg = Molinillo::DependencyGraph.new
- @base = base.materialized_for_resolution do |ls|
+ base.each do |ls|
dep = Dependency.new(ls.name, ls.version)
@base_dg.add_vertex(ls.name, DepProxy.get_proxy(dep, ls.platform), true)
end
diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb
index d7239f5c8c..14733269d6 100644
--- a/lib/bundler/spec_set.rb
+++ b/lib/bundler/spec_set.rb
@@ -82,15 +82,6 @@ module Bundler
end
end
- def materialized_for_resolution
- materialized = @specs.map do |s|
- spec = s.materialize_for_resolution
- yield spec if spec
- spec
- end.compact
- SpecSet.new(materialized)
- end
-
def incomplete_ruby_specs?(deps)
self.class.new(self.for(deps, true, [Gem::Platform::RUBY])).incomplete_specs.any?
end