Module: Paperclip::Storage::Filesystem

Defined in:
lib/polygallery/paperclip_integration.rb

Instance Method Summary collapse

Instance Method Details

#flush_deletesObject

:nodoc:



630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
# File 'lib/polygallery/paperclip_integration.rb', line 630

def flush_deletes #:nodoc:
  @queued_for_delete.each do |path|
    begin
      log("deleting #{path}")
      FileUtils.rm(path) if File.exist?(path)
    rescue Errno::ENOENT => e
      # ignore file-not-found, let everything else pass
    end
    begin
      while(true)
        path = File.dirname(path)
        FileUtils.rmdir(path)
        break if File.exist?(path) # Ruby 1.9.2 does not raise if the removal failed.
      end
    rescue Errno::EEXIST, Errno::ENOTEMPTY, Errno::ENOENT, Errno::EINVAL, Errno::ENOTDIR, Errno::EACCES
      # Stop trying to remove parent directories
    rescue SystemCallError => e
      log("There was an unexpected error while deleting directories: #{e.class}")
      # Ignore it
    end
  end
  @queued_for_delete = []
end

#flush_writesObject

:nodoc:



606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
# File 'lib/polygallery/paperclip_integration.rb', line 606

def flush_writes #:nodoc:
  @queued_for_write.each do |style_name, file|
    FileUtils.mkdir_p(File.dirname(path(style_name)))
    begin
      FileUtils.mv(file.path, path(style_name))
    rescue SystemCallError
      File.open(path(style_name), "wb") do |new_file|
        while chunk = file.read(16 * 1024)
          new_file.write(chunk)
        end
      end
    end
    unless @options[:override_file_permissions] == false
      resolved_chmod = (@options[:override_file_permissions] &~ 0111) || (0666 &~ File.umask)
      FileUtils.chmod( resolved_chmod, path(style_name) )
    end
    file.rewind
  end

  after_flush_writes # allows attachment to clean up temp files

  @queued_for_write = {}
end