Commit 9bae9132 authored by Tim Smith's avatar Tim Smith
Browse files

Don't define which helper on Chef 16+ to avoid conflicts



We have our own which helper in the DSL now, which takes 2 args. This
helper is getting injected over it, which works most of the time (not as
well), but doesn't work when someone passes additional args. This breaks
gem_package and probably some other things in the ecosystem. We need to
continue to support chef-sugar being installed on a modern chef-client
release since that's necessary for client upgrades, but we should not
allow the injection of a legacy helper over the built-in.
Signed-off-by: default avatarTim Smith <tsmith@chef.io>
parent 037f3ed2
......@@ -22,26 +22,29 @@ class Chef
module Shell
extend self
#
# Finds a command in $PATH
#
# @param [String] cmd
# the command to find
#
# @return [String, nil]
#
def which(cmd)
if Pathname.new(cmd).absolute?
File.executable?(cmd) ? cmd : nil
else
paths = ENV['PATH'].split(::File::PATH_SEPARATOR) + %w(/bin /usr/bin /sbin /usr/sbin)
paths.each do |path|
possible = File.join(path, cmd)
return possible if File.executable?(possible)
# this helpers have been moved to core chef
if !defined?(Chef::VERSION) || Gem::Requirement.new("< 16.0.257").satisfied_by?(Gem::Version.new(Chef::VERSION))
#
# Finds a command in $PATH
#
# @param [String] cmd
# the command to find
#
# @return [String, nil]
#
def which(cmd)
if Pathname.new(cmd).absolute?
File.executable?(cmd) ? cmd : nil
else
paths = ENV['PATH'].split(::File::PATH_SEPARATOR) + %w(/bin /usr/bin /sbin /usr/sbin)
paths.each do |path|
possible = File.join(path, cmd)
return possible if File.executable?(possible)
end
nil
end
nil
end
end
......@@ -128,8 +131,11 @@ class Chef
end
module DSL
# @see Chef::Sugar::Shell#which
def which(cmd); Chef::Sugar::Shell.which(cmd); end
# this helpers have been moved to core chef
if !defined?(Chef::VERSION) || Gem::Requirement.new("< 16.0.257").satisfied_by?(Gem::Version.new(Chef::VERSION))
# @see Chef::Sugar::Shell#which
def which(cmd); Chef::Sugar::Shell.which(cmd); end
end
# @see Chef::Sugar::Shell#dev_null
def dev_null; Chef::Sugar::Shell.dev_null(node); end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment