diff options
author | Luke Kanies <luke@madstop.com> | 2009-05-18 00:28:50 -0500 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-05-20 18:30:31 +1000 |
commit | c189b46e3f179ca60dfeb8e65080d19fe653e926 (patch) | |
tree | 78e22a9e1c49a447c30baa65c11598f15a0aa6f2 /lib | |
parent | 138f19fc6e7bb1d8ebf305decaa045c53787297c (diff) | |
download | puppet-c189b46e3f179ca60dfeb8e65080d19fe653e926.tar.gz puppet-c189b46e3f179ca60dfeb8e65080d19fe653e926.tar.xz puppet-c189b46e3f179ca60dfeb8e65080d19fe653e926.zip |
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 <luke@madstop.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/transaction.rb | 1 | ||||
-rw-r--r-- | lib/puppet/type/file.rb | 26 |
2 files changed, 13 insertions, 14 deletions
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 |