diff options
author | Philippe Huibonhoa <phuibonhoa@gmail.com> | 2011-09-29 18:59:40 -0700 |
---|---|---|
committer | Philippe Huibonhoa <phuibonhoa@gmail.com> | 2011-09-29 18:59:40 -0700 |
commit | 0baa8f8604e7766ce627120dfe572e09c247ef8c (patch) | |
tree | 30ddc6e35037a6e1da75c6856cb8cab6a80e5072 /activesupport | |
parent | d2888de5985c7018a5be23d44143ec3c6cef9032 (diff) | |
download | rails-0baa8f8604e7766ce627120dfe572e09c247ef8c.tar.gz rails-0baa8f8604e7766ce627120dfe572e09c247ef8c.tar.bz2 rails-0baa8f8604e7766ce627120dfe572e09c247ef8c.zip |
Added fix so that file store does not raise an exception when cache dir does not exist yet. This can happen if a delete_matched is called before anything is saved in the cache.
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/cache/file_store.rb | 1 | ||||
-rw-r--r-- | activesupport/test/caching_test.rb | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index 3f516d4808..b431041b76 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -161,6 +161,7 @@ module ActiveSupport end def search_dir(dir, &callback) + return if !File.exist?(dir) Dir.foreach(dir) do |d| next if d == "." || d == ".." name = File.join(dir, d) diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index b692a41312..793e62a74a 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -566,6 +566,13 @@ class FileStoreTest < ActiveSupport::TestCase assert path.split('/').all? { |dir_name| dir_name.size <= ActiveSupport::Cache::FileStore::FILENAME_MAX_SIZE} assert_equal 'B', File.basename(path) end + + def test_search_dir_when_directory_does_not_exist + ActiveSupport::Cache::FileStore.new('test').send(:search_dir, 'dir_does_not_exist') do |path| + flunk "search_dir yielded but should have done nothing" + end + assert true + end end class MemoryStoreTest < ActiveSupport::TestCase |