ruby-changes:69430
From: David <ko1@a...>
Date: Mon, 25 Oct 2021 20:55:10 +0900 (JST)
Subject: [ruby-changes:69430] 00412be204 (master): [rubygems/rubygems] Show a proper error if gem path is not writable
https://git.ruby-lang.org/ruby.git/commit/?id=00412be204 From 00412be20469407cd6da813eab6bfa5b63cd945f Mon Sep 17 00:00:00 2001 From: David Rodriguez <deivid.rodriguez@r...> Date: Thu, 14 Oct 2021 12:03:51 +0200 Subject: [rubygems/rubygems] Show a proper error if gem path is not writable Instead of showing the bug report place with an error at a randome place. https://github.com/rubygems/rubygems/commit/241854ce73 --- lib/bundler/errors.rb | 16 ++++++++++++++-- lib/bundler/rubygems_gem_installer.rb | 4 +++- spec/bundler/commands/install_spec.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/lib/bundler/errors.rb b/lib/bundler/errors.rb index 565aaeeb9d9..59898cd2526 100644 --- a/lib/bundler/errors.rb +++ b/lib/bundler/errors.rb @@ -75,10 +75,22 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/errors.rb#L75 end end + def permission_type + case @permission_type + when :create + "executable permissions for all parent directories and write permissions for `#{parent_folder}`" + else + "#{@permission_type} permissions for that path" + end + end + + def parent_folder + File.dirname(@path) + end + def message "There was an error while trying to #{action} `#{@path}`. " \ - "It is likely that you need to grant #{@permission_type} permissions " \ - "for that path." + "It is likely that you need to grant #{permission_type}." end status_code(23) diff --git a/lib/bundler/rubygems_gem_installer.rb b/lib/bundler/rubygems_gem_installer.rb index fa46451887f..39c9031c4a8 100644 --- a/lib/bundler/rubygems_gem_installer.rb +++ b/lib/bundler/rubygems_gem_installer.rb @@ -19,7 +19,9 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/rubygems_gem_installer.rb#L19 FileUtils.rm_rf gem_dir FileUtils.rm_rf spec.extension_dir - FileUtils.mkdir_p gem_dir, :mode => 0o755 + SharedHelpers.filesystem_access(gem_dir, :create) do + FileUtils.mkdir_p gem_dir, :mode => 0o755 + end extract_files diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb index 97257f689cc..a477369e4cb 100644 --- a/spec/bundler/commands/install_spec.rb +++ b/spec/bundler/commands/install_spec.rb @@ -678,6 +678,36 @@ RSpec.describe "bundle install with gem sources" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/commands/install_spec.rb#L678 end end + describe "when bundle gems path does not have write access", :permissions do + let(:gems_path) { bundled_app("vendor/#{Bundler.ruby_scope}/gems") } + + before do + FileUtils.mkdir_p(gems_path) + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + G + end + + it "should display a proper message to explain the problem" do + FileUtils.chmod("-x", gems_path) + bundle "config set --local path vendor" + + begin + bundle :install, :raise_on_error => false + ensure + FileUtils.chmod("+x", gems_path) + end + + expect(err).not_to include("ERROR REPORT TEMPLATE") + + expect(err).to include( + "There was an error while trying to create `#{gems_path.join("rack-1.0.0")}`. " \ + "It is likely that you need to grant executable permissions for all parent directories and write permissions for `#{gems_path}`." + ) + end + end + describe "when bundle cache path does not have write access", :permissions do let(:cache_path) { bundled_app("vendor/#{Bundler.ruby_scope}/cache") } -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/