Permalink
Browse files

Add Gem.user_dir and make use of it in installer.rb

git-svn-id: http://rubygems.rubyforge.org/svn/trunk@1837 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information...
1 parent 047835e commit 947f070e13cbfd7d123929cc166ceff83fdbca79 technomancy committed Jul 2, 2008
View
@@ -1,46 +1,40 @@
module Gem
- ##
# An Array of the default sources that come with RubyGems.
-
def self.default_sources
%w[http://gems.rubyforge.org/]
end
- ##
# Default home directory path to be used if an alternate value is not
# specified in the environment.
-
def self.default_dir
if defined? RUBY_FRAMEWORK_VERSION then
File.join File.dirname(ConfigMap[:sitedir]), 'Gems',
ConfigMap[:ruby_version]
- elsif defined? RUBY_ENGINE then
- File.join ConfigMap[:libdir], RUBY_ENGINE, 'gems',
- ConfigMap[:ruby_version]
else
- File.join ConfigMap[:libdir], 'ruby', 'gems', ConfigMap[:ruby_version]
+ File.join(ConfigMap[:libdir], ruby_engine, 'gems',
+ ConfigMap[:ruby_version])
end
end
- ##
- # Default gem load path.
+ # Path for gems in the user's home directory.
+ def self.user_dir
+ File.join(Gem.user_home, '.gem', ruby_engine,
+ ConfigMap[:ruby_version])
+ end
+ # Default gem load path.
def self.default_path
- [File.join(ENV['HOME'], '.gem'), default_dir]
+ [user_dir, default_dir]
end
- ##
# Deduce Ruby's --program-prefix and --program-suffix from its install name.
-
def self.default_exec_format
baseruby = ConfigMap[:BASERUBY] || 'ruby'
ConfigMap[:RUBY_INSTALL_NAME].sub(baseruby, '%s') rescue '%s'
end
- ##
# The default directory for binaries
-
def self.default_bindir
if defined? RUBY_FRAMEWORK_VERSION then # mac framework support
'/usr/bin'
@@ -49,19 +43,23 @@ def self.default_bindir
end
end
- ##
# The default system-wide source info cache directory.
-
def self.default_system_source_cache_dir
File.join Gem.dir, 'source_cache'
end
- ##
# The default user-specific source info cache directory.
-
def self.default_user_source_cache_dir
File.join Gem.user_home, '.gem', 'source_cache'
end
+ # A wrapper around RUBY_ENGINE const that may not be defined.
+ def self.ruby_engine
+ if defined? RUBY_ENGINE
+ RUBY_ENGINE
+ else
+ 'ruby'
+ end
+ end
end
@@ -105,7 +105,7 @@ def initialize(gem, options={})
if not File.writable? @gem_home or
# TODO: Shouldn't have to test for existence of bindir; tests need it.
- (@gem_home.to_s == Gem.dir and File.exist? Gem.bindir and
+ (@gem_home.to_s == Gem.dir and File.exist? Gem.bindir and
not File.writable? Gem.bindir)
if options[:user_install] == false # You explicitly don't want to use ~
raise Gem::FilePermissionError, @gem_home
@@ -116,15 +116,15 @@ def initialize(gem, options={})
end
if options[:user_install]
- @gem_home = File.join(ENV['HOME'], '.gem')
+ @gem_home = Gem.user_dir
user_bin_dir = File.join(@gem_home, 'gems', 'bin')
if !ENV['PATH'].split(':').include?(user_bin_dir)
say "You don't have #{user_bin_dir} in your PATH."
say "You won't be able to run gem-installed executables until you add it."
end
-
- Dir.mkdir @gem_home if ! File.directory? @gem_home
+
+ FileUtils.mkdir_p @gem_home if ! File.directory? @gem_home
# If it's still not writable, you've got issues.
raise Gem::FilePermissionError, @gem_home if ! File.writable? @gem_home
end
@@ -41,8 +41,10 @@ def test_user_install_enabled
@installer = Gem::Installer.new @gem, @cmd.options
@installer.install
- assert File.exist?(File.join(@userhome, '.gem', 'gems'))
- assert File.exist?(File.join(@userhome, '.gem', 'gems',
+ assert File.exist?(File.join(@userhome, '.gem', Gem.ruby_engine,
+ Gem::ConfigMap[:ruby_version], 'gems'))
+ assert File.exist?(File.join(@userhome, '.gem', Gem.ruby_engine,
+ Gem::ConfigMap[:ruby_version], 'gems',
@spec.full_name))
end
View
@@ -680,16 +680,19 @@ def test_install_user_local_fallback
File.chmod 0755, @userhome
File.chmod 0000, util_inst_bindir
File.chmod 0000, Gem.dir
- install_dir = File.join @userhome, '.gem', 'gems', @spec.full_name
@spec.executables = ["executable"]
use_ui @ui do
util_setup_gem
@installer.install
end
-
- assert File.exist?(File.join(install_dir, 'lib', 'code.rb'))
- assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable'))
+
+ assert File.exist?(File.join(@userhome, '.gem', Gem.ruby_engine,
+ Gem::ConfigMap[:ruby_version],
+ 'gems', @spec.full_name, 'lib', 'code.rb'))
+ assert File.exist?(File.join(@userhome, '.gem', Gem.ruby_engine,
+ Gem::ConfigMap[:ruby_version],
+ 'bin', 'executable'))
ensure
File.chmod 0755, Gem.dir
File.chmod 0755, util_inst_bindir
@@ -705,8 +708,10 @@ def test_install_bindir_read_only
util_setup_gem
@installer.install
end
-
- assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable'))
+
+ assert File.exist?(File.join(@userhome, '.gem', Gem.ruby_engine,
+ Gem::ConfigMap[:ruby_version],
+ 'bin', 'executable'))
ensure
File.chmod 0755, util_inst_bindir
end
@@ -268,7 +268,7 @@ def test_download_local_read_only
ensure
File.chmod 0755, File.join(@gemhome, 'cache')
end
-
+
def test_download_read_only
File.chmod 0555, File.join(@gemhome, 'cache')
File.chmod 0555, File.join(@gemhome)

0 comments on commit 947f070

Please sign in to comment.