diff options
author | Dominic Cleal <dcleal@redhat.com> | 2010-11-27 13:36:04 +0000 |
---|---|---|
committer | Dominic Cleal <dcleal@redhat.com> | 2010-11-27 13:36:04 +0000 |
commit | afe2d014feb2210a8666c93465d11e9c9d555f8b (patch) | |
tree | 208f5ac82b2c29610d2021821c8fca9b079e638b /lib/puppet/util/autoload.rb | |
parent | 143fc744a839affd328234fca26246d49d15d3d8 (diff) | |
parent | 4b35402ba85d8842d757becec5c8a7bf4d6f6654 (diff) | |
download | puppet-afe2d014feb2210a8666c93465d11e9c9d555f8b.tar.gz puppet-afe2d014feb2210a8666c93465d11e9c9d555f8b.tar.xz puppet-afe2d014feb2210a8666c93465d11e9c9d555f8b.zip |
Merge branch 'master' of github.com:domcleal/puppet into master-old
Diffstat (limited to 'lib/puppet/util/autoload.rb')
-rw-r--r-- | lib/puppet/util/autoload.rb | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb index c293ac14a..f0dd0a5c5 100644 --- a/lib/puppet/util/autoload.rb +++ b/lib/puppet/util/autoload.rb @@ -131,11 +131,23 @@ class Puppet::Util::Autoload # We have to require this late in the process because otherwise we might have # load order issues. require 'puppet/node/environment' - Puppet::Node::Environment.new(env).modulepath.collect do |dir| - Dir.entries(dir).reject { |f| f =~ /^\./ }.collect { |f| File.join(dir, f) } - end.flatten.collect { |d| [File.join(d, "plugins"), File.join(d, "lib")] }.flatten.find_all do |d| - FileTest.directory?(d) - end + + real_env = Puppet::Node::Environment.new(env) + + # We're using a per-thread cache of said module directories, so that + # we don't scan the filesystem each time we try to load something with + # this autoload instance. But since we don't want to cache for the eternity + # this env_module_directories gets reset after the compilation on the master. + # This is also reset after an agent ran. + # One of the side effect of this change is that this module directories list will be + # shared among all autoload that we have running at a time. But that won't be an issue + # as by definition those directories are shared by all autoload. + Thread.current[:env_module_directories] ||= {} + Thread.current[:env_module_directories][real_env] ||= real_env.modulepath.collect do |dir| + Dir.entries(dir).reject { |f| f =~ /^\./ }.collect { |f| File.join(dir, f) } + end.flatten.collect { |d| [File.join(d, "plugins"), File.join(d, "lib")] }.flatten.find_all do |d| + FileTest.directory?(d) + end end def search_directories(env=nil) |