From b3b76dffdd9cd8ed5c3d0230624bf05015bec5b8 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 23 Jul 2009 16:51:22 -0700 Subject: Fixing #2296 - overlapping recursions work again This fixes the behaviour when you have file recursions that overlap - we again correctly use the most specific information. It's still a bit expensive when you do this, but at least it behaves correctly, and it should be a rare circumstance. Signed-off-by: Luke Kanies --- lib/puppet/type/file.rb | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index 4efd901e5..79ab8eb95 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -580,7 +580,35 @@ module Puppet # remote system. mark_children_for_purging(children) if self.purge? - return children.values.sort { |a, b| a[:path] <=> b[:path] } + result = children.values.sort { |a, b| a[:path] <=> b[:path] } + remove_less_specific_files(result) + end + + # This is to fix bug #2296, where two files recurse over the same + # set of files. It's a rare case, and when it does happen you're + # not likely to have many actual conflicts, which is good, because + # this is a pretty inefficient implementation. + def remove_less_specific_files(files) + # We sort the paths so we can short-circuit some tests. + mypath = self[:path] + other_paths = catalog.vertices.find_all do |r| + r.is_a?(self.class) and r[:path][0..(mypath.length - 1)] == mypath + end.collect { |r| r[:path] }.sort { |a, b| a.length <=> b.length } - [self[:path]] + + return files if other_paths.empty? + + remove = [] + files.each do |file| + path = file[:path] + other_paths.each do |p| + if path[0..(p.length - 1)] == p + remove << file + break + end + end + end + + files - remove end # A simple method for determining whether we should be recursing. -- cgit