Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/puppet/provider/package/windows/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def self.with_key(&block)
open(hive, 'Software\Microsoft\Windows\CurrentVersion\Uninstall', mode) do |uninstall|
each_key(uninstall) do |name, wtime|
open(hive, "#{uninstall.keyname}\\#{name}", mode) do |key|
yield key, values(key)
# Ignore invalid values so that we can continue to enumerate other packages in the run
# The `valid?` methods in the derived classes will determine if the package is actually valid
yield key, values(key, true)
end
end
end
Expand Down
18 changes: 13 additions & 5 deletions lib/puppet/util/windows/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,29 @@ def delete_key(key, subkey_name, mode = KEY64)
reg_delete_key_ex(key, subkey_name, mode)
end

def values(key)
def values(key, ignore_invalid_values = false)
vals = {}
each_value(key) { |subkey, type, data| vals[subkey] = data }
each_value(key, ignore_invalid_values) { |subkey, type, data| vals[subkey] = data }
vals
end

def each_value(key, &block)
def each_value(key, ignore_invalid_values = false, &block)
index = 0
subkey = nil

_, value_max_len = reg_query_info_key_max_lengths(key)

begin
subkey, type, data = reg_enum_value(key, index, value_max_len)
yield subkey, type, data if !subkey.nil?
begin
subkey, type, data = reg_enum_value(key, index, value_max_len)
yield subkey, type, data if !subkey.nil?
rescue Exception => ex
if ignore_invalid_values
Puppet.debug "Error while enumerating registry value #{key.keyname}, value index #{index} - #{ex.inspect}"
else
raise
end
end
index += 1
end while !subkey.nil?

Expand Down
7 changes: 4 additions & 3 deletions spec/integration/util/windows/registry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,26 @@ def write_corrupt_dword(reg, valuename)

context "#values" do
let(:key) { stub('uninstall') }
let(:ignore_invalid_values) { false }

def expects_registry_value(array)
key.expects(:each_value).never
subject.expects(:each_value).with(key).multiple_yields(array)
subject.expects(:each_value).with(key, ignore_invalid_values).multiple_yields(array)

subject.values(key).first[1]
end

it "should return each value's name and data" do
key.expects(:each_value).never
subject.expects(:each_value).with(key).multiple_yields(
subject.expects(:each_value).with(key, ignore_invalid_values).multiple_yields(
['string', 1, 'foo'], ['dword', 4, 0]
)
expect(subject.values(key)).to eq({ 'string' => 'foo', 'dword' => 0 })
end

it "should return an empty hash if there are no values" do
key.expects(:each_value).never
subject.expects(:each_value).with(key)
subject.expects(:each_value).with(key, ignore_invalid_values)

expect(subject.values(key)).to eq({})
end
Expand Down