Rails 3 - File name too long error
Asked Answered
S

5

5

We have an online store running on Rails 3 Spree platform. Recently customers started reporting weird errors during checkout and after analyzing production logs I found the following error:

Errno::ENAMETOOLONG (File name too long - /var/www/store/tmp/cache/UPS-R43362140-US-NJ-FlorhamPark07932-1025786194_1%7C1025786087_1%7C1025786089_15%7C1025786146_4%7C1025786147_3%7C1025786098_3%7C1025786099_4%7C1025786100_2%7C1025786114_1%7C1025786120_1%7C1025786121_1%7C1025786181_1%7C1025786182_1%7C1025786208_120110412-2105-1e14pq5.lock)

I'm not sure why this file name is so long and if this error is specific to Rails or Spree. Also I'm not very familiar with Rails caching system. I would appreciate any help on how I can resolve this problem.

Suzansuzann answered 13/4, 2011 at 21:50 Comment(0)
C
5

I'm guessing you are using spree_active_shipping, as that looks like a cache id for a UPS shipping quote. This will happen when someone creates an order that has a lot of line items in it. With enough line items this will of course create a very large filename for the cache, thus giving you the error.

One option would be to use memcache or redis for your Rails.cache instead of using the filesystem cache. Another would be to modify the algorithm that generates the cache_key within app/models/active_shipping.rb in the spree_active_shipping gem.

The latter option would probably be best, and you could simply have the generated cache key run through a hash like MD5 or SHA1. This way you'll get predictable cache key lengths.

Really this should be fixed within spree_active_shipping though, it shouldn't be generating unpredictably long cache keys, even if you a key-value store is used, that's wasted memory.

Cytology answered 19/6, 2011 at 20:27 Comment(0)
C
3

It is more related to your file system. Either set up a file system which supports longer file names or change the software to make better (md5?timestamp?unique id?) file names.

Cudbear answered 13/4, 2011 at 21:55 Comment(0)
S
2

May be this help:

config.assets.digest and config.assets.debug can't both be true

It's a bug : https://github.com/rails/jquery-rails/issues/33

Suspensive answered 13/1, 2012 at 13:15 Comment(0)
N
0

I am using rails 3.2.x and having same issue. I end up generating MD5 digest in the view helper method used to generate cache key.

FILENAME_MAX_SIZE = 200    
def cache_key(prefix, params)
  params = Array.wrap(params) if params.instance_of?(String)
  key = "#{prefix}/" << params.entries.sort { |a,b| a[0].to_s <=> b[0].to_s }.map { |k,v| "#{k}:#{v}"}.join(',').to_s
  if URI.encode_www_form_component(key).size > FILENAME_MAX_SIZE
    key = Digest::MD5.hexdigest(key)
  end
  key
end

Here I have to check length of URI encoded key value using URI.encode_www_form_component(key).size because as you can see in my case, cache key is generated using : and , separators. Rails encodes the key before caching the results.

I took reference from the pull request.

Nogas answered 29/7, 2015 at 13:36 Comment(0)
W
0

Are you using paperclip gem? If yes, this issue is solved: https://github.com/thoughtbot/paperclip/issues/1246.

Please update your paperclip gem to the latest version.

Whitebook answered 13/10, 2015 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.