diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2019-05-23 17:06:58 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2019-05-23 17:12:18 -0700 |
commit | ee7f7785a6b2c5439850054467c6578ecca3de00 (patch) | |
tree | db975995edf76fe30a18124630dc4ee732bd503f /lib/chef/mixin | |
parent | ace17c29b95c118b76f3d5440b614c0075992e0c (diff) | |
download | chef-ee7f7785a6b2c5439850054467c6578ecca3de00.tar.gz |
make which/where be target-mode aware
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/mixin')
-rw-r--r-- | lib/chef/mixin/which.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/chef/mixin/which.rb b/lib/chef/mixin/which.rb index e373a52521..8f42a10dcf 100644 --- a/lib/chef/mixin/which.rb +++ b/lib/chef/mixin/which.rb @@ -40,11 +40,22 @@ class Chef # for test stubbing def env_path - ENV["PATH"] + if Chef::Config.target_mode + Chef.run_context.transport_connection.run_command("echo $PATH").stdout + else + ENV["PATH"] + end end def valid_executable?(filename, &block) - return false unless File.executable?(filename) && !File.directory?(filename) + is_executable = + if Chef::Config.target_mode + connection = Chef.run_context.transport_connection + connection.file(filename).stat[:mode] & 1 && !connection.file(filename).directory? + else + File.executable?(filename) && !File.directory?(filename) + end + return false unless is_executable block ? yield(filename) : true end end |