Permalink
Browse files

fall back on ~/.gem if GEM_HOME is not writable

git-svn-id: http://rubygems.rubyforge.org/svn/trunk@1809 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information...
1 parent 35b1c2f commit dc5124646c625addce5e85db0d96789d0313357e technomancy committed Jun 24, 2008
Showing with 15 additions and 21 deletions.
  1. +9 −1 lib/rubygems/installer.rb
  2. +6 −20 test/test_gem_installer.rb
View
@@ -85,6 +85,15 @@ def initialize(gem, options={})
raise Gem::InstallError, "invalid gem format for #{@gem}"
end
+ if ! File.writable? @gem_home # or ! File.writable? RbConfig::CONFIG['bindir']
+ STDERR.puts "Warning: #{@gem_home} and #{@bin_dir} are not both writable."
+ @gem_home = File.join(ENV['HOME'], '.gem')
+ STDERR.puts " Falling back to #{@gem_home}."
+ Dir.mkdir @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
+
@spec = @format.spec
@gem_dir = File.join(@gem_home, "gems", @spec.full_name).untaint
@@ -132,7 +141,6 @@ def install
end
FileUtils.mkdir_p @gem_home unless File.directory? @gem_home
- raise Gem::FilePermissionError, @gem_home unless File.writable? @gem_home
Gem.ensure_gem_subdirectories @gem_home
View
@@ -637,15 +637,17 @@ def test_install_missing_dirs
def test_install_user_local
Dir.mkdir util_inst_bindir
+ File.chmod 0755, @userhome
File.chmod 0000, util_inst_bindir
File.chmod 0000, Gem.dir
- gemdir = File.join @userhome, '.gem', 'gems'
-
+ install_dir = File.join @userhome, '.gem', 'gems', @spec.full_name
+ @spec.executables = ["executable"]
+
util_setup_gem
@installer.install
- assert File.exist?(File.join(gemdir, @spec.full_name, 'lib', 'code.rb'))
- assert File.exist?(File.join(gemdir, 'bin', 'executable'))
+ assert File.exist?(File.join(install_dir, 'lib', 'code.rb'))
+ assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable'))
ensure
File.chmod 0755, Gem.dir
File.chmod 0755, util_inst_bindir
@@ -663,22 +665,6 @@ def test_install_with_message
assert_match %r|I am a shiny gem!|, @ui.output
end
- def test_install_writable
- util_setup_gem
-
- orig_mode = File.stat(Gem.dir).mode
- File.chmod 0000, Gem.dir
-
- e = assert_raise Gem::FilePermissionError do
- @installer.install
- end
-
- assert_equal "You don't have write permissions into the #{@gemhome} directory.",
- e.message
- ensure
- File.chmod orig_mode, Gem.dir
- end
-
def test_install_wrong_ruby_version
use_ui @ui do
installer = Gem::Installer.new old_ruby_required

0 comments on commit dc51246

Please sign in to comment.