From 7f7a7f13ededda5c91d84c3493dc6ef3cec53d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 26 Oct 2023 18:44:20 +0200 Subject: [PATCH] [rubygems/rubygems] Don't show bug report template when GEM_HOME has no writable bit Instead, don't check that at all and proceed. If something fails to be written inside GEM_HOME, we'll eventually fail with a proper permissions error. In addition to that, the writable bit in GEM_HOME is not even reliable, because only the immediate parent is actually checked when writing. For example, ``` $ mkdir -p foo/bar $ chmod -w foo $ touch foo/bar/baz # writes without issue ``` https://github.com/rubygems/rubygems/commit/4bced7ac73 --- lib/bundler/rubygems_gem_installer.rb | 8 ++++++ spec/bundler/commands/install_spec.rb | 35 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/lib/bundler/rubygems_gem_installer.rb b/lib/bundler/rubygems_gem_installer.rb index 4d0e1c3fcc..8463b24bfa 100644 --- a/lib/bundler/rubygems_gem_installer.rb +++ b/lib/bundler/rubygems_gem_installer.rb @@ -45,6 +45,14 @@ module Bundler spec end + def pre_install_checks + super + rescue Gem::FilePermissionError + # Ignore permission checks in RubyGems. Instead, go on, and try to write + # for real. We properly handle permission errors when they happen. + nil + end + def generate_plugins return unless Gem::Installer.instance_methods(false).include?(:generate_plugins) diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb index aa86d5e316..e333e04108 100644 --- a/spec/bundler/commands/install_spec.rb +++ b/spec/bundler/commands/install_spec.rb @@ -792,6 +792,41 @@ RSpec.describe "bundle install with gem sources" do end end + describe "when gem home does not have the writable bit set, yet it's still writable", :permissions do + let(:gem_home) { bundled_app("vendor/#{Bundler.ruby_scope}") } + + before do + build_repo4 do + build_gem "foo", "1.0.0" do |s| + s.write "CHANGELOG.md", "foo" + end + end + + gemfile <<-G + source "#{file_uri_for(gem_repo4)}" + gem 'foo' + G + end + + it "should display a proper message to explain the problem" do + bundle "config set --local path vendor" + bundle :install + expect(out).to include("Bundle complete!") + expect(err).to be_empty + + FileUtils.chmod("-w", gem_home) + + begin + bundle "install --redownload" + ensure + FileUtils.chmod("+w", gem_home) + end + + expect(out).to include("Bundle complete!") + expect(err).to be_empty + end + end + describe "when bundle cache path does not have write access", :permissions do let(:cache_path) { bundled_app("vendor/#{Bundler.ruby_scope}/cache") }