From 612616925b3d5247748b8df98a13a70f74f8b4c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Fri, 8 Dec 2023 16:38:51 +0100 Subject: [PATCH] [rubygems/rubygems] Allow "default_user_install" to be overridden. For Ruby re-distributors, automatic user-install might be the right default. Therefore printing warning about installing into user directory is not always desirable. Let the default_user_install method be customizable. https://github.com/rubygems/rubygems/commit/2320dba544 --- lib/rubygems/defaults.rb | 12 ++++++++++++ lib/rubygems/installer.rb | 5 +---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb index 1fe6f36f38..00dc5707c3 100644 --- a/lib/rubygems/defaults.rb +++ b/lib/rubygems/defaults.rb @@ -235,6 +235,18 @@ module Gem default_cert_path end + ## + # Enables automatic installation into user directory + + def self.default_user_install # :nodoc: + if !ENV.key?("GEM_HOME") && (File.exist?(Gem.dir) && !File.writable?(Gem.dir)) + Gem.ui.say "Defaulting to user installation because default installation directory (#{Gem.dir}) is not writable." + return true + end + + false + end + ## # Install extensions into lib as well as into the extension directory. diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index cd1031dc2e..0396e94632 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -684,10 +684,7 @@ class Gem::Installer # * `true`: `--user-install` # * `false`: `--no-user-install` and # * `nil`: option was not specified - if options[:user_install] - @gem_home = Gem.user_dir - elsif options[:user_install].nil? && !ENV.key?("GEM_HOME") && (File.exist?(Gem.dir) && !File.writable?(Gem.dir)) - say "Defaulting to user installation because default installation directory (#{Gem.dir}) is not writable." + if options[:user_install] || (options[:user_install].nil? && Gem.default_user_install) @gem_home = Gem.user_dir end end