summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@chef.io>2019-05-24 09:20:54 -0700
committerGitHub <noreply@github.com>2019-05-24 09:20:54 -0700
commit1fd2e94a9ec124a1ea63d82bc42c4ca8e5ad2331 (patch)
tree40a4e024f879736a7c1c5960b55c13bc75f90436
parentf9b74d9846368bd7dd8b12cb24e89fa0dbc696e2 (diff)
parentc9e7371e4fb54daa02df949575e85dfcf812b3a2 (diff)
downloadchef-1fd2e94a9ec124a1ea63d82bc42c4ca8e5ad2331.tar.gz
Merge pull request #8588 from chef/lcg/target-mode-which
make which/where be target-mode aware
-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..974cb50fa3 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