summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/type/file.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
index 715836b22..1790c5e92 100644
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@ -257,11 +257,17 @@ Puppet::Type.newtype(:file) do
newvalues(:first, :all)
end
- # Autorequire any parent directories.
+ # Autorequire the nearest ancestor directory found in the catalog.
autorequire(:file) do
basedir = ::File.dirname(self[:path])
if basedir != self[:path]
- basedir
+ parents = []
+ until basedir == parents.last
+ parents << basedir
+ basedir = File.dirname(basedir)
+ end
+ # The filename of the first ancestor found, or nil
+ parents.find { |dir| catalog.resource(:file, dir) }
else
nil
end