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
29
30
31
32
# 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)

  # On Windows, temporarily use the c:\\hab\\bin\\*.bat binstubs
  bat_path = "C:\\hab\\bin\\#{bin}.bat"
  return bat_path if File.exist?(bat_path) && ChefUtils.windows?
  return path if bin == "#{ChefUtils::Dist::Infra::CLIENT}"

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

#chef_client_hab_package_binary_pathObject

once the binstubs under hab package have been fixed, restore this as the chef_client_hab_binary_path method



36
37
38
39
40
41
42
43
44
# File 'lib/chef/resource/helpers/path_helpers.rb', line 36

def chef_client_hab_package_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



46
47
48
49
# File 'lib/chef/resource/helpers/path_helpers.rb', line 46

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