From b37288c047681e02615b5b484fb265b394ddc612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Fri, 8 Dec 2023 14:03:07 +0100 Subject: [PATCH] [rubygems/rubygems] Make the "auto-user-install" logic easier to follow https://github.com/rubygems/rubygems/commit/4b4d9c0106 --- lib/rubygems/installer.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 0c3c28e9af..b4375c3f1c 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -675,16 +675,20 @@ class Gem::Installer @build_args = options[:build_args] - @gem_home = @install_dir || Gem.dir + @gem_home = @install_dir - # `--build-root` overrides `--user-install` and auto-user-install - if @build_root.nil? && @install_dir.nil? - if options[:user_install] - @gem_home = 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_home = Gem.user_dir + unless @gem_home + # `--build-root` overrides `--user-install` and auto-user-install + if @build_root.nil? + if options[:user_install] + @gem_home = 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_home = Gem.user_dir + end end + + @gem_home ||= Gem.dir end # If the user has asked for the gem to be installed in a directory that is