Skip to content

Commit

Permalink
Go back to W32 for the registry and add a helper with better failure …
Browse files Browse the repository at this point in the history
…messaging

Signed-off-by: Tim Smith <[email protected]>
  • Loading branch information
tas50 committed Nov 16, 2016
1 parent 14da869 commit a86e9ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
20 changes: 16 additions & 4 deletions libraries/sevenzip_command_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def initialize(resource)

attr_reader :resource

def node
resource.run_context.node
end

def sevenzip_command
if resource.strip_components <= 0
return sevenzip_command_builder(resource.path, 'x')
Expand All @@ -42,10 +46,18 @@ def sevenzip_command
end

def sevenzip_binary
@tar_binary ||= resource.run_context.node['ark']['sevenzip_binary'] ||
if registry_key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe\Path')
"\"#{registry_get_values('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe\Path')}\\7z.exe\""
end
@tar_binary ||= (node['ark']['sevenzip_binary'] || sevenzip_path_from_registry)
end

def sevenzip_path_from_registry
begin
basepath = ::Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe').read_s('Path')

# users like pretty errors
rescue ::Win32::Registry::Error
raise 'Failed to find the path of 7zip binary by searching checking HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe\Path. Make sure to install 7zip before using this resource. If 7zip is installed and you still receive this message you can also specify the 7zip binary path by setting node["ark"]["sevenzip_binary"]'
end
"#{basepath}7z.exe"
end

def sevenzip_command_builder(dir, command)
Expand Down
22 changes: 11 additions & 11 deletions libraries/tar_command_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ def initialize(resource)

private

def tar_binary
@tar_binary ||= resource.run_context.node['ark']['tar'] || case node['platform_family']
when 'mac_os_x', 'freebsd'
'/usr/bin/tar'
when 'smartos'
'/bin/gtar'
else
'/bin/tar'
end
end

attr_reader :resource

def node
resource.run_context.node
end

def tar_binary
@tar_binary ||= node['ark']['tar'] || case node['platform_family']
when 'mac_os_x', 'freebsd'
'/usr/bin/tar'
when 'smartos'
'/bin/gtar'
else
'/bin/tar'
end
end

def args
case resource.extension
when /^(tar)$/ then 'xf'
Expand Down

0 comments on commit a86e9ea

Please sign in to comment.