aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/installer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/installer.rb')
-rw-r--r--lib/rubygems/installer.rb28
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index ae699a90a0..5e2e8e0f42 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -85,6 +85,32 @@ class Gem::Installer
raise Gem::InstallError, "invalid gem format for #{@gem}"
end
+ 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
+ not File.writable? Gem.bindir)
+ if options[:user_install] == false # You explicitly don't want to use ~
+ raise Gem::FilePermissionError, @gem_home
+ elsif options[:user_install].nil?
+ say "Warning: falling back to user-level install since #{@gem_home} and #{@bin_dir} aren't both writable."
+ end
+ options[:user_install] = true
+ end
+
+ if options[:user_install]
+ @gem_home = File.join(ENV['HOME'], '.gem')
+
+ 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
+ # 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 +158,6 @@ class Gem::Installer
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
@@ -206,6 +231,7 @@ class Gem::Installer
file_name = File.join @gem_home, 'specifications',
"#{@spec.full_name}.gemspec"
+
file_name.untaint
File.open(file_name, "w") do |file|