Frequent "No such file or directory" when saving files via "Clip"

I feel that this will end at the moment of facepalm, but I have been banging on her head for too long.

I have a Rails seed.rb file that retrieves all files from a specific directory, creating a new object for each file and saving the file through Paperclip:

Dir["./**/*.jpg"].each do |f|
  ...
  p = Picture.new
  File.open(f, 'r') { |photo_file| p.photo = photo_file }
  p.save!
  ....
end

where photois the attribute assigned using a paper clip (picture.rb):

has_attached_file :photo,
                  :styles => { :medium => "500x500>", :thumb => "100x100#" },
                  :processors => [:rotator]

My problem occurs after a certain number of files (several times 50, several times), the script exits with the following error:

No such file or directory - /var/folders/oD/oDq1WD11EEaXmfi8VfNvfE+++TM/-Tmp-/stream,22423,0,22423,0
/Users/patgeorge/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/fileutils.rb:1407:in `stat'
/Users/patgeorge/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/fileutils.rb:1407:in `block in fu_each_src_dest'
/Users/patgeorge/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/fileutils.rb:1423:in `fu_each_src_dest0'
/Users/patgeorge/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/fileutils.rb:1405:in `fu_each_src_dest'
/Users/patgeorge/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/fileutils.rb:504:in `mv'
/Users/patgeorge/.rvm/gems/ruby-1.9.2-head@rails3/bundler/gems/paperclip-61f74de14812cabc026967a2b2c3ca8cbd2eed69-master/lib/paperclip/storage.rb:42:in `block in flush_writes'

I thought that maybe I didn’t close the file, but according to Ruby IO docs , using the block from openwill close the file.

, , , . .

Ruby 1.9.2 r28142, Rails 3.0.0.beta4 Paperclip 2.3.3.

:

Winfield , :

Dir["./**/*.jpg"].each do |f|
  ...
  File.open(f, 'r') do |photo_file|
    p = Picture.new
    p.photo = photo_file
    p.save!
  end
  ...
end

.

:

, script, (12 ). , , , 2 . , , "reset" . , .

+3
2

, File, , paperclip.

File.open() , . , , , , p.save!

:

File.open(f, 'r') {|photo_file| Picture.create!(:photo => photo_file) }
+1

Source: https://habr.com/ru/post/1755058/


All Articles