diff options
author | Homu <homu@barosl.com> | 2016-09-20 15:53:56 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2016-09-20 15:53:56 +0900 |
commit | 913d907b08ef41a8b822b0e347d3269903c2f91a (patch) | |
tree | c128cc9440f494b6b6b2dbd9efff61d0e844cd0a | |
parent | 4496a97ccc795561437b3136d5310999e5f8d734 (diff) | |
parent | 5a20eb0ef14121c23b3464d99836cd6e0ab85b4a (diff) | |
download | bundler-913d907b08ef41a8b822b0e347d3269903c2f91a.tar.gz |
Auto merge of #4956 - bundler:seg-prompt-for-sudo, r=indirect
Always prompt once for sudo
I think this should close #3006 ?
This is an alternate to https://github.com/bundler/bundler/issues/4905.
\c @b-ggs
-rw-r--r-- | lib/bundler.rb | 10 | ||||
-rw-r--r-- | lib/bundler/errors.rb | 1 |
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 8806ae01ef..f5bbd61f57 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -329,17 +329,23 @@ EOF def sudo(str) SUDO_MUTEX.synchronize do prompt = "\n\n" + <<-PROMPT.gsub(/^ {6}/, "").strip + " " - Your user account isn't allowed to install to the system Rubygems. + Your user account isn't allowed to install to the system RubyGems. You can cancel this installation and run: bundle install --path vendor/bundle to install the gems into ./vendor/bundle/, or you can enter your password - and install the bundled gems to Rubygems using sudo. + and install the bundled gems to RubyGems using sudo. Password: PROMPT + unless @prompted_for_sudo ||= system(%(sudo -k -p "#{prompt}" true)) + raise SudoNotPermittedError, + "Bundler requires sudo access to install at the moment. " \ + "Try installing again, granting Bundler sudo access when prompted, or installing into a different path." + end + `sudo -p "#{prompt}" #{str}` end end diff --git a/lib/bundler/errors.rb b/lib/bundler/errors.rb index 7681ea73ae..dd5782fb3d 100644 --- a/lib/bundler/errors.rb +++ b/lib/bundler/errors.rb @@ -52,6 +52,7 @@ module Bundler class CyclicDependencyError < BundlerError; status_code(21); end class GemfileLockNotFound < BundlerError; status_code(22); end class PluginError < BundlerError; status_code(29); end + class SudoNotPermittedError < BundlerError; status_code(30); end class GemfileEvalError < GemfileError; end class MarshalError < StandardError; end |