From 56486664f25f495182dd3e3708e760d4220b1199 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Wed, 11 Nov 2009 22:47:42 +0100 Subject: Add Environment#manifestdir and small refactoring This adds a new environment cached attribute: manifestdir. It is modeled on the code of modulepath, but returns the manifestdir. Signed-off-by: Brice Figureau --- lib/puppet/node/environment.rb | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'lib/puppet/node') diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb index 133f22c77..94f899200 100644 --- a/lib/puppet/node/environment.rb +++ b/lib/puppet/node/environment.rb @@ -55,15 +55,7 @@ class Puppet::Node::Environment if ENV["PUPPETLIB"] dirs = ENV["PUPPETLIB"].split(File::PATH_SEPARATOR) + dirs end - dirs.collect do |dir| - if dir !~ /^#{File::SEPARATOR}/ - File.join(Dir.getwd, dir) - else - dir - end - end.find_all do |p| - p =~ /^#{File::SEPARATOR}/ && FileTest.directory?(p) - end + validate_dirs(dirs) end # Return all modules from this environment. @@ -73,7 +65,26 @@ class Puppet::Node::Environment module_names.collect { |path| Puppet::Module.new(path, self) rescue nil }.compact end + # Cache the manifestdir, so that we aren't searching through + # all known directories all the time. + cached_attr(:manifestdir, :ttl => Puppet[:filetimeout]) do + validate_dirs(self[:manifestdir].split(File::PATH_SEPARATOR)) + end + def to_s name.to_s end + + def validate_dirs(dirs) + dirs.collect do |dir| + if dir !~ /^#{File::SEPARATOR}/ + File.join(Dir.getwd, dir) + else + dir + end + end.find_all do |p| + p =~ /^#{File::SEPARATOR}/ && FileTest.directory?(p) + end + end + end -- cgit