Skip to content

Commit

Permalink
Clean up the AppData directory when removing the Windows app
Browse files Browse the repository at this point in the history
  • Loading branch information
hartmantis committed Jul 25, 2016
1 parent 153ca52 commit 4591778
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
24 changes: 14 additions & 10 deletions libraries/resource_chef_dk_app_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,25 @@ class ChefDkAppWindows < ChefDkApp
when :repo
chocolatey_package('chefdk') { action :remove }
else
shout = powershell_out!('Get-WmiObject -Class win32_product').stdout
pkgs = shout.strip.split(/^\W*$/).map do |pkg|
pkg.strip.lines.each_with_object({}) do |line, hsh|
k, v = line.split(':').map(&:strip)
hsh[k] = v
end
lines = powershell_out!('Get-WmiObject -Class win32_product').stdout
.lines
idx = lines.index do |l|
l.match(/^\W*Name\W+:\W+Chef Development Kit/)
end
pkg = pkgs.find { |p| p['Name'].match(/^Chef Development Kit/) }
if pkg
execute "Uninstall #{pkg['Name']}" do
command "msiexec /qn /x \"#{pkg['IdentifyingNumber']}\""

if idx
name = lines[idx].split(':')[1].strip
idn = lines[idx - 1].split(':')[1].strip
execute "Uninstall #{name}" do
command "msiexec /qn /x \"#{idn}\""
end
else
package('Chef Development Kit') { action :remove }
end
directory ::File.expand_path('~/AppData/Local/chefdk') do
recursive true
action :delete
end
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/resources/chef_dk_app/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@
context c do
include_context description

it 'deletes the Chef-DK AppData directory' do
d = File.expand_path('~/AppData/Local/chefdk')
expect(chef_run).to delete_directory(d).with(recursive: true)
end

context 'app in the installed list' do
let(:listed?) { true }

Expand Down

0 comments on commit 4591778

Please sign in to comment.