Check File.file? first to avoid second stat()

This commit is contained in:
Jack Nagel 2014-07-06 13:35:44 -05:00
parent 6a0720071e
commit 7bd4f76b8c

View File

@ -185,7 +185,7 @@ end
def which cmd, path=ENV['PATH'] def which cmd, path=ENV['PATH']
path.split(File::PATH_SEPARATOR).each do |p| path.split(File::PATH_SEPARATOR).each do |p|
pcmd = File.expand_path(File.join(p, cmd)) pcmd = File.expand_path(File.join(p, cmd))
return Pathname.new(pcmd) if File.executable?(pcmd) && !File.directory?(pcmd) return Pathname.new(pcmd) if File.file?(pcmd) && File.executable?(pcmd)
end end
return nil return nil
end end