aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/cache/file_store.rb
diff options
context:
space:
mode:
authorAdam Panzer <apanzerj@gmail.com>2014-06-10 10:53:48 -0700
committerAdam Panzer <apanzerj@gmail.com>2014-06-10 10:53:48 -0700
commit9010274627a538c688e44737e7a50c659da7e863 (patch)
tree98e86aa8c8612b3b7ff3bd5bed47032b60f7ed7b /activesupport/lib/active_support/cache/file_store.rb
parent3681e1ac2c5448b9826f2e3c9b6508c50d2b4f17 (diff)
downloadrails-9010274627a538c688e44737e7a50c659da7e863.tar.gz
rails-9010274627a538c688e44737e7a50c659da7e863.tar.bz2
rails-9010274627a538c688e44737e7a50c659da7e863.zip
fix error with long keys in ActiveSupport::Cache::FileStore
Diffstat (limited to 'activesupport/lib/active_support/cache/file_store.rb')
-rw-r--r--activesupport/lib/active_support/cache/file_store.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb
index 8ed60aebac..d08ecd2f7d 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 = 228 # max filename size on file system is 255, minus room for timestamp and random characters appended by Tempfile (used by atomic write)
+ FILEPATH_MAX_SIZE = 900 # max is 1024, plus some room
EXCLUDED_DIRS = ['.', '..'].freeze
def initialize(cache_path, options = nil)
@@ -117,6 +118,10 @@ module ActiveSupport
# Translate a key into a file path.
def key_file_path(key)
+ if key.size > FILEPATH_MAX_SIZE
+ key = Digest::MD5.hexdigest(key)
+ end
+
fname = URI.encode_www_form_component(key)
hash = Zlib.adler32(fname)
hash, dir_1 = hash.divmod(0x1000)