From 8d63678d1406c5518d437709af0fde717c0248d7 Mon Sep 17 00:00:00 2001 From: Philippe Huibonhoa Date: Wed, 21 Sep 2011 21:00:46 -0700 Subject: Fixed issue in file store where it could create a filename that was too long for the file system. (https://github.com/rails/rails/issues/3072) --- activesupport/lib/active_support/cache/file_store.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'activesupport/lib/active_support/cache/file_store.rb') 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 -- cgit v1.2.3 From 667ef57de641f4915f50d93f35756892151ee34b Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 22 Sep 2011 14:14:24 -0300 Subject: No need to create a range object --- activesupport/lib/active_support/cache/file_store.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support/cache/file_store.rb') diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index ab2382d98c..3f516d4808 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -130,13 +130,13 @@ module ActiveSupport hash, dir_1 = hash.divmod(0x1000) dir_2 = hash.modulo(0x1000) fname_paths = [] - + # Make sure file name doesn't exceed file system limits. begin - fname_paths << fname[0...FILENAME_MAX_SIZE] + 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 -- cgit v1.2.3 From 0baa8f8604e7766ce627120dfe572e09c247ef8c Mon Sep 17 00:00:00 2001 From: Philippe Huibonhoa Date: Thu, 29 Sep 2011 18:59:40 -0700 Subject: Added fix so that file store does not raise an exception when cache dir does not exist yet. This can happen if a delete_matched is called before anything is saved in the cache. --- activesupport/lib/active_support/cache/file_store.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/lib/active_support/cache/file_store.rb') diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index 3f516d4808..b431041b76 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -161,6 +161,7 @@ module ActiveSupport end def search_dir(dir, &callback) + return if !File.exist?(dir) Dir.foreach(dir) do |d| next if d == "." || d == ".." name = File.join(dir, d) -- cgit v1.2.3 From 7670a5187d2000a577c9aa982158808550033dfd Mon Sep 17 00:00:00 2001 From: kennyj Date: Sun, 30 Oct 2011 21:50:17 +0900 Subject: Refactor ActiveSupport::Cache::FileStore. used method and deleted duplicate code. --- activesupport/lib/active_support/cache/file_store.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support/cache/file_store.rb') 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) -- cgit v1.2.3 From e34e4d43301618307f94123d3710f094297f91f3 Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Fri, 11 Nov 2011 17:04:50 +0800 Subject: Fix "in memory" where it should be "in-memory". --- activesupport/lib/active_support/cache/file_store.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/cache/file_store.rb') diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index 85e7e21624..9460532af0 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -8,7 +8,7 @@ module ActiveSupport # A cache store implementation which stores everything on the filesystem. # # FileStore implements the Strategy::LocalCache strategy which implements - # an in memory cache inside of a block. + # an in-memory cache inside of a block. class FileStore < Store attr_reader :cache_path -- cgit v1.2.3 From 9fd0cd3a12f969ca0c5c7ce6163e9e451637506d Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 11 Nov 2011 17:12:42 +0530 Subject: Revert "Fix "in memory" where it should be "in-memory"." This reverts commit e34e4d43301618307f94123d3710f094297f91f3. Reason: code changes are not allowed in docrails. --- activesupport/lib/active_support/cache/file_store.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/cache/file_store.rb') diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index 9460532af0..85e7e21624 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -8,7 +8,7 @@ module ActiveSupport # A cache store implementation which stores everything on the filesystem. # # FileStore implements the Strategy::LocalCache strategy which implements - # an in-memory cache inside of a block. + # an in memory cache inside of a block. class FileStore < Store attr_reader :cache_path -- cgit v1.2.3 From a02b40a3d28c4b262dd49a8a6166c0275dfd9964 Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Sun, 13 Nov 2011 13:18:55 +0800 Subject: Fix "in memory" where it should be "in-memory". --- activesupport/lib/active_support/cache/file_store.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/cache/file_store.rb') diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index 85e7e21624..9460532af0 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -8,7 +8,7 @@ module ActiveSupport # A cache store implementation which stores everything on the filesystem. # # FileStore implements the Strategy::LocalCache strategy which implements - # an in memory cache inside of a block. + # an in-memory cache inside of a block. class FileStore < Store attr_reader :cache_path -- cgit v1.2.3