summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2022-12-15 12:14:40 +0100
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2022-12-20 13:15:02 +0900
commit3fd33590f624ff74d91c1d505f85653902764384 (patch)
treef978c5711f41681ff49d86b79e2c9089ab4309f5 /lib
parent16b36a5b0c71afdcd125c530ee6fb809d4306822 (diff)
[rubygems/rubygems] Fix crash when lockfile is missing dependencies
We have a check for a corrupt lockfile right before installing. However, the check accounted for locked specs not satisfying locked dependencies, but not for locked specs missing for some locked dependencies. Instead of fixing this check, I decided to remove it in favor of automatically detecting the situation and re-resolve to automatically fix the lockfile rather than printing a warning but leave the problem there. https://github.com/rubygems/rubygems/commit/4a7a584252
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6966
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler/definition.rb13
-rw-r--r--lib/bundler/installer/parallel_installer.rb31
2 files changed, 12 insertions, 32 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 08f6c37de9..8659c64849 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -144,6 +144,8 @@ module Bundler
@dependency_changes = converge_dependencies
@local_changes = converge_locals
+
+ @incomplete_lockfile = check_missing_lockfile_specs
end
def gem_version_promoter
@@ -458,7 +460,7 @@ module Bundler
private :sources
def nothing_changed?
- !@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes
+ !@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes && !@incomplete_lockfile
end
def unlocking?
@@ -603,6 +605,7 @@ module Bundler
[@new_platform, "you added a new platform to your gemfile"],
[@path_changes, "the gemspecs for path gems changed"],
[@local_changes, "the gemspecs for git local gems changed"],
+ [@incomplete_lockfile, "your lock file is missing some gems"],
].select(&:first).map(&:last).join(", ")
end
@@ -657,6 +660,14 @@ module Bundler
!sources_with_changes.each {|source| @unlock[:sources] << source.name }.empty?
end
+ def check_missing_lockfile_specs
+ all_locked_specs = @locked_specs.map(&:name) << "bundler"
+
+ @locked_specs.any? do |s|
+ s.dependencies.any? {|dep| !all_locked_specs.include?(dep.name) }
+ end
+ end
+
def converge_paths
sources.path_sources.any? do |source|
specs_changed?(source)
diff --git a/lib/bundler/installer/parallel_installer.rb b/lib/bundler/installer/parallel_installer.rb
index 5b6680e5e1..dce7133769 100644
--- a/lib/bundler/installer/parallel_installer.rb
+++ b/lib/bundler/installer/parallel_installer.rb
@@ -53,10 +53,6 @@ module Bundler
@dependencies ||= all_dependencies.reject {|dep| ignorable_dependency? dep }
end
- def missing_lockfile_dependencies(all_spec_names)
- dependencies.reject {|dep| all_spec_names.include? dep.name }
- end
-
# Represents all dependencies
def all_dependencies
@spec.dependencies
@@ -84,8 +80,6 @@ module Bundler
end
def call
- check_for_corrupt_lockfile
-
if @rake
do_install(@rake, 0)
Gem::Specification.reset
@@ -128,31 +122,6 @@ module Bundler
Bundler.ui.warn(warning.join("\n"))
end
- def check_for_corrupt_lockfile
- missing_dependencies = @specs.map do |s|
- [
- s,
- s.missing_lockfile_dependencies(@specs.map(&:name)),
- ]
- end.reject {|a| a.last.empty? }
- return if missing_dependencies.empty?
-
- warning = []
- warning << "Your lockfile was created by an old Bundler that left some things out."
- if @size != 1
- warning << "Because of the missing DEPENDENCIES, we can only install gems one at a time, instead of installing #{@size} at a time."
- @size = 1
- end
- warning << "You can fix this by adding the missing gems to your Gemfile, running bundle install, and then removing the gems from your Gemfile."
- warning << "The missing gems are:"
-
- missing_dependencies.each do |spec, missing|
- warning << "* #{missing.map(&:name).join(", ")} depended upon by #{spec.name}"
- end
-
- Bundler.ui.warn(warning.join("\n"))
- end
-
private
def failed_specs