diff options
author | Andre Arko <andre@arko.net> | 2013-04-01 19:39:39 -0700 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2013-04-01 19:39:39 -0700 |
commit | 3fc6be1cd0047d9f42e1d95a979b9eac10b3494c (patch) | |
tree | 53e1103a62bb5ffe94bd468af28072822712e11f /lib | |
parent | 93003471ce5af70979301e87a37b35aada4d158f (diff) | |
download | bundler-3fc6be1cd0047d9f42e1d95a979b9eac10b3494c.tar.gz |
improve sudo install support
on some Linux environments, it appears that GEM_HOME is writable but
some (or all) subdirectories are not writable. by using sudo anytime one
of those subdirectories is not writable, it becomes possible to run
`bundle install` without special considerations on those machines.
fixes #2403
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler.rb | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 61fb7a0710..ff0f646de4 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -245,17 +245,29 @@ module Bundler end def requires_sudo? - return @requires_sudo if defined?(@checked_for_sudo) + return @requires_sudo if defined?(@requires_sudo_ran) - path = bundle_path - path = path.parent until path.exist? - sudo_present = which "sudo" - bin_dir = Pathname.new(Bundler.system_bindir) - bin_dir = bin_dir.parent until bin_dir.exist? + if settings.allow_sudo? + sudo_present = which "sudo" + end + + if sudo_present + # the bundle path and subdirectories need to be writable for Rubygems + # to be able to unpack and install gems without exploding + path = bundle_path + path = path.parent until path.exist? + + # bins are written to a different location on OS X + bin_dir = Pathname.new(Bundler.system_bindir) + bin_dir = bin_dir.parent until bin_dir.exist? + + # if any directory is not writable, we need sudo + dirs = [path, bin_dir] | Dir[path.join('*')] + sudo_needed = dirs.find{|d| !File.writable?(d) } + end - @checked_for_sudo = true - sudo_gems = !File.writable?(path) || !File.writable?(bin_dir) - @requires_sudo = settings.allow_sudo? && sudo_gems && sudo_present + @requires_sudo_ran = true + @requires_sudo = settings.allow_sudo? && sudo_present && sudo_needed end def mkdir_p(path) |