Skip to content
Browse files

fix FileUpdateChecker when file has wrong mtime (from future)

  • Loading branch information...
1 parent 0470ddc commit 20519efa6ede07b7a7f43ccd69d39b84c39f8195 @abonec abonec committed Jun 29, 2012
View
4 activesupport/lib/active_support/file_update_checker.rb
@@ -101,7 +101,9 @@ def watched
end
def updated_at(paths)
- @updated_at || paths.map { |path| File.mtime(path) }.max || Time.at(0)
+ time_now = Time.now
+ @updated_at || paths.map { |path| File.mtime(path) }.
+ reject { |time| time > time_now }.max || Time.at(0)
end
def compile_glob(hash)
View
14 activesupport/test/file_update_checker_test.rb
@@ -48,6 +48,20 @@ def test_should_be_robust_enough_to_handle_deleted_files
assert_equal 1, i
end
+ def test_should_be_robust_to_handle_files_with_wrong_modified_time
+ i = 0
+ time = 1.year.from_now # wrong mtime from the future
+ File.utime time, time, FILES[2]
+
+ checker = ActiveSupport::FileUpdateChecker.new(FILES){ i += 1 }
+
+ sleep(0.1)
+ FileUtils.touch(FILES[0..1])
+
+ assert checker.execute_if_updated
+ assert_equal 1, i
+ end
+
def test_should_cache_updated_result_until_execute
i = 0
checker = ActiveSupport::FileUpdateChecker.new(FILES){ i += 1 }

0 comments on commit 20519ef

Please sign in to comment.
Something went wrong with that request. Please try again.