diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2011-09-22 10:03:54 -0700 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2011-09-22 10:03:54 -0700 |
commit | 855184c468aefac2540367cefce603e7d45a937b (patch) | |
tree | 80df612d8aabe1321230b92b82ab2669ab8a6f3d /activesupport/lib | |
parent | 43d27e9105b385f64ec195f60d10ab3d64281bd4 (diff) | |
parent | a0352a425f4995f7f1e1035290fe59c93ac0d24f (diff) | |
download | rails-855184c468aefac2540367cefce603e7d45a937b.tar.gz rails-855184c468aefac2540367cefce603e7d45a937b.tar.bz2 rails-855184c468aefac2540367cefce603e7d45a937b.zip |
Merge pull request #3096 from phuibonhoa/master
FileStore key_file_path does not properly limit filenames to 255 characters
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/cache/file_store.rb | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index f7c01948b4..ab2382d98c 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -13,6 +13,7 @@ module ActiveSupport attr_reader :cache_path 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) def initialize(cache_path, options = nil) super(options) @@ -129,15 +130,13 @@ module ActiveSupport hash, dir_1 = hash.divmod(0x1000) dir_2 = hash.modulo(0x1000) fname_paths = [] - # Make sure file name is < 255 characters so it doesn't exceed file system limits. - if fname.size <= 255 - fname_paths << fname - else - while fname.size <= 255 - fname_path << fname[0, 255] - fname = fname[255, -1] - end - end + + # Make sure file name doesn't exceed file system limits. + begin + fname_paths << fname[0...FILENAME_MAX_SIZE] + fname = fname[FILENAME_MAX_SIZE..-1] + end until fname.blank? + File.join(cache_path, DIR_FORMATTER % dir_1, DIR_FORMATTER % dir_2, *fname_paths) end |