diff --git a/bundler/lib/bundler/rubygems_ext.rb b/bundler/lib/bundler/rubygems_ext.rb index e0582beba286..a7539f4adb7d 100644 --- a/bundler/lib/bundler/rubygems_ext.rb +++ b/bundler/lib/bundler/rubygems_ext.rb @@ -146,6 +146,18 @@ def dependencies_to_gemfile(dependencies, group = nil) end end + module BetterPermissionError + def data + Bundler::SharedHelpers.filesystem_access(loaded_from, :read) do + super + end + end + end + + class StubSpecification + prepend BetterPermissionError + end + class Dependency include ::Bundler::ForcePlatform diff --git a/bundler/spec/commands/install_spec.rb b/bundler/spec/commands/install_spec.rb index f0c9aaea8ede..1e57414377e7 100644 --- a/bundler/spec/commands/install_spec.rb +++ b/bundler/spec/commands/install_spec.rb @@ -1024,6 +1024,29 @@ def run end end + describe "when gemspecs are unreadable", :permissions do + let(:gemspec_path) { vendored_gems("specifications/rack-1.0.0.gemspec") } + + before do + gemfile <<~G + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + G + bundle "config path vendor/bundle" + bundle :install + expect(out).to include("Bundle complete!") + expect(err).to be_empty + + FileUtils.chmod("-r", gemspec_path) + end + + it "shows a good error" do + bundle :install, raise_on_error: false + expect(err).to include(gemspec_path.to_s) + expect(err).to include("grant read permissions") + end + end + context "after installing with --standalone" do before do install_gemfile <<-G