summaryrefslogtreecommitdiff
path: root/lib/gitlab/utils.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-12-08 21:10:18 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-12-08 21:10:18 +0000
commit52af12cfecb5d7332b19f6d68218f0aff2cc525d (patch)
tree7b69d25c61f674c701c97614fdba0f42638a584b /lib/gitlab/utils.rb
parent66b0c3d82e936f78e7f016bc0bf42d243d115efa (diff)
downloadgitlab-ce-52af12cfecb5d7332b19f6d68218f0aff2cc525d.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/utils.rb')
-rw-r--r--lib/gitlab/utils.rb16
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/gitlab/utils.rb b/lib/gitlab/utils.rb
index cb34ed69a9c..96cff024371 100644
--- a/lib/gitlab/utils.rb
+++ b/lib/gitlab/utils.rb
@@ -120,18 +120,14 @@ module Gitlab
Random.rand(Float::MAX.to_i).to_s(36)
end
- # See: http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
- # Cross-platform way of finding an executable in the $PATH.
+ # Behaves like `which` on Linux machines: given PATH, try to resolve the given
+ # executable name to an absolute path, or return nil.
#
# which('ruby') #=> /usr/bin/ruby
- def which(cmd, env = ENV)
- exts = env['PATHEXT'] ? env['PATHEXT'].split(';') : ['']
-
- env['PATH'].split(File::PATH_SEPARATOR).each do |path|
- exts.each do |ext|
- exe = File.join(path, "#{cmd}#{ext}")
- return exe if File.executable?(exe) && !File.directory?(exe)
- end
+ def which(filename)
+ ENV['PATH']&.split(File::PATH_SEPARATOR)&.each do |path|
+ full_path = File.join(path, filename)
+ return full_path if File.executable?(full_path)
end
nil