summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-09-07 20:47:36 +0200
committerSamuel Giddins <segiddins@segiddins.me>2016-09-07 20:47:36 +0200
commit5a20eb0ef14121c23b3464d99836cd6e0ab85b4a (patch)
treedbbf49c73401116a2a88bed3b780b3d788ffb179
parent4818f415d07e547533f48d3f6c59dfda2b73c3fd (diff)
downloadbundler-seg-prompt-for-sudo.tar.gz
Always prompt once for sudoseg-prompt-for-sudo
-rw-r--r--lib/bundler.rb10
-rw-r--r--lib/bundler/errors.rb1
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