Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fix using sysconfdir for 1.8.x rubies #291

Closed
wants to merge 2 commits into from

4 participants

@mpapis

for the line of rubies 1.8 rubygems did not load sysconfdir and defaulted back to /etc which lead to problems like this: https://gist.github.com/1981223

@djberg96
Collaborator

NOPE. Can't remove that Windows code. Just change the default "/etc" to RbConfig::CONFIG['sysconfdir'] || "/etc"

@mpapis

@djberg96 that would work via two exceptions, I have changed code to use first RbConfig::CONFIG['sysconfdir'] which should be the primary source of sysconfdir (at least for 1.8)

@evanphx evanphx closed this in c08a425
@jcast jcast referenced this pull request from a commit in jcasts/rubygems
@evanphx evanphx - Honor sysconfdir on 1.8. Fixes #291 f77a1ae
@bearded
$ git checkout origin/1.8 -b 1.8
Branch 1.8 set up to track remote branch 1.8 from origin.
Switched to a new branch '1.8'
$ ruby setup.rb 
RubyGems 1.8.18 installed

== 1.8.18 / 2012-03-11

* 4 bug fixes:

  * Use Psych API to emit more compatible YAML
  * Download and write inside `gem fetch` directly. Fixes #289
  * Honor sysconfdir on 1.8. Fixes #291
  * Search everywhere for a spec for `gem spec`. Fixes #288
  * Fix Gem.all_load_path. Fixes #171


------------------------------------------------------------------------------

RubyGems installed the following executables:
  /usr/local/rvm/rubies/ruby-1.9.1-p431/bin/gem
$ gem -v
/usr/local/rvm/rubies/ruby-1.9.1-p431/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:71:in `rescue in rescue in <class:ConfigFile>': uninitialized constant Gem::ConfigFile::RbConfig (NameError)
  from /usr/local/rvm/rubies/ruby-1.9.1-p431/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:53:in `rescue in <class:ConfigFile>'
  from /usr/local/rvm/rubies/ruby-1.9.1-p431/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:49:in `<class:ConfigFile>'
  from /usr/local/rvm/rubies/ruby-1.9.1-p431/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:28:in `<top (required)>'
  from /usr/local/rvm/rubies/ruby-1.9.1-p431/lib/ruby/site_ruby/1.9.1/rubygems/gem_runner.rb:9:in `require'
  from /usr/local/rvm/rubies/ruby-1.9.1-p431/lib/ruby/site_ruby/1.9.1/rubygems/gem_runner.rb:9:in `<top (required)>'
  from /usr/local/rvm/rubies/ruby-1.9.1-p431/bin/gem:9:in `require'
  from /usr/local/rvm/rubies/ruby-1.9.1-p431/bin/gem:9:in `<main>'
@mpapis

this might be because there is no explicit require "rbconfig" in the fix like it was in mine proposed code ...

@bearded

@mpapis, yes, require "rbconfig" solves this problem, and gem -v works on 1.8.7, 1.9.1, 1.9.2 and 1.9.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 23 deletions.
  1. +20 −23 lib/rubygems/config_file.rb
View
43 lib/rubygems/config_file.rb
@@ -45,33 +45,30 @@ class Gem::ConfigFile
PLATFORM_DEFAULTS = {}
- system_config_path =
+ require "rbconfig"
+ system_config_path = RbConfig::CONFIG['sysconfdir'] ||
begin
- require "etc"
- Etc.sysconfdir
- 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"
+ # TODO: remove after we drop 1.8.7 and 1.9.1 - Etc.sysconfdir
+ 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
+
SYSTEM_WIDE_CONFIG_FILE = File.join system_config_path, 'gemrc'
##
Something went wrong with that request. Please try again.