Carrierwave trick to solve "Too many links"

31 Aug 2012

This is for solving the problem “Too many links” in Linux.

You know that you cannot have more than 32,000 files in a single folder. (Increasing the inode limit is also not a good choice.)

So, this is the simplest way to solve it:

If you are using Mongoid, then you can use part of the `id` to create subfolders like this:

class RoomPhotoUploader < CarrierWave::Uploader::Base def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id.to_s[-3..-1]}/#{model.id.to_s[-6..-4]}/#{model.id}" end end

Now you can have like 4096 * 4096 * 32000 images…

Give it a kudos