From ee579641f72b399e9e13e989a7779b533004b634 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 30 Sep 2008 22:04:38 -0500 Subject: Modified the behaviour of resource-level 'retrieve' -- it only calls 'retrieve' on each property if the resource exists. Signed-off-by: Luke Kanies --- lib/puppet/type.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index c7a866e2c..1989fc057 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -906,14 +906,24 @@ class Type # get a hash of the current properties. def currentpropvalues(override_value = nil) - # it's important to use the method here, as it follows the order - # in which they're defined in the object + # it's important to use the 'properties' method here, as it follows the order + # in which they're defined in the object. It also guarantees that 'ensure' + # is the first property, which is important for skipping 'retrieve' on + # all the properties if the resource is absent. + ensure_state = false return properties().inject({}) { | prophash, property| - prophash[property] = override_value.nil? ? - property.retrieve : - override_value - prophash - } + if property.name == :ensure + ensure_state = property.retrieve + prophash[property] = ensure_state + else + if ensure_state == :absent + prophash[property] = :absent + else + prophash[property] = property.retrieve + end + end + prophash + } end # Are we running in noop mode? -- cgit