Skip to content
This repository
Browse code

Change FILENAME_MAX_SIZE in FileStore to 228.

In order that temp filenames generated from it will fit in 255 chars. See #4907
  • Loading branch information...
commit c33334fc921894ee035e79591732188a08b3eed9 1 parent af7daff
James Smith authored February 06, 2012
2  activesupport/lib/active_support/cache/file_store.rb
@@ -13,7 +13,7 @@ class FileStore < Store
13 13
       attr_reader :cache_path
14 14
 
15 15
       DIR_FORMATTER = "%03X"
16  
-      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)
  16
+      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)
17 17
       EXCLUDED_DIRS = ['.', '..'].freeze
18 18
 
19 19
       def initialize(cache_path, options = nil)
10  activesupport/test/caching_test.rb
@@ -575,6 +575,16 @@ def test_key_transformation_with_pathname
575 575
     assert_equal "views/index?id=1", @cache_with_pathname.send(:file_path_key, key)
576 576
   end
577 577
 
  578
+  # Test that generated cache keys are short enough to have Tempfile stuff added to them and 
  579
+  # remain valid
  580
+  def test_filename_max_size
  581
+    key = "#{'A' * ActiveSupport::Cache::FileStore::FILENAME_MAX_SIZE}"
  582
+    path = @cache.send(:key_file_path, key)
  583
+    Dir::Tmpname.create(path) do |tmpname, n, opts|
  584
+      assert (File.basename(tmpname+'.lock').length <= 255), "Temp filename too long: #{File.basename(tmpname+'.lock').length}"
  585
+    end
  586
+  end
  587
+
578 588
   # Because file systems have a maximum filename size, filenames > max size should be split in to directories
579 589
   # If filename is 'AAAAB', where max size is 4, the returned path should be AAAA/B
580 590
   def test_key_transformation_max_filename_size

0 notes on commit c33334f

Please sign in to comment.
Something went wrong with that request. Please try again.