Skip to content

Commit

Permalink
Registry keys and values were autorequiring all ancestors
Browse files Browse the repository at this point in the history
Previously, registry keys and values were including all of their
ancestors in the array returned by the `autorequire` block. If the catalog
contained those resources, then puppet was creating one dependency edge
between the registry key/value and each ancestor. This is not desirable,
as we only need one dependency edges between the resource and its nearest
ancestor that we're managing.

Also, registry values were autorequiring themselves.

This commit changes the autorequire blocks using the same logic as is used
in the file type. We walk our ancestors, looking for the nearest
registry_key that we're managing.

It also changes the `ascend` method to exclude the current resource from
enumeration, since both registry_key and registry_value had to do extra
work to exclude itself from the autorequire.

Also removed a spurious downcase method. Currently, we only canonicalize
the root key (to handled mixed case). A future commit will resolve
case-insensitivity for registry key paths and value path and names.
  • Loading branch information
joshcooper committed Apr 24, 2012
1 parent 92b1c40 commit 0de7a0a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 0 additions & 2 deletions lib/puppet/modules/registry/key_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ def munge(path)
def ascend(&block)
p = self.value

yield p

while idx = p.rindex('\\')
p = p[0, idx]
yield p
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/modules/registry/value_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def munge(path)
end

canonical = subkey.empty? ? "#{root}\\#{valuename}" : "#{root}\\#{subkey}\\#{valuename}"
canonical.downcase
canonical
end
end
7 changes: 6 additions & 1 deletion lib/puppet/type/registry_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ def self.title_patterns
newparam(:path, :parent => Puppet::Modules::Registry::KeyPath, :namevar => true) do
end

# Autorequire the nearest ancestor registry_key found in the catalog.
autorequire(:registry_key) do
parameter(:path).enum_for(:ascend).select { |p| self[:path] != p }
req = []
if found = parameter(:path).enum_for(:ascend).find { |p| catalog.resource(:registry_key, p.to_s) }
req << found.to_s
end
req
end
end
7 changes: 6 additions & 1 deletion lib/puppet/type/registry_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ def self.title_patterns
defaultto ''
end

# Autorequire the nearest ancestor registry_key found in the catalog.
autorequire(:registry_key) do
parameter(:path).enum_for(:ascend)
req = []
if found = parameter(:path).enum_for(:ascend).find { |p| catalog.resource(:registry_key, p.to_s) }
req << found.to_s
end
req
end
end

0 comments on commit 0de7a0a

Please sign in to comment.