diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2012-06-29 08:56:02 -0700 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2012-06-29 08:56:02 -0700 |
commit | 1abe31670fdad2c357b4356b40a4567a46d16693 (patch) | |
tree | 0407039c30d8c7919730748e68eecfbeba3bdced | |
parent | 5e7d6bba79393de0279917f93b82f3b7b176f4b5 (diff) | |
parent | 20519efa6ede07b7a7f43ccd69d39b84c39f8195 (diff) | |
download | rails-1abe31670fdad2c357b4356b40a4567a46d16693.tar.gz rails-1abe31670fdad2c357b4356b40a4567a46d16693.tar.bz2 rails-1abe31670fdad2c357b4356b40a4567a46d16693.zip |
Merge pull request #6911 from abonec/master
Bug with FileUpdateChecker with wrong mtime
-rw-r--r-- | activesupport/lib/active_support/file_update_checker.rb | 4 | ||||
-rw-r--r-- | activesupport/test/file_update_checker_test.rb | 14 |
2 files changed, 17 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/file_update_checker.rb b/activesupport/lib/active_support/file_update_checker.rb index 48c39d9370..9decbaef32 100644 --- a/activesupport/lib/active_support/file_update_checker.rb +++ b/activesupport/lib/active_support/file_update_checker.rb @@ -101,7 +101,9 @@ module ActiveSupport 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) diff --git a/activesupport/test/file_update_checker_test.rb b/activesupport/test/file_update_checker_test.rb index 8adff5de8d..9d5417b70c 100644 --- a/activesupport/test/file_update_checker_test.rb +++ b/activesupport/test/file_update_checker_test.rb @@ -48,6 +48,20 @@ class FileUpdateCheckerWithEnumerableTest < ActiveSupport::TestCase 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 } |