diff options
author | David RodrÃguez <[email protected]> | 2023-12-01 12:53:43 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2023-12-07 13:56:22 +0900 |
commit | 33bd95625756562f4865fbc6ad5c39e0cfbc26d6 (patch) | |
tree | ab0a3ade84487022e7fd92b09e61fb9139d2f591 /lib | |
parent | 0f3f907e17bba1b94c5e202cb57988af8c6c91fc (diff) |
[rubygems/rubygems] Better approach to falling back to user installation when GEM_HOME not writable
https://github.com/rubygems/rubygems/commit/f67bced16b
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rubygems/command.rb | 14 | ||||
-rw-r--r-- | lib/rubygems/installer.rb | 9 | ||||
-rw-r--r-- | lib/rubygems/path_support.rb | 21 |
3 files changed, 9 insertions, 35 deletions
diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb index c3a448bc21..1320d9f49f 100644 --- a/lib/rubygems/command.rb +++ b/lib/rubygems/command.rb @@ -23,15 +23,6 @@ class Gem::Command Gem::OptionParser.accept Symbol, &:to_sym ## - # Names of commands that should print "Defaulting to user installation" - # warning. - - COMMANDS_WITH_AUTO_INSTALL_DIR_WARNING = [ - "install", - "update", - ].freeze - - ## # The name of the command. attr_reader :command @@ -332,11 +323,6 @@ class Gem::Command elsif @when_invoked @when_invoked.call options else - if COMMANDS_WITH_AUTO_INSTALL_DIR_WARNING.include?(@command) && \ - Gem.paths.auto_user_install && !options[:install_dir] && !options[:user_install] - self.ui.say "Defaulting to user installation because default installation directory (#{Gem.default_dir}) is not writable." - end - execute end ensure diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index aca42a03b0..18170230df 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -676,7 +676,14 @@ class Gem::Installer @build_args = options[:build_args] @gem_home = @install_dir - @gem_home ||= options[:user_install] ? Gem.user_dir : Gem.dir + @gem_home ||= if options[:user_install] + Gem.user_dir + elsif !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." + Gem.user_dir + else + Gem.dir + end # If the user has asked for the gem to be installed in a directory that is # the system gem directory, then use the system bin directory, else create diff --git a/lib/rubygems/path_support.rb b/lib/rubygems/path_support.rb index 5d34120072..13091e29ba 100644 --- a/lib/rubygems/path_support.rb +++ b/lib/rubygems/path_support.rb @@ -19,31 +19,12 @@ class Gem::PathSupport attr_reader :spec_cache_dir # :nodoc: ## - # Whether `Gem.paths.home` defaulted to a user install or not. - attr_reader :auto_user_install - - ## # # Constructor. Takes a single argument which is to be treated like a # hashtable, or defaults to ENV, the system environment. # def initialize(env) - # Current implementation of @home, which is exposed as `Gem.paths.home`: - # 1. If `env["GEM_HOME"]` is defined in the environment: `env["GEM_HOME"]`. - # 2. If `Gem.default_dir` is writable: `Gem.default_dir`. - # 3. Otherwise: `Gem.user_dir`. - - if env.key?("GEM_HOME") - @home = normalize_home_dir(env["GEM_HOME"]) - elsif File.writable?(Gem.default_dir) - @home = normalize_home_dir(Gem.default_dir) - else - # If `GEM_HOME` is not set AND we can't use `Gem.default_dir`, - # default to a user installation and set `@auto_user_install`. - @auto_user_install = true - @home = normalize_home_dir(Gem.user_dir) - end - + @home = normalize_home_dir(env["GEM_HOME"] || Gem.default_dir) @path = split_gem_path env["GEM_PATH"], @home @spec_cache_dir = env["GEM_SPEC_CACHE"] || Gem.default_spec_cache_dir |