Permalink
Browse files

Added fix so that file store does not raise an exception when cache d…

…ir does not exist yet. This can happen if a delete_matched is called before anything is saved in the cache.
  • Loading branch information...
1 parent d2888de commit 0baa8f8604e7766ce627120dfe572e09c247ef8c @phuibonhoa phuibonhoa committed Sep 30, 2011
Showing with 8 additions and 0 deletions.
  1. +1 −0 activesupport/lib/active_support/cache/file_store.rb
  2. +7 −0 activesupport/test/caching_test.rb
@@ -161,6 +161,7 @@ def ensure_cache_path(path)
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)
@@ -566,6 +566,13 @@ def test_key_transformation_max_filename_size
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

0 comments on commit 0baa8f8

Please sign in to comment.