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

Commit

Permalink
Search $PATH for a binary rather than shelling out to which
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Dec 3, 2011
1 parent d1bed41 commit d3a69d3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -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|

This comment has been minimized.

Copy link
@bfolkens

bfolkens Apr 6, 2012

ENV['PATH'] is sometimes nil and breaks in a production environment I have with Passenger... Can we change it to ENV['PATH'].to_s or something to avoid that?

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
Expand Down

0 comments on commit d3a69d3

Please sign in to comment.