diff options
-rw-r--r-- | activesupport/lib/active_support/file_update_checker.rb | 14 |
1 files changed, 12 insertions, 2 deletions
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) |