From 5c6269c4593f8b1a83b72e157c460dd2b37338c7 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 23 Apr 2020 19:16:06 +0900 Subject: Support XDG_* (#2174) * Support XDG_CONFIG_HOME for gemrc. * Support XDG_DATA_HOME for .gem * Added test for XDG_DATA_HOME * Do not reuse environmental variable. * Unify .rdoc path to RDoc.home. * Support XDG_DATA_HOME for .rdoc * Ignore exists? * Extracted config_home path * Use XDG_CONFIG_HOME for default credential path * Fixed inconsistency location. * Fixed the broken tests. * Support XDG_CONFIG_HOME for irbrc * Introduce Gem.cache_home as XDG_CACHE_HOME * Use Gem.cache_home instead of Gem.config_home for the credential file of RubyGems. * Initialized the old configurations * Fixed test failure related the configuration initialization * restore XDG_DATA_HOME * Fixed the broken examples of bundler with XDG_* * Do not modify environmental variable on test file * Use XDG_DATA_HOME insted of XDG_CACHE_HOME for credential file * stub out Gem.data_home * Move dir accessor to defaults.rb file * Use XDG_DATA_HOME for signed gem features * Use XDG_DATA_HOME for spec cache * Do not rely on Gem.user_home * Gem.user_home is always exists. Don't need to use FileUitls.mkdir_p * Bump support version to RubyGems 3.2.0+ * Removed the needless fallback configuration * Fixed the inconsistency methods that are find_config_file and config_file * Use Gem.configuration.credentials_path instead of hard-coded path * gem_path is always provided * Removed the duplicated code of find_home * Also removed the duplicated code of user_home * use Gem::UNTAINT instead of untaint for surpressing the warnings * Use File.directory * Restore XDG_DATA_HOME * Use File.write --- lib/rubygems/config_file.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/rubygems/config_file.rb') diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index 54d8a9c152..393f947d77 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -261,7 +261,12 @@ if you believe they were disclosed to a third party. # Location of RubyGems.org credentials def credentials_path - File.join Gem.user_home, '.gem', 'credentials' + credentials = File.join Gem.user_home, '.gem', 'credentials' + if File.exist? credentials + credentials + else + File.join Gem.data_home, "gem", "credentials" + end end def load_api_keys @@ -444,6 +449,10 @@ if you believe they were disclosed to a third party. # Writes out this config file, replacing its source. def write + unless File.exist?(File.dirname(config_file_name)) + FileUtils.mkdir_p File.dirname(config_file_name) + end + File.open config_file_name, 'w' do |io| io.write to_yaml end -- cgit v1.2.3