Created
December 16, 2013 21:28
-
-
Save manleyhimself/7994763 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#source https://github.com/rails/rails/issues/10894 | |
module ActiveSupport | |
module Cache | |
class FileStore < Store | |
private | |
# Patch this so we don't have long paths | |
def key_file_path(key) | |
fname = URI.encode_www_form_component(key) | |
hash = Zlib.adler32(fname) | |
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 = fname[FILENAME_MAX_SIZE..-1] | |
end until fname.blank? | |
key = Digest::MD5.hexdigest(fname_paths.join()) | |
File.join(cache_path, DIR_FORMATTER % dir_1, DIR_FORMATTER % dir_2, key) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment