From c014b7f973d1aad21c1871df1d5a696c8baf7166 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Fri, 15 Sep 2023 14:15:28 -0600 Subject: [PATCH] Consider a dangling reference in the plugin index as not installed --- bundler/lib/bundler/plugin.rb | 4 +++- bundler/spec/plugins/install_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/bundler/lib/bundler/plugin.rb b/bundler/lib/bundler/plugin.rb index 41819433ac1f..07def00af2d7 100644 --- a/bundler/lib/bundler/plugin.rb +++ b/bundler/lib/bundler/plugin.rb @@ -241,7 +241,9 @@ def hook(event, *args, &arg_blk) # @return [String, nil] installed path def installed?(plugin) - index.installed?(plugin) + (path = index.installed?(plugin)) && + index.plugin_path(plugin).join(PLUGIN_FILE_NAME).file? && + path end # @return [true, false] whether the plugin is loaded diff --git a/bundler/spec/plugins/install_spec.rb b/bundler/spec/plugins/install_spec.rb index 223a02a4bf2f..0ce9700b9ac8 100644 --- a/bundler/spec/plugins/install_spec.rb +++ b/bundler/spec/plugins/install_spec.rb @@ -505,6 +505,27 @@ def exec(command, args) bundle "exec rake -T", :raise_on_error => false expect(err).not_to include("Plugin foo (>= 0) is not installed") end + + it "fails bundle commands gracefully when a plugin index reference is left dangling" do + build_lib "ga-plugin" do |s| + s.write "plugins.rb" + end + + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + plugin 'ga-plugin', :path => "#{lib_path("ga-plugin-1.0")}" + G + + expect(out).to include("Installed plugin ga-plugin") + plugin_should_be_installed("ga-plugin") + + FileUtils.rm_rf(lib_path("ga-plugin-1.0")) + + plugin_should_not_be_installed("ga-plugin") + + bundle "check", :raise_on_error => false + expect(err).to include("Plugin ga-plugin (>= 0) is not installed") + end end context "inline gemfiles" do