mirror of
https://github.com/kemko/paperclip.git
synced 2026-01-01 16:05:40 +03:00
More flush and rewind
This commit is contained in:
@@ -317,11 +317,17 @@ module Paperclip
|
||||
new_original = Tempfile.new("paperclip-reprocess-#{instance.class.table_name}-#{instance.id}-")
|
||||
new_original.binmode
|
||||
old_original = to_file(:original)
|
||||
# по идее копирование нужно не всегда
|
||||
new_original.write( old_original.read )
|
||||
new_original.flush
|
||||
new_original.rewind
|
||||
@queued_for_write = { :original => new_original }
|
||||
post_process
|
||||
old_original.close if old_original.respond_to?(:close)
|
||||
if old_original.respond_to?(:close!)
|
||||
old_original.close!
|
||||
elsif old_original.respond_to?(:close)
|
||||
old_original.close
|
||||
end
|
||||
save
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ module Paperclip
|
||||
# генерим файл из оригинального
|
||||
source_style = options[:thumbnail] || :original
|
||||
# TODO: вообще queued_for_write[source_style] место в NoCacheS3#to_file
|
||||
f = attachment&.queued_for_write&.dig(source_style)&.tap(&:rewind)
|
||||
f = attachment&.queued_for_write&.dig(source_style)&.tap(&:flush)&.tap(&:rewind)
|
||||
# TODO: и надо сносить файл если все же была загрузка
|
||||
f ||= attachment.to_file(source_style) rescue file # rubocop:disable Style/RescueModifier
|
||||
super(f, options, attachment)
|
||||
|
||||
@@ -143,7 +143,7 @@ module Paperclip
|
||||
end
|
||||
# HACK: Iostream пишет в tempfile, и он нигде не закрывается. Будем закрывать хотя бы тут
|
||||
queued_for_write.each_value do |file|
|
||||
file.is_a?(Tempfile) && file.close!
|
||||
file.respond_to?(:close!) && file.close!
|
||||
end
|
||||
queued_for_write.clear
|
||||
end
|
||||
@@ -233,6 +233,7 @@ module Paperclip
|
||||
}.merge(self.class.upload_options)
|
||||
files.each do |style, file|
|
||||
path = key(style)
|
||||
file.flush
|
||||
file.rewind
|
||||
log "Saving to #{store_id}:#{path}"
|
||||
store.put_object(common_options.merge(key: path, body: file))
|
||||
|
||||
Reference in New Issue
Block a user