Module: Chef::ResourceHelpers::PathHelpers

Overview

Helpers for path manipulation

Instance Method Summary collapse

Instance Method Details

#chef_client_hab_binary_pathString

This method returns the absolute path to the chef-client binary that is currently executing. In a Habitat environment, you might have multiple versions of chef-client installed, we want to ensure we get the path to the one currently running.

Examples:

chef_client_hab_binary_path
# => "/hab/pkgs/chef/chef-infra-client/19.10.0/20250822151044/bin/chef-client"
# Or on Windows:
# => "C:/hab/pkgs/chef/chef-infra-client/19.10.0/20250822151044/bin/chef-client"

Returns:

  • (String)

    The absolute path to the chef-client binary if found, or an empty string if no valid binary path is detected.



21
22
23
24
25
26
27
28
# File 'lib/chef/resource/helpers/path_helpers.rb', line 21

def chef_client_hab_binary_path
  path = File.realpath($PROGRAM_NAME)
  bin = File.basename(path)
  return path if bin == "#{ChefUtils::Dist::Infra::CLIENT}"

  # Return empty string if no valid path is found
  ""
end

#hab_executable_binary_pathObject



30
31
32
33
# File 'lib/chef/resource/helpers/path_helpers.rb', line 30

def hab_executable_binary_path
  # Find hab in PATH
  which("hab") || ""
end