summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-12-02 19:15:23 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-12-02 19:15:23 -0800
commitd3a69d32af97bf7c9d04eb2d258d152f102e9910 (patch)
tree981bcbd9ad3aaa73ca9bb70aaaf4a2af2a4ea684
parentd1bed41cabf3dbba3a4835fbf38ee937d048783a (diff)
downloadbundler-d3a69d32af97bf7c9d04eb2d258d152f102e9910.tar.gz
Search $PATH for a binary rather than shelling out to `which`
-rw-r--r--lib/bundler.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 97e6e28300..53b5125101 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -229,7 +229,7 @@ module Bundler
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 @@ module Bundler
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