Permalink
Browse files

explains why the file update checker ignores mtimes in the future, pl…

…us a little refactor for the same price
  • Loading branch information...
fxn committed Jul 2, 2012
1 parent b8a5bb2 commit 65dc45ea2d0da224494b2dee800853cc29cea1f0
Showing with 12 additions and 2 deletions.
  1. +12 −2 activesupport/lib/active_support/file_update_checker.rb
@@ -101,9 +101,19 @@ def watched
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)

0 comments on commit 65dc45e

Please sign in to comment.