aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-10-02 02:30:44 -0700
committerJosé Valim <jose.valim@gmail.com>2011-10-02 02:30:44 -0700
commit1efe41dc366d21123842dea34ba95ddf1ab284d4 (patch)
tree39998149570c99ca072f6a0f5bbcdd1108b7cf95
parent6e8fe1bf021139a2fbd06a10778ad2c6b67930ef (diff)
parent119a484e808898a7ff55a27326ad49d8d493eb59 (diff)
downloadrails-1efe41dc366d21123842dea34ba95ddf1ab284d4.tar.gz
rails-1efe41dc366d21123842dea34ba95ddf1ab284d4.tar.bz2
rails-1efe41dc366d21123842dea34ba95ddf1ab284d4.zip
Merge pull request #3174 from phuibonhoa/master
Fixed file store to handle delete_matched being called before cache dir is created.
-rw-r--r--activesupport/lib/active_support/cache/file_store.rb1
-rw-r--r--activesupport/test/caching_test.rb8
2 files changed, 9 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..cb5362525f 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -566,6 +566,14 @@ 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
+
+ # If nothing has been stored in the cache, there is a chance the cache directory does not yet exist
+ # Ensure delete_matched gracefully handles this case
+ def test_delete_matched_when_cache_directory_does_not_exist
+ assert_nothing_raised(Exception) do
+ ActiveSupport::Cache::FileStore.new('/test/cache/directory').delete_matched(/does_not_exist/)
+ end
+ end
end
class MemoryStoreTest < ActiveSupport::TestCase