From 65dc45ea2d0da224494b2dee800853cc29cea1f0 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 2 Jul 2012 23:56:13 +0200 Subject: explains why the file update checker ignores mtimes in the future, plus a little refactor for the same price --- activesupport/lib/active_support/file_update_checker.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/file_update_checker.rb b/activesupport/lib/active_support/file_update_checker.rb index 9decbaef32..1cc852a3e6 100644 --- a/activesupport/lib/active_support/file_update_checker.rb +++ b/activesupport/lib/active_support/file_update_checker.rb @@ -101,9 +101,19 @@ module ActiveSupport end def updated_at(paths) + @updated_at || max_mtime(paths) || Time.at(0) + end + + # This method returns the maximum mtime of the files in +paths+, or +nil+ + # if the array is empty. + # + # Files with a mtime in the future are ignored. Such abnormal situation + # can happen for example if the user changes the clock by hand. It is + # healthy to consider this edge case because with mtimes in the future + # reloading is not triggered. + def max_mtime(paths) time_now = Time.now - @updated_at || paths.map { |path| File.mtime(path) }. - reject { |time| time > time_now }.max || Time.at(0) + paths.map {|path| File.mtime(path)}.reject {|mtime| time_now < mtime}.max end def compile_glob(hash) -- cgit v1.2.3