diff options
| author | Markus Roberts <Markus@reality.com> | 2009-09-30 15:00:19 -0700 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-10-15 20:43:49 +1100 |
| commit | b0518c3938be6cef34eafeb0460116d98b2a64ca (patch) | |
| tree | c974faa6c80ad4b08b3c76182775abc3e0a4d21a | |
| parent | 8a7308249783fc75d450fc2428cba52a5ad30a10 (diff) | |
| download | puppet-b0518c3938be6cef34eafeb0460116d98b2a64ca.tar.gz puppet-b0518c3938be6cef34eafeb0460116d98b2a64ca.tar.xz puppet-b0518c3938be6cef34eafeb0460116d98b2a64ca.zip | |
Fix for #2681 (duplicate resource)
Refactor to not generate explicit resources and to not bail out if
one of a set can not be ensured absend.
Signed-off-by: Markus Roberts <Markus@reality.com>
| -rw-r--r-- | lib/puppet/type/resources.rb | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/lib/puppet/type/resources.rb b/lib/puppet/type/resources.rb index ab564a1d6..87bde972b 100644 --- a/lib/puppet/type/resources.rb +++ b/lib/puppet/type/resources.rb @@ -85,33 +85,33 @@ Puppet::Type.newtype(:resources) do end end + def able_to_ensure_absent?(resource) + begin + resource[:ensure] = :absent + rescue ArgumentError, Puppet::Error => detail + err "The 'ensure' attribute on #{self[:name]} resources does not accept 'absent' as a value" + false + end + end + # Generate any new resources we need to manage. This is pretty hackish # right now, because it only supports purging. def generate return [] unless self.purge? - hascheck = false - method = - resource_type.instances.find_all do |resource| - ! resource.managed? - end.find_all do |resource| - check(resource) - end.each do |resource| - begin - resource[:ensure] = :absent - rescue ArgumentError, Puppet::Error => detail - err "The 'ensure' attribute on %s resources does not accept 'absent' as a value" % - [self[:name]] - return [] - end + resource_type.instances. + reject { |r| managed? }. + reject { |r| catalog.resources.include? r.ref }. + select { |r| check(r) }. + select { |r| able_to_ensure_absent?(r) }. + each { |resource| @parameters.each do |name, param| - next unless param.metaparam? - resource[name] = param.value + resource[name] = param.value if param.metaparam? end # Mark that we're purging, so transactions can handle relationships # correctly resource.purging - end + } end def resource_type |
