Skip to content

Commit

Permalink
(#12126) Track mtime of autoloaded files
Browse files Browse the repository at this point in the history
  • Loading branch information
pcarlisle committed Feb 28, 2012
1 parent bbfec56 commit 432426f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/puppet/util/autoload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ class Puppet::Util::Autoload
include Puppet::Util::Autoload::FileCache

@autoloaders = {}
@loaded = []
@loaded = {}

class << self
attr_reader :autoloaders, :loaded
private :autoloaders, :loaded

# List all loaded files.
def list_loaded
@loaded.sort { |a,b| a[0] <=> b[0] }.collect do |path, hash|
@loaded.keys.sort { |a,b| a[0] <=> b[0] }.collect do |path, hash|
"#{path}: #{hash[:file]}"
end
end
Expand All @@ -36,9 +36,9 @@ def loaded?(path)
# Save the fact that a given path has been loaded. This is so
# we can load downloaded plugins if they've already been loaded
# into memory.
def mark_loaded(file)
$" << file + ".rb" unless $".include?(file)
@loaded << file unless @loaded.include?(file)
def mark_loaded(name, file)
$" << name + ".rb" unless $".include?(name)
@loaded[name] = [file, File.mtime(file)]
end

# Load a single plugin by name. We use 'load' here so we can reload a
Expand All @@ -52,7 +52,7 @@ def load_file(name, env=nil)
next unless File.exist?(file)
begin
Kernel.load file, @wrap
mark_loaded(name)
mark_loaded(name, file)
return true
rescue SystemExit,NoMemoryError
raise
Expand Down
4 changes: 4 additions & 0 deletions spec/unit/util/autoload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
before do
@autoload.class.stubs(:search_directories).returns %w{/a}
FileTest.stubs(:directory?).returns true
@time_a = Time.utc(2010, 'jan', 1, 6, 30)
File.stubs(:mtime).returns @time_a
end

[RuntimeError, LoadError, SyntaxError].each do |error|
Expand Down Expand Up @@ -129,6 +131,8 @@
FileTest.stubs(:directory?).returns true
Dir.stubs(:glob).returns "/a/foo/file.rb"
File.stubs(:exist?).returns true
@time_a = Time.utc(2010, 'jan', 1, 6, 30)
File.stubs(:mtime).returns @time_a

@autoload.class.stubs(:loaded?).returns(false)
end
Expand Down

0 comments on commit 432426f

Please sign in to comment.