From c189b46e3f179ca60dfeb8e65080d19fe653e926 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 18 May 2009 00:28:50 -0500 Subject: Fixing #2273 - file purging works more intuitively It now correctly purges files whether we're recursing locally or remotely. *Please* test various scenarios you can think of with this. I've tested: * Local recursion with no remote source * Remote recursion with a source * Recursion with an extra locally managed file Signed-off-by: Luke Kanies --- lib/puppet/transaction.rb | 1 + lib/puppet/type/file.rb | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 14 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 37f51b2e5..54163c521 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -349,6 +349,7 @@ class Transaction make_parent_child_relationship(resource, [r]) end rescue Puppet::Resource::Catalog::DuplicateResourceError + made.delete(res) next end end diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index f22b19fc3..99f5b96c1 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -513,6 +513,14 @@ module Puppet @stat = nil end + + # Configure discovered resources to be purged. + def mark_children_for_purging(children) + children.each do |name, child| + next if child[:source] + child[:ensure] = :absent + end + end # Create a new file or directory object as a child to the current # object. @@ -580,6 +588,10 @@ module Puppet recurse_remote(children) end + # If we're purging resources, then delete any resource that isn't on the + # remote system. + mark_children_for_purging(children) if self.purge? + return children.values.sort { |a, b| a[:path] <=> b[:path] } end @@ -661,20 +673,6 @@ module Puppet children[meta.relative_path].parameter(:source).metadata = meta end - # If we're purging resources, then delete any resource that isn't on the - # remote system. - if self.purge? - # Make a hash of all of the resources we found remotely -- all we need is the - # fast lookup, the values don't matter. - remotes = total.inject({}) { |hash, meta| hash[meta.relative_path] = true; hash } - - children.each do |name, child| - unless remotes.include?(name) - child[:ensure] = :absent - end - end - end - children end -- cgit