diff options
author | ryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-01-19 00:08:49 +0000 |
---|---|---|
committer | ryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-01-19 00:08:49 +0000 |
commit | e798ccbacf489a3af2201ae30058ff0ae7f79045 (patch) | |
tree | 4147a7834eb88323057fd2120a2ddc96c1eb32ab /lib/rubygems/config_file.rb | |
parent | d26fb035cae8d351dc238376722c980230dc5fbd (diff) | |
download | ruby-e798ccbacf489a3af2201ae30058ff0ae7f79045.tar.gz |
Import rubygems 1.5.0 (release candidate)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/config_file.rb')
-rw-r--r-- | lib/rubygems/config_file.rb | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index 1a96356fa8..f3593999d3 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -1,3 +1,9 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + #-- # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others. # All rights reserved. @@ -47,10 +53,29 @@ class Gem::ConfigFile system_config_path = begin - require 'etc.so' + require "etc" Etc.sysconfdir - rescue LoadError - '/etc' + rescue LoadError, NoMethodError + begin + # TODO: remove after we drop 1.8.7 and 1.9.1 + require 'Win32API' + + CSIDL_COMMON_APPDATA = 0x0023 + path = 0.chr * 260 + if RUBY_VERSION > '1.9' then + SHGetFolderPath = Win32API.new 'shell32', 'SHGetFolderPath', 'PLPLP', + 'L', :stdcall + SHGetFolderPath.call nil, CSIDL_COMMON_APPDATA, nil, 1, path + else + SHGetFolderPath = Win32API.new 'shell32', 'SHGetFolderPath', 'LLLLP', + 'L' + SHGetFolderPath.call 0, CSIDL_COMMON_APPDATA, 0, 1, path + end + + path.strip + rescue LoadError + "/etc" + end end SYSTEM_WIDE_CONFIG_FILE = File.join system_config_path, 'gemrc' @@ -192,7 +217,7 @@ class Gem::ConfigFile dirname = File.dirname(credentials_path) Dir.mkdir(dirname) unless File.exists?(dirname) - require 'yaml' + Gem.load_yaml File.open(credentials_path, 'w') do |f| f.write config.to_yaml @@ -202,9 +227,10 @@ class Gem::ConfigFile end def load_file(filename) + Gem.load_yaml + return {} unless filename and File.exists?(filename) begin - require 'yaml' YAML.load(File.read(filename)) rescue ArgumentError warn "Failed to load #{config_file_name}" @@ -299,7 +325,6 @@ class Gem::ConfigFile # Writes out this config file, replacing its source. def write - require 'yaml' open config_file_name, 'w' do |io| io.write to_yaml end |