From f21162bdbae516d2613052d35a2f8bbd34d0bf86 Mon Sep 17 00:00:00 2001 From: Ian Ward Comfort Date: Thu, 17 Feb 2011 17:23:29 -0800 Subject: (#6368) Make the File type autorequire its nearest ancestor directory The File type will now autorequire the nearest ancestor directory found in the catalog, not just the file's parent directory. This is useful for setting up transitive relationships in cases when a package or other resource creates a large directory hierarchy, e.g. package { 'foo': ensure => present } file { '/var/lib/foo': require => Package['foo'] } This will make File resources at arbitrarily deep levels under /var/lib/foo automatically (transitively) require the foo package. Only the nearest ancestor is autorequired, to prevent explosion of the relationship graph. --- lib/puppet/type/file.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index 963b9e5dd..da093921b 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -244,11 +244,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 -- cgit