aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/cache
diff options
context:
space:
mode:
authorkennyj <kennyj@gmail.com>2011-10-30 21:50:17 +0900
committerkennyj <kennyj@gmail.com>2011-10-30 21:50:17 +0900
commit7670a5187d2000a577c9aa982158808550033dfd (patch)
tree6f3e13c5dac1b6a9fd12eb8255f7d5abc553a1f3 /activesupport/lib/active_support/cache
parent3e6ecfb454dac5220f5ba87e1ae2d9c563210c51 (diff)
downloadrails-7670a5187d2000a577c9aa982158808550033dfd.tar.gz
rails-7670a5187d2000a577c9aa982158808550033dfd.tar.bz2
rails-7670a5187d2000a577c9aa982158808550033dfd.zip
Refactor ActiveSupport::Cache::FileStore. used method and deleted duplicate code.
Diffstat (limited to 'activesupport/lib/active_support/cache')
-rw-r--r--activesupport/lib/active_support/cache/file_store.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb
index b431041b76..85e7e21624 100644
--- a/activesupport/lib/active_support/cache/file_store.rb
+++ b/activesupport/lib/active_support/cache/file_store.rb
@@ -14,6 +14,7 @@ module ActiveSupport
DIR_FORMATTER = "%03X"
FILENAME_MAX_SIZE = 230 # max filename size on file system is 255, minus room for timestamp and random characters appended by Tempfile (used by atomic write)
+ EXCLUDED_DIRS = ['.', '..'].freeze
def initialize(cache_path, options = nil)
super(options)
@@ -22,7 +23,7 @@ module ActiveSupport
end
def clear(options = nil)
- root_dirs = Dir.entries(cache_path).reject{|f| f.in?(['.', '..'])}
+ root_dirs = Dir.entries(cache_path).reject{|f| f.in?(EXCLUDED_DIRS)}
FileUtils.rm_r(root_dirs.collect{|f| File.join(cache_path, f)})
end
@@ -149,7 +150,7 @@ module ActiveSupport
# Delete empty directories in the cache.
def delete_empty_directories(dir)
return if dir == cache_path
- if Dir.entries(dir).reject{|f| f.in?(['.', '..'])}.empty?
+ if Dir.entries(dir).reject{|f| f.in?(EXCLUDED_DIRS)}.empty?
File.delete(dir) rescue nil
delete_empty_directories(File.dirname(dir))
end
@@ -163,7 +164,7 @@ module ActiveSupport
def search_dir(dir, &callback)
return if !File.exist?(dir)
Dir.foreach(dir) do |d|
- next if d == "." || d == ".."
+ next if d.in?(EXCLUDED_DIRS)
name = File.join(dir, d)
if File.directory?(name)
search_dir(name, &callback)