summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/util/autoload.rb6
-rw-r--r--lib/puppet/util/autoload/file_cache.rb14
-rwxr-xr-xspec/unit/util/autoload.rb8
-rwxr-xr-xspec/unit/util/autoload/file_cache.rb24
4 files changed, 49 insertions, 3 deletions
diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb
index db06ea934..fb15adf92 100644
--- a/lib/puppet/util/autoload.rb
+++ b/lib/puppet/util/autoload.rb
@@ -73,6 +73,8 @@ class Puppet::Util::Autoload
# Load a single plugin by name. We use 'load' here so we can reload a
# given plugin.
def load(name)
+ return false if named_file_missing?(name)
+
path = name.to_s + ".rb"
searchpath.each do |dir|
@@ -92,10 +94,10 @@ class Puppet::Util::Autoload
puts detail.backtrace
end
end
- return false
+ return named_file_is_missing(name)
end
end
- return false
+ return named_file_is_missing(name)
end
# Mark the named object as loaded. Note that this supports unqualified
diff --git a/lib/puppet/util/autoload/file_cache.rb b/lib/puppet/util/autoload/file_cache.rb
index 6de525a8d..12400f620 100644
--- a/lib/puppet/util/autoload/file_cache.rb
+++ b/lib/puppet/util/autoload/file_cache.rb
@@ -79,6 +79,20 @@ module Puppet::Util::Autoload::FileCache
missing_files[path] = Time.now
end
+ def named_file_missing?(name)
+ @named_files ||= {}
+ if time = @named_files[name] and ! data_expired?(time)
+ return true
+ end
+ false
+ end
+
+ def named_file_is_missing(name)
+ @named_files ||= {}
+ @named_files[name] = Time.now
+ false
+ end
+
private
def cached_data?(path, type = nil)
diff --git a/spec/unit/util/autoload.rb b/spec/unit/util/autoload.rb
index 3bd5b50ad..d05bc15f0 100755
--- a/spec/unit/util/autoload.rb
+++ b/spec/unit/util/autoload.rb
@@ -71,11 +71,17 @@ describe Puppet::Util::Autoload do
end
it "should skip files that it knows are missing" do
- @autoload.expects(:missing_file?).returns true
+ @autoload.expects(:named_file_missing?).with("foo").returns true
@autoload.expects(:eachdir).never
@autoload.load("foo")
end
+
+ it "should register that files are missing if they cannot be found" do
+ @autoload.load("foo")
+
+ @autoload.should be_named_file_missing("foo")
+ end
end
describe "when loading all files" do
diff --git a/spec/unit/util/autoload/file_cache.rb b/spec/unit/util/autoload/file_cache.rb
index ad4e75f74..333ddb545 100755
--- a/spec/unit/util/autoload/file_cache.rb
+++ b/spec/unit/util/autoload/file_cache.rb
@@ -126,4 +126,28 @@ describe Puppet::Util::Autoload::FileCache do
other.should be_directory_exist("/my/file")
end
end
+
+ describe "when checking whether a named file exists" do
+ it "should have a method for testing whether a named file is missing" do
+ @cacher.should respond_to(:named_file_missing?)
+ end
+
+ it "should have a method for registering that a named file is missing" do
+ @cacher.should respond_to(:named_file_is_missing)
+ end
+
+ it "should cache that a file is missing for 15 seconds" do
+ now = Time.now
+
+ later = now + 16
+
+ Time.expects(:now).times(2).returns(now).then.returns(later)
+ @cacher.named_file_is_missing("foo")
+ @cacher.should_not be_named_file_missing("foo")
+ end
+
+ it "should return false when registering a file as missing" do
+ @cacher.named_file_is_missing("foo").should be_false
+ end
+ end
end