diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-17 22:04:18 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-17 22:04:18 +0000 |
commit | 9d4f37f51fb2ffdef5e318afb3cb81516dcba4f7 (patch) | |
tree | 2eb3c16c59259a25f5d9315edacc61dfc8c59d62 /lib/rubygems/config_file.rb | |
parent | f98e6b91dec68ddd010ccb3bad651a18e7dca338 (diff) | |
download | ruby-9d4f37f51fb2ffdef5e318afb3cb81516dcba4f7.tar.gz |
Update RubyGems to 1.1.1 r1778 (almost 1.2)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/config_file.rb')
-rw-r--r-- | lib/rubygems/config_file.rb | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index 5bca0bd14e..c657bf7f01 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -18,6 +18,22 @@ class Gem::ConfigFile DEFAULT_VERBOSITY = true DEFAULT_UPDATE_SOURCES = true + system_config_path = + begin + require 'Win32API' + + CSIDL_COMMON_APPDATA = 0x0023 + path = 0.chr * 260 + SHGetFolderPath = Win32API.new 'shell32', 'SHGetFolderPath', 'LLLLP', 'L' + SHGetFolderPath.call 0, CSIDL_COMMON_APPDATA, 0, 1, path + + path.strip + rescue LoadError + '/etc' + end + + SYSTEM_WIDE_CONFIG_FILE = File.join system_config_path, 'gemrc' + # List of arguments supplied to the config file object. attr_reader :args @@ -81,18 +97,8 @@ class Gem::ConfigFile @verbose = DEFAULT_VERBOSITY @update_sources = DEFAULT_UPDATE_SOURCES - begin - # HACK $SAFE ok? - @hash = open(config_file_name.dup.untaint) {|f| YAML.load(f) } - rescue ArgumentError - warn "Failed to load #{config_file_name}" - rescue Errno::ENOENT - # Ignore missing config file error. - rescue Errno::EACCES - warn "Failed to load #{config_file_name} due to permissions problem." - end - - @hash ||= {} + @hash = load_file(SYSTEM_WIDE_CONFIG_FILE) + @hash.merge!(load_file(config_file_name.dup.untaint)) # HACK these override command-line args, which is bad @backtrace = @hash[:backtrace] if @hash.key? :backtrace @@ -105,6 +111,16 @@ class Gem::ConfigFile handle_arguments arg_list end + def load_file(filename) + begin + YAML.load(File.read(filename)) if filename and File.exist?(filename) + rescue ArgumentError + warn "Failed to load #{config_file_name}" + rescue Errno::EACCES + warn "Failed to load #{config_file_name} due to permissions problem." + end or {} + end + # True if the backtrace option has been specified, or debug is on. def backtrace @backtrace or $DEBUG |