From 7122f472265581c397e1b10216c9bcf7e2511faf 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 e890759096ca..b14257107873 100644 --- a/bundler/lib/bundler/plugin.rb +++ b/bundler/lib/bundler/plugin.rb @@ -240,7 +240,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 # Post installation processing and registering with index diff --git a/bundler/spec/plugins/install_spec.rb b/bundler/spec/plugins/install_spec.rb index 51a0fa09c2ed..5f8f89b56a6a 100644 --- a/bundler/spec/plugins/install_spec.rb +++ b/bundler/spec/plugins/install_spec.rb @@ -493,6 +493,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