From b8837066dcaa389c00aaf22565bb6988ded3932e Mon Sep 17 00:00:00 2001 From: Charles Jones Date: Mon, 18 Feb 2013 18:37:48 -0600 Subject: Fix deletion of empty directories: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- activesupport/lib/active_support/cache/file_store.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support/cache') diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index 8e265ad863..0c55aa8a32 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -150,9 +150,9 @@ module ActiveSupport # Delete empty directories in the cache. def delete_empty_directories(dir) - return if dir == cache_path + return if File.realpath(dir) == File.realpath(cache_path) if Dir.entries(dir).reject {|f| EXCLUDED_DIRS.include?(f)}.empty? - File.delete(dir) rescue nil + Dir.delete(dir) rescue nil delete_empty_directories(File.dirname(dir)) end end -- cgit v1.2.3