Module: Chef::Resource::ArchiveDllLocator
- Defined in:
- lib/chef/resource/archive_dll_locator.rb
Overview
Locates archive.dll for a Habitat-packaged Chef on Windows. Sources are tried from most to least authoritative so that a stray or older libarchive package on the machine is only used when nothing more specific exists:
1. RUBY_DLL_PATH (set by the Habitat plan)
2. the hab CLI (`hab pkg path core/libarchive`)
3. a search of the hab root derived from the location of chef itself
Constant Summary collapse
- DLL_NAME =
"archive.dll".freeze
Class Method Summary collapse
- .find(source_file: __FILE__, env: ::ENV) ⇒ Object
- .from_hab_cli ⇒ Object
- .from_hab_root_search(source_file) ⇒ Object
- .from_ruby_dll_path(env = ::ENV) ⇒ Object
Class Method Details
.find(source_file: __FILE__, env: ::ENV) ⇒ Object
31 32 33 |
# File 'lib/chef/resource/archive_dll_locator.rb', line 31 def self.find(source_file: __FILE__, env: ::ENV) from_ruby_dll_path(env) || from_hab_cli || from_hab_root_search(source_file) end |
.from_hab_cli ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chef/resource/archive_dll_locator.rb', line 45 def self.from_hab_cli stdout, stderr, status = Open3.capture3("hab pkg path core/libarchive") unless status.success? Chef::Log.debug("Failed to determine Habitat libarchive path: #{stderr}") return nil end candidate = ::File.join(stdout.strip.tr("\\", "/"), "bin", DLL_NAME) return candidate if ::File.exist?(candidate) Chef::Log.debug("#{DLL_NAME} not found in Habitat path: #{candidate}") nil rescue SystemCallError => e Chef::Log.debug("hab CLI not available to locate libarchive: #{e.}") nil end |
.from_hab_root_search(source_file) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/chef/resource/archive_dll_locator.rb', line 62 def self.from_hab_root_search(source_file) hab_root = source_file.tr("\\", "/")[%r{\A(.*?/hab)/pkgs/}, 1] return nil unless hab_root ::Dir.glob("#{hab_root}/pkgs/core/libarchive/*/*/bin/#{DLL_NAME}").max end |
.from_ruby_dll_path(env = ::ENV) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/chef/resource/archive_dll_locator.rb', line 35 def self.from_ruby_dll_path(env = ::ENV) env["RUBY_DLL_PATH"].to_s.split(::File::PATH_SEPARATOR).each do |dir| next if dir.empty? candidate = ::File.join(dir.tr("\\", "/"), DLL_NAME) return candidate if ::File.exist?(candidate) end nil end |