aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorCharles Jones <cj32@txstate.edu>2013-02-18 18:37:48 -0600
committerCharles Jones <cj32@txstate.edu>2013-02-25 18:54:44 -0600
commitb8837066dcaa389c00aaf22565bb6988ded3932e (patch)
tree5908955d9a31e49bd7d290aca1da990b44fee54e /activesupport/test
parent202041e762a98cb433c3a24a0b03308d4e05a99d (diff)
downloadrails-b8837066dcaa389c00aaf22565bb6988ded3932e.tar.gz
rails-b8837066dcaa389c00aaf22565bb6988ded3932e.tar.bz2
rails-b8837066dcaa389c00aaf22565bb6988ded3932e.zip
Fix deletion of empty directories:
1. When comparing the directory to delete against the top level cache_path, use File.realpath to make sure we aren't comparing two unequal strings that point to the same path. This occurs, for example, when cache_path has a trailing slash, which it does in the default Rails configuration. Since the input to delete_empty_directories never has a trailing slash, the comparison will never be true and the top level cache directory (and above) may be deleted. However… 2. File.delete raises EPERM when trying to delete a directory, so no directories have ever been deleted. Changing the code to Dir.delete fixes that.
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/caching_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index 5158bbc196..ede08e23d5 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -672,6 +672,18 @@ class FileStoreTest < ActiveSupport::TestCase
end
end
+ def test_delete_does_not_delete_empty_parent_dir
+ sub_cache_dir = File.join(cache_dir, 'subdir/')
+ sub_cache_store = ActiveSupport::Cache::FileStore.new(sub_cache_dir)
+ assert_nothing_raised(Exception) do
+ assert sub_cache_store.write('foo', 'bar')
+ assert sub_cache_store.delete('foo')
+ end
+ assert File.exist?(cache_dir), "Parent of top level cache dir was deleted!"
+ assert File.exist?(sub_cache_dir), "Top level cache dir was deleted!"
+ assert Dir.entries(sub_cache_dir).reject {|f| ActiveSupport::Cache::FileStore::EXCLUDED_DIRS.include?(f)}.empty?
+ end
+
def test_log_exception_when_cache_read_fails
File.expects(:exist?).raises(StandardError, "failed")
@cache.send(:read_entry, "winston", {})