summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-05-23 17:06:58 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-05-23 17:12:18 -0700
commitee7f7785a6b2c5439850054467c6578ecca3de00 (patch)
treedb975995edf76fe30a18124630dc4ee732bd503f
parentace17c29b95c118b76f3d5440b614c0075992e0c (diff)
downloadchef-ee7f7785a6b2c5439850054467c6578ecca3de00.tar.gz
make which/where be target-mode aware
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/mixin/which.rb15
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