Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Search $PATH for a binary rather than shelling out to `which`

  • Loading branch information...
commit d3a69d32af97bf7c9d04eb2d258d152f102e9910 1 parent d1bed41
@tenderlove authored
Showing with 12 additions and 1 deletion.
  1. +12 −1 lib/bundler.rb
View
13 lib/bundler.rb
@@ -229,7 +229,7 @@ def requires_sudo?
path = bundle_path
path = path.parent until path.exist?
- sudo_present = !(`which sudo` rescue '').empty?
+ sudo_present = which "sudo"
bin_dir = Pathname.new(Bundler.system_bindir)
bin_dir = bin_dir.parent until bin_dir.exist?
@@ -246,6 +246,17 @@ def mkdir_p(path)
end
end
+ def which(binary)
+ if File.executable? binary
+ binary
+ else
+ path = ENV['PATH'].split(File::PATH_SEPARATOR).find { |path|
+ File.executable? File.join(path, binary)
+ }
+ path && File.expand_path(binary, path)
+ end
+ end
+
def sudo(str)
`sudo -p 'Enter your password to install the bundled RubyGems to your system: ' #{str}`
end
Please sign in to comment.
Something went wrong with that request. Please try again.