From 59b89ed7344bb0cbc0b70b3dfa149b3035b90215 Mon Sep 17 00:00:00 2001 From: Paul Barry Date: Tue, 27 Apr 2010 20:03:10 -0400 Subject: [PATCH] [#4028] If the cache dir is missing, delete_matched should not throw an error. The cache dir is created as needed by #write, so having a missing cache dir could just be an indication that nothing has been cached yet and should not be treated as an error condition. --- .../lib/active_support/cache/file_store.rb | 17 ++++++++++------- activesupport/test/caching_test.rb | 7 +++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index fc225e7..32f2e28 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -173,14 +173,17 @@ module ActiveSupport end def search_dir(dir, &callback) - Dir.foreach(dir) do |d| - next if d == "." || d == ".." - name = File.join(dir, d) - if File.directory?(name) - search_dir(name, &callback) - else - callback.call name + begin + Dir.foreach(dir) do |d| + next if d == "." || d == ".." + name = File.join(dir, d) + if File.directory?(name) + search_dir(name, &callback) + else + callback.call name + end end + rescue SystemCallError end end end diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index d9ff120..8097c8d 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -317,6 +317,13 @@ module CacheDeleteMatchedBehavior assert_equal false, @cache.exist?("foo") assert_equal true, @cache.exist?("fu") end + def test_delete_matched_does_not_exit + assert_nothing_raised do + cache = ActiveSupport::Cache.lookup_store(:file_store, File.join(Dir.pwd, "dir_that_does_not_exist")) + # The dir doesn't exist, but it shouldn't throw an exception + cache.delete_matched(/some.pattern/) + end + end end module CacheIncrementDecrementBehavior -- 1.6.6.1