Howdy, It looks like one of the recent updates to attachment_fu has changed the way it names/stores files in the filesystem. I''m guessing it was this one: * add default ID partitioning for attachments Anyway, my files used to be stored in directories named after the PK. Now it seems that things have changed and files are stored with a new scheme. So, anyone have any suggestions as to how I can migrate to the new storage setup? All the images in my app are broken. Thanks, Hunter --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 4/5/07, Hunter Hillegas <lists-HAWAbpnI61OZ1JSuHaJ1sQC/G2K4zDHf@public.gmane.org> wrote:> > Howdy, > > It looks like one of the recent updates to attachment_fu has changed > the way it names/stores files in the filesystem. I''m guessing it was > this one: > > * add default ID partitioning for attachments > > Anyway, my files used to be stored in directories named after the PK. > Now it seems that things have changed and files are stored with a new > scheme. > > So, anyone have any suggestions as to how I can migrate to the new > storage setup? All the images in my app are broken.Hah, sorry about that. If it makes you feel any better, I broke Lighthouse too :) For now, you can just hack your model like so: def partitioned_path(*args) [attachment_path_id] + args end I did a manual migration looping through all the records and moving them manually. This isn''t the exact code, but something like this should work. class Avatar def old_full_filename(thumbnail = nil) file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s File.join(RAILS_ROOT, file_system_path, attachment_path_id.to_s, thumbnail_name_for(thumbnail)) end Avatar.find(:all).each do |av| next unless File.exist?(av.old_full_filename) FileUtils.mkdir_p(File.dirname(av.full_filename)) File.move av.old_full_filename, av.full_filename end -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
lists-HAWAbpnI61OZ1JSuHaJ1sQC/G2K4zDHf@public.gmane.org
2007-Apr-09 23:08 UTC
Re: attachment_fu File System Storage Change - Update?
Rick, Thanks a ton for this. I just realized this response was sitting in my spam folder and I''ve since re-sent the question to the list so please ignore those. Whoops. This looks good - I will give it a go. Thanks again for this and the great plug-in! Hunter -----Original Message----- From: Rick Olson <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> Sent: Sat, April 7, 2007 10:45 pm To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails] Re: attachment_fu File System Storage Change - Update? On 4/5/07, Hunter Hillegas <lists-HAWAbpnI61OZ1JSuHaJ1sQC/G2K4zDHf@public.gmane.org> wrote:> > Howdy, > > It looks like one of the recent updates to attachment_fu has changed > the way it names/stores files in the filesystem. I''m guessing it was > this one: > > * add default ID partitioning for attachments > > Anyway, my files used to be stored in directories named after the PK. > Now it seems that things have changed and files are stored with a new > scheme. > > So, anyone have any suggestions as to how I can migrate to the new > storage setup? All the images in my app are broken.Hah, sorry about that. If it makes you feel any better, I broke Lighthouse too :) For now, you can just hack your model like so: def partitioned_path(*args) [attachment_path_id] + args end I did a manual migration looping through all the records and moving them manually. This isn''t the exact code, but something like this should work. class Avatar def old_full_filename(thumbnail = nil) file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s File.join(RAILS_ROOT, file_system_path, attachment_path_id.to_s, thumbnail_name_for(thumbnail)) end Avatar.find(:all).each do |av| next unless File.exist?(av.old_full_filename) FileUtils.mkdir_p(File.dirname(av.full_filename)) File.move av.old_full_filename, av.full_filename end -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Walter McGinnis
2007-Jun-18 03:33 UTC
Re: attachment_fu File System Storage Change - Update?
Unfortunately I had a lot of links pointing back at legacy paths. Here''s my middleground solution that I think allows me to move forward with the new scheme for paths while not having to move my old files: # workaround for legacy attachments def partitioned_path(*args) if LEGACY_IMAGE_FILE_PATHS_UP_TO.nil? or attachment_path_id.to_i > LEGACY_IMAGE_FILE_PATHS_UP_TO.to_i ("%08d" % attachment_path_id).scan(/..../) + args else [attachment_path_id.to_s] + args end end I''ve got about 10k existing image files with ids up to about 49081, since the new scheme starts creating directories at 0000, I doubt I''ll see any directory names that will collide. I must admit to being lazy in the math department. Am I missing anything? Cheers, Walter --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---