diff options
| author | Ian Ward Comfort <icomfort@stanford.edu> | 2011-02-17 17:23:29 -0800 |
|---|---|---|
| committer | Jacob Helwig <jacob@puppetlabs.com> | 2011-04-22 11:10:59 -0700 |
| commit | f21162bdbae516d2613052d35a2f8bbd34d0bf86 (patch) | |
| tree | 41eb0d91a769542ef9b2eb5318db702e2f9f315a /lib/puppet | |
| parent | ea348761df0b5297dbac50c7f1c48d22746524fa (diff) | |
| download | puppet-f21162bdbae516d2613052d35a2f8bbd34d0bf86.tar.gz puppet-f21162bdbae516d2613052d35a2f8bbd34d0bf86.tar.xz puppet-f21162bdbae516d2613052d35a2f8bbd34d0bf86.zip | |
(#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.
Diffstat (limited to 'lib/puppet')
| -rw-r--r-- | lib/puppet/type/file.rb | 10 |
1 files changed, 8 insertions, 2 deletions
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 |
