Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Always prompt once for sudo
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Sep 7, 2016
1 parent 4818f41 commit 5a20eb0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/bundler.rb
Expand Up @@ -329,17 +329,23 @@ def which(executable)
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
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/errors.rb
Expand Up @@ -52,6 +52,7 @@ class LockfileError < BundlerError; status_code(20); end
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

Expand Down

0 comments on commit 5a20eb0

Please sign in to comment.